}\r
});\r
\r
+ var reloadHistory = function() {\r
+ $.ajax({\r
+ method: 'get',\r
+ url: '/' + gettext('editor') + '/' + document_id + '/history',\r
+ success: function(data) {\r
+ history = data; \r
+ sandbox.publish('historyItemAdded', data.slice(-1)[0]);\r
+ },\r
+ });\r
+ }\r
+ \r
return {\r
start: function() {\r
sandbox.publish('ready');\r
method: 'post',\r
url: '/' + gettext('editor') + '/' + document_id,\r
data: JSON.stringify({document:doc}),\r
- success: function() {sandbox.publish('savingEnded', 'success');},\r
+ success: function() {sandbox.publish('savingEnded', 'success'); reloadHistory();},\r
error: function() {sandbox.publish('savingEnded', 'error');}\r
});\r
},\r
historyItems.add(item);\r
var view = new itemView(item);\r
itemViews.push(view);\r
- domNodes.itemList.append(view.dom);\r
+ domNodes.itemList.prepend(view.dom);\r
}\r
\r
var toggleItemViews = function(toggle) {\r
\r
return {\r
start: function() { sandbox.publish('ready'); },\r
- setHistory: function(history) {\r
+ addHistory: function(history) {\r
history.forEach(function(historyItem) {\r
addHistoryItem(historyItem);\r
});\r
savingEnded: function(status) {\r
sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
sandbox.getModule('indicator').clearMessage();\r
+ },\r
+ historyItemAdded: function(item) {\r
+ sandbox.getModule('documentHistory').addHistory([item]);\r
}\r
}\r
\r
\r
eventHandlers.documentHistory = {\r
ready: function() {\r
- sandbox.getModule('documentHistory').setHistory(sandbox.getModule('data').getHistory());\r
+ sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());\r
addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView());\r
}\r
}\r