Project

General

Profile

1
dojo.require("dojo.rpc.*");
2
dojo.hostenv.writeIncludes();
3
dojo.require();
4
var collectionService = new dojo.rpc.JsonService("CollectionInfo");
5

    
6
// used by allcollections.jsp and my collections.jsp
7
function searchCollection(collectionId) {
8
	var term = $('searchCollectionTerm').value.trim();
9
	
10
	if (term != "") {
11
		var termArray = term.split(" ");
12
		var query = "";
13
		
14
		for (var i = 0; i < termArray.length; i++) {
15
			if (i == 0)
16
				query = termArray[i];
17
			else
18
				query = query + " AND " + termArray[i];
19
		}
20
		
21
		query = '(' + query + ')';
22
	
23
		window.location = "showResults.action?query=" + query + "&collectionId='" + collectionId + "'&refine=&history=false&referer=showResults";
24
	}
25
}
26

    
27
// used by my collections.jsp
28
function updateCollection() {
29
	
30
	var name = document.getElementById('collectionName').value;
31
	var description = document.getElementById('collectionDescription').value;
32
	var subject = document.getElementById('collectionSubject').value;
33
	var iconUrl = document.getElementById('collectionIconUrl').value;
34
	var frozen = true;
35
	var isPrivate = (document.getElementById('collectionPrivateTrue').checked == true);
36

    
37
	var callback = function(bean) {
38
		if (bean.name != null) {
39
			document.getElementById('collectionLastUpdateDate').innerHTML = dateFormat(Date(bean.lastUpdateDate), "mmmm dd, yyyy");
40
			document.getElementById('collectionTitle').value = bean.name;
41
			document.getElementById('col_title').value = bean.name;
42

    
43
			if (bean.iconUrl != "")
44
				document.getElementById('collectionImage').src = bean.iconUrl;
45
			else
46
				document.getElementById('collectionImage').src = "struts/images/logo_driver.png";
47

    
48
			var node = tree.getNodeByProperty("id", bean.resourceId);
49

    
50
			if (bean.visible) {
51
				node.label = bean.name;
52
			} else
53
				node.label = "<i>" + bean.name + "</i>";
54

    
55
			tree.render();
56
			roarQueue.alert('<p>Collection has been updated successfully.</p><p></p>');
57
		} else
58
			alert("A problem occured while updating collection");
59
	};
60

    
61
	var collectionBean = {
62
		"resourceId" :editedCollectionResourceId,
63
		"name" :name,
64
		"description" : [ description ],
65
		"visible" :true,
66
		"private" :isPrivate,
67
		"frozen" :frozen,
68
		"subject" :subject,
69
		"iconUrl" :iconUrl
70
	};
71

    
72
	var defered = collectionService.updateCollection(collectionBean);
73
	defered.addCallback(callback);
74
}
75

    
76
// used by collection.jsp 
77
function addFather(collectionId, collectionName) {
78
	if (collectionId == 'InfoSpace') {
79
		document.getElementById('collectionFather').innerHTML = "My collections";
80
		document.getElementById('collectionFatherId').value = "InfoSpace";
81
	} else {
82
		document.getElementById('collectionFather').innerHTML = collectionName;
83
		document.getElementById('collectionFatherId').value = collectionId;
84
	}
85
}
86

    
87
function saveCollection() {
88
	var name = document.getElementById('collectionName').value;
89
	var description = document.getElementById('collectionDescription').value;
90
	var subject = document.getElementById('collectionSubject').value;
91
	var iconUrl = document.getElementById('collectionIconUrl').value;
92
	var visible = true;
93
	var frozen = true;
94
	var isPrivate = ( document.getElementById('collectionPrivate').checked == true);
95
	var father = "InfoSpace";
96
	var query;
97
	
98
	if (document.getElementById('collectionQueryCriteria'))
99
		query = document.getElementById('collectionQueryCriteria').innerHTML;
100
	
101
	if (document.getElementById('collectionFather')) {
102
		if (document.getElementById('collectionFatherId').value != "") {
103
			father = document.getElementById('collectionFatherId').value;
104
		}
105
	}
106

    
107
	var callback = function(bean) {
108
		if (bean.name != null) {
109
			roarQueue.alert('<p>Your collection has been saved.</p><p></p>');
110
			
111
			window.location = 'AllDRIVERCollections.action?collectionID=' + bean.resourceId;
112
		} else
113
			alert("A problem occured while saving collection");
114
	};
115

    
116
	var collectionBean;
117

    
118
	if (query) {
119
		collectionBean = {
120
			"name" :name,
121
			"description" : [ description ],
122
			"visible" :visible,
123
			"private" :isPrivate,
124
			"frozen" :frozen,
125
			"subject" :subject,
126
			"iconUrl" :iconUrl,
127
			"query" :query,
128
			"father" :father };
129
	} else {
130
		collectionBean = {
131
			"name" :name,
132
			"description" : [ description ],
133
			"visible" :visible,
134
			"private" :isPrivate,
135
			"frozen" :frozen,
136
			"subject" :subject,
137
			"iconUrl" :iconUrl,
138
			"father" :father };
139
	}
140
	
141
	var defered = service.saveCollection(collectionBean);
142
	defered.addCallback(callback);
143
}
(9-9/21)