From: Aleksander Ɓukasz Date: Thu, 13 Jun 2013 13:27:20 +0000 (+0200) Subject: history wip: Selecting versions in history view X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/0479fc5313b1730d4de86b2b71a7bc721ab2b44a history wip: Selecting versions in history view --- diff --git a/modules/documentHistory/documentHistory.js b/modules/documentHistory/documentHistory.js index 0db2a75..d5f20d4 100644 --- a/modules/documentHistory/documentHistory.js +++ b/modules/documentHistory/documentHistory.js @@ -27,16 +27,17 @@ return function(sandbox) { var toggleItemViews = function(toggle) { itemViews.forEach(function(view) { - view.toggle(toggle); + if(!historyItems.selected(view.item)) + view.toggle(toggle); }); } var historyItems = { _itemsById: {}, _selected: [], - select: function(id) { + select: function(item) { if(this._selected.length < 2) { - this._selected.push(id); + this._selected.push(item.version); if(this._selected.length === 2) toggleItemViews(false); return true; @@ -44,40 +45,40 @@ return function(sandbox) { return false; }, unselect: function(item) { - this._selected = _.without(this._selected, id); + this._selected = _.without(this._selected, item.version); if(this._selected.length < 2) toggleItemViews(true); }, add: function(item) { - this._itemsById[item.id] = item; + this._itemsById[item.version] = item; }, selected: function(item) { - return _.contains(_selected, item.id); + return _.contains(this._selected, item.version); } }; var itemView = function(item) { this.item = item; this.dom = $(this.template(item)); - this.dom.on('click', this.onItemClicked); + this.dom.on('click', _.bind(this.onItemClicked, this)); }; itemView.prototype.template = _.template(itemTemplateSrc); itemView.prototype.onItemClicked = function() { - if(historyItems.selected(item)) { - historyItems.unselect(item); + if(historyItems.selected(this.item)) { + historyItems.unselect(this.item); this.dimItem(); - } else if(historyItems.select(item)) { + } else if(historyItems.select(this.item)) { this.highlightItem(); } }; itemView.prototype.highlightItem = function() { - + this.dom.addClass('highlighted'); }; itemView.prototype.dimItem = function() { - + this.dom.removeClass('highlighted'); }; itemView.prototype.toggle = function(toggle) { - + this.dom.toggleClass('disabled', !toggle); }; diff --git a/modules/documentHistory/documentHistory.less b/modules/documentHistory/documentHistory.less index 0c2e9b5..9a73977 100644 --- a/modules/documentHistory/documentHistory.less +++ b/modules/documentHistory/documentHistory.less @@ -1,18 +1,30 @@ -.rng-module-documentHistory-item { +.rng-module-documentHistory { - margin: 0 0 15px 0; - - .version { - float: left; - width: 30px; - font-weight: bold; + .item { + padding: 5px 5px; + margin: 0 0 15px 0; + cursor: pointer; + + .version { + float: left; + width: 30px; + font-weight: bold; + } + + .date, .author, .description { + margin: 5px 10px 0 40px; + } + + .description { + font-size: .9em; + } } - .date, .author, .description { - margin: 5px 10px 0 40px; + .item.highlighted { + background: #ffec63; } - .description { - font-size: .9em; + .item.disabled { + cursor: default; } } \ No newline at end of file diff --git a/modules/documentHistory/templates/item.html b/modules/documentHistory/templates/item.html index d5b81a7..f3afb3d 100644 --- a/modules/documentHistory/templates/item.html +++ b/modules/documentHistory/templates/item.html @@ -1,4 +1,4 @@ -
+
<%= version %>
<%= date %>
<%= author %>