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
80 historyItems._updateUI();
\r
82 var itemView = function(item) {
\r
84 this.dom = $(this.template(item));
\r
85 this.dom.on('click', _.bind(this.onItemClicked, this));
\r
87 itemView.prototype.template = _.template(itemTemplateSrc);
\r
88 itemView.prototype.onItemClicked = function() {
\r
89 if(historyItems.selected(this.item)) {
\r
90 historyItems.unselect(this.item);
\r
92 } else if(historyItems.select(this.item)) {
\r
93 this.highlightItem();
\r
96 itemView.prototype.highlightItem = function() {
\r
97 this.dom.addClass('highlighted');
\r
99 itemView.prototype.dimItem = function() {
\r
100 this.dom.removeClass('highlighted');
\r
102 itemView.prototype.toggle = function(toggle) {
\r
103 this.dom.toggleClass('disabled', !toggle);
\r
109 start: function() { sandbox.publish('ready'); },
110 addHistory: function(history, options) {
\r
111 history.forEach(function(historyItem) {
\r
112 addHistoryItem(historyItem, options || {});
\r
115 getView: function() {
\r