aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs/user-edit.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/dialogs/user-edit.js')
-rw-r--r--data/assets/js/admin/dialogs/user-edit.js65
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;
+ });
+});