aboutsummaryrefslogtreecommitdiff
path: root/data/stuff/test
diff options
context:
space:
mode:
Diffstat (limited to 'data/stuff/test')
-rw-r--r--data/stuff/test/auth.js97
1 files changed, 82 insertions, 15 deletions
diff --git a/data/stuff/test/auth.js b/data/stuff/test/auth.js
index 5876a41..0776bfd 100644
--- a/data/stuff/test/auth.js
+++ b/data/stuff/test/auth.js
@@ -5,8 +5,8 @@ jQuery(function($) {
"<a ",
"href='#' ",
"class='list-group-item %{css|h}' ",
- "title='Set user to \"%{user_name|h}.\"' ",
- "data-user_id='%{user_id|h}' ",
+ "title='Edit user \"%{user_name|h}\".' ",
+ "data-row='%{row|json|h}' ",
">",
"<i class='fa fa-fw fa-spinner fa-spin hidden loading'></i>",
"<i class='fa fa-fw fa-user loading'></i>",
@@ -51,7 +51,7 @@ jQuery(function($) {
}).done(function(r) {
list.html($.map(r.users, function(row) {
return TEMPLATES.run('user', $.extend({}, row, {
- css: (r.user_id == row.user_id) ? 'active' : '',
+ row: row,
}));
}).join(''));
});
@@ -74,20 +74,10 @@ jQuery(function($) {
var me = $(this);
// update highlight
- var last = $('#users .active').removeClass('active');
+ $('#users .active').removeClass('active');
me.addClass('active');
- // show spinner
- me.addClass('disabled').find('.loading').toggleClass('hidden');
-
- set_user(me.data('user_id')).always(function() {
- // hide spinner
- me.removeClass('disabled').find('.loading').toggleClass('hidden');
- }).fail(function(r) {
- // restore old highlight
- me.removeClass('active');
- last.addClass('active');
- });
+ $('#edit-dialog').data('row', me.data('row')).modal('show');
// stop event
return false;
@@ -100,6 +90,21 @@ jQuery(function($) {
$('#add-role').val('guest');
});
+ $('#add-dialog').on('shown.bs.modal', function() {
+ $('#add-name').focus();
+ });
+
+ $('#add-name, #add-email, #add-password').keydown(function(ev) {
+ if (ev.which == 13) {
+ setTimeout(function() {
+ $('#add-confirm').click();
+ }, 10);
+
+ // stop event
+ return false;
+ }
+ });
+
$('#add-confirm').click(function() {
var me = $(this);
@@ -130,6 +135,68 @@ jQuery(function($) {
return false;
});
+ $('#edit-dialog').on('show.bs.modal', function() {
+ var row = $(this).data('row');
+
+ $.each({
+ name: 'user_name',
+ email: 'email',
+ role: 'role_name',
+ }, function(id, col) {
+ $('#edit-' + id).val(row[col]);
+ });
+ });
+
+ $('#edit-dialog').on('shown.bs.modal', function() {
+ $('#edit-name').focus();
+ });
+
+ $('#edit-dialog').on('hide.bs.modal', function() {
+ // clear highlight
+ $('#users .active').removeClass('active');
+ });
+
+ $('#edit-name, #edit-email').keydown(function(ev) {
+ if (ev.which == 13) {
+ setTimeout(function() {
+ $('#edit-confirm').click();
+ }, 10);
+
+ // stop event
+ return false;
+ }
+ });
+
+ $('#edit-confirm').click(function() {
+ var me = $(this),
+ user_id = $('#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: $('#edit-name').val(),
+ email: $('#edit-email').val(),
+ role: $('#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);
+ reload();
+ $('#edit-dialog').modal('hide');
+ });
+
+ // stop event
+ return false;
+ });
+
$('#login').click(function() {
var me = $(this);