2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
2020-06-04 20:27:22 +00:00
|
|
|
|
|
|
|
/* global __ */
|
2021-02-14 13:44:41 +00:00
|
|
|
/* global xhrPost, xhrJson, dojo, dijit, Notify, Tables, App, fox */
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
const Users = {
|
|
|
|
reload: function(sort) {
|
2021-02-18 18:51:18 +00:00
|
|
|
const user_search = App.byId("user_search");
|
2020-06-04 17:04:17 +00:00
|
|
|
const search = user_search ? user_search.value : "";
|
|
|
|
|
|
|
|
xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => {
|
2021-02-11 12:49:32 +00:00
|
|
|
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();
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
edit: function(id) {
|
2021-02-14 13:44:41 +00:00
|
|
|
xhrJson('backend.php', {op: 'pref-users', method: 'edit', id: id}, (reply) => {
|
|
|
|
const user = reply.user;
|
2021-02-17 16:34:54 +00:00
|
|
|
const admin_disabled = (user.id == 1);
|
2021-02-14 13:44:41 +00:00
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
|
|
|
id: "userEditDlg",
|
|
|
|
title: __("User Editor"),
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
Notify.progress("Saving data...", true);
|
2020-06-04 17:04:17 +00:00
|
|
|
|
2021-02-14 13:44:41 +00:00
|
|
|
xhrPost("backend.php", this.attr('value'), () => {
|
2021-02-12 12:22:10 +00:00
|
|
|
dialog.hide();
|
|
|
|
Users.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-02-14 13:44:41 +00:00
|
|
|
content: `
|
|
|
|
<form onsubmit='return false'>
|
|
|
|
|
2021-02-17 16:34:54 +00:00
|
|
|
${App.FormFields.hidden_tag('id', user.id.toString())}
|
|
|
|
${App.FormFields.hidden_tag('op', 'pref-users')}
|
|
|
|
${App.FormFields.hidden_tag('method', 'editSave')}
|
2021-02-14 13:44:41 +00:00
|
|
|
|
|
|
|
<div dojoType="dijit.layout.TabContainer" style="height : 400px">
|
|
|
|
<div dojoType="dijit.layout.ContentPane" title="${__('Edit user')}">
|
|
|
|
|
|
|
|
<header>${__("User")}</header>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<fieldset>
|
|
|
|
<label>${__("Login:")}</label>
|
|
|
|
<input style='font-size : 16px'
|
2021-02-17 16:34:54 +00:00
|
|
|
${admin_disabled ? "disabled='1'" : ''}
|
2021-02-14 13:44:41 +00:00
|
|
|
dojoType='dijit.form.ValidationTextBox' required='1'
|
|
|
|
name='login' value="${App.escapeHtml(user.login)}">
|
|
|
|
|
2021-02-17 16:34:54 +00:00
|
|
|
${admin_disabled ? App.FormFields.hidden_tag("login", user.login) : ''}
|
2021-02-14 13:44:41 +00:00
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<header>${__("Authentication")}</header>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<fieldset>
|
|
|
|
<label>${__('Access level: ')}</label>
|
|
|
|
${App.FormFields.select_hash("access_level",
|
2021-02-17 16:34:54 +00:00
|
|
|
user.access_level, reply.access_level_names, {disabled: admin_disabled.toString()})}
|
2021-02-14 13:44:41 +00:00
|
|
|
|
2021-02-17 16:34:54 +00:00
|
|
|
${admin_disabled ? App.FormFields.hidden_tag("access_level",
|
2021-02-14 13:44:41 +00:00
|
|
|
user.access_level.toString()) : ''}
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
|
|
<label>${__("New password:")}</label>
|
|
|
|
<input dojoType='dijit.form.TextBox' type='password' size='20'
|
|
|
|
placeholder='${__("Change password")}' name='password'>
|
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<header>${__("Options")}</header>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<fieldset>
|
|
|
|
<label>${__("E-mail:")}</label>
|
|
|
|
<input dojoType='dijit.form.TextBox' size='30' name='email'
|
|
|
|
value="${App.escapeHtml(user.email)}">
|
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
<div dojoType="dijit.layout.ContentPane" title="${__('User details')}">
|
|
|
|
<script type='dojo/method' event='onShow' args='evt'>
|
|
|
|
if (this.domNode.querySelector('.loading')) {
|
|
|
|
xhrPost("backend.php", {op: 'pref-users', method: 'userdetails', id: ${user.id}}, (transport) => {
|
|
|
|
this.attr('content', transport.responseText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<span class='loading'>${__("Loading, please wait...")}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<footer>
|
|
|
|
<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>
|
|
|
|
${__('Save')}
|
|
|
|
</button>
|
|
|
|
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>
|
|
|
|
${__('Cancel')}
|
|
|
|
</button>
|
|
|
|
</footer>
|
|
|
|
</form>
|
|
|
|
`
|
2021-02-12 12:22:10 +00:00
|
|
|
});
|
2020-06-04 17:04:17 +00:00
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
dialog.show();
|
2020-06-04 17:04:17 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
resetSelected: function() {
|
|
|
|
const rows = this.getSelection();
|
|
|
|
|
|
|
|
if (rows.length == 0) {
|
|
|
|
alert(__("No users selected."));
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
if (rows.length > 1) {
|
|
|
|
alert(__("Please select one user."));
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
if (confirm(__("Reset password of selected user?"))) {
|
|
|
|
Notify.progress("Resetting password for selected user...");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
const id = rows[0];
|
2018-12-02 14:00:58 +00:00
|
|
|
|
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);
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
removeSelected: function() {
|
|
|
|
const sel_rows = this.getSelection();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
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...");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
const query = {
|
|
|
|
op: "pref-users", method: "remove",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
xhrPost("backend.php", query, () => {
|
|
|
|
this.reload();
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
} else {
|
|
|
|
alert(__("No users selected."));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getSelection :function() {
|
2021-02-06 13:24:40 +00:00
|
|
|
return Tables.getSelected("users-list");
|
2020-06-04 17:04:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|