sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2})\r
},\r
});\r
+ },\r
+ restoreVersion: function(options) {\r
+ if(options.version && options.description) {\r
+ sandbox.publish('restoringStarted', {version: options.version});\r
+ $.ajax({\r
+ method: 'post',\r
+ dataType: 'json',\r
+ url: '/' + gettext('editor') + '/' + document_id + '/revert',\r
+ data: JSON.stringify(options),\r
+ success: function(data) {\r
+ doc = data.document;\r
+ reloadHistory();\r
+ sandbox.publish('documentReverted', {document: data.document, version: data.version});\r
+ },\r
+ }); \r
+ }\r
}\r
}\r
};\r
define([\r
'libs/jquery-1.9.1.min',\r
'libs/underscore-min',\r
+'./restoreDialog',\r
'libs/text!./templates/main.html',\r
'libs/text!./templates/item.html'\r
-], function($, _, mainTemplateSrc, itemTemplateSrc) {\r
+], function($, _, restoreDialog, mainTemplateSrc, itemTemplateSrc) {\r
\r
'use strict';\r
\r
var selected = historyItems.getSelected();\r
sandbox.publish('compare', selected[0], selected[1]);\r
});\r
+ \r
+ dom.find('.btn.restore').click(function(e) {\r
+ var dialog = restoreDialog.create();\r
+ dialog.on('restore', function(event) {\r
+ sandbox.publish('restoreVersion', {version: historyItems.getSelected()[0], description: event.data.description});\r
+ event.success();\r
+ });\r
+ dialog.show();\r
+ });\r
\r
var addHistoryItem = function(item, options) {\r
historyItems.add(item);\r
--- /dev/null
+define([\r
+'libs/text!./templates/restoreDialog.html',\r
+'libs/underscore-min',\r
+'libs/backbone-min',\r
+'libs/jquery-1.9.1.min'\r
+], function(restoreDialogTemplate, _, Backbone, $) {\r
+\r
+ var DialogView = Backbone.View.extend({\r
+ template: _.template(restoreDialogTemplate),\r
+ events: {\r
+ 'click .restore-btn': 'onSave',\r
+ 'click .cancel-btn': 'close',\r
+ 'click .close': 'close'\r
+ },\r
+ initialize: function() {\r
+ _.bindAll(this);\r
+ this.actionsDisabled = false;\r
+ },\r
+ show: function() { \r
+ this.setElement(this.template());\r
+ this.$el.modal({backdrop: 'static'});\r
+ this.$el.modal('show');\r
+\r
+ },\r
+ onSave: function(e) {\r
+ e.preventDefault();\r
+ var view = this;\r
+ this.trigger('restore', {\r
+ data: {description: view.$el.find('textarea').val()},\r
+ success: function() { view.actionsDisabled = false; view.close(); },\r
+ error: function() { view.actionsDisabled = false; view.close(); },\r
+ })\r
+ },\r
+ close: function(e) {\r
+ if(e)\r
+ e.preventDefault();\r
+ if(!this.actionsDisabled) {\r
+ this.$el.modal('hide');\r
+ this.$el.remove();\r
+ }\r
+ },\r
+ toggleButtons: function(toggle) {\r
+ this.$('.btn, button').toggleClass('disabled', !toggle);\r
+ this.$('textarea').attr('disabled', !toggle);\r
+ this.actionsDisabled = !toggle;\r
+ }\r
+ });\r
+\r
+ return {\r
+ create: function() {\r
+ return new DialogView();\r
+ }\r
+ }\r
+\r
+});
\ No newline at end of file
--- /dev/null
+<div class="rng-module-data-saveDialog modal hide static">\r
+ <div class="modal-header">\r
+ <button type="button" class="close">×</button>\r
+ <h1>Przywróć wersję</h1>\r
+ </div>\r
+ <div class="modal-body">\r
+ <label>Opisz powód przywrócenia</label>\r
+ <textarea rows="5"></textarea>\r
+ </div>\r
+ <div class="modal-footer">\r
+ <a href="#" class="btn btn-info btn-mini restore-btn">Przywróć</a>\r
+ <a href="#" class="btn btn-danger btn-mini cancel-btn">Anuluj</a>\r
+ </div>\r
+</div>
\ No newline at end of file
sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);\r
sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);\r
\r
+ },\r
+ resetDocument: function(document, reason) {\r
+ var modules = [];\r
+ if(reason === 'source_edit')\r
+ modules = ['documentCanvas', 'metadataEditor'];\r
+ else if (reason === 'edit')\r
+ modules = ['sourceEditor'];\r
+ else if (reason === 'revert')\r
+ modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];\r
+ \r
+ modules.forEach(function(moduleName) {\r
+ sandbox.getModule(moduleName).setDocument(document);\r
+ });\r
}\r
}\r
\r
});\r
},\r
documentChanged: function(document, reason) {\r
- var modules = [];\r
- if(reason === 'source_edit')\r
- modules = ['documentCanvas', 'metadataEditor'];\r
- else if (reason === 'edit')\r
- modules = ['sourceEditor'];\r
- \r
- modules.forEach(function(moduleName) {\r
- sandbox.getModule(moduleName).setDocument(document);\r
- });\r
+ commands.resetDocument(document, reason);\r
},\r
savingStarted: function() {\r
sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});\r
},\r
+ restoringStarted: function(event) {\r
+ sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
+ sandbox.getModule('indicator').showMessage(gettext('Restoring version ' + event.version + '...'));\r
+ },\r
historyItemAdded: function(item) {\r
sandbox.getModule('documentHistory').addHistory([item], {animate: true});\r
},\r
diffFetched: function(diff) {\r
sandbox.getModule('diffViewer').setDiff(diff);\r
+ },\r
+ documentReverted: function(event) {\r
+ commands.resetDocument(event.document, 'revert');\r
+ sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
+ sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.version + ' przywrócona'});\r
}\r
}\r
\r
},\r
compare: function(ver1, ver2) {\r
sandbox.getModule('data').fetchDiff(ver1, ver2);\r
+ },\r
+ restoreVersion: function(event) {\r
+ sandbox.getModule('data').restoreVersion(event);\r
}\r
}\r
\r