2 'libs/jquery-1.9.1.min',
\r
3 'libs/underscore-min',
\r
4 'libs/text!./templates/main.html',
\r
5 'libs/text!./templates/item.html'
\r
6 ], function($, _, mainTemplateSrc, itemTemplateSrc) {
\r
10 return function(sandbox) {
\r
12 var dom = $(_.template(mainTemplateSrc)());
\r
14 itemList: dom.find('.rng-module-documentHistory-itemsList'),
\r
18 var addHistoryItem = function(item) {
\r
19 historyItems.add(item);
\r
20 var view = new itemView(item);
\r
21 itemViews.push(view);
\r
22 domNodes.itemList.prepend(view.dom);
\r
25 var toggleItemViews = function(toggle) {
\r
26 itemViews.forEach(function(view) {
\r
27 view.toggle(toggle);
\r
31 var historyItems = {
\r
34 select: function(id) {
\r
35 if(this._selected.length < 2) {
\r
36 this._selected.push(id);
\r
37 if(this._selected.length === 2)
\r
38 toggleItemViews(false);
\r
43 unselect: function(item) {
\r
44 this._selected = _.without(this._selected, id);
\r
45 if(this._selected.length < 2)
\r
46 toggleItemViews(true);
\r
48 add: function(item) {
\r
49 this._itemsById[item.id] = item;
\r
51 selected: function(item) {
\r
52 return _.contains(_selected, item.id);
\r
56 var itemView = function(item) {
\r
58 this.dom = $(this.template(item));
\r
59 this.dom.on('click', this.onItemClicked);
\r
61 itemView.prototype.template = _.template(itemTemplateSrc);
\r
62 itemView.prototype.onItemClicked = function() {
\r
63 if(historyItems.selected(item)) {
\r
64 historyItems.unselect(item);
\r
66 } else if(historyItems.select(item)) {
\r
67 this.highlightItem();
\r
70 itemView.prototype.highlightItem = function() {
\r
73 itemView.prototype.dimItem = function() {
\r
76 itemView.prototype.toggle = function(toggle) {
\r
83 start: function() { sandbox.publish('ready'); },
\r
84 addHistory: function(history) {
\r
85 history.forEach(function(historyItem) {
\r
86 addHistoryItem(historyItem);
\r
89 getView: function() {
\r