From 23ba337de24e88c6aaf6ceb37507997f5c5f4920 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 2 Apr 2016 01:09:45 -0400 Subject: fully working edit dialog --- data/stuff/js/util.js | 4 ++ data/stuff/test/auth.js | 97 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 15 deletions(-) (limited to 'data/stuff') 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($) { "", "", "", @@ -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); -- cgit v1.2.3