source: extensions/AddUsersNotes/js/usersnotes.js @ 32693

Last change on this file since 32693 was 32693, checked in by ddtddt, 2 years ago

[AddUsersNotes] compatybilité piwigo 12

File size: 5.2 KB
Line 
1function fill_container_user_info(container, user_index) {
2    let user = current_users[user_index];
3    let registration_dates = user.registration_date.split(' ');
4    container.attr('key', user_index);
5    container.find(".user-container-username span").html(user.username);
6        container.find(".user-container-usernotes span").html(user.usernotes);
7    container.find(".user-container-initials span").html(get_initials(user.username)).addClass(color_icons[user.id % 5]);
8    container.find(".user-container-status span").html(user.status);
9    container.find(".user-container-email span").html(user.email);
10    generate_groups(container, user.groups);
11    container.find(".user-container-registration-date").html(registration_dates[0]);
12    container.find(".user-container-registration-time").html(registration_dates[1]);
13    container.find(".user-container-registration-date-since").html(user.registration_date_since);
14}
15
16function fill_user_edit_summary(user_to_edit, pop_in, isGuest) {
17    console.log(isGuest);
18    if (isGuest) {
19      pop_in.find('.user-property-initials span').removeClass(color_icons.join(' ')).addClass(color_icons[user_to_edit.id % 5]);
20    } else {
21      pop_in.find('.user-property-initials span').html(get_initials(user_to_edit.username)).removeClass(color_icons.join(' ')).addClass(color_icons[user_to_edit.id % 5]);
22    }
23    pop_in.find('.user-property-username span:first').html(user_to_edit.username); 
24   
25   
26    if (user_to_edit.id === connected_user || user_to_edit.id === 1) {
27        pop_in.find('.user-property-username .edit-username-specifier').show();
28    } else {
29        pop_in.find('.user-property-username .edit-username-specifier').hide();
30    }
31    pop_in.find('.user-property-username-change input').val(user_to_edit.username);
32    pop_in.find('.user-property-password-change input').val('');
33    pop_in.find('.user-property-permissions a').attr('href', `admin.php?page=user_perm&user_id=${user_to_edit.id}`);
34    pop_in.find('.user-property-register').html(get_formatted_date(user_to_edit.registration_date));
35    pop_in.find('.user-property-register').tipTip({content:`${registered_str}<br />${user_to_edit.registration_date_since}`});
36    pop_in.find('.user-property-last-visit').html(get_formatted_date(user_to_edit.last_visit));
37    pop_in.find('.user-property-last-visit').tipTip({content: `${last_visit_str}<br />${user_to_edit.last_visit_since}`});
38        pop_in.find('.usernotes-title').html(user_to_edit.usernotes);
39        pop_in.find('.user-property-usernotes-change input').val(user_to_edit.usernotes);
40}
41
42$( document ).ready(function() {
43    $('.edit-usernotes').click(function () {
44        $('.user-property-usernotes').hide();
45        $('.user-property-usernotes-change').show().css('display', 'flex');
46    })
47
48    $('.edit-usernotes-cancel').click(function () {
49        //possibly reset input value
50        $('.user-property-usernotes').show();
51        $('.user-property-usernotes-change').hide();
52    })
53        console.log("toto3");
54});
55
56function fill_user_edit_update(user_to_edit, pop_in) {
57    pop_in.find('.update-user-button').unbind("click").click(
58        user_to_edit.id === guest_id ? update_guest_info : update_user_info);
59    pop_in.find('.edit-username-validate').unbind("click").click(update_user_username);
60    pop_in.find('.edit-password-validate').unbind("click").click(update_user_password);
61        pop_in.find('.edit-usernotes-validate').unbind("click").click(update_user_usernotes);
62    pop_in.find('.delete-user-button').unbind("click").click(function () {
63        $.confirm({
64            title: title_msg.replace('%s', user_to_edit.username),
65            buttons: {
66                confirm: {
67                    text: confirm_msg,
68                    btnClass: 'btn-red',
69                    action: function () {
70                        delete_user(user_to_edit.id);
71                    }
72                },
73                cancel: {
74                    text: cancel_msg
75                }
76            },
77            ...jConfirm_confirm_options
78        });
79    })
80}
81
82
83function update_user_usernotes() {
84    let pop_in_container = $('.UserListPopInContainer');
85    let ajax_data = {
86        pwg_token: pwg_token,
87        user_id: last_user_id
88    };
89    ajax_data['usernotes'] = pop_in_container.find('.user-property-input-usernotes').val();
90    jQuery.ajax({
91        url: "ws.php?format=json&method=pwg.users.setInfo",
92        type: "POST",
93        data: ajax_data,
94        success: (raw_data) => {
95            data = jQuery.parseJSON(raw_data);
96            if (data.stat == 'ok') {
97                if (last_user_index != -1) {
98                    current_users[last_user_index].usernotes = data.result.users[0].usernotes;
99                    $('#UserList .user-property-usernotes .usernotes-title').html(current_users[last_user_index].usernotes);
100                    fill_container_user_info($('#user-table-content .user-container').eq(last_user_index), last_user_index);
101                }
102                $("#UserList .update-user-success").fadeIn().delay(1500).fadeOut(2500);
103                $('.user-property-usernotes').show();
104                $('.user-property-usernotes-change').hide();
105            }
106        }
107    })
108}
Note: See TracBrowser for help on using the repository browser.