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