X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f2b74d1a157449d5fc89d37680d95737ef8eb3b8..5e64f92aabe77137fde16fa8aab604fe1fce5f62:/modules/documentHistory/documentHistory.js diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js index 2c3a3b6..d435617 100644 --- a/modules/documentHistory/documentHistory.js +++ b/modules/documentHistory/documentHistory.js @@ -1,9 +1,10 @@ define([ 'libs/jquery-1.9.1.min', 'libs/underscore-min', +'./restoreDialog', 'libs/text!./templates/main.html', 'libs/text!./templates/item.html' -], function($, _, mainTemplateSrc, itemTemplateSrc) { +], function($, _, restoreDialog, mainTemplateSrc, itemTemplateSrc) { 'use strict'; @@ -14,6 +15,25 @@ return function(sandbox) { itemList: dom.find('.rng-module-documentHistory-itemsList'), } var itemViews = []; + + + dom.find('.btn.compare').click(function(e) { + var selected = historyItems.getSelected(); + sandbox.publish('compare', selected[0], selected[1]); + }); + + dom.find('.btn.restore').click(function(e) { + var dialog = restoreDialog.create(); + dialog.on('restore', function(event) { + sandbox.publish('restoreVersion', {version: historyItems.getSelected()[0], description: event.data.description}); + event.success(); + }); + dialog.show(); + }); + + dom.find('.btn.display').click(function(e) { + sandbox.publish('displayVersion', {version: historyItems.getSelected()[0]}); + }); var addHistoryItem = function(item, options) { historyItems.add(item); @@ -27,7 +47,7 @@ return function(sandbox) { var toggleItemViews = function(toggle) { itemViews.forEach(function(view) { - if(!historyItems.selected(view.item)) + if(!historyItems.isSelected(view.item)) view.toggle(toggle); }); } @@ -54,26 +74,31 @@ return function(sandbox) { add: function(item) { this._itemsById[item.version] = item; }, - selected: function(item) { + isSelected: function(item) { return _.contains(this._selected, item.version); }, + getSelected: function() { + return this._selected; + }, _updateUI: function() { var len = this._selected.length; if(len === 0) { toggleButton('compare', false); - toggleButton('show2', false); + toggleButton('display', false); toggleButton('restore', false); } if(len === 1) { toggleButton('compare', false); - toggleButton('show2', true); + toggleButton('display', true); toggleButton('restore', true); } if(len === 2) { toggleItemViews(false); toggleButton('compare', true); - toggleButton('show2', false); + toggleButton('display', false); toggleButton('restore', false); + } else { + toggleItemViews(true); } } }; @@ -86,7 +111,7 @@ return function(sandbox) { }; itemView.prototype.template = _.template(itemTemplateSrc); itemView.prototype.onItemClicked = function() { - if(historyItems.selected(this.item)) { + if(historyItems.isSelected(this.item)) { historyItems.unselect(this.item); this.dimItem(); } else if(historyItems.select(this.item)) {