'use strict' /* global __ */ /* global xhrPost, xhrJson, dojo, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { const user_search = App.byId("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); 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(); }); } }, edit: function(id) { xhrJson('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: __("User Editor"), execute: function () { if (this.validate()) { Notify.progress("Saving data...", true); xhrPost("backend.php", this.attr('value'), () => { dialog.hide(); Users.reload(); }); } }, content: `
${App.FormFields.hidden_tag('id', user.id.toString())} ${App.FormFields.hidden_tag('op', 'pref-users')} ${App.FormFields.hidden_tag('method', 'editSave')}
${__("User")}
${admin_disabled ? App.FormFields.hidden_tag("login", user.login) : ''}
${__("Authentication")}
${App.FormFields.select_hash("access_level", user.access_level, reply.access_level_names, {disabled: admin_disabled.toString()})} ${admin_disabled ? App.FormFields.hidden_tag("access_level", user.access_level.toString()) : ''}
${__("Options")}
${__("Loading, please wait...")}
` }); 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]; xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { Notify.close(); Notify.info(transport.responseText, 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() }; xhrPost("backend.php", query, () => { this.reload(); }); } } else { alert(__("No users selected.")); } }, getSelection :function() { return Tables.getSelected("users-list"); } }