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, options) {
\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
23 if(options.animate) {
\r
24 view.dom.hide().slideDown();
\r
28 var toggleItemViews = function(toggle) {
\r
29 itemViews.forEach(function(view) {
\r
30 if(!historyItems.selected(view.item))
\r
31 view.toggle(toggle);
\r
35 var toggleButton = function(btn, toggle) {
\r
36 dom.find('button.'+btn).toggleClass('disabled', !toggle);
\r
39 var historyItems = {
\r
42 select: function(item) {
\r
43 if(this._selected.length < 2) {
\r
44 this._selected.push(item.version);
\r
50 unselect: function(item) {
\r
51 this._selected = _.without(this._selected, item.version);
\r
54 add: function(item) {
\r
55 this._itemsById[item.version] = item;
\r
57 selected: function(item) {
\r
58 return _.contains(this._selected, item.version);
\r
60 _updateUI: function() {
\r
61 var len = this._selected.length;
\r
63 toggleButton('compare', false);
\r
64 toggleButton('show2', false);
\r
65 toggleButton('restore', false);
\r
68 toggleButton('compare', false);
\r
69 toggleButton('show2', true);
\r
70 toggleButton('restore', true);
\r
73 toggleItemViews(false);
\r
74 toggleButton('compare', true);
\r
75 toggleButton('show2', false);
\r
76 toggleButton('restore', false);
\r
78 toggleItemViews(true);
\r
82 historyItems._updateUI();
\r
84 var itemView = function(item) {
\r
86 this.dom = $(this.template(item));
\r
87 this.dom.on('click', _.bind(this.onItemClicked, this));
\r
89 itemView.prototype.template = _.template(itemTemplateSrc);
\r
90 itemView.prototype.onItemClicked = function() {
\r
91 if(historyItems.selected(this.item)) {
\r
92 historyItems.unselect(this.item);
\r
94 } else if(historyItems.select(this.item)) {
\r
95 this.highlightItem();
\r
98 itemView.prototype.highlightItem = function() {
\r
99 this.dom.addClass('highlighted');
\r
101 itemView.prototype.dimItem = function() {
\r
102 this.dom.removeClass('highlighted');
\r
104 itemView.prototype.toggle = function(toggle) {
\r
105 this.dom.toggleClass('disabled', !toggle);
\r
111 start: function() { sandbox.publish('ready'); },
112 addHistory: function(history, options) {
\r
113 history.forEach(function(historyItem) {
\r
114 addHistoryItem(historyItem, options || {});
\r
117 getView: function() {
\r