aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs/user-add.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/dialogs/user-add.js')
-rw-r--r--data/assets/js/admin/dialogs/user-add.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/data/assets/js/admin/dialogs/user-add.js b/data/assets/js/admin/dialogs/user-add.js
new file mode 100644
index 0000000..692d8a4
--- /dev/null
+++ b/data/assets/js/admin/dialogs/user-add.js
@@ -0,0 +1,55 @@
+jQuery(function($) {
+ "use strict";
+
+ $('#user-add-dialog').on('show.bs.modal', function() {
+ $.each(['name', 'email', 'password'], function(i, id) {
+ $('#user-add-' + id).val('');
+ });
+ $('#user-add-role').val('viewer');
+ });
+
+ $('#user-add-dialog').on('shown.bs.modal', function() {
+ $('#user-add-name').focus();
+ });
+
+ $('#user-add-name, #user-add-email, #user-add-password').keydown(function(ev) {
+ if (ev.which == 13) {
+ setTimeout(function() {
+ $('#user-add-confirm').click();
+ }, 10);
+
+ // stop event
+ return false;
+ }
+ });
+
+ $('#user-add-confirm').click(function() {
+ var me = $(this);
+
+ if (me.hasClass('disabled'))
+ return false;
+
+ // toggle loading
+ me.toggleClass('disabled').find('.loading').toggleClass('hidden');
+
+ send('test/add_user', {
+ name: $('#user-add-name').val(),
+ email: $('#user-add-email').val(),
+ password: $('#user-add-password').val(),
+ role: $('#user-add-role').val(),
+ active: 't',
+ }).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-add-dialog').modal('hide');
+ });
+
+ // stop event
+ return false;
+ });
+});