history wip - displaying history items
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 13 Jun 2013 09:37:46 +0000 (11:37 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 13 Jun 2013 12:57:53 +0000 (14:57 +0200)
modules.js
modules/data.js
modules/documentHistory/documentHistory.js [new file with mode: 0644]
modules/documentHistory/documentHistory.less [new file with mode: 0644]
modules/documentHistory/templates/item.html [new file with mode: 0644]
modules/documentHistory/templates/main.html [new file with mode: 0644]
modules/rng/rng.js
styles/main.less

index 9accc7d..6c514b5 100644 (file)
@@ -21,5 +21,7 @@ define(function(require) {
         nodeFamilyTree: require('modules/nodeFamilyTree/nodeFamilyTree'),\r
         nodeBreadCrumbs: require('modules/nodeBreadCrumbs/nodeBreadCrumbs'),\r
         \r
+        documentHistory: require('modules/documentHistory/documentHistory')\r
+        \r
     }\r
 });
\ No newline at end of file
index 2848454..df40322 100644 (file)
@@ -6,6 +6,7 @@ return function(sandbox) {
 \r
     var doc = sandbox.getBootstrappedData().document;\r
     var document_id = sandbox.getBootstrappedData().document_id;\r
+    var history = sandbox.getBootstrappedData().history;\r
 \r
     \r
     if(doc === '') {\r
@@ -62,7 +63,10 @@ return function(sandbox) {
                 success: function() {sandbox.publish('savingEnded', 'success');},\r
                 error: function() {sandbox.publish('savingEnded', 'error');}\r
             });\r
-        } \r
+        },\r
+        getHistory: function() {\r
+            return history;\r
+        }\r
     }\r
 };\r
 \r
diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js
new file mode 100644 (file)
index 0000000..05cddbc
--- /dev/null
@@ -0,0 +1,95 @@
+define([\r
+'libs/jquery-1.9.1.min',\r
+'libs/underscore-min',\r
+'libs/text!./templates/main.html',\r
+'libs/text!./templates/item.html'\r
+], function($, _, mainTemplateSrc, itemTemplateSrc) {\r
+\r
+'use strict';\r
+    \r
+return function(sandbox) {\r
+    \r
+    var dom = $(_.template(mainTemplateSrc)());\r
+    var domNodes = {\r
+        itemList: dom.find('.rng-module-documentHistory-itemsList'),\r
+    }\r
+    var itemViews = [];\r
+        \r
+    var addHistoryItem = function(item) {\r
+        historyItems.add(item);\r
+        var view = new itemView(item);\r
+        itemViews.push(view);\r
+        domNodes.itemList.append(view.dom);\r
+    }\r
+    \r
+    var toggleItemViews = function(toggle) {\r
+        itemViews.forEach(function(view) {\r
+            view.toggle(toggle);\r
+        });\r
+    }\r
+    \r
+    var historyItems = {\r
+        _itemsById: {},\r
+        _selected: [],\r
+        select: function(id) {\r
+            if(this._selected.length < 2) {\r
+                this._selected.push(id);\r
+                if(this._selected.length === 2)\r
+                    toggleItemViews(false);\r
+                return true;\r
+            }\r
+            return false;\r
+        },\r
+        unselect: function(item) {\r
+            this._selected = _.without(this._selected, id);\r
+            if(this._selected.length < 2)\r
+                toggleItemViews(true);\r
+        },\r
+        add: function(item) {\r
+            this._itemsById[item.id] = item;\r
+        },\r
+        selected: function(item) {\r
+            return _.contains(_selected, item.id);\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
+    };\r
+    itemView.prototype.template = _.template(itemTemplateSrc);\r
+    itemView.prototype.onItemClicked = function() {\r
+        if(historyItems.selected(item)) {\r
+            historyItems.unselect(item);\r
+            this.dimItem();\r
+        } else if(historyItems.select(item)) {\r
+            this.highlightItem();\r
+        }            \r
+    };\r
+    itemView.prototype.highlightItem = function() {\r
+        \r
+    };\r
+    itemView.prototype.dimItem = function() {\r
+    \r
+    };\r
+    itemView.prototype.toggle = function(toggle) {\r
+    \r
+    };\r
+\r
+    \r
+    \r
+    return {\r
+        start: function() { sandbox.publish('ready'); },\r
+        setHistory: function(history) {\r
+            history.forEach(function(historyItem) {\r
+                addHistoryItem(historyItem);\r
+            });\r
+        },\r
+        getView: function() {\r
+            return dom;\r
+        }\r
+    }\r
+}\r
+\r
+});
\ No newline at end of file
diff --git a/modules/documentHistory/documentHistory.less b/modules/documentHistory/documentHistory.less
new file mode 100644 (file)
index 0000000..0c2e9b5
--- /dev/null
@@ -0,0 +1,18 @@
+.rng-module-documentHistory-item {\r
+    \r
+    margin: 0 0 15px 0;\r
+\r
+    .version {\r
+        float: left;\r
+        width: 30px;\r
+        font-weight: bold;\r
+    }\r
+    \r
+    .date, .author, .description {\r
+        margin: 5px 10px 0 40px;\r
+    }\r
+    \r
+    .description {\r
+        font-size: .9em;\r
+    }\r
+}
\ No newline at end of file
diff --git a/modules/documentHistory/templates/item.html b/modules/documentHistory/templates/item.html
new file mode 100644 (file)
index 0000000..d5b81a7
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="rng-module-documentHistory-item">\r
+    <div class="version"><%= version %></div>\r
+    <div class="date"><%= date %></div>\r
+    <div class="author"><%= author %></div>\r
+    <div class="description"><%= description %></div>\r
+</div>
\ No newline at end of file
diff --git a/modules/documentHistory/templates/main.html b/modules/documentHistory/templates/main.html
new file mode 100644 (file)
index 0000000..68f1f66
--- /dev/null
@@ -0,0 +1,4 @@
+<div class="rng-module-documentHistory">\r
+    <div class="rng-module-documentHistory-toolbar"></div>\r
+    <div class="rng-module-documentHistory-itemsList"></div>\r
+<div>
\ No newline at end of file
index 992d601..3f89cd7 100644 (file)
@@ -108,7 +108,7 @@ return function(sandbox) {
         ready: function() {\r
             views.mainLayout.setView('mainView', views.mainTabs.getAsView());\r
             \r
-            _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {\r
+            _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory'], function(moduleName) {\r
                 sandbox.getModule(moduleName).start();\r
             });\r
         },\r
@@ -246,6 +246,13 @@ return function(sandbox) {
         }        \r
     }\r
     \r
+    eventHandlers.documentHistory = {\r
+        ready: function() {\r
+            sandbox.getModule('documentHistory').setHistory(sandbox.getModule('data').getHistory());\r
+            addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView());\r
+        }\r
+    }\r
+    \r
     /* api */\r
     \r
     return {\r
index 040ff6f..8a6dd79 100644 (file)
@@ -6,6 +6,7 @@
 @import '../modules/sourceEditor/sourceEditor.less';\r
 @import '../modules/mainBar/mainBar.less';\r
 @import '../modules/documentToolbar/documentToolbar.less';\r
+@import '../modules/documentHistory/documentHistory.less';\r
 @import '../modules/indicator/indicator.less';\r
 @import '../modules/nodePane/nodePane.less';\r
 @import '../modules/nodeFamilyTree/nodeFamilyTree.less';\r