diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-07-30 14:21:14 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-07-30 14:21:14 -0400 |
commit | e6ebc011f255596f09fec40f69049514d52bebef (patch) | |
tree | 20685173557726f1f470a7f40321281e1347d4eb /data/assets/js/admin/dialogs/site-add.js | |
parent | b0083827f30fccc9aabcabed0557ace83d570b8c (diff) | |
download | guff-e6ebc011f255596f09fec40f69049514d52bebef.tar.bz2 guff-e6ebc011f255596f09fec40f69049514d52bebef.zip |
add tabs to site-add, refactor textarea handling, and fix site_id post edit dialogs
Diffstat (limited to 'data/assets/js/admin/dialogs/site-add.js')
-rw-r--r-- | data/assets/js/admin/dialogs/site-add.js | 43 |
1 files changed, 26 insertions, 17 deletions
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 |