Project

General

Profile

1
var tree;
2
var specifiedCollectionID = "";
3

    
4
function formTree(collectionID, userActive, userPresent) {
5
	treeInit(userActive, userPresent);
6

    
7
	if (collectionID != "")
8
		specifiedCollectionID = collectionID;
9
}
10

    
11
function treeInit(usersActive, userPresent) {
12
	tree = new YAHOO.widget.TreeView("treeDiv1");
13
	var root = tree.getRoot();
14
	
15
	var tmpNode = new YAHOO.widget.TextNode( 
16
		{	label: "Driver Collections",
17
			id: "Driver Collections",
18
			expanded: true }, root);
19
	tmpNode.renderHidden = true;
20
	tmpNode.expand();
21
	
22
	if (userPresent) {
23
		tmpNode = new YAHOO.widget.TextNode( 
24
				{	label: "My Collections",
25
					id: "My Collections",
26
					expanded: false }, root);
27
		
28
		tmpNode.renderHidden = true;
29
	}
30
	
31
	if (usersActive) {
32
		tmpNode = new YAHOO.widget.TextNode( 
33
				{	label: "User Collections",
34
					id: "User Collections",
35
					expanded: false }, root);
36
		tmpNode.renderHidden = true;
37
	}
38
	tree.setDynamicLoad(getPublicChildren);
39
	
40
	// handler for expanding all nodes
41
	YAHOO.util.Event.on("expand", "click", function(e) {
42
		tree.destroy();
43
		tree = new YAHOO.widget.TreeView("treeDiv1");
44
	
45
		tree.setDynamicLoad(getAllPublicChildren);
46
		
47
		var root = tree.getRoot();
48
		var tmpNode = new YAHOO.widget.TextNode( 
49
			{	label: "Driver Collections",
50
				id: "Driver Collections",
51
				expanded: true }, root);
52
		tmpNode.renderHidden = true;
53
		tmpNode.expand();
54
	
55
		if (userPresent) {
56
			tmpNode = new YAHOO.widget.TextNode( 
57
				{	label: "My Collections",
58
					id: "My Collections",
59
					expanded: true }, root);
60
		
61
			tmpNode.renderHidden = true;
62
		}
63
	
64
		tmpNode = new YAHOO.widget.TextNode( 
65
			{	label: "User Collections",
66
				id: "User Collections",
67
				expanded: true }, root);
68
	
69
		tmpNode.renderHidden = true;
70

    
71
		tree.render();
72
	});
73

    
74
	// handler for collapsing all nodes
75
	YAHOO.util.Event.on("collapse", "click", function(e) {
76
		tree.collapseAll();
77
		YAHOO.util.Event.preventDefault(e);
78
	});
79

    
80
	tree.render();
81
}
82

    
83
function getPublicChildren(node, onCompleteCallback) {
84
	var callback = function(collectionArray) {
85
		for ( var i = 0; i < collectionArray.length; i++) {
86
			var myobj = {
87
				label :collectionArray[i].collection.name,
88
				id :collectionArray[i].collection.resourceId,
89
				expanded: false,
90
				href :"javascript:fetchCollection('" + collectionArray[i].collection.resourceId + "');"
91
			};
92

    
93
			if (collectionArray[i].collection['private'])
94
				myobj.label = myobj.label + ' *';
95

    
96
			var tmpNode = new YAHOO.widget.TextNode(myobj, node);
97

    
98
			tmpNode.isLeaf = !collectionArray[i].expandable;
99
			
100
			if(specifiedCollectionID != "") {
101
				fetchCollection(specifiedCollectionID);
102
				specifiedCollectionID = "";
103
			} else {
104
				if(collectionArray[i].collection.father == null && i == 0) 
105
					fetchCollection(collectionArray[i].collection.resourceId);
106
			}
107
		}
108
		onCompleteCallback();
109
	};
110

    
111
	var defered = collectionService.getBrowsableChildren(node.data.id);
112
	defered.addCallback(callback);
113
}
114

    
115
function getAllPublicChildren(node, onCompleteCallback) {
116
	var callback = function(collectionArray) {
117
		for ( var i = 0; i < collectionArray.length; i++) {
118
			var myobj = {
119
				label :collectionArray[i].collection.name,
120
				id :collectionArray[i].collection.resourceId,
121
				enableHighlight :true,
122
				expanded: collectionArray[i].expandable,
123
				href :"javascript:fetchCollection('" + collectionArray[i].collection.resourceId + "');"
124
			};
125

    
126
			if (collectionArray[i].collection['private'])
127
				myobj.label = myobj.label + ' *';
128

    
129
			var tmpNode = new YAHOO.widget.TextNode(myobj, node);
130
			tmpNode.isLeaf = !collectionArray[i].expandable;
131
		}
132

    
133
		onCompleteCallback();
134
	};
135

    
136
	var defered = collectionService.getBrowsableChildren(node.data.id);
137
	defered.addCallback(callback);
138
}
139

    
140

    
141
function fetchCollection(collectionId) {
142
	squeezeBoxLoading.open($('collection_loading'));
143
	
144
	var callback = function(bean) {
145
		$('permanentLink').href = 'AllDRIVERCollections.action?collectionID=' + collectionId;
146
		
147
		if (bean.isFatherPrivate != null) {
148
			$('maincolumn2').setStyle('display', 'block');
149
			document.getElementById('col_ID').value = collectionId;
150
			document.getElementById('col_title').innerHTML = bean.collection.name;
151
			document.getElementById('col_name').innerHTML = bean.collection.name;
152
			document.getElementById('col_description').innerHTML = bean.collection.description;
153
			document.getElementById('col_subject').innerHTML = bean.collection.subject;
154
			
155
			if (bean.collection.query != "") {
156
				document.getElementById('col_queryCriteria').innerHTML = bean.collection.query;
157
				$('searchCollection').setStyle('display', 'block');
158
				$('searchCollectionLink').href = "javascript:searchCollection('" + collectionId + "')";
159

    
160
			} else {
161
				document.getElementById('col_queryCriteria').innerHTML = "<i>No query defined.</i>";
162
				$('searchCollection').setStyle('display', 'none');
163
			}
164
			
165
			if (bean.collection.iconUrl != "") {
166
				document.getElementById('col_image').src = bean.collection.iconUrl;
167
			} else {
168
				document.getElementById('col_image').src = "struts/images/logo_driver.png";
169
			}
170
			
171
			document.getElementById('col_lastUpdateDate').innerHTML = dateFormat(Date(bean.collection.lastUpdateDate), "mmmm dd, yyyy");
172
			document.getElementById('col_documentCount').innerHTML = bean.collection.documentCount;
173
			document.getElementById('col_itemsInBasket').innerHTML = bean.collection.documentsInBasket.length;
174
			
175
			if (bean.ownerEmail != null) {
176
				document.getElementById('col_ownerEmail').innerHTML = bean.ownerEmail;
177
			} else {
178
				document.getElementById('col_ownerEmail').innerHTML = '<i>Not specified.</i>';
179
			}
180
			
181
			if (bean.basketDocuments != null) {
182
				$('documentList').innerHTML = "";
183
				$('basketExpandAll').setStyle('display', 'block');
184

    
185
				for(var i = 0; i < bean.basketDocuments.length; i++)
186
					addDocumentDiv(i, bean.basketDocuments[i].title, bean.basketDocuments[i].documentId, bean.basketDocuments[i].summaryFields, 'documentList', false);
187
			} else {
188
				$('basketExpandAll').setStyle('display', 'none');
189
				$('documentList').innerHTML = "<div class=\"collectionField\"><span class=\"collectionFieldComments\">There are no documents in your basket.</span></div>";
190
			}
191

    
192
			if (bean.queryResults != null && bean.queryResults.length > 0)  {
193
				$('showAllDocumentsLinkDiv').setStyle('display', 'block');
194
				$('documentsDisplayed').innerHTML = bean.queryResults.length;
195
				$('totalDocuments').innerHTML = bean.queryResultCount;
196
				$('showAllDocumentsLink').href = "showResults.action?collectionId='" + collectionId + "'&refine=&history=false&referer=showResults";
197
				$('col_documentCount').innerHTML = bean.queryResultCount;
198
				$('queryResultsList').innerHTML = "";
199
				
200
				for(var i = 0; i < bean.queryResults.length; i++) 
201
					addDocumentDiv(i, bean.queryResults[i].title, bean.queryResults[i].documentId, bean.queryResults[i].summaryFields, 'queryResultsList', false);
202
				
203
				$('queryExpandAll').setStyle('display', 'block');
204
			} else {
205
				$('showAllDocumentsLinkDiv').setStyle('display', 'none');
206
				$('queryExpandAll').setStyle('display', 'none');
207
				$('queryResultsList').innerHTML = "<div class=\"collectionField\"><span class=\"collectionFieldComments\">There are no query resultsfor this collection.</span></div>";
208
			}
209
			
210
			if (bean.editable) {
211
				$('editCollectionDiv').setStyle('display', 'block');
212
				$('editCollectionLink').href = 'BrowseCollections.action?mode=edit&collectionID=' + collectionId;
213
				$('deleteCollectionLink').href = "javascript:deleteCollection('" + collectionId + "')";
214
			} else {
215
				$('editCollectionDiv').setStyle('display', 'none');
216
			}
217
			
218
			// implement the more/fewer options sliders on ALL dropbox items on
219
			// the page
220
			$$('.mydriveritem').each(function(item){
221
				if (item.getElement('.document_details')) {
222
					var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
223
					item.getElement('.document_fewer').hide();			
224
					item.getElement('.document_more').addEvent('click', function(e){
225
						e.stop();
226
						document_details.slideIn();
227
					});
228
					item.getElement('.document_fewer').addEvent('click', function(e){
229
						e.stop();
230
						document_details.slideOut();
231
					});
232
					document_details.addEvent('complete', function() {
233
						if (this.open) {
234
							item.getElement('.document_more').hide();
235
							item.getElement('.document_fewer').show();
236
						}
237
						else {
238
							item.getElement('.document_more').show();
239
							item.getElement('.document_fewer').hide();					
240
						}
241
					});
242
				}
243
			});
244
			
245
			//implement the show all / hide all functionality
246
			$$('.showAll').each(function(aaa) {
247
				aaa.addEvent('click', function(e) {
248
					$$('.mydriveritem').each(function(item) {
249
						var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
250
						document_details.slideIn();
251
						
252
						document_details.addEvent('complete', function() {
253
							if (this.open) {
254
								item.getElement('.document_more').hide();
255
								item.getElement('.document_fewer').show();
256
							}
257
							else {
258
								item.getElement('.document_more').show();
259
								item.getElement('.document_fewer').hide();					
260
							}
261
						});
262
					});
263
					$$('.showAll').each(function(e){
264
						e.setStyle('display', 'none');
265
					});
266
					$$('.hideAll').each(function(e){
267
						e.setStyle('display', 'block');
268
					});
269
				});
270
			});
271
			
272
			$$('.hideAll').each(function(aaa) {
273
				aaa.addEvent('click', function(e) {
274
					$$('.mydriveritem').each(function(item) {
275
						var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
276
						document_details.slideOut();
277
						
278
						document_details.addEvent('complete', function() {
279
							if (this.open) {
280
								item.getElement('.document_more').hide();
281
								item.getElement('.document_fewer').show();
282
							}
283
							else {
284
								item.getElement('.document_more').show();
285
								item.getElement('.document_fewer').hide();					
286
							}
287
						});
288
					});
289
					$$('.showAll').each(function(e){
290
						e.setStyle('display', 'block');
291
					});
292
					$$('.hideAll').each(function(e){
293
						e.setStyle('display', 'none');
294
					});
295
				});
296
			});
297
			
298
			$$('.hideAll').each(function(e){
299
				e.setStyle('display', 'none');
300
			});
301
			
302
		} else {
303
			alert("A problem occured while getting collection");
304
		}
305

    
306
		// adding a small delay to make sure that the "loading" popup has finished loading.
307
		setTimeout("squeezeBoxLoading.close()", 200);
308
	};
309

    
310
	var defered = collectionService.getCollection(collectionId);
311
	defered.addCallback(callback);
312
}
313

    
314
function addDocumentDiv(index, title, documentId, summaryFields , targetDiv , editMode) {
315
	  var documentListDiv = document.getElementById(targetDiv);
316
	  var documentDiv = document.createElement('div');
317
	  var mydriveritemDiv = document.createElement('div');
318
	  var contentDiv = document.createElement('div');
319
	  var titleDiv = document.createElement('div');
320
	  var document_detailsDiv = document.createElement('div');
321
	  
322
	  contentDiv.setAttribute('class', "content");	
323
	  mydriveritemDiv.setAttribute('class', "mydriveritem");	
324
	  
325
	  titleDiv.innerHTML = '<h2><img src="static-content/images/icons/document_text.png" alt="PDF" width="25" height="25" style="vertical-align: middle; margin-bottom: 0.25em;" />' + title + '</h2>';
326
	  
327
	  document_detailsDiv.setAttribute('class', "document_details");
328
	  
329
	  for (var key in summaryFields) {	  
330
		  var summaryFieldDiv = document.createElement('div');
331
		  summaryFieldDiv.setAttribute('class', "resultsField")
332
	  	  summaryFieldDiv.innerHTML = '<span class="resultsFieldNm">' + key + ':&nbsp;&nbsp;</span>' + summaryFields[key]; 	
333
		  document_detailsDiv.appendChild(summaryFieldDiv);
334
	  }  
335
	  
336
	  var document_infoDiv = document.createElement('div');
337
	  document_infoDiv.setAttribute('class',"document_info");
338
	  
339
	  var document_moreDiv = document.createElement('div');
340
	  document_moreDiv.setAttribute('class',"document_more");
341
	  document_moreDiv.innerHTML = "Show document details"; 
342
		
343
	  var document_fewerDiv = document.createElement('div');
344
	  document_fewerDiv.setAttribute('class',"document_fewer");
345
	  document_fewerDiv.innerHTML = "Hide document details";
346
	  document_infoDiv.appendChild(document_moreDiv);
347
	  document_infoDiv.appendChild(document_fewerDiv);
348
	  
349
	  contentDiv.appendChild(titleDiv);
350
	  contentDiv.appendChild(document_detailsDiv);
351
	  contentDiv.appendChild(document_infoDiv);
352
		
353
	  mydriveritemDiv.appendChild(contentDiv);
354
	  documentDiv.appendChild(mydriveritemDiv);
355
	  documentListDiv.appendChild(documentDiv);
356
}
357

    
358
function deleteCollection(collectionId) {
359
	var callback = function(bean) {
360
		if (bean == true) {
361
			window.location = 'AllDRIVERCollections.action';
362
		} else {
363
			roarQueue.alert('<p>There was an error deleting collection.</p><p></p>');
364
		}
365
	}
366
	
367
	if (confirm('Delete collection?'))
368
		collectionService.deleteCollection(collectionId).addCallback(callback);
369
}
(7-7/21)