diff options
Diffstat (limited to 'data/assets/js/admin/dialogs/site.js')
-rw-r--r-- | data/assets/js/admin/dialogs/site.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/data/assets/js/admin/dialogs/site.js b/data/assets/js/admin/dialogs/site.js new file mode 100644 index 0000000..e35d389 --- /dev/null +++ b/data/assets/js/admin/dialogs/site.js @@ -0,0 +1,94 @@ +jQuery(function($) { + "use strict"; + + // cache dialogs + var DIALOGS = DATA.site_dialogs; + + $.each(DIALOGS.paths, function(dialog_id, save_path) { + var p = '#site-' + dialog_id + '-'; + + $(p + 'dialog').on('show.bs.modal', function() { + var me = $(this); + + // show spinner + me.find('.modal-body').addClass('hidden'); + me.find('.modal-body.loading').removeClass('hidden'); + }).on('guff.loaded', function(ev) { + // populate text fields + $.each(DIALOGS.fields.text, function(_, id) { + $(p + id).val(ev.site_data[id]); + }); + + // populate textareas + $.each(DIALOGS.fields.list, function(_, id) { + $(p + id).val(ev.site_data[id].join("\n")); + }); + + // hide spinner, show body + $(this).find('.modal-body').toggleClass('hidden'); + }).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'); + + // build args + var args = DIALOGS.fields.text.reduce(function(r, id) { + r[id] = $(p + id).val(); + return r; + }, DIALOGS.fields.list.reduce(function(r, id) { + r[id] = listify(p + id); + return r; + }, { + site_id: $(p + 'dialog').data('site_id'), + + // hard-code this for now + is_full_feed: 't', + })); + + // send request + send(save_path, args).always(function() { + // toggle loading + me.toggleClass('disabled').find('.loading').toggleClass('hidden'); + }).fail(function(r) { + gripe(r, dialog_id + ' site'); + }).done(function(r) { + $('#sites-reload').click(); + $(p + 'dialog').modal('hide'); + }); + + // stop event + return false; + }); + }); +}); |