Disabling save dialog's text area while saving
[fnpeditor.git] / modules / documentHistory / documentHistory.js
index 05cddbc..d5f20d4 100644 (file)
@@ -15,25 +15,29 @@ return function(sandbox) {
     }\r
     var itemViews = [];\r
         \r
-    var addHistoryItem = function(item) {\r
+    var addHistoryItem = function(item, options) {\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
+        if(options.animate) {\r
+            view.dom.hide().slideDown();\r
+        }\r
     }\r
     \r
     var toggleItemViews = function(toggle) {\r
         itemViews.forEach(function(view) {\r
-            view.toggle(toggle);\r
+            if(!historyItems.selected(view.item))\r
+                view.toggle(toggle);\r
         });\r
     }\r
     \r
     var historyItems = {\r
         _itemsById: {},\r
         _selected: [],\r
-        select: function(id) {\r
+        select: function(item) {\r
             if(this._selected.length < 2) {\r
-                this._selected.push(id);\r
+                this._selected.push(item.version);\r
                 if(this._selected.length === 2)\r
                     toggleItemViews(false);\r
                 return true;\r
@@ -41,49 +45,49 @@ return function(sandbox) {
             return false;\r
         },\r
         unselect: function(item) {\r
-            this._selected = _.without(this._selected, id);\r
+            this._selected = _.without(this._selected, item.version);\r
             if(this._selected.length < 2)\r
                 toggleItemViews(true);\r
         },\r
         add: function(item) {\r
-            this._itemsById[item.id] = item;\r
+            this._itemsById[item.version] = item;\r
         },\r
         selected: function(item) {\r
-            return _.contains(_selected, item.id);\r
+            return _.contains(this._selected, item.version);\r
         }\r
     };\r
     \r
     var itemView = function(item) {\r
         this.item = item;\r
         this.dom = $(this.template(item));\r
-        this.dom.on('click', this.onItemClicked);\r
+        this.dom.on('click', _.bind(this.onItemClicked, this));\r
     };\r
     itemView.prototype.template = _.template(itemTemplateSrc);\r
     itemView.prototype.onItemClicked = function() {\r
-        if(historyItems.selected(item)) {\r
-            historyItems.unselect(item);\r
+        if(historyItems.selected(this.item)) {\r
+            historyItems.unselect(this.item);\r
             this.dimItem();\r
-        } else if(historyItems.select(item)) {\r
+        } else if(historyItems.select(this.item)) {\r
             this.highlightItem();\r
         }            \r
     };\r
     itemView.prototype.highlightItem = function() {\r
-        \r
+        this.dom.addClass('highlighted');\r
     };\r
     itemView.prototype.dimItem = function() {\r
-    \r
+        this.dom.removeClass('highlighted');\r
     };\r
     itemView.prototype.toggle = function(toggle) {\r
-    \r
+        this.dom.toggleClass('disabled', !toggle);\r
     };\r
 \r
     \r
     \r
     return {\r
-        start: function() { sandbox.publish('ready'); },\r
-        setHistory: function(history) {\r
+        start: function() { sandbox.publish('ready'); },
+        addHistory: function(history, options) {\r
             history.forEach(function(historyItem) {\r
-                addHistoryItem(historyItem);\r
+                addHistoryItem(historyItem, options || {});\r
             });\r
         },\r
         getView: function() {\r