Project

General

Profile

1 12865 katerina.i
dojo.require("dojo.rpc.*");
2
dojo.hostenv.writeIncludes();
3
4
var dropboxService = new dojo.rpc.JsonService("AddToDropbox");
5
6
var roarQueue;
7
8
function equalize(tag) {
9
	var columns = $$(tag);
10
	var max_height = 0;
11
12
	columns.each(function(item) {
13
		max_height = Math.max(max_height, item.getSize().y);
14
	});
15
16
	columns.setStyle('height', max_height);
17
}
18
19
window.addEvent('domready', function() {
20
	SqueezeBox.initialize();
21
	/**
22
	 * That CSS selector will find all <a> elements with the
23
	 * attribute rel="popup" and href starting with a #.
24
	 */
25
	SqueezeBox.assign($$('a[rel=popup][href^=#]'), {
26
		handler: 'adopt',
27
		overlayOpacity: 0.4,
28
		minSize: {x: 200, y: 200},
29
		maxSize: {x: 800, y:700},
30
		automaticResize: true,
31
		onOpen: function() {
32
			smartBox.closeBox();
33
34
			this.content.getChildren().setStyle('display','block');
35
			this.showContent();
36
		}, // unhide the divs
37
		onClose: function() {
38
			var parent_id = $(this.url.match(/#([\w-]+)$/)[1]).get('id') + "_container";		// get the original parent id
39
			this.content.getChildren().inject($(parent_id)).setStyle('display', 'none');	// inject back to parent and hide
40
		}
41
	});
42
	/**
43
	 * Now hide corresponding divs
44
	 */
45
	$$('a[rel=popup][href^=#]').each(function(el) {
46
			$(el.get('href').match(/#([\w-]+)$/)[1]).setStyle('display', 'none');
47
	});
48
});
49
50
window.addEvent('load', function() {
51
	roarQueue = new Roar({
52
		position :'upperRight',
53
		container :$('roarQueue_container'),
54
		duration :5000
55
	});
56
});
57
window.addEvent('domready', function(){equalize('.equalize')});
58
window.addEvent('domready', function(){equalize('.equalize2')});
59
60
var smartBox;
61
window.addEvent('domready', function(){
62
	// implement the more/fewer options sliders on ALL dropbox items on the page
63
	$$('.mydriveritem').each(function(item){
64
		if (item.getElement('.document_details')) {
65
			var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
66
			item.getElement('.document_fewer').hide();
67
			item.getElement('.document_more').addEvent('click', function(e){
68
				e.stop();
69
				document_details.slideIn();
70
			});
71
			item.getElement('.document_fewer').addEvent('click', function(e){
72
				e.stop();
73
				document_details.slideOut();
74
			});
75
			document_details.addEvent('complete', function() {
76
				if (this.open) {
77
					item.getElement('.document_more').hide();
78
					item.getElement('.document_fewer').show();
79
				}
80
				else {
81
					item.getElement('.document_more').show();
82
					item.getElement('.document_fewer').hide();
83
				}
84
			});
85
		}
86
	});
87
	// implement the hover box for the save query button
88
	smartBox = new SmartHoverBox( {
89
		xOffset :0,
90
		yOffset :5,
91
		lockY :'bottom',
92
		smartBoxSuffix :'_smarthbox'
93
	});
94
95
	//implement the show all / hide all functionality
96
	var showAllLink = $('showAll');
97
	var hideAllLink = $('hideAll');
98
99
	if (showAllLink != null) {
100
		showAllLink.addEvent('click', function(e) {
101
			$$('.mydriveritem').each(function(item) {
102
				var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
103
				document_details.slideIn();
104
105
				document_details.addEvent('complete', function() {
106
					if (this.open) {
107
						item.getElement('.document_more').hide();
108
						item.getElement('.document_fewer').show();
109
					}
110
					else {
111
						item.getElement('.document_more').show();
112
						item.getElement('.document_fewer').hide();
113
					}
114
				});
115
			});
116
			$('showAll').setStyle('display', 'none');
117
			$('hideAll').setStyle('display', 'block');
118
		});
119
	}
120
	if (hideAllLink != null) {
121
		hideAllLink.addEvent('click', function(e) {
122
			$$('.mydriveritem').each(function(item) {
123
				var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
124
				document_details.slideOut();
125
126
				document_details.addEvent('complete', function() {
127
					if (this.open) {
128
						item.getElement('.document_more').hide();
129
						item.getElement('.document_fewer').show();
130
					}
131
					else {
132
						item.getElement('.document_more').show();
133
						item.getElement('.document_fewer').hide();
134
					}
135
				});
136
			});
137
			$('showAll').setStyle('display', 'block');
138
			$('hideAll').setStyle('display', 'none');
139
		});
140
		$('hideAll').setStyle('display', 'none');
141
	}
142
});
143
144
function removeDropoboxDocuments(documentListDIV) {
145
	var callback = function(bean) {
146
		if(bean != -1) {
147
			removeDocumentsFromUI(getSelectedDocumentDivIds(documentListDIV));
148
			roarQueue.alert("<p>Item(s) removed from your dropbox.</p>");
149
			$('dropboxDocCount').innerHTML = bean;
150
		} else {
151
			alert("A problem occured while removing document from dropbox.");
152
		}
153
	};
154
155
	var defered = dropboxService.removeFromDropbox(getSelectedDocumentIds(documentListDIV));
156
	defered.addCallback(callback);
157
}
158
159
function addToCollection(documentListDIV, collectionId) {
160
	SqueezeBox.close();
161
162
	var callback = function() {
163
		roarQueue.alert("<p>Selected documents added to collection basket.</p>");
164
	};
165
166
	var deferred = dropboxService.addToCollection(getSelectedDocumentIds(documentListDIV), collectionId);
167
	deferred.addCallback(callback);
168
}
169
170
function addToCommunity(documentListDIV, communityId) {
171
	SqueezeBox.close();
172
173
	var callback = function() {
174
		roarQueue.alert("<p>Selected documents added to community.</p>");
175
	};
176
177
	var deferred = dropboxService.addToCommunity(getSelectedDocumentIds(documentListDIV), communityId)
178
	deferred.addCallback(callback);
179
}
180
181
function removeDocumentsFromUI(selectedDocs) {
182
  	for (var i = 0; i < selectedDocs.length; i++) {
183
    	var op = document.getElementById(selectedDocs[i]);
184
185
    	op.parentNode.removeChild(op);
186
    }
187
}
188
189
function addDocumentToDropbox(documentId) {
190
	var docCount = eval($('dropboxDocCount').innerHTML);
191
192
	var callback = function(bean) {
193
		if (bean == true) {
194
			roarQueue.alert("<p>Item added in your dropbox.</p>");
195
			$('dropboxDocCount').innerHTML = docCount + 1;
196
		} else {
197
			roarQueue.alert("<p>Item already in your dropbox or maximum dropbox size reached.</p>");
198
		}
199
	};
200
201
	var defered = dropboxService.add(documentId);
202
	defered.addCallback(callback);
203
}