From: Aleksander Ɓukasz Date: Thu, 25 Apr 2013 19:55:45 +0000 (+0200) Subject: Visual editor - tweaking saving document ui & behavior X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/4ae1d665fcd3af9fb06d664418f02f365933d9ae?hp=1dcf69f7caa40430482c79f46c5478f84f6afc0a Visual editor - tweaking saving document ui & behavior - save button instead of a link - simple message on saving --- diff --git a/editor.css b/editor.css index c587b50..a8470f7 100644 --- a/editor.css +++ b/editor.css @@ -11,10 +11,28 @@ body { display: none; } +#rng-skelton { + position: relative; +} + #rng-skelton-menu { float: right; } +#rng-skelton-messages { + position: absolute; + top: -22px; + width:100%; + text-align:center; +} + +#rng-skelton-messages span { + font-weight: bold; + background: #f9edbe; + padding: 2px 5px; + border: solid 1px #f6e39c; +} + #rng-skelton-menu ul { list-style-type: none; } diff --git a/modules/data.js b/modules/data.js index 5f3fd39..7a59cfb 100644 --- a/modules/data.js +++ b/modules/data.js @@ -52,10 +52,13 @@ rng.modules.data = function(sandbox) { sandbox.publish('documentChanged', doc, reason); }, saveDocument: function() { + sandbox.publish('savingStarted'); $.ajax({ method: 'post', url: '/' + gettext('editor') + '/' + document_id, - data: JSON.stringify({document:doc}) + data: JSON.stringify({document:doc}), + success: function() {sandbox.publish('savingEnded', 'success');}, + error: function() {sandbox.publish('savingEnded', 'error');} }); } diff --git a/modules/rng.js b/modules/rng.js index 0a39ed8..36bd2f8 100644 --- a/modules/rng.js +++ b/modules/rng.js @@ -70,6 +70,14 @@ rng.modules.rng = function(sandbox) { documentChanged: function(document, reason) { var slug = (reason === 'visual_edit' ? 'source' : 'visual'); sandbox.getModule(slug+'Editor').setDocument(document); + }, + savingStarted: function() { + sandbox.getModule('skelton').deactivateCommand('save'); + sandbox.getModule('skelton').showMessage(gettext('Saving...')); + }, + savingEnded: function(status) { + sandbox.getModule('skelton').activateCommand('save'); + sandbox.getModule('skelton').clearMessage(); } } diff --git a/modules/skelton.js b/modules/skelton.js index 0e6749a..3141459 100644 --- a/modules/skelton.js +++ b/modules/skelton.js @@ -2,7 +2,7 @@ rng.modules.skelton = function(sandbox) { var view = $(sandbox.getTemplate('main')()); - view.find('#rng-skelton-menu a').click(function(e) { + view.find('#rng-skelton-menu button').click(function(e) { e.preventDefault(); sandbox.publish('cmd.' + $(e.target).attr('data-cmd')); }); @@ -14,6 +14,18 @@ rng.modules.skelton = function(sandbox) { }, setMainView: function(mainView) { view.find('#rng-skelton-mainView').html(mainView); + }, + showMessage: function(message) { + view.find('#rng-skelton-messages').html(''+message+'').show(); + }, + clearMessage: function() { + view.find('#rng-skelton-messages').empty().hide(); + }, + deactivateCommand: function(cmd) { + view.find('[data-cmd='+cmd+']').addClass('disabled'); + }, + activateCommand: function(cmd) { + view.find('[data-cmd='+cmd+']').removeClass('disabled'); } } }; \ No newline at end of file