ttrss/js/PrefUsers.js

183 lines
5.1 KiB
JavaScript
Raw Normal View History

'use strict'
/* global __, xhr, dijit, Notify, Tables, App, fox */
2020-06-04 17:04:17 +00:00
const Users = {
reload: function(sort) {
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) => {
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) => {
Users.reload().then(() => {
Notify.info(reply);
})
});
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;
const admin_disabled = (user.id == 1);
2021-02-14 13:44:41 +00:00
const dialog = new fox.SingleUseDialog({
id: "userEditDlg",
title: __("Edit user"),
execute: function () {
if (this.validate()) {
Notify.progress("Saving data...", true);
2020-06-04 17:04:17 +00:00
xhr.post("backend.php", this.attr('value'), (reply) => {
dialog.hide();
Users.reload().then(() => {
Notify.info(reply);
});
});
}
},
2021-02-14 13:44:41 +00:00
content: `
<form onsubmit='return false'>
${App.FormFields.hidden_tag('id', user.id.toString())}
2023-10-25 09:55:09 +00:00
${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')}">
<section>
<fieldset>
<label>${__("Login:")}</label>
<input style='font-size : 16px'
${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)}">
${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",
user.access_level, reply.access_level_names, {disabled: admin_disabled.toString()}, "", {numeric_sort: true})}
2021-02-14 13:44:41 +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) => {
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>
`
});
2020-06-04 17:04:17 +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;
}
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];
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();
Notify.info(reply, true);
2020-06-04 17:04:17 +00:00
});
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 = {
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()
};
2021-02-19 08:28:14 +00:00
xhr.post("backend.php", query, () => {
2020-06-04 17:04:17 +00:00
this.reload();
});
}
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
}
}