From d2f0823c983c6f77bb5474fb6546e16a8acd245b Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 3 Apr 2016 13:34:41 -0400 Subject: update post, pag,e and project edit dialogs --- data/stuff/test/tab-posts.js | 133 +++--------- src/guff/views/ecrs/test/auth.ecr | 415 ++++++++++++++++++++++---------------- src/guff/views/html/test/auth.cr | 64 ++++++ 3 files changed, 332 insertions(+), 280 deletions(-) diff --git a/data/stuff/test/tab-posts.js b/data/stuff/test/tab-posts.js index b9692a5..90c26de 100644 --- a/data/stuff/test/tab-posts.js +++ b/data/stuff/test/tab-posts.js @@ -38,114 +38,41 @@ jQuery(function($) { ], }); - - var POST_TYPES = { - type: { - last: false, - name: "Type", - }, - - blog: { - last: true, - name: "Blog Post", - - cbs: { - show: function() { - $('#post-new-blog-name').val(''); - $('#post-new-blog-slug').val(''); - $('#post-new-blog-body').val(''); - }, - - shown: function() { - $('#post-new-blog-name').focus(); - }, - }, - }, - - page: { - last: true, - name: "Page", - }, - - project: { - last: true, - name: "Project", - }, - }; - - $('#post-new-dialog').on('show.bs.modal', function() { - $('#post-new-type-blog').click(); - - $('#post-new-tab-type').parent().removeClass('active') - $('#post-new-tab-type').click(); - }); - - $.each(POST_TYPES, function(id, data) { - $('#post-new-tab-' + id).on('show.bs.tab', function() { - // update buttons - $('#post-new-back').toggleClass('disabled', !data.last); - $('#post-new-next').toggleClass('hidden', data.last); - $('#post-new-confirm').toggleClass('hidden', !data.last) - .find('span.name').text(data.name); + $.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() { + // reset close confirmation + $(this).data('close-dialog-confirmed', false); + + // TODO load post + $(p + 'name').val(''); + $(p + 'slug').val(''); + }).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); }); - - if (data.cbs) { - // add event handlers - $.each(data.cbs, function(ev_id, fn) { - $('#post-new-tab-' + id).on(ev_id + '.bs.tab', fn); - }); - } - }); - - $('#post-new-back').click(function() { - $('#post-new-tab-type').click(); - - // stop event - return false; - }); - - $('#post-new-next').click(function() { - $.each(POST_TYPES, function(id, data) { - if ($('#post-new-type-' + id).is(':checked')) { - // select tab - $('#post-new-tab-' + id).click(); + $(p + 'confirm').click(function() { + if ($(this).hasClass('disabled')) return false; - } - }); - // stop event - return false; - }); + // TODO: see #user-add-confirm + alert('TODO: create'); - $('#post-new-confirm').click(function() { - if (me.hasClass('disabled')) + // stop event return false; - - // TODO: see #user-add-confirm - alert('TODO: create'); - - // stop event - return false; - }); - - $('#post-new-tab-pane-type label').dblclick(function() { - $(this).find('input[type="radio"]').prop('checked', true); - $('#post-new-next').click(); - - // stop event - return false; - }); - - $('#post-new-tab-blog').one('shown.bs.tab', function() { - // lazy-init editor - console.log('initializing editor'); -/* - * tinymce.init({ - * selector: '#post-new-blog-body', - * plugins: 'fullscreen', - * }); - */ - CKEDITOR.replace('post-new-blog-body'); + }); }); }); diff --git a/src/guff/views/ecrs/test/auth.ecr b/src/guff/views/ecrs/test/auth.ecr index 10b9518..228c0a5 100644 --- a/src/guff/views/ecrs/test/auth.ecr +++ b/src/guff/views/ecrs/test/auth.ecr @@ -26,18 +26,9 @@
- +
<%= + get_new_post_button + %>
@@ -53,18 +44,9 @@
diff --git a/src/guff/views/html/test/auth.cr b/src/guff/views/html/test/auth.cr index 60bafb3..59e151f 100644 --- a/src/guff/views/html/test/auth.cr +++ b/src/guff/views/html/test/auth.cr @@ -38,6 +38,66 @@ class Guff::TestAuthHTMLView ", + + new_post_button: " + + + New Post + + + + + + + + ", }) def self.run(models, context : HTTP::Server::Context) @@ -82,5 +142,9 @@ class Guff::TestAuthHTMLView }.join end + def get_new_post_button + TEMPLATES[:new_post_button].run + end + ECR.def_to_s("./src/guff/views/ecrs/test/auth.ecr") end -- cgit v1.2.3