'use strict' /* global __, xhr, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { return new Promise((resolve, reject) => { const user_search = App.byId("user_search"); const search = user_search ? user_search.value : ""; xhr.post("backend.php", { op: "pref-users", sort: sort, search: search }, (reply) => { dijit.byId('usersTab').attr('content', reply); Notify.close(); resolve(); }, (e) => { reject(e) }); }); }, add: function() { const login = prompt(__("Please enter username:"), ""); if (login) { Notify.progress("Adding user..."); xhr.post("backend.php", {op: "pref-users", method: "add", login: login}, (reply) => { Users.reload().then(() => { Notify.info(reply); }) }); } }, edit: function(id) { xhr.json('backend.php', {op: 'pref-users', method: 'edit', id: id}, (reply) => { const user = reply.user; const admin_disabled = (user.id == 1); const dialog = new fox.SingleUseDialog({ id: "userEditDlg", title: __("Edit user"), execute: function () { if (this.validate()) { Notify.progress("Saving data...", true); xhr.post("backend.php", this.attr('value'), (reply) => { dialog.hide(); Users.reload().then(() => { Notify.info(reply); }); }); } }, content: `
` }); dialog.show(); }); }, resetSelected: function() { const rows = this.getSelection(); if (rows.length == 0) { alert(__("No users selected.")); return; } if (rows.length > 1) { alert(__("Please select one user.")); return; } if (confirm(__("Reset password of selected user?"))) { Notify.progress("Resetting password for selected user..."); const id = rows[0]; xhr.post("backend.php", {op: "pref-users", method: "resetPass", id: id}, (reply) => { Notify.close(); Notify.info(reply, true); }); } }, removeSelected: function() { const sel_rows = this.getSelection(); if (sel_rows.length > 0) { if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { Notify.progress("Removing selected users..."); const query = { op: "pref-users", method: "remove", ids: sel_rows.toString() }; xhr.post("backend.php", query, () => { this.reload(); }); } } else { alert(__("No users selected.")); } }, getSelection :function() { return Tables.getSelected("users-list"); } }