From e6ebc011f255596f09fec40f69049514d52bebef Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 30 Jul 2016 14:21:14 -0400 Subject: add tabs to site-add, refactor textarea handling, and fix site_id post edit dialogs --- data/assets/js/admin/dialogs/page-edit.js | 4 +-- data/assets/js/admin/dialogs/post-edit.js | 11 +++----- data/assets/js/admin/dialogs/site-add.js | 43 +++++++++++++++++++------------ 3 files changed, 31 insertions(+), 27 deletions(-) (limited to 'data/assets/js/admin/dialogs') diff --git a/data/assets/js/admin/dialogs/page-edit.js b/data/assets/js/admin/dialogs/page-edit.js index 9e32d89..0e7a5b3 100644 --- a/data/assets/js/admin/dialogs/page-edit.js +++ b/data/assets/js/admin/dialogs/page-edit.js @@ -22,9 +22,7 @@ jQuery(function($) { // get assets var assets = ASSET_TYPES.reduce(function(r, key) { - var s = $(p + key).val().replace(/^\s+|\s$/mg, ''); - r[key] = JSON.stringify((s.length > 0) ? s.split(/\s+/m) : []); - + r[key] = listify(p + key); return r; }, {}); diff --git a/data/assets/js/admin/dialogs/post-edit.js b/data/assets/js/admin/dialogs/post-edit.js index 9d90b99..d7eb120 100644 --- a/data/assets/js/admin/dialogs/post-edit.js +++ b/data/assets/js/admin/dialogs/post-edit.js @@ -5,13 +5,8 @@ jQuery(function($) { }); function update_slug(name, slug) { - if (slug.prop('disabled')) { - slug.val( - name.val().toLowerCase() - .replace(/[^a-z0-9_-]+/g, '-') - .replace(/^-+|-+$/g, '') - ); - } + if (slug.prop('disabled')) + slug.val(slugify(name.val())); } $.each(['blog', 'page', 'project'], function(i, id) { @@ -22,6 +17,7 @@ jQuery(function($) { slug_lock = (r.slug_lock == "1"); $(p + 'name').val(r.name); + $(p + 'site').val(r.site_id); $(p + 'slug').val(r.slug) .prop('disabled', slug_lock ? 'disabled' : null); @@ -100,6 +96,7 @@ jQuery(function($) { send(id + "/set", $.extend({ post_id: $(p + 'dialog').data('post_id'), + site_id: $(p + 'site').val(), name: $(p + 'name').val(), slug_lock: $(p + 'slug-lock').hasClass('btn-default') ? 't' : 'f', slug: $(p + 'slug').val(), diff --git a/data/assets/js/admin/dialogs/site-add.js b/data/assets/js/admin/dialogs/site-add.js index 9a3c02f..8cdc772 100644 --- a/data/assets/js/admin/dialogs/site-add.js +++ b/data/assets/js/admin/dialogs/site-add.js @@ -1,34 +1,35 @@ jQuery(function($) { "use strict"; - var IDS = ['name', 'slug', 'body', 'lang', 'theme_id']; + var p = '#site-add-', + IDS = ['name', 'slug', 'body', 'lang', 'theme_id']; + var DEFAULTS = { lang: DATA.default_lang, theme_id: DATA.default_theme_id, }; - function get_domains() { - var r = $('#site-add-domains').val().replace(/^\s+|\s+$/m, ''); - return (r.length > 0) ? r.split(/\s+/m) : []; - } - - $('#site-add-dialog').on('show.bs.modal', function() { + $(p + 'dialog').on('show.bs.modal', function() { $.each(IDS, function(_, id) { - $('#site-add-' + id).val(DEFAULTS[id] || ''); + $(p + id).val(DEFAULTS[id] || ''); }); // clear list of domains - $('#site-add-domains').val(''); + $(p + 'domains').val(''); }); - $('#site-add-dialog').on('shown.bs.modal', function() { - $('#site-add-name').focus(); + $(p + 'dialog').on('shown.bs.modal', function() { + // show content tab + $(p + 'tab-content').click(); + + // focus name field + $(p + 'name').focus(); }); - $('#site-add-dialog input[type="text"]').keydown(function(ev) { + $(p + 'dialog input[type="text"]').keydown(function(ev) { if (ev.which == 13) { setTimeout(function() { - $('#site-add-confirm').click(); + $(p + 'confirm').click(); }, 10); // stop event @@ -36,7 +37,15 @@ jQuery(function($) { } }); - $('#site-add-confirm').click(function() { + $(p + 'name').keydown(function(ev) { + var me = $(this); + + setTimeout(function() { + $(p + 'slug').val(slugify(me.val())); + }, 10); + }); + + $(p + 'confirm').click(function() { var me = $(this); if (me.hasClass('disabled')) @@ -46,11 +55,11 @@ jQuery(function($) { me.toggleClass('disabled').find('.loading').toggleClass('hidden'); send('site/add', IDS.reduce(function(r, id) { - r[id] = $('#site-add-' + id).val(); + r[id] = $(p + id).val(); return r; }, { is_full_feed: 't', - domains: JSON.stringify(get_domains()), + domains: listify(p + 'domains'), })).always(function() { // toggle loading me.toggleClass('disabled').find('.loading').toggleClass('hidden'); @@ -58,7 +67,7 @@ jQuery(function($) { gripe(r, 'add site'); }).done(function(r) { $('#sites-reload').click(); - $('#site-add-dialog').modal('hide'); + $(p + 'dialog').modal('hide'); }); // stop event -- cgit v1.2.3