From b0083827f30fccc9aabcabed0557ace83d570b8c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 30 Jul 2016 05:32:26 -0400 Subject: add sites list and site-add dialog --- data/assets/css/admin.css | 4 ++ data/assets/js/admin/dialogs/site-add.js | 67 ++++++++++++++++++++++++++++++++ data/assets/js/admin/tabs/posts.js | 1 + data/assets/js/admin/tabs/sites.js | 2 +- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 data/assets/js/admin/dialogs/site-add.js (limited to 'data/assets') diff --git a/data/assets/css/admin.css b/data/assets/css/admin.css index 60b0afd..ba65585 100644 --- a/data/assets/css/admin.css +++ b/data/assets/css/admin.css @@ -7,6 +7,10 @@ height: 20vh; } +#site-add-domains { + min-height: 100px; +} + #project-edit-releases { height: 40vh; overflow: auto; 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; + }); +}); diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js index 25f659e..38fd094 100644 --- a/data/assets/js/admin/tabs/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -111,6 +111,7 @@ jQuery(function($) { send('post/get_posts', { type: $('#posts-filter-type li.active a').data('id'), state: $('#posts-filter-state li.active a').data('id'), + site_id: $('#posts-filter-site li.active a').data('id'), user_id: $('#posts-filter-user li.active a').data('id'), q: $('#posts-q').data('q'), page: 1, diff --git a/data/assets/js/admin/tabs/sites.js b/data/assets/js/admin/tabs/sites.js index 9ef9564..8644705 100644 --- a/data/assets/js/admin/tabs/sites.js +++ b/data/assets/js/admin/tabs/sites.js @@ -85,7 +85,7 @@ jQuery(function($) { return TEMPLATES.run('site', $.extend({}, row, { q: [row.site_id, row.slug, row.name, row.body].join(' ').toLowerCase(), - badge_css: row.is_default ? '' : 'hidden', + badge_css: +row.is_default ? '' : 'hidden', })); }).join('')); -- cgit v1.2.3