diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-05-24 00:45:23 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-05-24 00:45:23 -0400 |
commit | 6e40b628484c0aef29bc6a258a3a9fa08f4a31b2 (patch) | |
tree | f3830edee334b05338f6eb89a5b11219924f54c7 /data/assets/js/admin/dialogs/user-edit.js | |
parent | 2a87c79df590a1ad55420900ce0709f4a881a448 (diff) | |
download | guff-6e40b628484c0aef29bc6a258a3a9fa08f4a31b2.tar.bz2 guff-6e40b628484c0aef29bc6a258a3a9fa08f4a31b2.zip |
asdf
Diffstat (limited to 'data/assets/js/admin/dialogs/user-edit.js')
-rw-r--r-- | data/assets/js/admin/dialogs/user-edit.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/data/assets/js/admin/dialogs/user-edit.js b/data/assets/js/admin/dialogs/user-edit.js new file mode 100644 index 0000000..2e43d42 --- /dev/null +++ b/data/assets/js/admin/dialogs/user-edit.js @@ -0,0 +1,65 @@ +jQuery(function($) { + "use strict"; + + $('#user-edit-dialog').on('show.bs.modal', function() { + var row = $(this).data('row'); + + $.each({ + name: 'user_name', + email: 'email', + role: 'role_name', + }, function(id, col) { + $('#user-edit-' + id).val(row[col]); + }); + }); + + $('#user-edit-dialog').on('shown.bs.modal', function() { + $('#user-edit-name').focus(); + }); + + $('#user-edit-dialog').on('hide.bs.modal', function() { + // clear highlight + $('#users .active').removeClass('active'); + }); + + $('#user-edit-name, #user-edit-email').keydown(function(ev) { + if (ev.which == 13) { + setTimeout(function() { + $('#user-edit-confirm').click(); + }, 10); + + // stop event + return false; + } + }); + + $('#user-edit-confirm').click(function() { + var me = $(this), + user_id = $('#user-edit-dialog').data('row').user_id; + + if (me.hasClass('disabled')) + return false; + + // toggle loading + me.toggleClass('disabled').find('.loading').toggleClass('hidden'); + + send('test/edit_user', { + user_id: user_id, + name: $('#user-edit-name').val(), + email: $('#user-edit-email').val(), + role: $('#user-edit-role').val(), + }).always(function() { + // toggle loading + me.toggleClass('disabled').find('.loading').toggleClass('hidden'); + }).fail(function(r) { + alert('Error ' + r.responseText); + }).done(function(r) { + console.log(r); + $('#users-reload').click(); + $('#user-edit-dialog').modal('hide'); + }); + + // stop event + return false; + }); +}); |