Project

General

Profile

1
var tree;
2
var specifiedCollectionID = "";
3
var editedCollectionResourceId;
4
var squeezeBoxLoading;
5
var roarQueue;
6

    
7
window.addEvent('domready', function() {
8
	roarQueue = new Roar( {
9
		position :'upperRight',
10
		container :$('roarQueue_container'),
11
		duration :5000
12
	});
13
	new SimpleTabs('tabblock1', {selector: 'h3'});
14
	new SimpleTabs('tabblock2', {selector: 'h3'});
15

    
16
	// implement the hover box for the save query button
17
	var smartBox = new SmartHoverBox( {
18
			xOffset :0,
19
			yOffset :5,
20
			lockY :'bottom',
21
			smartBoxSuffix :'_smarthbox'
22
	});
23
	
24
	squeezeBoxLoading = SqueezeBox.initialize({
25
		handler: 'clone',
26
		overlayOpacity: 0.4,
27
		automaticResize: true,
28
		closable: false,
29
		onOpen: function() {
30
			this.content.getChildren().setStyle('display','block');
31
			this.closeBtn.setStyle('display','none');
32
			this.showContent();
33
		}
34
	});
35
	
36
	$('collection_loading').setStyle('display', 'none');
37
});
38

    
39
function formTree(mode, collectionID) {
40
	var treeDiv = document.getElementById('treeDiv1');
41

    
42
	treeInit(mode);
43
	
44
	if(collectionID != "")
45
		specifiedCollectionID = collectionID;
46
	
47
	// handler for expanding all nodes
48
	YAHOO.util.Event.on("expand", "click", function(e) {
49
		YAHOO.log("Expanding all TreeView  nodes.", "info", "example");
50
		tree.destroy();
51
		tree = new YAHOO.widget.TreeView("treeDiv1");
52
		
53
		if(mode)
54
			tree.setDynamicLoad(loadDataForTree);
55
		else
56
			tree.setDynamicLoad(loadDataForPublicTree);
57
		
58
		var root = tree.getRoot();
59
		var tmpNode = new YAHOO.widget.TextNode( {
60
			label :"Collections",
61
			id :"InfoSpace",
62
			expanded :true
63
		}, root);
64

    
65
		tree.render();
66

    
67
	});
68

    
69
	// handler for collapsing all nodes
70
	YAHOO.util.Event.on("collapse", "click", function(e) {
71
		YAHOO.log("Collapsing all TreeView  nodes.", "info", "example");
72
		tree.collapseAll();
73
		YAHOO.util.Event.preventDefault(e);
74
	});
75
}
76

    
77
function treeInit(mode) {
78
	tree = new YAHOO.widget.TreeView("treeDiv1");
79
	
80
	if(mode)
81
		tree.setDynamicLoad(loadDataForNode);
82
	else
83
		tree.setDynamicLoad(loadDataForPublicNode);
84
	
85
	var root = tree.getRoot();
86

    
87
	var tmpNode = new YAHOO.widget.TextNode( {
88
		label :"Collections",
89
		id :"InfoSpace",
90
		expanded :false,
91
		enableHighlight :false
92
	}, root);
93
	
94
	tmpNode.expand();
95

    
96
	tmpNode.highlight(false);
97
	tmpNode.renderHidden = true;
98

    
99
	tree.setNodesProperty('enableHighlight', 'false');
100
	// The tree is not created in the DOM until this method is called:
101
	tree.render();
102
}
103

    
104
function loadDataForNode(node, onCompleteCallback) {
105
	getChildren(node, onCompleteCallback);
106
}
107

    
108
function loadDataForPublicNode(node, onCompleteCallback) {
109
	getPublicChildren(node, onCompleteCallback);
110
}
111

    
112
function loadDataForTree(node, onCompleteCallback) {
113
	getAllChildren(node, onCompleteCallback);
114
}
115

    
116
function loadDataForPublicTree(node, onCompleteCallback) {
117
	getAllPublicChildren(node, onCompleteCallback);
118
}
119

    
120
function getAllChildren(node, onCompleteCallback) {
121
	var callback = function(bean) {
122
		for ( var i = 0; i < bean.length; i++) {
123
			var myobj = {
124
				label :bean[i].collection.name,
125
				id :bean[i].collection.resourceId,
126
				enableHighlight :false,
127
				href :"javascript:fetchCollection('" + bean[i].collection.resourceId + "');"
128
			};
129
 
130
                        if (bean[i].collection['private'])
131
                                myobj.label = myobj.label + ' *';
132

    
133
			var tmpNode = new YAHOO.widget.TextNode(myobj, node, true);
134

    
135
			if (bean[i].collection.children.length == 0)
136
				tmpNode.isLeaf = true;
137
			
138
			// fetch first root collection
139
			if(bean[i].collection.father == null && i == 0) 
140
				fetchCollection(bean[i].collection.resourceId);
141
		}
142
		// Be sure to notify the TreeView component when the data load is
143
		// complete
144
		onCompleteCallback();
145
	};
146

    
147
	var defered = collectionService.getUserChildren(node.data.id);
148
	defered.addCallback(callback);
149
}
150

    
151
function getChildren(node, onCompleteCallback) {
152
	var callback = function(bean) {
153
		for ( var i = 0; i < bean.length; i++) {
154
			var myobj = {
155
				label :bean[i].collection.name,
156
				id :bean[i].collection.resourceId,
157
				enableHighlight :false,
158
				href :"javascript:fetchCollection('" + bean[i].collection.resourceId + "');"
159
			};
160

    
161
                        if (bean[i].collection['private'])
162
                                myobj.label = myobj.label + ' *';
163

    
164
			var tmpNode = new YAHOO.widget.TextNode(myobj, node, false);
165

    
166
			if (bean[i].collection.children.length == 0) {
167
				tmpNode.isLeaf = true;
168
			}
169
			
170
			if(specifiedCollectionID != "") {
171
				fetchCollection(specifiedCollectionID);
172
				specifiedCollectionID = "";
173
			} else {
174
			// fetch first root collection
175
			if(bean[i].collection.father == null && i == 0) 
176
				fetchCollection(bean[i].collection.resourceId);
177
			}
178
		}
179
		// Be sure to notify the TreeView component when the data load is
180
		// complete
181
		onCompleteCallback();
182
	};
183

    
184
	var defered = collectionService.getUserChildren(node.data.id);
185
	defered.addCallback(callback);
186
}
187

    
188
function getPublicChildren(node, onCompleteCallback) {
189

    
190
	var callback = function(bean) {
191
		for ( var i = 0; i < bean.length; i++) {
192

    
193
			var myobj = {
194
				label :bean[i].name,
195
				id :bean[i].resourceId,
196
				enableHighlight :false,
197
				href :"javascript:fetchCollection('" + bean[i].resourceId
198
						+ "');"
199
			};
200

    
201
                        if (bean[i].collection['private'])
202
                                myobj.label = myobj.label + ' *';
203

    
204
			var tmpNode = new YAHOO.widget.TextNode(myobj, node, false);
205
			if (bean[i].children.length == 0) {
206
				tmpNode.isLeaf = true;
207
			}
208
			
209
			if(specifiedCollectionID != "") {
210
				
211
				fetchCollection(specifiedCollectionID);
212
				specifiedCollectionID = "";
213
			}
214
			else {
215
			// fetch first root collection
216
			if(bean[i].father == null && i == 0) 
217
				fetchCollection(bean[i].resourceId);
218
			}
219
			
220

    
221
		}
222
		// Be sure to notify the TreeView component when the data load is
223
		// complete
224
		onCompleteCallback();
225

    
226
	};
227

    
228
	// execute remote method
229
	var defered = collectionService.getPublicVisibleChildren(node.data.id);
230
	defered.addCallback(callback);
231
}
232

    
233
function getAllPublicChildren(node, onCompleteCallback) {
234

    
235
	var callback = function(bean) {
236

    
237
		for ( var i = 0; i < bean.length; i++) {
238

    
239
			var myobj = {
240
				label :bean[i].name,
241
				id :bean[i].resourceId,
242
				enableHighlight :false,
243
				href :"javascript:fetchCollection('" + bean[i].resourceId
244
						+ "');"
245
			};
246

    
247
                        if (bean[i].collection['private'])
248
                                myobj.label = myobj.label + ' *';
249

    
250
			var tmpNode = new YAHOO.widget.TextNode(myobj, node, true);
251
			if (bean[i].children.length == 0)
252
				tmpNode.isLeaf = true;
253
			
254
			// fetch first root collection
255
			if(bean[i].father == null && i == 0) 
256
				fetchCollection(bean[i].resourceId);
257
			
258

    
259
		}
260
		// Be sure to notify the TreeView component when the data load is
261
		// complete
262
		onCompleteCallback();
263

    
264
	};
265

    
266
	// execute remote method
267
	var defered = collectionService.getPublicVisibleChildren(node.data.id);
268
	defered.addCallback(callback);
269

    
270
}
271

    
272
function fetchCollection(collectionId) {
273
	squeezeBoxLoading.open($('collection_loading'));
274

    
275
	// function called when remote method returns
276
	var callback = function(bean) {
277
		$('permanentLink').href = 'BrowseCollections.action?collectionID=' + collectionId;
278

    
279
		if(bean.isFatherPrivate != null) {
280
			document.getElementById('maincolumn2').style.display = 'block';
281
			
282
			document.getElementById('col_ID').value = collectionId;
283
			document.getElementById('collectionID').value = collectionId;
284
			document.getElementById('col_title').innerHTML = bean.collection.name;
285
			document.getElementById('collectionTitle').innerHTML = bean.collection.name;
286
			document.getElementById('col_name').innerHTML = bean.collection.name;
287
			document.getElementById('collectionName').value = bean.collection.name;
288
			document.getElementById('col_description').innerHTML = bean.collection.description;
289
			document.getElementById('collectionDescription').value = bean.collection.description;
290
			document.getElementById('col_subject').innerHTML = bean.collection.subject;
291
			document.getElementById('collectionSubject').value = bean.collection.subject;
292
			
293
			if (bean.collection.query != "") {
294
				document.getElementById('col_queryCriteria').innerHTML = bean.collection.query;
295
				document.getElementById('collectionQueryCriteria').innerHTML = bean.collection.query;
296
				$('searchCollection').setStyle('display', 'block');
297
				$('searchCollectionLink').href = "javascript:searchCollection('" + collectionId + "')";
298

    
299
			} else {
300
				document.getElementById('col_queryCriteria').innerHTML = "<i>No query defined.</i>";
301
				document.getElementById('collectionQueryCriteria').innerHTML = "<i>No query defined</i>";
302
				$('searchCollection').setStyle('display', 'none');
303
			}
304
			
305
			if(bean.collection.iconUrl != "") {
306
				document.getElementById('col_image').src = bean.collection.iconUrl;
307
				document.getElementById('collectionImage').src = bean.collection.iconUrl;
308
				
309
			} else {
310
				document.getElementById('col_image').src = "static-content/images/logo_driver.png";
311
				document.getElementById('collectionImage').src = "static-content/images/logo_driver.png";
312
			}
313
			
314
			document.getElementById('col_lastUpdateDate').innerHTML = dateFormat(Date(bean.collection.lastUpdateDate), "mmmm dd, yyyy");
315
			document.getElementById('collectionLastUpdateDate').innerHTML = dateFormat(Date(bean.collection.lastUpdateDate), "mmmm dd, yyyy");
316
			document.getElementById('col_documentCount').innerHTML = bean.collection.documentCount;
317
			document.getElementById('collectionDocumentCount').innerHTML = bean.collection.documentCount;
318
			document.getElementById('col_itemsInBasket').innerHTML = bean.collection.documentsInBasket.length;
319
			document.getElementById('collectionItemsInBasket').innerHTML = bean.collection.documentsInBasket.length;
320
			
321
			editedCollectionResourceId = bean.collection.resourceId;
322

    
323
			document.getElementById('collectionPrivateTrue').disabled = false;
324
			document.getElementById('collectionPrivateFalse').disabled = false;
325

    
326
			if (bean.collection['private']) {
327
				document.getElementById('collectionPrivateTrue').checked = true;
328
				// if father is private you cannot turn to public
329
				if (bean.isFatherPrivate) {
330
					document.getElementById('collectionPrivateTrue').disabled = true;
331
					document.getElementById('collectionPrivateFalse').disabled = true;
332
				}
333
			} else {
334
				document.getElementById('collectionPrivateFalse').checked = true;
335
				// if you have children you cannot turn to private
336
				if (bean.collection.children.length > 0) {
337
					document.getElementById('collectionPrivateTrue').disabled = true;
338
					document.getElementById('collectionPrivateFalse').disabled = true;
339
				}
340
			}
341
			
342
			if (bean.ownerEmail != null) {
343
				document.getElementById('col_ownerEmail').innerHTML = bean.ownerEmail;
344
				document.getElementById('collectionOwnerEmail').innerHTML = bean.ownerEmail;
345
			} else {
346
				document.getElementById('col_ownerEmail').innerHTML = '<i>Not specified.</i>';
347
				document.getElementById('collectionOwnerEmail').innerHTML = '<i>Not specified.</i>';
348
			}
349
			
350
			if (bean.basketDocuments != null) {
351
				$('documentList').innerHTML = "";
352
				$('collectionsDocumentList').innerHTML = "";
353
				$('basketExpandAll').setStyle('display', 'block');
354
				
355
				for(var i = 0; i < bean.basketDocuments.length; i++) 
356
					addDocumentDiv(i, bean.basketDocuments[i].title, bean.basketDocuments[i].documentId, bean.basketDocuments[i].summaryFields,'documentList',false);
357
				
358
				for ( var i = 0; i < bean.basketDocuments.length; i++)
359
					addDocumentDiv(i, bean.basketDocuments[i].title, bean.basketDocuments[i].documentId, bean.basketDocuments[i].summaryFields, 'collectionsDocumentList',true);
360
			} else {
361
				$('basketExpandAll').setStyle('display', 'none');
362
				$('documentList').innerHTML = "<div class=\"collectionField\"><span  class=\"collectionFieldComments\">There are no documents in your basket.</span></div>";
363
				$('collectionsDocumentList').innerHTML = "<div class=\"collectionField\"><span  class=\"collectionFieldComments\">There are no documents in your basket.</span></div>";
364
			}
365

    
366
			if (bean.queryResults != null && bean.queryResults.length > 0)  {
367
				/*
368
				 * TODO Enable when cql parser works
369
				$('showAllDocumentsLinkDiv').setStyle('display', 'block');
370
				$('showAllDocumentsLink').href = "An me vreis, ftiakse me";
371
				*/
372
				
373
				$('showAllDocumentsLinkDiv').setStyle('display', 'block');
374
				$('documentsDisplayed').innerHTML = bean.queryResults.length;
375
				$('totalDocuments').innerHTML = bean.queryResultCount;
376
				$('showAllDocumentsLink').href = "showResults.action?query=(textual)&collectionId='" + collectionId + "'&refine=&history=false&referer=showResults";
377
				$('col_documentCount').innerHTML = bean.queryResultCount;
378
				
379
				document.getElementById('queryResultsList').innerHTML = "";
380
				
381
				for(var i = 0; i < bean.queryResults.length; i++)
382
				        addDocumentDiv(i, bean.queryResults[i].title, bean.queryResults[i].documentId, bean.queryResults[i].summaryFields, 'queryResultsList', false);
383
				
384
				$('queryExpandAll').setStyle('display', 'block');
385
			} else {
386
				$('showAllDocumentsLinkDiv').setStyle('display', 'none');
387
				$('queryExpandAll').setStyle('display', 'none');
388
				document.getElementById('queryResultsList').innerHTML = "<h2>There are no query results for this collection.</h2>";
389
			}
390
			
391
		//	document.getElementById('editDIV').style.display = 'none';
392
		//	document.getElementById('browseDIV').style.display = 'block';
393
			
394
			if (bean.highlighted && viewMode == 'view') {
395
				$('editCollectionDiv').setStyle('display', 'block');
396
				$('editCollectionLink').href = 'BrowseCollections.action?mode=edit&collectionID=' + collectionId;
397
				$('deleteCollectionLink').href = "javascript:deleteCollection('" + collectionId + "')";
398
			} else {
399
				$('editCollectionDiv').setStyle('display', 'none');
400
			}
401

    
402
			// implement the more/fewer options sliders on ALL dropbox items on
403
			// the page
404
			$$('.mydriveritem').each(function(item){
405
				if (item.getElement('.document_details')) {
406
					var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
407
					item.getElement('.document_fewer').hide();			
408
					item.getElement('.document_more').addEvent('click', function(e){
409
						e.stop();
410
						document_details.slideIn();
411
					});
412
					item.getElement('.document_fewer').addEvent('click', function(e){
413
						e.stop();
414
						document_details.slideOut();
415
					});
416
					document_details.addEvent('complete', function() {
417
						if (this.open) {
418
							item.getElement('.document_more').hide();
419
							item.getElement('.document_fewer').show();
420
						}
421
						else {
422
							item.getElement('.document_more').show();
423
							item.getElement('.document_fewer').hide();					
424
						}
425
					});
426
				}
427
			});
428
			
429
			//implement the show all / hide all functionality
430
			$$('.showAll').each(function(aaa) {
431
				aaa.addEvent('click', function(e) {
432
					$$('.mydriveritem').each(function(item) {
433
						var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
434
						document_details.slideIn();
435
						
436
						document_details.addEvent('complete', function() {
437
							if (this.open) {
438
								item.getElement('.document_more').hide();
439
								item.getElement('.document_fewer').show();
440
							}
441
							else {
442
								item.getElement('.document_more').show();
443
								item.getElement('.document_fewer').hide();					
444
							}
445
						});
446
					});
447
					$$('.showAll').each(function(e){
448
						e.setStyle('display', 'none');
449
					});
450
					$$('.hideAll').each(function(e){
451
						e.setStyle('display', 'block');
452
					});
453
				});
454
			});
455
			
456
			$$('.hideAll').each(function(aaa) {
457
				aaa.addEvent('click', function(e) {
458
					$$('.mydriveritem').each(function(item) {
459
						var document_details = new Fx.Slide(item.getElement('.document_details')).hide();
460
						document_details.slideOut();
461
						
462
						document_details.addEvent('complete', function() {
463
							if (this.open) {
464
								item.getElement('.document_more').hide();
465
								item.getElement('.document_fewer').show();
466
							}
467
							else {
468
								item.getElement('.document_more').show();
469
								item.getElement('.document_fewer').hide();					
470
							}
471
						});
472
					});
473
					$$('.showAll').each(function(e){
474
						e.setStyle('display', 'block');
475
					});
476
					$$('.hideAll').each(function(e){
477
						e.setStyle('display', 'none');
478
					});
479
				});
480
			});
481
			
482
			$$('.hideAll').each(function(e){
483
				e.setStyle('display', 'none');
484
			});
485
			
486
		} else {
487
			alert("A problem occured while getting collection");
488
		}
489
		
490
		squeezeBoxLoading.close();
491
	};
492

    
493
	var defered = collectionService.getCollection(collectionId);
494
	defered.addCallback(callback);
495
}
496

    
497
	function addDocumentDiv(index, title, documentId, summaryFields , targetDiv , editMode) {
498
	var documentListDiv = document.getElementById(targetDiv);
499
	var documentDiv = document.createElement('div');
500
	  
501
	if(!editMode)
502
		documentDiv.setAttribute('id',"doc"+index);
503
	else
504
		documentDiv.setAttribute('id',"document"+index);
505
	
506
	var mydriveritemDiv = document.createElement('div');
507
	mydriveritemDiv.setAttribute('class',"mydriveritem");	
508
		
509
	var contentDiv = document.createElement('div');
510
	contentDiv.setAttribute('class',"content");	
511
	  
512
	if (editMode) {
513
	var rightDiv = document.createElement('div');
514
		rightDiv.setAttribute('class', "right");
515
		rightDiv.innerHTML = "<h2>" + "<input type=\"checkbox\" name=\"" + documentId + "\" value=\"true\" id=\"" + documentId + " />" + "</h2>";
516
		contentDiv.appendChild(rightDiv);
517
	}
518
	
519
	var titleDiv = document.createElement('div');
520
	titleDiv.innerHTML = "<h2><img src=\"static-content/images/icons/document_text.png\" alt=\"PDF\" width=\"25\" height=\"25\" align=\"absmiddle\" />"+title+"</h2>";
521
	
522
	var document_detailsDiv = document.createElement('div');
523
	document_detailsDiv.setAttribute('class', "document_details");
524
	
525
	for(var key in summaryFields) {	  
526
		var summaryFieldDiv = document.createElement('div');
527
		summaryFieldDiv.setAttribute('class', "resultsField")
528
	  	summaryFieldDiv.innerHTML = '<span class="resultsFieldNm">' + key + ':&nbsp;&nbsp;</span>' + summaryFields[key];
529
		document_detailsDiv.appendChild(summaryFieldDiv);
530
	}  
531
	
532
	var document_infoDiv = document.createElement('div');
533
	document_infoDiv.setAttribute('class',"document_info");
534
	
535
	var document_moreDiv = document.createElement('div');
536
	document_moreDiv.setAttribute('class',"document_more");
537
	document_moreDiv.innerHTML = "Show document details"; 
538
	
539
	var document_fewerDiv = document.createElement('div');
540
	document_fewerDiv.setAttribute('class',"document_fewer");
541
	document_fewerDiv.innerHTML = "Hide document details";
542
	document_infoDiv.appendChild(document_moreDiv);
543
	document_infoDiv.appendChild(document_fewerDiv);
544
	
545
	contentDiv.appendChild(titleDiv);
546
	contentDiv.appendChild(document_detailsDiv);
547
	contentDiv.appendChild(document_infoDiv);
548
	
549
	mydriveritemDiv.appendChild(contentDiv);
550
	documentDiv.appendChild(mydriveritemDiv);
551
	documentListDiv.appendChild(documentDiv);
552
}
553

    
554
function toggleViewMode() {
555
	if (viewMode == 'view') {
556
		setViewMode('edit');
557
	} else {
558
		setViewMode('view');
559
	}
560
}
561

    
562
function setViewMode(mode) {
563
	viewMode = mode;
564
	if (viewMode == 'view') {
565
		document.getElementById('editDIV').style.display = 'none';
566
		document.getElementById('browseDIV').style.display = 'block';
567
		$('editCollectionDiv').setStyle('display', 'block');
568

    
569
	} else {
570
		document.getElementById('editDIV').style.display = 'block';
571
		document.getElementById('browseDIV').style.display = 'none';
572
		$('editCollectionDiv').setStyle('display', 'none');
573
	}
574
}
575

    
576
function removeCollectionDocs(documentListDIV) {
577
	var col_ID = document.getElementById('collectionID').value;
578
	var docIds = getSelectedDocumentIds(documentListDIV);
579
	
580
	var callback = function(bean) {
581
		if(bean != -1) {
582
			removeDocumentsFromUI(getSelectedDocumentDivIds(documentListDIV));
583
			roarQueue.alert("<p>Document(s) removed from collection.</p>");
584
		} else {
585
			alert("A problem occured while removing document from collection.");
586
		}
587
	};
588

    
589
	var defered = collectionService.removeFromBasket(docIds, col_ID);
590
	defered.addCallback(callback);
591
}
592

    
593
function removeDocumentsFromUI(selectedDocs) {
594
  	for (var i = 0; i < selectedDocs.length; i++) {
595
    	var op = document.getElementById(selectedDocs[i]);
596

    
597
    	op.parentNode.removeChild(op);
598
    }
599
}
600

    
601
function deleteCollection(collectionId) {
602
	var callback = function(bean) {
603
		if (bean == true) {
604
			window.location = 'BrowseCollections.action';
605
		} else {
606
			roarQueue.alert('<p>There was an error deleting collection.</p><p></p>');
607
		}
608
	}
609
	
610
	if (confirm('Delete collection?'))
611
		collectionService.deleteCollection(collectionId).addCallback(callback);
612
}
(17-17/21)