2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
2020-06-04 20:27:22 +00:00
|
|
|
|
2021-03-01 12:24:18 +00:00
|
|
|
/* global __, xhr, 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-03-01 12:24:18 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const user_search = App.byId("user_search");
|
|
|
|
const search = user_search ? user_search.value : "";
|
2020-06-04 17:04:17 +00:00
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", { op: "Pref_Users", sort: sort, search: search }, (reply) => {
|
2021-03-01 12:24:18 +00:00
|
|
|
dijit.byId('usersTab').attr('content', reply);
|
|
|
|
Notify.close();
|
|
|
|
resolve();
|
|
|
|
}, (e) => { reject(e) });
|
2020-06-04 17:04:17 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
add: function() {
|
|
|
|
const login = prompt(__("Please enter username:"), "");
|
|
|
|
|
|
|
|
if (login) {
|
|
|
|
Notify.progress("Adding user...");
|
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", {op: "Pref_Users", method: "add", login: login}, (reply) => {
|
2021-03-01 12:24:18 +00:00
|
|
|
Users.reload().then(() => {
|
|
|
|
Notify.info(reply);
|
|
|
|
})
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
|
2020-06-04 17:04:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
edit: function(id) {
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.json('backend.php', {op: 'Pref_Users', method: 'edit', id: id}, (reply) => {
|
2021-02-14 13:44:41 +00:00
|
|
|
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",
|
2021-03-03 11:10:18 +00:00
|
|
|
title: __("Edit user"),
|
2021-02-12 12:22:10 +00:00
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
Notify.progress("Saving data...", true);
|
2020-06-04 17:04:17 +00:00
|
|
|
|
2021-03-01 12:24:18 +00:00
|
|
|
xhr.post("backend.php", this.attr('value'), (reply) => {
|
2021-02-12 12:22:10 +00:00
|
|
|
dialog.hide();
|
2021-03-01 12:24:18 +00:00
|
|
|
Users.reload().then(() => {
|
|
|
|
Notify.info(reply);
|
|
|
|
});
|
2021-02-12 12:22:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
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())}
|
2023-10-25 09:55:09 +00:00
|
|
|
${App.FormFields.hidden_tag('op', 'Pref_Users')}
|
2021-02-17 16:34:54 +00:00
|
|
|
${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')}">
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
2021-03-02 10:27:41 +00:00
|
|
|
<hr/>
|
2021-02-14 13:44:41 +00:00
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label>${__('Access level: ')}</label>
|
|
|
|
${App.FormFields.select_hash("access_level",
|
2021-11-10 17:44:51 +00:00
|
|
|
user.access_level, reply.access_level_names, {disabled: admin_disabled.toString()}, "", {numeric_sort: true})}
|
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>
|
2021-03-02 10:27:41 +00:00
|
|
|
<fieldset>
|
|
|
|
<label></label>
|
|
|
|
<label class="checkbox">
|
|
|
|
${App.FormFields.checkbox_tag("otp_enabled", user.otp_enabled)}
|
|
|
|
${__('OTP enabled')}
|
|
|
|
</fieldset>
|
2021-02-14 13:44:41 +00:00
|
|
|
|
2021-03-02 10:27:41 +00:00
|
|
|
<hr/>
|
2021-02-14 13:44:41 +00:00
|
|
|
|
|
|
|
<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')) {
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", {op: 'Pref_Users', method: 'userdetails', id: ${user.id}}, (reply) => {
|
2021-02-19 10:44:56 +00:00
|
|
|
this.attr('content', reply);
|
2021-02-14 13:44:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
</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()'>
|
2021-03-05 12:16:41 +00:00
|
|
|
${App.FormFields.icon("save")}
|
2021-02-14 13:44:41 +00:00
|
|
|
${__('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
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", {op: "Pref_Users", method: "resetPass", id: id}, (reply) => {
|
2020-06-04 17:04:17 +00:00
|
|
|
Notify.close();
|
2021-02-19 10:44:56 +00:00
|
|
|
Notify.info(reply, true);
|
2020-06-04 17:04:17 +00:00
|
|
|
});
|
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 = {
|
2023-10-25 09:55:09 +00:00
|
|
|
op: "Pref_Users", method: "remove",
|
2020-06-04 17:04:17 +00:00
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-19 08:28:14 +00:00
|
|
|
xhr.post("backend.php", query, () => {
|
2020-06-04 17:04:17 +00:00
|
|
|
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
|
|
|
|