From: Aleksander Ɓukasz Date: Thu, 13 Jun 2013 12:51:33 +0000 (+0200) Subject: history wip: Updating history list after saving document X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/cb800d0ee02280d6e2663cf0524fb74681c8173e?hp=e6e83eed52400d6e8a6ee6339cbe212c8cac1f90 history wip: Updating history list after saving document --- diff --git a/modules/data.js b/modules/data.js index df40322..33c8df6 100644 --- a/modules/data.js +++ b/modules/data.js @@ -43,6 +43,17 @@ return function(sandbox) { } }); + var reloadHistory = function() { + $.ajax({ + method: 'get', + url: '/' + gettext('editor') + '/' + document_id + '/history', + success: function(data) { + history = data; + sandbox.publish('historyItemAdded', data.slice(-1)[0]); + }, + }); + } + return { start: function() { sandbox.publish('ready'); @@ -60,7 +71,7 @@ return function(sandbox) { method: 'post', url: '/' + gettext('editor') + '/' + document_id, data: JSON.stringify({document:doc}), - success: function() {sandbox.publish('savingEnded', 'success');}, + success: function() {sandbox.publish('savingEnded', 'success'); reloadHistory();}, error: function() {sandbox.publish('savingEnded', 'error');} }); }, diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js index 05cddbc..c90c879 100644 --- a/modules/documentHistory/documentHistory.js +++ b/modules/documentHistory/documentHistory.js @@ -19,7 +19,7 @@ return function(sandbox) { historyItems.add(item); var view = new itemView(item); itemViews.push(view); - domNodes.itemList.append(view.dom); + domNodes.itemList.prepend(view.dom); } var toggleItemViews = function(toggle) { @@ -81,7 +81,7 @@ return function(sandbox) { return { start: function() { sandbox.publish('ready'); }, - setHistory: function(history) { + addHistory: function(history) { history.forEach(function(historyItem) { addHistoryItem(historyItem); }); diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 3f89cd7..fe666e0 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -130,6 +130,9 @@ return function(sandbox) { savingEnded: function(status) { sandbox.getModule('mainBar').setCommandEnabled('save', true); sandbox.getModule('indicator').clearMessage(); + }, + historyItemAdded: function(item) { + sandbox.getModule('documentHistory').addHistory([item]); } } @@ -248,7 +251,7 @@ return function(sandbox) { eventHandlers.documentHistory = { ready: function() { - sandbox.getModule('documentHistory').setHistory(sandbox.getModule('data').getHistory()); + sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory()); addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView()); } }