aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-04-02 01:09:45 -0400
committerPaul Duncan <pabs@pablotron.org>2016-04-02 01:09:45 -0400
commit23ba337de24e88c6aaf6ceb37507997f5c5f4920 (patch)
treef5a6fc8d925dafd62ee45973b4e357234ea9ec9a /data
parent7788012457346ae59fa58ed35fc08aa2b9e6b9ef (diff)
downloadold-guff-23ba337de24e88c6aaf6ceb37507997f5c5f4920.tar.bz2
old-guff-23ba337de24e88c6aaf6ceb37507997f5c5f4920.zip
fully working edit dialog
Diffstat (limited to 'data')
-rw-r--r--data/stuff/js/util.js4
-rw-r--r--data/stuff/test/auth.js97
2 files changed, 86 insertions, 15 deletions
diff --git a/data/stuff/js/util.js b/data/stuff/js/util.js
index a6826db..c021499 100644
--- a/data/stuff/js/util.js
+++ b/data/stuff/js/util.js
@@ -9,4 +9,8 @@ jQuery(function($) {
data: args,
});
};
+
+ LuigiTemplate.FILTERS.json = function(val) {
+ return JSON.stringify(val);
+ };
});
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);