diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-07-30 18:40:08 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-07-30 18:40:08 -0400 |
commit | bb2a315df93c173db84d2d6fc0cf1b2bdbd931a7 (patch) | |
tree | 831f46bd240348af1df70eb0abf98bb92b360f3e /data/assets/js/admin/dialogs/site-add.js | |
parent | 9cec164e724465c11ff91772cdad3126de663ade (diff) | |
download | guff-bb2a315df93c173db84d2d6fc0cf1b2bdbd931a7.tar.bz2 guff-bb2a315df93c173db84d2d6fc0cf1b2bdbd931a7.zip |
refactor site dialogs and add site editing
Diffstat (limited to 'data/assets/js/admin/dialogs/site-add.js')
-rw-r--r-- | data/assets/js/admin/dialogs/site-add.js | 93 |
1 files changed, 14 insertions, 79 deletions
diff --git a/data/assets/js/admin/dialogs/site-add.js b/data/assets/js/admin/dialogs/site-add.js index bf95b8e..2d96c9f 100644 --- a/data/assets/js/admin/dialogs/site-add.js +++ b/data/assets/js/admin/dialogs/site-add.js @@ -1,85 +1,20 @@ jQuery(function($) { "use strict"; - var p = '#site-add-'; - - var FIELDS = { - text: ['name', 'slug', 'body', 'lang', 'theme_id'], - list: ['domains', 'styles', 'scripts'], - } - - var DEFAULTS = { - lang: DATA.default_lang, - theme_id: DATA.default_theme_id, - }; - - $(p + 'dialog').on('show.bs.modal', function() { - $.each(FIELDS.text, function(_, id) { - $(p + id).val(DEFAULTS[id] || ''); + // cache fields + var FIELDS = DATA.site_dialogs.fields; + + $('#site-add-dialog').on('show.bs.modal', function() { + $(this).trigger({ + type: 'guff.loaded', + + site_data: FIELDS.text.reduce(function(r, id) { + r[id] = FIELDS.defaults[id] || ''; + return r; + }, FIELDS.list.reduce(function(r, id) { + r[id] = []; + return r; + }, {})), }); - - // clear list textareas - $.each(FIELDS.list, function(_, id) { - $(p + id).val(''); - }); - }); - - $(p + 'dialog').on('shown.bs.modal', function() { - // show content tab - $(p + 'tab-content').click(); - - // focus name field - $(p + 'name').focus(); - }); - - $(p + 'dialog input[type="text"]').keydown(function(ev) { - if (ev.which == 13) { - setTimeout(function() { - $(p + 'confirm').click(); - }, 10); - - // stop event - return false; - } - }); - - $(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')) - return false; - - // toggle loading - me.toggleClass('disabled').find('.loading').toggleClass('hidden'); - - send('site/add', FIELDS.text.reduce(function(r, id) { - r[id] = $(p + id).val(); - return r; - }, FIELDS.list.reduce(function(r, id) { - r[id] = listify(p + id); - return r; - }, { - // hard-code this for now - is_full_feed: 't', - }))).always(function() { - // toggle loading - me.toggleClass('disabled').find('.loading').toggleClass('hidden'); - }).fail(function(r) { - gripe(r, 'add site'); - }).done(function(r) { - $('#sites-reload').click(); - $(p + 'dialog').modal('hide'); - }); - - // stop event - return false; }); }); |