1 | gs.functions = new Array();
|
---|
2 |
|
---|
3 | gs.functions.ajaxRequest = function()
|
---|
4 | {
|
---|
5 | var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
|
---|
6 | if(window.ActiveXObject)
|
---|
7 | {
|
---|
8 | for (var i=0; i<activexmodes.length; i++)
|
---|
9 | {
|
---|
10 | try
|
---|
11 | {
|
---|
12 | return new ActiveXObject(activexmodes[i]);
|
---|
13 | }
|
---|
14 | catch(e){}
|
---|
15 | }
|
---|
16 | }
|
---|
17 | else if (window.XMLHttpRequest)
|
---|
18 | {
|
---|
19 | return new XMLHttpRequest();
|
---|
20 | }
|
---|
21 | else
|
---|
22 | {
|
---|
23 | return false
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | gs.functions.makeToggle = function(buttons, divs)
|
---|
28 | {
|
---|
29 | var buttonArray = (buttons.length) ? buttons : [buttons];
|
---|
30 | var divArray = (divs.length) ? divs : [divs];
|
---|
31 |
|
---|
32 | for(var i = 0; i < buttonArray.length; i++)
|
---|
33 | {
|
---|
34 | buttonArray[i].onclick = function()
|
---|
35 | {
|
---|
36 | for(var j = 0; j < divArray.length; j++)
|
---|
37 | {
|
---|
38 | if(divArray[j].style.display == "none")
|
---|
39 | {
|
---|
40 | divArray[j].style.display = "block";
|
---|
41 | }
|
---|
42 | else
|
---|
43 | {
|
---|
44 | divArray[j].style.display = "none";
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | for(var j = 0; j < buttonArray.length; j++)
|
---|
49 | {
|
---|
50 | if(buttonArray[j].getAttribute("src") == gs.imageURLs.collapse)
|
---|
51 | {
|
---|
52 | buttonArray[j].setAttribute("src", gs.imageURLs.expand);
|
---|
53 | }
|
---|
54 | else if(buttonArray[j].getAttribute("src") == gs.imageURLs.expand)
|
---|
55 | {
|
---|
56 | buttonArray[j].setAttribute("src", gs.imageURLs.collapse);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | };
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | gs.functions.buildCollections = function(collections, finalFunction)
|
---|
64 | {
|
---|
65 | if(!collections || collections.length == 0)
|
---|
66 | {
|
---|
67 | console.log("List of collections to build is empty");
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | var counter = 0;
|
---|
72 | var buildFunction = function()
|
---|
73 | {
|
---|
74 | var ajax = new gs.functions.ajaxRequest();
|
---|
75 | ajax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);
|
---|
76 | ajax.onreadystatechange = function()
|
---|
77 | {
|
---|
78 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
79 | {
|
---|
80 | var text = ajax.responseText;
|
---|
81 | var xml = validateXML(text);
|
---|
82 |
|
---|
83 | if(!xml || checkForErrors(xml))
|
---|
84 | {
|
---|
85 | console.log("Could not build collection -> " + collections[counter] + ", aborting");
|
---|
86 | return;
|
---|
87 | }
|
---|
88 |
|
---|
89 | var status = xml.getElementsByTagName("status")[0];
|
---|
90 | var pid = status.getAttribute("pid");
|
---|
91 |
|
---|
92 | startCheckLoop(pid, "BuildCollection", function()
|
---|
93 | {
|
---|
94 | var localAjax = new gs.functions.ajaxRequest();
|
---|
95 | localAjax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
|
---|
96 | localAjax.onreadystatechange = function()
|
---|
97 | {
|
---|
98 | if(localAjax.readyState == 4 && localAjax.status == 200)
|
---|
99 | {
|
---|
100 | var localText = localAjax.responseText;
|
---|
101 | var localXML = validateXML(localText);
|
---|
102 |
|
---|
103 | if(!xml || checkForErrors(xml))
|
---|
104 | {
|
---|
105 | console.log("Could not activate collection -> " + collections[counter] + ", aborting");
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 | var localStatus = localXML.getElementsByTagName("status")[0];
|
---|
110 | if(localStatus)
|
---|
111 | {
|
---|
112 | var localPID = localStatus.getAttribute("pid");
|
---|
113 | startCheckLoop(localPID, "ActivateCollection", function()
|
---|
114 | {
|
---|
115 | if (++counter == _collections.length)
|
---|
116 | {
|
---|
117 | //Run this function once we are done building all the collections
|
---|
118 | if(finalFunction){finalFunction();}
|
---|
119 | }
|
---|
120 | else
|
---|
121 | {
|
---|
122 | buildFunction();
|
---|
123 | }
|
---|
124 | });
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | localAjax.send();
|
---|
129 | });
|
---|
130 | }
|
---|
131 | }
|
---|
132 | ajax.send();
|
---|
133 | }
|
---|
134 | buildFunction();
|
---|
135 | }
|
---|
136 |
|
---|
137 | function startCheckLoop(pid, serverFunction, callbackFunction)
|
---|
138 | {
|
---|
139 | var ajaxFunction = function()
|
---|
140 | {
|
---|
141 | var ajax = new gs.functions.ajaxRequest();
|
---|
142 | ajax.open("GET", _baseURL + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
|
---|
143 | ajax.onreadystatechange = function()
|
---|
144 | {
|
---|
145 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
146 | {
|
---|
147 | var text = ajax.responseText;
|
---|
148 | var xml = validateXML(text);
|
---|
149 |
|
---|
150 | if(!xml || checkForErrors(xml))
|
---|
151 | {
|
---|
152 | console.log("Could not check status of " + serverFunction + ", there was an error in the XML, aborting");
|
---|
153 | return;
|
---|
154 | }
|
---|
155 |
|
---|
156 | var status = xml.getElementsByTagName("status")[0];
|
---|
157 | var code = status.getAttribute("code");
|
---|
158 |
|
---|
159 | if (code == COMPLETED || code == SUCCESS)
|
---|
160 | {
|
---|
161 | callbackFunction();
|
---|
162 | }
|
---|
163 | else if (code == HALTED || code == ERROR)
|
---|
164 | {
|
---|
165 | console.log("Could not check status of " + serverFunction + ", there was an error on the server, aborting");
|
---|
166 | }
|
---|
167 | else
|
---|
168 | {
|
---|
169 | setTimeout(ajaxFunction, 1000);
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 | ajax.send();
|
---|
174 | }
|
---|
175 | ajaxFunction();
|
---|
176 | }
|
---|
177 |
|
---|
178 | function callMetadataServer(callingFunction, url, responseFunction)
|
---|
179 | {
|
---|
180 | var ajax = new gs.functions.ajaxRequest();
|
---|
181 | ajax.open("GET", url, true);
|
---|
182 | ajax.onreadystatechange = function()
|
---|
183 | {
|
---|
184 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
185 | {
|
---|
186 | console.log("(" + callingFunction + ") Response received from server: " + ajax.responseText);
|
---|
187 |
|
---|
188 | if(responseFunction != null)
|
---|
189 | {
|
---|
190 | responseFunction(ajax.responseText);
|
---|
191 | }
|
---|
192 | }
|
---|
193 | else if(ajax.readyState == 4)
|
---|
194 | {
|
---|
195 | console.log("(" + callingFunction + ") Failed");
|
---|
196 | }
|
---|
197 | }
|
---|
198 | ajax.send();
|
---|
199 | }
|
---|
200 |
|
---|
201 | /*************************
|
---|
202 | * SET METADATA FUNCTIONS *
|
---|
203 | *************************/
|
---|
204 |
|
---|
205 | gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, prevMetadataValue, metamode, responseFunction)
|
---|
206 | {
|
---|
207 | callMetadataServer("setImportMetadata", "cgi-bin/metadata-server.pl?a=set-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&prevmetavalue=" + prevMetadataValue + "&metamode=" + metamode, responseFunction);
|
---|
208 | }
|
---|
209 |
|
---|
210 | gs.functions.setArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction)
|
---|
211 | {
|
---|
212 | if(metadataPosition != null)
|
---|
213 | {
|
---|
214 | callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
|
---|
215 | }
|
---|
216 | else if(prevMetadataValue != null)
|
---|
217 | {
|
---|
218 | callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&prevmetavalue=" + prevMetadataValue + "&metamode=" + metamode, responseFunction);
|
---|
219 | }
|
---|
220 | else
|
---|
221 | {
|
---|
222 | callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | gs.functions.setIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction)
|
---|
227 | {
|
---|
228 | if(metadataPosition != null)
|
---|
229 | {
|
---|
230 | callMetadataServer("setIndexMetadata", "cgi-bin/metadata-server.pl?a=set-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
|
---|
231 | }
|
---|
232 | else if(prevMetadataValue != null)
|
---|
233 | {
|
---|
234 | callMetadataServer("setIndexMetadata", "cgi-bin/metadata-server.pl?a=set-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&prevmetavalue=" + prevMetadataValue + "&metamode=" + metamode, responseFunction);
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | gs.functions.setMetadata = function(collection, site, documentID, metadataName, metadataValue, metamode, responseFunction)
|
---|
239 | {
|
---|
240 | var nameArray = ["setImportMetadata", "setArchivesMetadata", "setIndexMetadata"];
|
---|
241 | var functionArray = ["set-import-metadata", "set-archives-metadata", "set-metadata"];
|
---|
242 |
|
---|
243 | for(var i = 0; i < nameArray.length; i++)
|
---|
244 | {
|
---|
245 | callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | /*************************
|
---|
250 | * GET METADATA FUNCTIONS *
|
---|
251 | *************************/
|
---|
252 |
|
---|
253 | gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction)
|
---|
254 | {
|
---|
255 | var url = "cgi-bin/metadata-server.pl?a=get-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
256 | callMetadataServer("getImportMetadata", url, function(responseText)
|
---|
257 | {
|
---|
258 | var metadata = new GSMetadata(collection, site, documentID, metadataName, null, responseText);
|
---|
259 | if(responseFunction != null)
|
---|
260 | {
|
---|
261 | responseFunction(metadata);
|
---|
262 | }
|
---|
263 | });
|
---|
264 | }
|
---|
265 |
|
---|
266 | gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
|
---|
267 | {
|
---|
268 | var url = "cgi-bin/metadata-server.pl?a=get-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
269 | if(metadataPosition != null)
|
---|
270 | {
|
---|
271 | url += "&metapos=" + metadataPosition;
|
---|
272 | }
|
---|
273 |
|
---|
274 | callMetadataServer("getArchivesMetadata", url, function(responseText)
|
---|
275 | {
|
---|
276 | var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, responseText);
|
---|
277 | if(responseFunction != null)
|
---|
278 | {
|
---|
279 | responseFunction(metadata);
|
---|
280 | }
|
---|
281 | });
|
---|
282 | }
|
---|
283 |
|
---|
284 | gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
|
---|
285 | {
|
---|
286 | var url = "cgi-bin/metadata-server.pl?a=get-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
287 | if(metadataPosition != null)
|
---|
288 | {
|
---|
289 | url += "&metapos=" + metadataPosition;
|
---|
290 | }
|
---|
291 |
|
---|
292 | callMetadataServer("getIndexMetadata", url, function(responseText)
|
---|
293 | {
|
---|
294 | var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, responseText);
|
---|
295 |
|
---|
296 | if(responseFunction != null)
|
---|
297 | {
|
---|
298 | responseFunction(metadata);
|
---|
299 | }
|
---|
300 | });
|
---|
301 | }
|
---|
302 |
|
---|
303 | /****************************
|
---|
304 | * REMOVE METADATA FUNCTIONS *
|
---|
305 | ****************************/
|
---|
306 |
|
---|
307 | gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
308 | {
|
---|
309 | callMetadataServer("removeImportMetadata", "cgi-bin/metadata-server.pl?a=remove-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
310 | }
|
---|
311 |
|
---|
312 | gs.functions.removeArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
313 | {
|
---|
314 | if(metadataPosition != null)
|
---|
315 | {
|
---|
316 | callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
317 | }
|
---|
318 | else if(metadataValue != null)
|
---|
319 | {
|
---|
320 | callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | gs.functions.removeIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
325 | {
|
---|
326 | if(metadataPosition != null)
|
---|
327 | {
|
---|
328 | callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
329 | }
|
---|
330 | else if(metadataValue != null)
|
---|
331 | {
|
---|
332 | callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | gs.functions.removeMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
337 | {
|
---|
338 | var nameArray = ["removeImportMetadata", "removeArchivesMetadata", "removeIndexMetadata"];
|
---|
339 | var functionArray = ["remove-import-metadata", "remove-archives-metadata", "remove-metadata"];
|
---|
340 |
|
---|
341 | for(var i = 0; i < nameArray.length; i++)
|
---|
342 | {
|
---|
343 | callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
344 | }
|
---|
345 | }
|
---|