From cb93a9925be700e5e1b0314f6cf66b19e7da5a34 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 11 May 2015 17:42:06 +0200 Subject: adds a simple publish status UI to show errors --- public/editor/editor.js | 59 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'public/editor/editor.js') diff --git a/public/editor/editor.js b/public/editor/editor.js index a0873d6..08c09b0 100644 --- a/public/editor/editor.js +++ b/public/editor/editor.js @@ -31,7 +31,13 @@ $(function () { }); $.post('/editor/test-login', {}, function(response) { - $('#publish_btn span').text(response.logged_in ? 'Publish' : 'Sign In'); + if(response.logged_in) { + $('.publish-dropdown .action-publish').removeClass('hidden'); + $('.publish-dropdown .action-signin').addClass('hidden'); + } else { + $('.publish-dropdown .action-publish').addClass('hidden'); + $('.publish-dropdown .action-signin').removeClass('hidden'); + } }); $('#publish_btn').click(function(){ @@ -42,28 +48,43 @@ $(function () { } }); - $('#--publish_btn').click(function(){ - if($('#publish_btn span').text() == 'Publish') { - - $.post('/editor/publish', { - name: $("#post-name").val(), - body: editor.serialize().content.value - }, function(response) { - if(response.location) { - reset_page().then(function(){ - window.location = response.location; - }); - } - }); + $('#new_btn').click(function(){ + if(confirm('This will discard your current post. Are you sure?')) { + reset_page(); + } + }); - } else { - var url = prompt("Enter your URL"); - window.location = '/auth/start?me=' + encodeURIComponent(url) + '&redirect=/editor'; + $('#signin-domain').on('keydown', function(e){ + if(e.keyCode == 13) { + $('#signin-btn').click(); } }); + $('#signin-btn').click(function(){ + window.location = '/auth/start?me=' + encodeURIComponent($('#signin-domain').val()) + '&redirect=/editor'; + }); + $('#publish-confirm').click(function(){ + $('#publish-help').addClass('hidden'); + $('#publish-in-progress').removeClass('hidden'); - $('#new_btn').click(function(){ - reset_page(); + $.post('/editor/publish', { + name: $("#post-name").val(), + body: editor.serialize().content.value + }, function(response) { + if(response.location) { + reset_page().then(function(){ + $('#publish-success-url').attr('href', response.location); + $('#publish-in-progress').addClass('hidden'); + $('#publish-error-debug').html('').addClass('hidden'); + $('#publish-error').addClass('hidden'); + $('#publish-success').removeClass('hidden'); + }); + } else { + $('#publish-in-progress').addClass('hidden'); + $('#publish-error-debug').html(response.response).removeClass('hidden'); + $('#publish-error').removeClass('hidden'); + $('#publish-success').addClass('hidden'); + } + }); }); }); -- cgit v1.2.3