diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-07-30 05:32:26 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-07-30 05:32:26 -0400 |
commit | b0083827f30fccc9aabcabed0557ace83d570b8c (patch) | |
tree | 71e0c356e6a8177a949856d8c9b21a8fe029130d /data/assets/js/admin/dialogs/site-add.js | |
parent | 9db15612b16b140bd7958be983d93de0b943cb01 (diff) | |
download | guff-b0083827f30fccc9aabcabed0557ace83d570b8c.tar.bz2 guff-b0083827f30fccc9aabcabed0557ace83d570b8c.zip |
add sites list and site-add dialog
Diffstat (limited to 'data/assets/js/admin/dialogs/site-add.js')
-rw-r--r-- | data/assets/js/admin/dialogs/site-add.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/data/assets/js/admin/dialogs/site-add.js b/data/assets/js/admin/dialogs/site-add.js new file mode 100644 index 0000000..9a3c02f --- /dev/null +++ b/data/assets/js/admin/dialogs/site-add.js @@ -0,0 +1,67 @@ +jQuery(function($) { + "use strict"; + + var 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() { + $.each(IDS, function(_, id) { + $('#site-add-' + id).val(DEFAULTS[id] || ''); + }); + + // clear list of domains + $('#site-add-domains').val(''); + }); + + $('#site-add-dialog').on('shown.bs.modal', function() { + $('#site-add-name').focus(); + }); + + $('#site-add-dialog input[type="text"]').keydown(function(ev) { + if (ev.which == 13) { + setTimeout(function() { + $('#site-add-confirm').click(); + }, 10); + + // stop event + return false; + } + }); + + $('#site-add-confirm').click(function() { + var me = $(this); + + if (me.hasClass('disabled')) + return false; + + // toggle loading + me.toggleClass('disabled').find('.loading').toggleClass('hidden'); + + send('site/add', IDS.reduce(function(r, id) { + r[id] = $('#site-add-' + id).val(); + return r; + }, { + is_full_feed: 't', + domains: JSON.stringify(get_domains()), + })).always(function() { + // toggle loading + me.toggleClass('disabled').find('.loading').toggleClass('hidden'); + }).fail(function(r) { + gripe(r, 'add site'); + }).done(function(r) { + $('#sites-reload').click(); + $('#site-add-dialog').modal('hide'); + }); + + // stop event + return false; + }); +}); |