X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f61fd6fa1d5871782b079ee50fb6bb10777cadc2..969f365b3ee6d3cb54f98b23e1ebb97df9f801dd:/modules/documentHistory/documentHistory.js diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js index 0693469..2647ee3 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'; @@ -12,7 +13,7 @@ return function(sandbox) { var dom = $(_.template(mainTemplateSrc)()); var domNodes = { itemList: dom.find('.rng-module-documentHistory-itemsList'), - } + }; var itemViews = []; @@ -20,6 +21,19 @@ return function(sandbox) { 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); @@ -29,18 +43,18 @@ return function(sandbox) { if(options.animate) { view.dom.hide().slideDown(); } - } + }; var toggleItemViews = function(toggle) { itemViews.forEach(function(view) { if(!historyItems.isSelected(view.item)) view.toggle(toggle); }); - } + }; var toggleButton = function(btn, toggle) { dom.find('button.'+btn).toggleClass('disabled', !toggle); - } + }; var historyItems = { _itemsById: {}, @@ -70,18 +84,18 @@ return function(sandbox) { 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); @@ -126,7 +140,7 @@ return function(sandbox) { getView: function() { return dom; } - } -} + }; +}; }); \ No newline at end of file