mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
related to #2158 update user and guest pop in
- Implementation of a new modal for modifying a user or guest - Addition of a function to allow plugins to add a tab to the new user modal - Fix bug: "badger-number" is updated when a user is added or deleted - Fix bug: When the user who is editing has permissions to delete the user he is modifying, the delete icon is now displayed correctly - Added a new api method for modifying the main user and generating a link to reset a password - Passed $conf[‘webmaster_id’] in database configuration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const color_icons = ["icon-red", "icon-blue", "icon-yellow", "icon-purple", "icon-green"];
|
||||
const status_arr = ['webmaster', 'admin', 'normal', 'generic', 'guest'];
|
||||
const level_arr = ['0', '1', '2', '4', '8'];
|
||||
const king_template = '<span class="icon-king" id="the_king"></span>';
|
||||
let current_users = [];
|
||||
let guest_id = 0;
|
||||
let guest_user = {};
|
||||
@@ -16,6 +17,11 @@ let selection = [];
|
||||
let first_update = true;
|
||||
let total_users = 0
|
||||
let filter_by = 'id DESC';
|
||||
let plugins_set_functions = {};
|
||||
let plugins_get_functions = {};
|
||||
let plugins_load = [];
|
||||
let plugins_users_infos_table = [];
|
||||
let owner_username = '';
|
||||
/*----------------
|
||||
Escape of pop-in
|
||||
----------------*/
|
||||
@@ -23,7 +29,8 @@ Escape of pop-in
|
||||
//get out of pop in via escape key
|
||||
$(document).on('keydown', function (e) {
|
||||
if ( e.keyCode === 27) { // ESC button
|
||||
$("#UserList").fadeOut();
|
||||
hide_modals();
|
||||
close_user_list();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -59,6 +66,7 @@ function open_user_list() {
|
||||
|
||||
function close_user_list() {
|
||||
hide_temporary_messages();
|
||||
$('#result_send_mail_copy_input').val('');
|
||||
$("#UserList").fadeOut();
|
||||
}
|
||||
|
||||
@@ -77,7 +85,6 @@ function isSelectionMode() {
|
||||
return $("#toggleSelectionMode").is(":checked")
|
||||
}
|
||||
|
||||
|
||||
$( document ).ready(function() {
|
||||
$(".user-property-register").tipTip({
|
||||
maxWidth: "300px",
|
||||
@@ -92,25 +99,42 @@ $( document ).ready(function() {
|
||||
fadeOut: 200
|
||||
});
|
||||
$(".advanced-filter-level select option").eq(1).remove();
|
||||
$('.edit-password').click(function () {
|
||||
$('.user-property-password').hide();
|
||||
$('.user-property-password-change').show().css('display', 'flex');
|
||||
|
||||
/* Edit Password */
|
||||
$('.button-edit-password-icon').click(function () {
|
||||
reset_password_modals();
|
||||
$('.user-property-password-change').fadeIn();
|
||||
})
|
||||
|
||||
$('.edit-password-cancel').click(function () {
|
||||
//possibly reset input value
|
||||
$('.user-property-password').show();
|
||||
$('.user-property-password-change').hide();
|
||||
$('.user-property-password-change').fadeOut();
|
||||
reset_input_password();
|
||||
})
|
||||
|
||||
$('.icon-show-password').on('click', function() {
|
||||
const icon = $(this);
|
||||
const closestInput = icon.siblings();
|
||||
if (closestInput.attr('type') === 'password') {
|
||||
closestInput.attr('type', 'text');
|
||||
icon.removeClass('icon-eye').addClass('icon-eye-off');
|
||||
} else {
|
||||
closestInput.attr('type', 'password');
|
||||
icon.removeClass('icon-eye-off').addClass('icon-eye');
|
||||
}
|
||||
});
|
||||
|
||||
// Password input onkeyup clear error
|
||||
$('#edit_user_password, #edit_user_conf_password').on('keyup', function() {
|
||||
hide_error_edit_user();
|
||||
});
|
||||
|
||||
/* Edit Username */
|
||||
$('.edit-username').click(function () {
|
||||
$('.user-property-username').hide();
|
||||
$('.user-property-username-change').show().css('display', 'flex');
|
||||
$('.user-property-username-change').show();
|
||||
})
|
||||
|
||||
$('.edit-username-cancel').click(function () {
|
||||
//possibly reset input value
|
||||
$('.user-property-username').show();
|
||||
$('.user-property-username-change').hide();
|
||||
})
|
||||
|
||||
@@ -156,7 +180,16 @@ $( document ).ready(function() {
|
||||
$(this).siblings().attr("data-selected", "0");
|
||||
}
|
||||
})
|
||||
$(".AddUserGenPassword").click(gen_password);
|
||||
$(".AddUserGenPassword").on('click', function() {
|
||||
const password = gen_password();
|
||||
$("#AddUserPassword").val(password);
|
||||
});
|
||||
$('.EditUserGenPassword').on('click', function() {
|
||||
const password = gen_password();
|
||||
$('#edit_user_password').val(password);
|
||||
$('#edit_user_conf_password').val(password);
|
||||
hide_error_edit_user();
|
||||
});
|
||||
$('.AddUserSubmit').click(add_user);
|
||||
$('.AddUserCancel').click(add_user_close);
|
||||
$(".CloseAddUser").click(add_user_close);
|
||||
@@ -349,6 +382,49 @@ $( document ).ready(function() {
|
||||
}
|
||||
update_user_list();
|
||||
});
|
||||
|
||||
/* tabsheet pop in user */
|
||||
editTabsBind();
|
||||
|
||||
$('.edit-user-slides').on('scroll', function() {
|
||||
const slides = $('.edit-user-slides').children();
|
||||
const rectView = this.getBoundingClientRect();
|
||||
$('.edit-user-tabsheet').removeClass('selected');
|
||||
// for debug
|
||||
// console.log('RECT REFERENCES left / right', rectView.left.toFixed(0), ' / ', rectView.right.toFixed(0));
|
||||
|
||||
slides.each(function() {
|
||||
const rect = this.getBoundingClientRect();
|
||||
// for debug
|
||||
// console.log('rect',$(this).attr('id'), ' left / right : ', rect.left, ' / ', rect.right);
|
||||
if (+rect.left.toFixed(0) >= +rectView.left.toFixed(0) - 1 && +rect.right.toFixed(0) <= +rectView.right.toFixed(0) + 1) {
|
||||
const tabId = $(this).attr('id');
|
||||
$('#name_' + tabId).addClass('selected');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/* tabsheet pop in guest */
|
||||
$('.guest-edit-user-tabsheet').off('click').on('click', function() {
|
||||
const tabName = $(this).attr('id').split('_');
|
||||
const tabId = tabName[1] + '_' + tabName[2] + '_' + tabName[3];
|
||||
$('#' + tabId)[0].scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
$('.guest-edit-user-slides').on('scroll', function() {
|
||||
const slides = $('.guest-edit-user-slides').children();
|
||||
const rectView = this.getBoundingClientRect();
|
||||
$('.guest-edit-user-tabsheet').removeClass('selected');
|
||||
slides.each(function() {
|
||||
const rect = this.getBoundingClientRect();
|
||||
if (+rect.left.toFixed(0) >= +rectView.left.toFixed(0) - 1 && +rect.right.toFixed(0) <= +rectView.right.toFixed(0) + 1) {
|
||||
const tabId = $(this).attr('id');
|
||||
$('#name_' + tabId).addClass('selected');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
function set_view_selector(view_type) {
|
||||
@@ -722,9 +798,7 @@ function setupRegisterDates(register_dates) {
|
||||
Add User
|
||||
------------------*/
|
||||
|
||||
function gen_password(e) {
|
||||
e.preventDefault();
|
||||
|
||||
function gen_password() {
|
||||
var characterSet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789';
|
||||
|
||||
var i;
|
||||
@@ -736,7 +810,7 @@ function gen_password(e) {
|
||||
password += characterSet.charAt(Math.floor(Math.random() * characterSet.length));
|
||||
}
|
||||
|
||||
jQuery("#AddUserPassword").val(password);
|
||||
return password;
|
||||
}
|
||||
|
||||
function add_user_close() {
|
||||
@@ -931,6 +1005,260 @@ function get_container_index_from_uid(uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
function hide_error_edit_user() {
|
||||
$('#UserList .EditUserErrors').animate({opacity: 0}, 100);
|
||||
}
|
||||
|
||||
function show_error_edit_user() {
|
||||
$('#UserList .EditUserErrors').animate({opacity: 1}, 300);
|
||||
}
|
||||
|
||||
function reset_input_password() {
|
||||
$('#edit_user_password, #edit_user_conf_password').val('');
|
||||
}
|
||||
|
||||
function editTabsBind () {
|
||||
$('.edit-user-tabsheet').off('click').on('click', function() {
|
||||
const tabName = $(this).attr('id').split('_');
|
||||
const tabId = tabName[1] + '_' + tabName[2];
|
||||
|
||||
$('#' + tabId)[0].scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function check_tabs (title_tab_name_id) {
|
||||
if (plugins_load.length > 2) {
|
||||
$('.edit-user-tab-title').css({gap : '0px', justifyContent: 'space-between'});
|
||||
const countMoresPlugins = plugins_load.length - 2;
|
||||
if (!document.getElementById('mores_plugins_expand')) {
|
||||
$('.edit-user-tab-title').append(
|
||||
'<span class="close mores-plugins" id="mores_plugins_expand"></span>' +
|
||||
'<div class="dropdown-mores-plugins" id="dropdown_mores_plugins"></div>'
|
||||
);
|
||||
}
|
||||
$('#mores_plugins_expand').html('+' + countMoresPlugins);
|
||||
|
||||
const dropdown = $('#dropdown_mores_plugins');
|
||||
const tabsheetTitle = $('#' + title_tab_name_id);
|
||||
$('.edit-user-tab-title').css('margin-top', '3px');
|
||||
$('.edit-user-tab-title p:lt(4)').css('padding-top', '5px');
|
||||
tabsheetTitle.css({'max-width': '100%'});
|
||||
tabsheetTitle.appendTo(dropdown);
|
||||
|
||||
if (1 === countMoresPlugins) {
|
||||
tabsheetTitle.css('border-radius', '10px');
|
||||
} else {
|
||||
dropdown.children().css('border-radius', '0');
|
||||
dropdown.children().first().css('border-radius', '10px 10px 0 0');
|
||||
dropdown.children().last().css('border-radius', '0 0 10px 10px');
|
||||
}
|
||||
|
||||
$('#mores_plugins_expand').off('click').on('click', function () {
|
||||
const icon = $(this);
|
||||
if(icon.hasClass('open')) {
|
||||
icon.removeClass('open').addClass('close');
|
||||
dropdown.fadeOut();
|
||||
} else {
|
||||
icon.removeClass('close').addClass('open');
|
||||
dropdown.fadeIn();
|
||||
$(window).off('click.hideUsersModal').on('click.hideUsersModal', function(e) {
|
||||
if (!$(e.target).closest('#dropdown_mores_plugins').length && !$(e.target).is('#mores_plugins_expand')) {
|
||||
$('#dropdown_mores_plugins').fadeOut();
|
||||
icon.removeClass('open').addClass('close');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new tab to the user's modal
|
||||
* @param {string} tab_name - The tab name (will also be used for the new tab id)
|
||||
* @param {string} content_id - The id of the HTML element
|
||||
* @param {string | null} users_table - The name of the column created in the users table (must be null if the set_data_function and get_data_function functions are used)
|
||||
* @param {() => {} | null} set_data_function - API call set function with ajax (must be null if users_table is used)
|
||||
* @param {() => {} | null} get_data_function - API call get function with ajax (must be null if users_table is used)
|
||||
* @returns {void} Displays the new tab in the user's modal
|
||||
*/
|
||||
function plugin_add_tab_in_user_modal(tab_name, content_id, users_table=null, set_data_function=null, get_data_function=null) {
|
||||
// verification
|
||||
if (typeof tab_name !== 'string') {
|
||||
throw new TypeError('tab_name must be a string.');
|
||||
}
|
||||
const name = tab_name.replace(/ /g, '').toLowerCase();
|
||||
if (document.getElementById('name_tab_' + name)) {
|
||||
throw new TypeError('An element with this tab_name already exists.');
|
||||
}
|
||||
|
||||
if (typeof content_id !== 'string') {
|
||||
throw new TypeError('content_id must be a string.');
|
||||
} else if (!document.getElementById(content_id)) {
|
||||
throw new TypeError('HTML element "' + content_id + '" not found.');
|
||||
} else if (document.querySelector('.edit-user-slides #' + content_id)) {
|
||||
throw new TypeError('An element with this content_id already exists.');
|
||||
}
|
||||
|
||||
if (users_table && typeof users_table !== 'string') {
|
||||
throw new TypeError('users_table must be a string.');
|
||||
}
|
||||
if (users_table && (set_data_function || get_data_function)) {
|
||||
throw new TypeError('users_table must be null if set_data_function or get_data_function is used.');
|
||||
}
|
||||
|
||||
if (set_data_function && typeof set_data_function !== 'function') {
|
||||
throw new TypeError('set_data_function must be a function.');
|
||||
} else if (set_data_function && typeof set_data_function === 'function') {
|
||||
plugins_set_functions[name + '_set_function'] = set_data_function;
|
||||
}
|
||||
|
||||
if (get_data_function && typeof get_data_function !== 'function') {
|
||||
throw new TypeError('get_data_function must be a function.');
|
||||
} else if (get_data_function && typeof get_data_function === 'function') {
|
||||
plugins_get_functions[name + '_get_function'] = get_data_function;
|
||||
}
|
||||
|
||||
if (users_table) {
|
||||
plugins_users_infos_table.push({content_id, users_table});
|
||||
}
|
||||
|
||||
// DOM modification
|
||||
const content = $('#' + content_id);
|
||||
|
||||
$('.edit-user-tab-title').append(
|
||||
'<p class="edit-user-tabsheet" id="name_tab_' + name + '" title="'+ tab_name +'">'+ tab_name +'</p>'
|
||||
);
|
||||
|
||||
$('.edit-user-slides').append(
|
||||
'<div class="edit-user-tabsheet-plugins '+ name +'-container" id="tab_'+ name +'"></div>'
|
||||
);
|
||||
|
||||
content.appendTo('#tab_' + name);
|
||||
content.show();
|
||||
|
||||
editTabsBind();
|
||||
|
||||
$('.edit-user-tabsheet').addClass('tab-with-plugin');
|
||||
|
||||
plugins_load.push('name_tab_' + name);
|
||||
check_tabs('name_tab_' + name);
|
||||
|
||||
if (plugins_load.length <= 2) {
|
||||
$('#name_tab_' + name).tipTip({
|
||||
delay: 0,
|
||||
fadeIn: 200,
|
||||
fadeOut: 200,
|
||||
edgeOffset: 3
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reset_password_modals() {
|
||||
$('.user-property-password-change').hide();
|
||||
$('.user-property-password-change-inputs').hide();
|
||||
$('#edit_password_success_change').hide();
|
||||
$('#edit_password_result_mail').hide();
|
||||
$('#edit_password_result_mail_copy').hide();
|
||||
$('.user-property-password-choice').show();
|
||||
}
|
||||
|
||||
function reset_username_modals() {
|
||||
$('.edit-username-success').hide();
|
||||
$('.user-property-username-change-input').show();
|
||||
}
|
||||
|
||||
function reset_main_user_modals() {
|
||||
$('#main_user_rewrite').val('');
|
||||
$('#main_user_rewrite_icon').removeClass('icon-ok icon-green icon-cancel icon-red');
|
||||
$('.main-user-rewrite').hide();
|
||||
$('.main-user-validate').hide();
|
||||
$('.main-user-success').hide();
|
||||
$('.main-user-proceed').show();
|
||||
}
|
||||
|
||||
function hide_modals() {
|
||||
$('.user-property-username-change').hide();
|
||||
$('.user-property-password-change').hide();
|
||||
$('.user-property-main-user-change').hide();
|
||||
reset_password_modals();
|
||||
reset_username_modals();
|
||||
reset_main_user_modals();
|
||||
}
|
||||
|
||||
function display_long_string(username) {
|
||||
const formatedUsername = username.length > 20 ? username.slice(0, 17) + '...' : username;
|
||||
return formatedUsername;
|
||||
}
|
||||
|
||||
function generate_random_string() {
|
||||
const string = 'abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let result = '';
|
||||
let c = 5;
|
||||
for (let i = 0; i < c; i++) {
|
||||
result += string.charAt(Math.floor(Math.random() * string.length));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ---------------
|
||||
Who is the king functions (main user)
|
||||
----------------*/
|
||||
function open_main_user_modal(user_to_edit) {
|
||||
const modal = $('.user-property-main-user-change');
|
||||
reset_main_user_modals();
|
||||
$('.main-user-proceed-desc').html(sprintf(mainUserContinue, `<b>${display_long_string(user_to_edit.username)}</b>`, `<b>${display_long_string(owner_username)}</b>`));
|
||||
modal.fadeIn();
|
||||
|
||||
// set event
|
||||
$('.main-user-btn-proceed').off('click').on('click', function() {
|
||||
const gen_string = generate_random_string();
|
||||
$('.main-user-rewrite-desc').html(sprintf(mainUserRewrite, `<b>${gen_string}</b>`) + ' :');
|
||||
$('.main-user-proceed').hide();
|
||||
$('.main-user-rewrite').fadeIn();
|
||||
event_check_string_main_user(user_to_edit.username, user_to_edit.id, gen_string);
|
||||
});
|
||||
|
||||
$('.user-property-main-user-cancel, #main_user_success_close').off('click').on('click', function() {
|
||||
modal.fadeOut();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function set_main_user_success() {
|
||||
const indexKey = current_users.findIndex(u => u.id === owner_id);
|
||||
const new_main = $('.user-container[key="' + indexKey + '"]').find('.user-container-username');
|
||||
let king = $('#the_king');
|
||||
if (!king.length) {
|
||||
king = $(king_template);
|
||||
}
|
||||
king.appendTo(new_main);
|
||||
$('.main-user-validate').hide();
|
||||
$('.main-user-success').fadeIn();
|
||||
}
|
||||
|
||||
function event_check_string_main_user(new_main_username, new_main_id, stringToCheck) {
|
||||
const icon = $('#main_user_rewrite_icon');
|
||||
$('#main_user_rewrite').off('keyup').on('keyup', function() {
|
||||
icon.removeClass('icon-ok icon-green').addClass('icon-cancel icon-red');
|
||||
if (stringToCheck === $(this).val()) {
|
||||
icon.removeClass('icon-cancel icon-red').addClass('icon-ok icon-green');
|
||||
$('.main-user-validate-desc').html(sprintf(mainUserValidate, `<b>${display_long_string(owner_username)}</b>`, `<b>${display_long_string(new_main_username)}</b>`));
|
||||
$('.main-user-success-desc').html(sprintf(mainUserSuccess, display_long_string(new_main_username)));
|
||||
$('.main-user-rewrite').hide();
|
||||
$('.main-user-validate').fadeIn();
|
||||
event_validate_main_user(new_main_username, new_main_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function event_validate_main_user(new_main_username, user_id) {
|
||||
$('.main-user-btn-validate').off('click').on('click', function() {
|
||||
set_main_user(user_id, new_main_username);
|
||||
});
|
||||
}
|
||||
|
||||
/*-----------------------
|
||||
Generate User Containers
|
||||
-----------------------*/
|
||||
@@ -1006,6 +1334,9 @@ function fill_container_user_info(container, user_index) {
|
||||
let registration_dates = user.registration_date.split(' ');
|
||||
container.attr('key', user_index);
|
||||
container.find(".user-container-username span").html(user.username);
|
||||
if(user.id === owner_id) {
|
||||
container.find(".user-container-username").append(king_template);
|
||||
}
|
||||
container.find(".user-container-initials span").html(get_initials(user.username)).addClass(color_icons[user.id % 5]);
|
||||
container.find(".user-container-status span").html(status_to_str[user.status]);
|
||||
container.find(".user-container-email span").html(user.email);
|
||||
@@ -1027,6 +1358,9 @@ function generate_user_list() {
|
||||
$(".user-container").click(user_container_click);
|
||||
}
|
||||
|
||||
function copyToClipboard(toCopy) {
|
||||
navigator.clipboard.writeText(toCopy);
|
||||
}
|
||||
/*---------------------
|
||||
Fill the pop-in values
|
||||
---------------------*/
|
||||
@@ -1083,11 +1417,26 @@ function fill_user_edit_summary(user_to_edit, pop_in, isGuest) {
|
||||
pop_in.find('.user-property-username-change input').val(user_to_edit.username);
|
||||
pop_in.find('.user-property-password-change input').val('');
|
||||
pop_in.find('.user-property-permissions a').attr('href', `admin.php?page=user_perm&user_id=${user_to_edit.id}`);
|
||||
pop_in.find('.user-property-register').html(get_formatted_date(user_to_edit.registration_date));
|
||||
pop_in.find('.user-property-register').html(user_to_edit.registration_date_string);
|
||||
pop_in.find('.user-property-register').tipTip({content:`${registered_str}<br />${user_to_edit.registration_date_since}`});
|
||||
pop_in.find('.user-property-last-visit').html(get_formatted_date(user_to_edit.last_visit));
|
||||
pop_in.find('.user-property-last-visit').html(user_to_edit.last_visit_string);
|
||||
pop_in.find('.user-property-last-visit').tipTip({content: `${last_visit_str}<br />${user_to_edit.last_visit_since}`});
|
||||
pop_in.find('.user-property-history a').attr('href', history_base_url + user_to_edit.id);
|
||||
|
||||
// Hide the copy password button and change modal copy password
|
||||
// if you are not using https
|
||||
if(!window.isSecureContext) {
|
||||
$('#copy_password').hide();
|
||||
$('.update-password-success').css('margin', '40px 0');
|
||||
$('#result_send_mail_copy').hide();
|
||||
$('#result_send_mail_copy_btn')
|
||||
.css({'cursor': 'not-allowed', 'background-color' : 'grey', 'color': '#ffffff'})
|
||||
.attr('title', cantCopy)
|
||||
.on('mouseenter', function() {
|
||||
$(this).css('background-color', 'grey');
|
||||
})
|
||||
.tipTip();
|
||||
}
|
||||
}
|
||||
|
||||
function fill_user_edit_properties(user_to_edit, pop_in) {
|
||||
@@ -1137,7 +1486,70 @@ function fill_user_edit_update(user_to_edit, pop_in) {
|
||||
pop_in.find('.update-user-button').unbind("click").click(
|
||||
user_to_edit.id === guest_id ? update_guest_info : update_user_info);
|
||||
pop_in.find('.edit-username-validate').unbind("click").click(update_user_username);
|
||||
pop_in.find('.edit-password-validate').unbind("click").click(update_user_password);
|
||||
pop_in.find('#edit_modal_password').off('click').on('click', function() {
|
||||
$('.user-property-password-choice').hide();
|
||||
$('.user-property-password-change-inputs').fadeIn();
|
||||
});
|
||||
if (user_to_edit.email) {
|
||||
pop_in.find('#send_password_link')
|
||||
.removeClass('unavailable tiptip')
|
||||
.attr('title', '')
|
||||
.off('click')
|
||||
.on('click', function () {
|
||||
send_link_password(user_to_edit.email, user_to_edit.username, user_to_edit.id, true);
|
||||
});
|
||||
pop_in.find('#send_password_link').off('mouseenter mouseleave focus blur');
|
||||
} else {
|
||||
pop_in.find('#send_password_link')
|
||||
.addClass('unavailable tiptip')
|
||||
.off('click')
|
||||
.attr('title', cannotSendMail)
|
||||
.tipTip({
|
||||
delay: 0,
|
||||
fadeIn: 200,
|
||||
fadeOut: 200,
|
||||
edgeOffset: 3
|
||||
});
|
||||
}
|
||||
pop_in.find('#copy_password_link').off('click').on('click', function() {
|
||||
const inputValue = $('#result_send_mail_copy_input').val();
|
||||
if (inputValue === '') {
|
||||
send_link_password(user_to_edit.email, user_to_edit.username, user_to_edit.id, false);
|
||||
} else {
|
||||
if (window.isSecureContext && navigator.clipboard) {
|
||||
copyToClipboard(inputValue);
|
||||
};
|
||||
}
|
||||
$('.user-property-password-choice').hide();
|
||||
$('#edit_password_result_mail_copy').fadeIn();
|
||||
$('#close_password_mail_send_close').off('click').on('click', function() {
|
||||
reset_password_modals();
|
||||
});
|
||||
$('#result_send_mail_copy_btn').off('click').on('click', function() {
|
||||
if (window.isSecureContext && navigator.clipboard) {
|
||||
const success = $('#result_send_mail_copy');
|
||||
success.fadeOut(100);
|
||||
copyToClipboard($('#result_send_mail_copy_input').val());
|
||||
success.fadeIn(100);
|
||||
};
|
||||
});
|
||||
$('#result_send_mail_copy_input').trigger('focus');
|
||||
});
|
||||
pop_in.find('.edit-password-validate').unbind("click").click(function() {
|
||||
const errDiv = $('#UserList .EditUserErrors');
|
||||
const inputPassword = $('#edit_user_password').val();
|
||||
const inputConfirmPassword = $('#edit_user_conf_password').val();
|
||||
|
||||
if (inputPassword === '' || inputConfirmPassword === '') {
|
||||
errDiv.html(missingField);
|
||||
show_error_edit_user();
|
||||
} else if (inputPassword !== inputConfirmPassword) {
|
||||
errDiv.html(noMatchPassword);
|
||||
show_error_edit_user();
|
||||
} else {
|
||||
update_user_password();
|
||||
}
|
||||
});
|
||||
pop_in.find('.delete-user-button').unbind("click").click(function () {
|
||||
$.confirm({
|
||||
title: title_msg.replace('%s', user_to_edit.username),
|
||||
@@ -1172,6 +1584,7 @@ function fill_user_edit_permissions(user_to_edit, pop_in) {
|
||||
pop_in.find(".user-property-status .user-property-select").addClass("notClickable");
|
||||
pop_in.find(".user-property-username .edit-username").hide();
|
||||
} else {
|
||||
pop_in.find(".delete-user-button").show();
|
||||
pop_in.find(".user-property-password.edit-password").show();
|
||||
pop_in.find(".user-property-email .user-property-input").removeAttr('disabled');
|
||||
pop_in.find(".user-property-status .user-property-select").removeClass("notClickable");
|
||||
@@ -1194,12 +1607,14 @@ function fill_user_edit_permissions(user_to_edit, pop_in) {
|
||||
pop_in.find(".user-property-status .user-property-select").addClass("notClickable");
|
||||
} else if (user_to_edit.status == "webmaster" && connected_user_status == "admin") {
|
||||
// I'm admin and I want to edit webmaster
|
||||
pop_in.find(".delete-user-button").hide();
|
||||
pop_in.find(".user-property-password.edit-password").hide();
|
||||
pop_in.find(".user-property-email .user-property-input").attr('disabled','disabled');
|
||||
pop_in.find(".user-property-status .user-property-select").addClass("notClickable");
|
||||
pop_in.find(".user-property-username .edit-username").hide();
|
||||
} else if (user_to_edit.status == "admin" && connected_user_status == "webmaster") {
|
||||
// I'm webmaster and I want to edit admin
|
||||
pop_in.find(".delete-user-button").show();
|
||||
pop_in.find(".user-property-password.edit-password").show();
|
||||
pop_in.find(".user-property-email .user-property-input").removeAttr('disabled');
|
||||
pop_in.find(".user-property-status .user-property-select").removeClass("notClickable");
|
||||
@@ -1231,12 +1646,29 @@ function is_owner(user_id) {
|
||||
}
|
||||
|
||||
function fill_user_edit(user_to_edit) {
|
||||
let pop_in = $('.UserListPopInContainer');
|
||||
let pop_in = $('#UserList');
|
||||
fill_user_edit_summary(user_to_edit, pop_in, false);
|
||||
fill_user_edit_properties(user_to_edit, pop_in);
|
||||
fill_user_edit_preferences(user_to_edit, pop_in);
|
||||
fill_user_edit_update(user_to_edit, pop_in);
|
||||
fill_user_edit_permissions(user_to_edit, pop_in);
|
||||
fill_who_is_the_king(user_to_edit, pop_in);
|
||||
|
||||
// plugins get function
|
||||
if (Object.keys(plugins_get_functions).length > 0) {
|
||||
Object.entries(plugins_get_functions).forEach((f) => {
|
||||
f[1]();
|
||||
});
|
||||
}
|
||||
const keyUserToEdit = Object.keys(user_to_edit);
|
||||
plugins_users_infos_table.forEach((i) => {
|
||||
$('#' + i.content_id).val('');
|
||||
if (keyUserToEdit.includes(i.users_table)) {
|
||||
$('#' + i.content_id).val(user_to_edit[i.users_table]);
|
||||
} else {
|
||||
console.error(i.users_table, ' doesn\'t exist in USER_INFOS_TABLE');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fill_guest_edit() {
|
||||
@@ -1248,6 +1680,53 @@ function fill_guest_edit() {
|
||||
fill_user_edit_update(user_to_edit, pop_in);
|
||||
}
|
||||
|
||||
function fill_who_is_the_king(user_to_edit, pop_in) {
|
||||
const who_is_the_king = pop_in.find("#who_is_the_king");
|
||||
// By default I'm an admin and I only see who is the Main User
|
||||
who_is_the_king
|
||||
.removeClass('princes-of-this-piwigo king-of-this-piwigo can-change')
|
||||
.addClass('royal-court-of-this-piwigo cannot-change')
|
||||
.attr('title', mainAskWebmaster)
|
||||
.tipTip();
|
||||
who_is_the_king.off('click');
|
||||
// I'm an webmaster
|
||||
if (connected_user_status === 'webmaster') {
|
||||
// check user to edit status
|
||||
switch (user_to_edit.status) {
|
||||
// user to edit is an webmaster
|
||||
case 'webmaster':
|
||||
who_is_the_king
|
||||
.removeClass('royal-court-of-this-piwigo king-of-this-piwigo cannot-change')
|
||||
.addClass('princes-of-this-piwigo can-change')
|
||||
.attr('title', mainUserSet)
|
||||
.tipTip();
|
||||
if (!is_owner(user_to_edit.id)) {
|
||||
who_is_the_king.off('click').on('click', function() {
|
||||
open_main_user_modal(user_to_edit);
|
||||
});
|
||||
}
|
||||
break;
|
||||
// if user to edit is not an webmaster he cannot be set as a main user
|
||||
default:
|
||||
who_is_the_king
|
||||
.removeClass('princes-of-this-piwigo king-of-this-piwigo')
|
||||
.addClass('royal-court-of-this-piwigo')
|
||||
.attr('title', mainUserUpgradeWebmaster)
|
||||
.tipTip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Main User also the King
|
||||
if (is_owner(user_to_edit.id)) {
|
||||
who_is_the_king
|
||||
.removeClass('princes-of-this-piwigo royal-court-of-this-piwigo can-change')
|
||||
.addClass('king-of-this-piwigo cannot-change')
|
||||
.attr('title', mainUserStr)
|
||||
.tipTip();
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------
|
||||
Fill data for setInfo
|
||||
-------------------*/
|
||||
@@ -1351,7 +1830,7 @@ function select_whole_set() {
|
||||
}
|
||||
|
||||
function update_user_username() {
|
||||
let pop_in_container = $('.UserListPopInContainer');
|
||||
let pop_in_container = $('#UserList');
|
||||
let ajax_data = {
|
||||
pwg_token: pwg_token,
|
||||
user_id: last_user_id
|
||||
@@ -1374,16 +1853,20 @@ function update_user_username() {
|
||||
$('#UserList .user-property-initials span').html(get_initials(current_users[last_user_index].username));
|
||||
fill_container_user_info($('#user-table-content .user-container').eq(last_user_index), last_user_index);
|
||||
}
|
||||
$("#UserList .update-user-success").fadeIn().delay(1500).fadeOut(2500);
|
||||
$('.user-property-username').show();
|
||||
$('.user-property-username-change').hide();
|
||||
$('.user-property-username-change-input').hide();
|
||||
$('.edit-username-success').fadeIn();
|
||||
$('#close_username_success').on('click', function () {
|
||||
$('.edit-username-success').hide();
|
||||
$('.user-property-username-change-input').show();
|
||||
$('.user-property-username-change').hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function update_user_password() {
|
||||
let pop_in_container = $('.UserListPopInContainer');
|
||||
let pop_in_container = $('#UserList');
|
||||
let ajax_data = {
|
||||
pwg_token: pwg_token,
|
||||
user_id: last_user_id
|
||||
@@ -1396,9 +1879,22 @@ function update_user_password() {
|
||||
success: (raw_data) => {
|
||||
data = jQuery.parseJSON(raw_data);
|
||||
if (data.stat == 'ok') {
|
||||
$("#UserList .update-user-success").fadeIn().delay(1500).fadeOut(2500);
|
||||
$('.user-property-password').show();
|
||||
$('.user-property-password-change').hide();
|
||||
$('.user-property-password-change-inputs').hide();
|
||||
$('#edit_password_success_change').fadeIn();
|
||||
|
||||
if (window.isSecureContext && navigator.clipboard) {
|
||||
$('#copy_password').on('click', async function() {
|
||||
copyToClipboard(ajax_data['password'])
|
||||
$('#password_msg_success').html(passwordCopied);
|
||||
});
|
||||
};
|
||||
|
||||
$('#close_password_success').on('click', function() {
|
||||
$('.user-property-password-change').hide();
|
||||
$('#edit_password_success_change').hide();
|
||||
$('.user-property-password-change-inputs').show();
|
||||
reset_input_password();
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1414,6 +1910,16 @@ function update_user_info() {
|
||||
pwg_token: pwg_token,
|
||||
user_id: last_user_id
|
||||
};
|
||||
if (plugins_users_infos_table.length > 0) {
|
||||
const keyCurrentUsers = Object.keys(current_users[last_user_index]);
|
||||
plugins_users_infos_table.forEach((i) => {
|
||||
if (keyCurrentUsers.includes(i.users_table)) {
|
||||
ajax_data[i.users_table] = $('#' + i.content_id).val();
|
||||
} else {
|
||||
console.error(i.users_table, ' doesn\'t exist in USER_INFOS_TABLE');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ajax_data = fill_ajax_data_from_container(ajax_data, pop_in_container);
|
||||
jQuery.ajax({
|
||||
@@ -1449,6 +1955,16 @@ function update_user_info() {
|
||||
$(".update-user-button i").removeClass("icon-spin6 animate-spin").addClass("icon-floppy");
|
||||
$(".update-user-button").removeClass("unclickable");
|
||||
|
||||
// update plugins
|
||||
if (Object.keys(plugins_get_functions).length > 0) {
|
||||
Object.entries(plugins_set_functions).forEach((f) => {
|
||||
f[1]();
|
||||
});
|
||||
}
|
||||
|
||||
// update who is the king
|
||||
fill_who_is_the_king(result_user, $('#UserList'));
|
||||
|
||||
} else if (data.stat === 'fail') {
|
||||
$("#UserList .update-user-fail").html(data.message);
|
||||
$("#UserList .update-user-fail").fadeIn();
|
||||
@@ -1575,6 +2091,9 @@ function update_user_list() {
|
||||
last_user_index = uid_index;
|
||||
fill_user_edit(current_users[uid_index]);
|
||||
$("#UserList").fadeIn();
|
||||
$('#tab_properties')[0].scrollIntoView({
|
||||
behavior: 'instant'
|
||||
});
|
||||
});
|
||||
set_selected_to_selection();
|
||||
|
||||
@@ -1634,6 +2153,7 @@ function add_user() {
|
||||
})
|
||||
$("#AddUserSuccess label span:first").html(user_added_str.replace("%s", ajax_data.username));
|
||||
$("#AddUserSuccess").css("display", "flex");
|
||||
$('.badge-number').html(+$('.badge-number').html() + 1);
|
||||
}
|
||||
else {
|
||||
$("#AddUser .AddUserErrors").html(data.message)
|
||||
@@ -1657,6 +2177,7 @@ function delete_user(uid) {
|
||||
success:function(data) {
|
||||
close_user_list();
|
||||
update_user_list();
|
||||
$('.badge-number').html(+$('.badge-number').html() - 1);
|
||||
// msg where user was deleted
|
||||
//jQuery('#showAddUser .infos').html('✔ User '+username+' deleted').show();
|
||||
},
|
||||
@@ -1690,3 +2211,91 @@ function show_filter_infos(nb_filters) {
|
||||
$(".filter-counter").css('display', 'none').html(0);
|
||||
}
|
||||
}
|
||||
|
||||
function send_link_password(email, username, user_id, send_by_mail) {
|
||||
$.ajax({
|
||||
url: "ws.php?format=json",
|
||||
dataType: "json",
|
||||
data: {
|
||||
method: 'pwg.users.generateResetPasswordLink',
|
||||
user_id: user_id,
|
||||
send_by_mail: send_by_mail,
|
||||
pwg_token: pwg_token
|
||||
},
|
||||
success: function(response) {
|
||||
if('ok' === response.stat) {
|
||||
$('#result_send_mail_copy_input').val(response.result.generated_link);
|
||||
if(send_by_mail) {
|
||||
if(response.result.send_by_mail) {
|
||||
$('#result_send_mail').removeClass('update-password-fail icon-red').addClass('update-password-success icon-green');
|
||||
$('#icon_password_msg_result_mail').removeClass('icon-cancel').addClass('icon-ok');
|
||||
$('#password_msg_result_mail').html(sprintf(mailSentAt, username, email));
|
||||
} else {
|
||||
$('#result_send_mail').removeClass('update-password-success icon-green').addClass('update-password-fail icon-red');
|
||||
$('#icon_password_msg_result_mail').removeClass('icon-ok').addClass('icon-cancel');
|
||||
$('#password_msg_result_mail').html(errorMailSent);
|
||||
}
|
||||
$('.user-property-password-choice').hide();
|
||||
$('#edit_password_result_mail').fadeIn();
|
||||
$('#close_password_mail_close').off('click').on('click', function() {
|
||||
reset_password_modals();
|
||||
});
|
||||
} else {
|
||||
$('#result_send_mail_copy').removeClass('update-password-fail icon-red').addClass('update-password-success icon-green');
|
||||
$('#result_send_mail_copy_icon').removeClass('icon-cancel').addClass('icon-ok');
|
||||
$('#result_send_mail_copy_msg').html(copyLinkStr);
|
||||
if (window.isSecureContext && navigator.clipboard) {
|
||||
copyToClipboard(response.result.generated_link);
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(err) {
|
||||
console.log('Error send_link_password :', err);
|
||||
if (!send_by_mail) {
|
||||
$('#result_send_mail_copy').removeClass('update-password-success icon-green').addClass('update-password-fail icon-red');
|
||||
$('#result_send_mail_copy_icon').removeClass('icon-ok').addClass('icon-cancel');
|
||||
$('#result_send_mail_copy_msg').html(errorStr);
|
||||
} else {
|
||||
$('#result_send_mail').removeClass('update-password-success icon-green').addClass('update-password-fail icon-red');
|
||||
$('#icon_password_msg_result_mail').removeClass('icon-ok').addClass('icon-cancel');
|
||||
$('#password_msg_result_mail').html(errorMailSent);
|
||||
$('.user-property-password-choice').hide();
|
||||
$('#edit_password_result_mail').fadeIn();
|
||||
$('#close_password_mail_close').off('click').on('click', function() {
|
||||
reset_password_modals();
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function set_main_user(user_id, new_username) {
|
||||
$.ajax({
|
||||
url: 'ws.php?format=json',
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
data: {
|
||||
method: 'pwg.users.setMainUser',
|
||||
user_id: user_id,
|
||||
pwg_token: pwg_token
|
||||
},
|
||||
success: function(res) {
|
||||
if('ok' === res.stat) {
|
||||
$('#who_is_the_king')
|
||||
.off('click')
|
||||
.removeClass('princes-of-this-piwigo royal-court-of-this-piwigo can-change')
|
||||
.addClass('king-of-this-piwigo cannot-change')
|
||||
.attr('title', mainUserStr)
|
||||
.tipTip();
|
||||
|
||||
owner_id = user_id;
|
||||
owner_username = new_username;
|
||||
set_main_user_success();
|
||||
}
|
||||
},
|
||||
error: function(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user