ttrss/js/PrefUsers.js

120 lines
2.6 KiB
JavaScript
Raw Normal View History

'use strict'
/* global __ */
/* global xhrPost, dojo, dijit, Notify, Tables */
2020-06-04 17:04:17 +00:00
const Users = {
reload: function(sort) {
const user_search = $("user_search");
const search = user_search ? user_search.value : "";
xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => {
dijit.byId('usersTab').attr('content', transport.responseText);
2020-06-04 17:04:17 +00:00
Notify.close();
});
},
add: function() {
const login = prompt(__("Please enter username:"), "");
if (login) {
Notify.progress("Adding user...");
xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => {
alert(transport.responseText);
Users.reload();
});
2020-06-04 17:04:17 +00:00
}
},
edit: function(id) {
const query = "backend.php?op=pref-users&method=edit&id=" +
encodeURIComponent(id);
if (dijit.byId("userEditDlg"))
dijit.byId("userEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "userEditDlg",
title: __("User Editor"),
execute: function () {
if (this.validate()) {
Notify.progress("Saving data...", true);
xhrPost("backend.php", dojo.formToObject("user_edit_form"), (/* transport */) => {
2020-06-04 17:04:17 +00:00
dialog.hide();
Users.reload();
});
}
},
href: query
});
dialog.show();
},
resetSelected: function() {
const rows = this.getSelection();
if (rows.length == 0) {
alert(__("No users selected."));
return;
}
2020-06-04 17:04:17 +00:00
if (rows.length > 1) {
alert(__("Please select one user."));
return;
}
2020-06-04 17:04:17 +00:00
if (confirm(__("Reset password of selected user?"))) {
Notify.progress("Resetting password for selected user...");
2020-06-04 17:04:17 +00:00
const id = rows[0];
2020-06-04 17:04:17 +00:00
xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => {
Notify.close();
Notify.info(transport.responseText, true);
});
2020-06-04 17:04:17 +00:00
}
},
removeSelected: function() {
const sel_rows = this.getSelection();
2020-06-04 17:04:17 +00:00
if (sel_rows.length > 0) {
if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) {
Notify.progress("Removing selected users...");
2020-06-04 17:04:17 +00:00
const query = {
op: "pref-users", method: "remove",
ids: sel_rows.toString()
};
2020-06-04 17:04:17 +00:00
xhrPost("backend.php", query, () => {
this.reload();
});
}
2020-06-04 17:04:17 +00:00
} else {
alert(__("No users selected."));
}
},
editSelected: function() {
const rows = this.getSelection();
2020-06-04 17:04:17 +00:00
if (rows.length == 0) {
alert(__("No users selected."));
return;
}
2020-06-04 17:04:17 +00:00
if (rows.length > 1) {
alert(__("Please select one user."));
return;
}
2020-06-04 17:04:17 +00:00
this.edit(rows[0]);
},
getSelection :function() {
2021-02-06 13:24:40 +00:00
return Tables.getSelected("users-list");
2020-06-04 17:04:17 +00:00
}
}