diff options
-rw-r--r-- | data/assets/js/admin/dialogs/blog-edit.js | 7 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/page-edit.js | 7 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/post-edit.js | 119 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/project-edit.js | 7 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/user-add.js | 55 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/user-edit.js | 65 | ||||
-rw-r--r-- | data/assets/js/admin/tabs/posts.js (renamed from data/assets/js/admin/posts.js) | 7 | ||||
-rw-r--r-- | data/assets/js/admin/tabs/users.js (renamed from data/assets/js/admin/users.js) | 114 | ||||
-rw-r--r-- | src/guff.cr | 2 | ||||
-rw-r--r-- | src/views/admin-page.ecr | 40 |
10 files changed, 295 insertions, 128 deletions
diff --git a/data/assets/js/admin/dialogs/blog-edit.js b/data/assets/js/admin/dialogs/blog-edit.js new file mode 100644 index 0000000..46a782b --- /dev/null +++ b/data/assets/js/admin/dialogs/blog-edit.js @@ -0,0 +1,7 @@ +jQuery(function($) { + "use strict"; + + $('#blog-edit-dialog').on('post-data-loaded', function(r) { + console.log(r); + }); +}); diff --git a/data/assets/js/admin/dialogs/page-edit.js b/data/assets/js/admin/dialogs/page-edit.js new file mode 100644 index 0000000..46a782b --- /dev/null +++ b/data/assets/js/admin/dialogs/page-edit.js @@ -0,0 +1,7 @@ +jQuery(function($) { + "use strict"; + + $('#blog-edit-dialog').on('post-data-loaded', function(r) { + console.log(r); + }); +}); diff --git a/data/assets/js/admin/dialogs/post-edit.js b/data/assets/js/admin/dialogs/post-edit.js new file mode 100644 index 0000000..31b85ee --- /dev/null +++ b/data/assets/js/admin/dialogs/post-edit.js @@ -0,0 +1,119 @@ +jQuery(function($) { + "use strict"; + + var TEMPLATES = new LuigiTemplate.Cache({ + }); + + function update_slug(name, slug) { + if (slug.prop('disabled')) { + slug.val( + name.val().toLowerCase() + .replace(/[^a-z0-9_\.-]+/g, '-') + .replace(/^-+|-+$/g, '') + ); + } + } + + $.each(['blog', 'page', 'project'], function(i, id) { + var p = '#' + id + '-edit-'; + + $(p + 'dialog').one('shown.bs.modal', function() { + // lazy-init editor + CKEDITOR.replace(id + '-edit-body'); + }).on('show.bs.modal', function() { + var me = $(this); + + // reset close confirmation + me.data('close-dialog-confirmed', false); + + // show loading text + me.find('.modal-body').addClass('hidden'); + me.find('.modal-body.loading-text').removeClass('hidden'); + + send(id + '/get', { + post_id: me.data('post_id') + }).always(function() { + me.find('.modal-body.loading-text').addClass('hidden'); + }).fail(function(r) { + var error = r.responseText; + + try { + // try to extract error message from json response + var data = $.parseJSON(r.responseText); + if ('error' in data) + error = data.error; + } catch (e) {} + + me.find('.modal-body.loading-error').removeClass('hidden') + .find('.error-text').text(error); + }).done(function(r) { + me.find('.modal-body.loading-done').removeClass('hidden'); + + me.trigger({ + type: "post-data-loaded", + post_data: r, + }); + }); + }).on('shown.bs.modal', function() { + $(p + 'name').focus(); + }).on('hide.bs.modal', function() { + return ( + $(this).data('close-dialog-confirmed') || + confirm('Close without saving changes?') + ); + }).find('button[data-dismiss="modal"]').click(function() { + // override close confirmation + // FIXME: should this only be on save? + $(p + 'dialog').data('close-dialog-confirmed', true); + }); + + $(p + 'confirm').click(function() { + if ($(this).hasClass('disabled')) + return false; + + // TODO: see #user-add-confirm + alert('TODO: create'); + + // stop event + return false; + }); + }); + + $('.post-name').keydown(function() { + var name = $(this), + slug = $(this).parents('.modal-body').find('.post-slug'); + + setTimeout(function() { + update_slug(name, slug); + }, 10); + }); + + $('.post-slug-lock').click(function() { + var modal_body = $(this).parents('.modal-body'); + + // toggle locked state + $(this).toggleClass('btn-default btn-primary') + .find('.fa').toggleClass('fa-lock fa-unlock'); + var locked = $(this).hasClass('btn-default'); + + // update slug disabled state + var slug = modal_body.find('.post-slug'); + slug.prop('disabled', locked ? 'disabled' : null); + + if (locked) { + // auto-generate slug + update_slug(modal_body.find('.post-name'), slug); + } + + // stop event + return false; + }); + + $('.state-buttons').on('a', 'click', function() { + $(this).parent().find('.btn-primary').toggleClass('btn-default btn-primary'); + $(this).toggleClass('btn-default btn-primary'); + + // stop event + return false; + }); +}); diff --git a/data/assets/js/admin/dialogs/project-edit.js b/data/assets/js/admin/dialogs/project-edit.js new file mode 100644 index 0000000..46a782b --- /dev/null +++ b/data/assets/js/admin/dialogs/project-edit.js @@ -0,0 +1,7 @@ +jQuery(function($) { + "use strict"; + + $('#blog-edit-dialog').on('post-data-loaded', function(r) { + console.log(r); + }); +}); 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; + }); +}); 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; + }); +}); diff --git a/data/assets/js/admin/posts.js b/data/assets/js/admin/tabs/posts.js index e5fe341..00117d6 100644 --- a/data/assets/js/admin/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -58,9 +58,8 @@ jQuery(function($) { // reset close confirmation $(this).data('close-dialog-confirmed', false); - // TODO load post - $(p + 'name').val(''); - $(p + 'slug').val(''); + // hide all bodies + $(this).find('.modal-body').addClass('hidden'); }).on('shown.bs.modal', function() { $(p + 'name').focus(); }).on('hide.bs.modal', function() { @@ -116,7 +115,7 @@ jQuery(function($) { return false; }); - $('.post-state').click(function() { + $('.state-buttons').on('a', 'click', function() { $(this).parent().find('.btn-primary').toggleClass('btn-default btn-primary'); $(this).toggleClass('btn-default btn-primary'); diff --git a/data/assets/js/admin/users.js b/data/assets/js/admin/tabs/users.js index a5eef0f..22348e2 100644 --- a/data/assets/js/admin/users.js +++ b/data/assets/js/admin/tabs/users.js @@ -106,120 +106,6 @@ jQuery(function($) { return false; }); - $('#user-add-dialog').on('show.bs.modal', function() { - $.each(['name', 'email', 'password'], function(i, id) { - $('#user-add-' + id).val(''); - }); - $('#user-add-role').val('guest'); - }); - - $('#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); - reload(); - $('#user-add-dialog').modal('hide'); - }); - - // stop event - return false; - }); - - $('#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); - reload(); - $('#user-edit-dialog').modal('hide'); - }); - - // stop event - return false; - }); - $('#users-reload').click(reload); // load users diff --git a/src/guff.cr b/src/guff.cr index 19a3ace..b082b4e 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -1631,7 +1631,7 @@ module Guff state_button: " <a href='#' - class='btn %s post-state' + class='btn %s' title='Mark as %s.' > <i class='fa %s'></i> diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr index a1a636e..71beb6f 100644 --- a/src/views/admin-page.ecr +++ b/src/views/admin-page.ecr @@ -333,7 +333,21 @@ </h4><!-- modal-title --> </div><!-- modal-header --> - <div class='modal-body'> + <div class='modal-body loading-text'> + <p> + <i class='fa fa-spinner fa-spin'></i> + Loading... + </p> + </div><!-- modal-body --> + + <div class='modal-body loading-error'> + <div class='well well'> + <i class='fa fa-exclamation-triangle'></i> + Error: <span class='error-text'></span> + </div><!-- well --> + </div><!-- modal-body --> + + <div class='modal-body loading-done'> <div class='form-group'> <label for='user-edit-name'> Name @@ -528,7 +542,7 @@ State </label> - <div class='btn-group btn-group-justified'><%= + <div class='btn-group btn-group-justified state-buttons'><%= state_buttons %></div><!-- btn-group --> @@ -669,11 +683,12 @@ Layout </label> - <div class='btn-group btn-group-justified'> + <div class='btn-group btn-group-justified state-buttons'> <a href='#' - class='btn btn-default post-state' + class='btn btn-default' title='Use blank layout for this page.' + data-val='blank' > <i class='fa fa-file-o'></i> Blank @@ -681,8 +696,9 @@ <a href='#' - class='btn btn-primary post-state' + class='btn btn-primary' title='Use default layout for this page.' + data-val='default' > <i class='fa fa-newspaper-o'></i> Default @@ -699,7 +715,7 @@ State </label> - <div class='btn-group btn-group-justified'><%= + <div class='btn-group btn-group-justified state-buttons'><%= state_buttons %></div><!-- btn-group --> @@ -861,7 +877,7 @@ State </label> - <div class='btn-group btn-group-justified'><%= + <div class='btn-group btn-group-justified state-buttons'><%= state_buttons %></div><!-- btn-group --> @@ -910,8 +926,14 @@ assets/bootstrap-3.3.6/js/bootstrap.min.js assets/ckeditor-4.5.8-custom/ckeditor.js assets/js/search-field.js - assets/js/admin/users.js - assets/js/admin/posts.js + assets/js/admin/tabs/users.js + assets/js/admin/tabs/posts.js + assets/js/admin/dialogs/user-add.js + assets/js/admin/dialogs/user-edit.js + assets/js/admin/dialogs/post-edit.js + assets/js/admin/dialogs/blog-edit.js + assets/js/admin/dialogs/page-edit.js + assets/js/admin/dialogs/project-edit.js } %> </html> |