From cb800d0ee02280d6e2663cf0524fb74681c8173e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 13 Jun 2013 14:51:33 +0200 Subject: [PATCH] history wip: Updating history list after saving document --- modules/data.js | 13 ++++++++++++- modules/documentHistory/documentHistory.js | 4 ++-- modules/rng/rng.js | 5 ++++- 3 files changed, 18 insertions(+), 4 deletions(-) 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()); } } -- 2.20.1