diff options
Diffstat (limited to 'data/assets')
-rw-r--r-- | data/assets/js/admin/dialogs/blog-edit.js | 20 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/page-edit.js | 23 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/post-edit.js | 88 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/project-edit.js | 21 | ||||
-rw-r--r-- | data/assets/js/admin/tabs/posts.js | 124 |
5 files changed, 143 insertions, 133 deletions
diff --git a/data/assets/js/admin/dialogs/blog-edit.js b/data/assets/js/admin/dialogs/blog-edit.js index 46a782b..0084028 100644 --- a/data/assets/js/admin/dialogs/blog-edit.js +++ b/data/assets/js/admin/dialogs/blog-edit.js @@ -1,7 +1,23 @@ jQuery(function($) { "use strict"; - $('#blog-edit-dialog').on('post-data-loaded', function(r) { - console.log(r); + var p = '#blog-edit-'; + + $(p + 'dialog').on('guff.loaded', function(ev) { + var r = ev.post_data; + $(p + 'tags').val(r.tags); + }); + + $(p + 'confirm').click(function() { + $(p + 'dialog').trigger({ + type: 'guff.save', + + post_data: { + tags: $(p + 'tags').val(), + }, + }); + + // stop event + return false; }); }); diff --git a/data/assets/js/admin/dialogs/page-edit.js b/data/assets/js/admin/dialogs/page-edit.js index 8af9ec2..05d69a7 100644 --- a/data/assets/js/admin/dialogs/page-edit.js +++ b/data/assets/js/admin/dialogs/page-edit.js @@ -1,7 +1,26 @@ jQuery(function($) { "use strict"; - $('#page-edit-dialog').on('post-data-loaded', function(r) { - console.log(r); + var p = '#page-edit-'; + + $(p + 'dialog').on('guff.loaded', function(ev) { + var r = ev.post_data; + + $(p + 'layout a').removeClass('btn-primary').addClass('btn-default'); + $(p + 'layout a[data-val="' + r.layout + '"]') + .toggleClass('btn-primary btn-default'); + }); + + $(p + 'confirm').click(function() { + $(p + 'dialog').trigger({ + type: 'guff.save', + + post_data: { + layout: $(p + 'layout .btn-primary').data('val'), + }, + }); + + // stop event + return false; }); }); diff --git a/data/assets/js/admin/dialogs/post-edit.js b/data/assets/js/admin/dialogs/post-edit.js index 31b85ee..01baba1 100644 --- a/data/assets/js/admin/dialogs/post-edit.js +++ b/data/assets/js/admin/dialogs/post-edit.js @@ -8,7 +8,7 @@ jQuery(function($) { if (slug.prop('disabled')) { slug.val( name.val().toLowerCase() - .replace(/[^a-z0-9_\.-]+/g, '-') + .replace(/[^a-z0-9_-]+/g, '-') .replace(/^-+|-+$/g, '') ); } @@ -17,9 +17,39 @@ jQuery(function($) { $.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'); + $(p + 'dialog').on('guff.loaded', function(ev) { + var r = ev.post_data, + slug_lock = (r.slug_lock == "1"); + + $(p + 'name').val(r.name); + $(p + 'slug').val(r.slug) + .prop('disabled', slug_lock ? 'disabled' : null); + + $(p + 'slug-lock') + .toggleClass('btn-default', slug_lock) + .toggleClass('btn-primary', !slug_lock) + .find('fa') + .toggleClass('fa-lock', slug_lock) + .toggleClass('fa-unlock', !slug_lock); + + var editor = CKEDITOR.instances[id + '-edit-body']; + if (!editor) { + // lazy-init editor + editor = CKEDITOR.replace(id + '-edit-body'); + } + + if (editor.status == 'ready') { + // editor is ready, set body data + editor.setData(r.body); + } else { + editor.once('instanceReady', function() { + editor.setData(r.body); + }); + } + + $(p + 'state a').removeClass('btn-primary').addClass('btn-default'); + $(p + 'state a[data-val="' + r.state + '"]') + .toggleClass('btn-primary btn-default'); }).on('show.bs.modal', function() { var me = $(this); @@ -50,7 +80,7 @@ jQuery(function($) { me.find('.modal-body.loading-done').removeClass('hidden'); me.trigger({ - type: "post-data-loaded", + type: "guff.loaded", post_data: r, }); }); @@ -61,21 +91,40 @@ jQuery(function($) { $(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); - }); + }).on('guff.save', function(ev) { + $(p + 'confirm').addClass('disabled') + .find('.loading').toggleClass('hidden'); + + send(id + "/set", $.extend({ + post_id: $(p + 'dialog').data('post_id'), + name: $(p + 'name').val(), + slug_lock: $(p + 'slug-lock').hasClass('btn-default') ? 't' : 'f', + slug: $(p + 'slug').val(), + body: CKEDITOR.instances[id + '-edit-body'].getData(), + state: $(p + 'state .btn-primary').data('val'), + }, ev.post_data)).always(function() { + $(p + 'confirm').removeClass('disabled') + .find('.loading').toggleClass('hidden'); + }).fail(function(r) { + var error = r.responseText; - $(p + 'confirm').click(function() { - if ($(this).hasClass('disabled')) - return false; + try { + var data = $.parseJSON(r.responseText); + if (data.error) + error = data.error; + } catch (e) {} - // TODO: see #user-add-confirm - alert('TODO: create'); + alert('Error: ' + error); + }).done(function(r) { + // reload posts + $('#posts-reload').click(); - // stop event - return false; + // dismiss dialog + $(p + 'dialog').data('close-dialog-confirmed', true).modal('hide'); + }); + }).find('button[data-dismiss="modal"]').click(function() { + // override close confirmation dialog + $(p + 'dialog').data('close-dialog-confirmed', true); }); }); @@ -109,8 +158,9 @@ jQuery(function($) { return false; }); - $('.state-buttons').on('a', 'click', function() { - $(this).parent().find('.btn-primary').toggleClass('btn-default btn-primary'); + $('.state-buttons a').click(function() { + $(this).parent().find('.btn-primary') + .toggleClass('btn-default btn-primary'); $(this).toggleClass('btn-default btn-primary'); // stop event diff --git a/data/assets/js/admin/dialogs/project-edit.js b/data/assets/js/admin/dialogs/project-edit.js index a31abf2..17236f6 100644 --- a/data/assets/js/admin/dialogs/project-edit.js +++ b/data/assets/js/admin/dialogs/project-edit.js @@ -1,7 +1,24 @@ jQuery(function($) { "use strict"; - $('#project-edit-dialog').on('post-data-loaded', function(r) { - console.log(r); + var p = '#project-edit-'; + + $(p + 'dialog').on('guff.loaded', function(ev) { + var r = ev.post_data; + + $(p + 'repo').val(r.repo_url); + }); + + $(p + 'confirm').click(function() { + $(p + 'dialog').trigger({ + type: 'guff.save', + + post_data: { + repo_url: $(p + 'repo').val(), + }, + }); + + // stop event + return false; }); }); diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js index 00117d6..03f3483 100644 --- a/data/assets/js/admin/tabs/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -2,122 +2,30 @@ jQuery(function($) { "use strict"; var TEMPLATES = new LuigiTemplate.Cache({ - user: [ - "<a ", - "href='#' ", - "class='list-group-item %{css|h}' ", - "title='Edit user \"%{user_name|h}\".' ", - "data-row='%{row|json|h}' ", - "data-q='%{q|h}' ", - ">", - "<i class='fa fa-fw fa-spinner fa-spin hidden loading'></i>", - "<i class='fa fa-fw fa-user loading'></i>", - " ", - "%{user_name|h} (%{email|h})", - - "<span class='badge pull-right'>", - "%{role_name|h}", - "</span>", - "</a>", - ], - - loading: [ - "<span class='list-group-item disabled'>", - "<i class='fa fa-spinner fa-spin'></i>", - " ", - "Loading...", - "</span>", - ], - - error: [ - "<span class='list-group-item list-group-item-danger disabled'>", - "<i class='fa fa-exclamation-triangle'></i>", - " ", - "Error: %{responseText|h}", - "</span>", - ], }); - function update_slug(name, slug) { - if (slug.prop('disabled')) { - slug.val( - name.val().toLowerCase() - .replace(/[^a-z0-9_\.-]+/g, '-') - .replace(/^-+|-+$/g, '') - ); - } - } + $('.add-post').click(function() { + var type = $(this).data('type'); - $.each(['blog', 'page', 'project'], function(i, id) { - var p = '#' + id + '-edit-'; + // dismiss dropdown + $('body').trigger('click'); - $(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); - - // hide all bodies - $(this).find('.modal-body').addClass('hidden'); - }).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); - }); + send(type + '/add').fail(function(r) { + var msg = r.responseText; - $(p + 'confirm').click(function() { - if ($(this).hasClass('disabled')) - return false; + try { + var data = $.parseJSON(r); + if (data.error) + msg = data.error; + } catch (e) {} - // TODO: see #user-add-confirm - alert('TODO: create'); + alert('Error: ' + msg); + }).done(function(r) { + console.log(r); - // stop event - return false; + // show edit dialog + $('#' + type + '-edit-dialog').data('post_id', r.post_id).modal('show') }); - }); - - $('.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; |