Some code improvements suggested by linter
[fnpeditor.git] / modules / documentHistory / documentHistory.js
index 0693469..2647ee3 100644 (file)
@@ -1,9 +1,10 @@
 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
@@ -12,7 +13,7 @@ return function(sandbox) {
     var dom = $(_.template(mainTemplateSrc)());\r
     var domNodes = {\r
         itemList: dom.find('.rng-module-documentHistory-itemsList'),\r
-    }\r
+    };\r
     var itemViews = [];\r
     \r
     \r
@@ -20,6 +21,19 @@ return function(sandbox) {
         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
+    dom.find('.btn.display').click(function(e) {\r
+        sandbox.publish('displayVersion', {version: historyItems.getSelected()[0]});\r
+    });\r
         \r
     var addHistoryItem = function(item, options) {\r
         historyItems.add(item);\r
@@ -29,18 +43,18 @@ return function(sandbox) {
         if(options.animate) {\r
             view.dom.hide().slideDown();\r
         }\r
-    }\r
+    };\r
     \r
     var toggleItemViews = function(toggle) {\r
         itemViews.forEach(function(view) {\r
             if(!historyItems.isSelected(view.item))\r
                 view.toggle(toggle);\r
         });\r
-    }\r
+    };\r
     \r
     var toggleButton = function(btn, toggle) {\r
         dom.find('button.'+btn).toggleClass('disabled', !toggle);\r
-    }\r
+    };\r
     \r
     var historyItems = {\r
         _itemsById: {},\r
@@ -70,18 +84,18 @@ return function(sandbox) {
             var len = this._selected.length;\r
             if(len === 0) {\r
                 toggleButton('compare', false);\r
-                toggleButton('show2', false);\r
+                toggleButton('display', false);\r
                 toggleButton('restore', false);\r
             }\r
             if(len === 1) {\r
                 toggleButton('compare', false);\r
-                toggleButton('show2', true);\r
+                toggleButton('display', true);\r
                 toggleButton('restore', true);\r
             }\r
             if(len === 2) {\r
                 toggleItemViews(false);\r
                 toggleButton('compare', true);\r
-                toggleButton('show2', false);\r
+                toggleButton('display', false);\r
                 toggleButton('restore', false);\r
             } else {\r
                 toggleItemViews(true);\r
@@ -126,7 +140,7 @@ return function(sandbox) {
         getView: function() {\r
             return dom;\r
         }\r
-    }\r
-}\r
+    };\r
+};\r
 \r
 });
\ No newline at end of file