source: main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js@ 31543

Last change on this file since 31543 was 31543, checked in by ak19, 7 years ago

Next incremental change to adding user comments in GS3. This time to make the get-meta-array and set-meta-array functions be called asynchronously from user_comments.js (these operations can be called synchronously by any others wishing to tuse them, and do so by default). user_comments.js chooses to call get-meta-array and even set-meta-array asynchronously by passing in the appropriate flag to make the ajax calls asynchronous. To protect against any overlapping read/write issues and mutliple submit comments (set-meta-array calls) from being fired off with overlap, the submit button gets disabled until the set-meta-array call has returned and its callback is called. Similarly, the submit button is disabled until the page has finished loading existing user comments (get-meta-array call).

File size: 24.5 KB
Line 
1var SUCCESS = 1;
2var ACCEPTED = 2;
3var ERROR = 3;
4var CONTINUING = 10;
5var COMPLETED = 11;
6var HALTED = 12;
7
8gs.functions = new Array();
9
10gs.jqGet = function(id)
11{
12 return $("#" + id.replace(/\./g, "\\.").replace(/:/g,"\\:"));
13}
14
15gs.functions.ajaxRequest = function()
16{
17 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
18 if(window.ActiveXObject)
19 {
20 for (var i=0; i<activexmodes.length; i++)
21 {
22 try
23 {
24 return new ActiveXObject(activexmodes[i]);
25 }
26 catch(e){}
27 }
28 }
29 else if (window.XMLHttpRequest)
30 {
31 return new XMLHttpRequest();
32 }
33 else
34 {
35 return false
36 }
37}
38
39gs.functions.hasClass = function(elem, classVal)
40{
41 if(!elem || !elem.getAttribute("class"))
42 {
43 return false;
44 }
45
46 return (elem.getAttribute("class").search(classVal) != -1)
47}
48
49gs.functions.getElementsByClassName = function(cl)
50{
51 var nodes = new Array();
52 var classRegEx = new RegExp('\\b'+cl+'\\b');
53 var allElems = document.getElementsByTagName('*');
54
55 for (var i = 0; i < allElems.length; i++)
56 {
57 var classes = allElems[i].className;
58 if (classRegEx.test(classes))
59 {
60 nodes.push(allElems[i]);
61 }
62 }
63 return nodes;
64};
65
66gs.functions.makeToggle = function(buttons, divs)
67{
68 var buttonArray = (buttons.length) ? buttons : [buttons];
69 var divArray = (divs.length) ? divs : [divs];
70
71 for(var i = 0; i < buttonArray.length; i++)
72 {
73 buttonArray[i].onclick = function()
74 {
75 for(var j = 0; j < divArray.length; j++)
76 {
77 if(divArray[j].style.display == "none")
78 {
79 divArray[j].style.display = "block";
80 }
81 else
82 {
83 divArray[j].style.display = "none";
84 }
85 }
86
87 for(var j = 0; j < buttonArray.length; j++)
88 {
89 if(buttonArray[j].getAttribute("src") == gs.imageURLs.collapse)
90 {
91 buttonArray[j].setAttribute("src", gs.imageURLs.expand);
92 }
93 else if(buttonArray[j].getAttribute("src") == gs.imageURLs.expand)
94 {
95 buttonArray[j].setAttribute("src", gs.imageURLs.collapse);
96 }
97 }
98 };
99 }
100}
101
102gs.functions.checkForErrors = function(xml)
103{
104 var errorElems = xml.getElementsByTagName("error");
105
106 if(errorElems && errorElems.length > 0)
107 {
108 var errorString = gs.text.dse.error_saving_changes + ": ";
109 for(var i = 0; i < errorElems.length; i++)
110 {
111 errorString += " " + errorElems.item(i).firstChild.nodeValue;
112 }
113 alert(errorString);
114 return true;
115 }
116 return false; //No errors
117}
118
119gs.functions.validateXML = function(txt)
120{
121 // code for IE
122 if (window.ActiveXObject)
123 {
124 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
125 xmlDoc.async = "false";
126 xmlDoc.loadXML(document.all(txt).value);
127
128 if(xmlDoc.parseError.errorCode!=0)
129 {
130 txt = dse.error_code + ": " + xmlDoc.parseError.errorCode + "\n";
131 txt = txt + dse.error_reason + ": " + xmlDoc.parseError.reason;
132 txt = txt + dse.error_line + ": " + xmlDoc.parseError.line;
133 console.log(txt);
134 return null;
135 }
136
137 return xmlDoc;
138 }
139 // code for Mozilla, Firefox, Opera, etc.
140 else if (document.implementation.createDocument)
141 {
142 var parser = new DOMParser();
143 var xmlDoc = parser.parseFromString(txt,"text/xml");
144
145 if (xmlDoc.getElementsByTagName("parsererror").length > 0)
146 {
147 console.log(gs.text.dse.xml_error);
148 return null;
149 }
150
151 return xmlDoc;
152 }
153 else
154 {
155 console.log(gs.text.dse.browse_cannot_validate_xml);
156 }
157 return null;
158}
159
160gs.functions.buildCollections = function(collections, finalFunction)
161{
162 if(!collections || collections.length == 0)
163 {
164 console.log("List of collections to build is empty");
165 return;
166 }
167
168 var counter = 0;
169 var buildFunction = function()
170 {
171 var ajax = new gs.functions.ajaxRequest();
172 ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);
173 ajax.onreadystatechange = function()
174 {
175 if(ajax.readyState == 4 && ajax.status == 200)
176 {
177 var text = ajax.responseText;
178 var xml = gs.functions.validateXML(text);
179
180 if(!xml || gs.functions.checkForErrors(xml))
181 {
182 console.log("Could not build collection -> " + collections[counter] + ", aborting");
183 return;
184 }
185
186 var status = xml.getElementsByTagName("status")[0];
187 var pid = status.getAttribute("pid");
188
189 gs.functions.startCheckLoop(pid, "BuildCollection", function()
190 {
191 var localAjax = new gs.functions.ajaxRequest();
192 localAjax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
193 localAjax.onreadystatechange = function()
194 {
195 if(localAjax.readyState == 4 && localAjax.status == 200)
196 {
197 var localText = localAjax.responseText;
198 var localXML = gs.functions.validateXML(localText);
199
200 if(!xml || gs.functions.checkForErrors(xml))
201 {
202 console.log("Could not activate collection -> " + collections[counter] + ", aborting");
203 return;
204 }
205
206 var localStatus = localXML.getElementsByTagName("status")[0];
207 if(localStatus)
208 {
209 var localPID = localStatus.getAttribute("pid");
210 gs.functions.startCheckLoop(localPID, "ActivateCollection", function()
211 {
212 if (++counter == collections.length)
213 {
214 //Run this function once we are done building all the collections
215 if(finalFunction){finalFunction();}
216 }
217 else
218 {
219 buildFunction();
220 }
221 });
222 }
223 }
224 }
225 localAjax.send();
226 });
227 }
228 }
229 ajax.send();
230 }
231 buildFunction();
232}
233
234gs.functions.startCheckLoop = function(pid, serverFunction, callbackFunction)
235{
236 var ajaxFunction = function()
237 {
238 var ajax = new gs.functions.ajaxRequest();
239 ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
240 ajax.onreadystatechange = function()
241 {
242 if(ajax.readyState == 4 && ajax.status == 200)
243 {
244 var text = ajax.responseText;
245 var xml = gs.functions.validateXML(text);
246
247 if(!xml || gs.functions.checkForErrors(xml))
248 {
249 console.log("Could not check status of " + serverFunction + ", there was an error in the XML, aborting");
250 return;
251 }
252
253 var status = xml.getElementsByTagName("status")[0];
254 var code = status.getAttribute("code");
255
256 if (code == COMPLETED || code == SUCCESS)
257 {
258 callbackFunction();
259 }
260 else if (code == HALTED || code == ERROR)
261 {
262 console.log("Could not check status of " + serverFunction + ", there was an error on the server, aborting");
263 }
264 else
265 {
266 setTimeout(ajaxFunction, 1000);
267 }
268 }
269 }
270 ajax.send();
271 }
272 ajaxFunction();
273}
274
275function inc(a, b)
276{
277 var carry = 0;
278 var num = 0;
279 var i = 0;
280
281 while((carry || (i < a.length) || (i < b.length)) && (i < 100))
282 {
283 num = carry;
284 if(i < a.length){num += a[i];}
285 if(i < b.length){num += b[i];}
286
287 if(num >= 256)
288 {
289 num -= 256;
290 carry = 1;
291 }
292 else
293 {
294 carry = 0;
295 }
296
297 a[i] = num;
298
299 i++;
300 }
301}
302
303function ifposDec(a, b)
304{
305 var carry = 0;
306 var num = 0;
307 var i = 0;
308
309 if(b.length > a.length){return a;}
310 if(b.length == a.length)
311 {
312 i = a.length - 1;
313 while(i >= 0)
314 {
315 if(a[i] > b[i]){break;}
316 if(a[i] < b[i]){return a;}
317 i--;
318 }
319 }
320
321 i = 0;
322 var len = 0;
323 var outString = "";
324 while((i < a.length) || (i < b.length))
325 {
326 num = -carry;
327 if(i < a.length){num += a[i];}
328 if(i < b.length){num -= b[i];}
329
330 if(num < 0)
331 {
332 num += 256;
333 carry = 1;
334 }
335 else
336 {
337 carry = 0;
338 }
339
340 a[i] = num;
341 outString += num + ","
342 i++
343
344 if(num != 0){len = i}
345 }
346
347 if(len < a.length)
348 {
349 a = a.slice(0, len);
350 }
351
352 return a;
353}
354
355function convertNum(a)
356{
357 var result = new Array();
358 var i;
359 var convert = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
360
361 if(a.length == 0)
362 {
363 result.push("0");
364 return result;
365 }
366
367 for(i = a.length - 1; i >= 0; i--)
368 {
369 result.push(convert[Math.floor(a[i]/16)]);
370 result.push(convert[Math.floor(a[i]%16)]);
371 }
372
373 var resultString = "";
374 for(var j = 0; j < result.length; j++)
375 {
376 resultString += result[j];
377 }
378
379 return resultString;
380}
381
382gs.functions.hashString = function(str)
383{
384 var remainder = new Array();
385 var primePow = new Array();
386 var pow =
387 [
388 255, 255, 255,
389 255, 255, 255,
390 255, 255, 255,
391 255, 255, 1
392 ];
393
394 for(var i = 0; i < 8; i++)
395 {
396 primePow.push(pow.slice()); //The javascript way to do an array copy (yuck!)
397 inc(pow, pow);
398 }
399
400 for(var i = 0; i < str.length; i++)
401 {
402 var c = str.charCodeAt(i);
403
404 if(remainder.length == 99)
405 {
406 return null;
407 }
408
409 for(var j = remainder.length; j > 0; j--)
410 {
411 remainder[j] = remainder[j-1];
412 }
413 remainder[0] = c;
414
415 for(var j = 7; j >= 0; j--)
416 {
417 remainder = ifposDec(remainder, primePow[j]);
418 }
419 }
420
421 return convertNum(remainder);
422}
423
424// No function overloading in JavaScript. Can pass a custom object, however, see
425// http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
426function callMetadataServerGET(callingFunction, url, responseFunction, opts)
427{
428 var async_setting = true; // Internal processing of 'read' operations (get meta) is not order dependent
429
430 // If doing set- or remove- (not get-) metadata, then rewrite URLs to call GS2Construct's ModfiyMetadata service instead (which will ensure this only works when authenticated).
431 // From:
432 // <gs3server>/cgi-bin/metadata-server.pl?a=set-archives-metadata&c=smallcol&site=localsite&d=HASH01454f31011f6b6b26eaf8d7&metaname=Title&metavalue=Moo&prevmetavalue=Blabla&metamode=override
433 // To:
434 // <gs3server>/library?a=g&rt=r&ro=1&s=ModifyMetadata&s1.a=set-archives-metadata&s1.collection=smallcol&s1.site=localsite&s1.d=HASH01454f31011f6b6b26eaf8d7&s1.metaname=Title&s1.metavalue=Moo&s1.prevmetavalue=Blabla&s1.metamode=override
435
436 // if we're doing a set- or remove- metadata operations, then we'll be changing the URL to make sure we go through GS3's authentication
437 if(url.indexOf("set-") != -1 || url.indexOf("remove-") != -1) {
438
439 url = url.replace("&c=", "&collection="); // c is a special param name for GS2Construct
440 url = url.replace(/(&|\?)([^=]*=)/g, "$1"+"s1.$2"); // prefix param names with "s1."
441 url = url.replace("cgi-bin/metadata-server.pl?", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=ModifyMetadata&");
442
443 //console.log("@@@@@ URL is " + url);
444
445 async_setting = false; // for 'write' operations (set/remove meta), we force sequential processing of the internal operation.
446
447 } // otherwise, such as for get- metadata operation, we proceed as before, which will not require authentication
448
449 if (opts != null && opts["forceSync"] != null) {
450 async_setting = (!opts["forceSync"]);
451 }
452
453 console.log("Away to call: " + url);
454 var ajaxResponse = null;
455
456 $.ajax(url, {async: async_setting})
457 .success(function(response)
458 {
459 console.log("(" + callingFunction + ") Response received from server: " + ajaxResponse);
460
461 ajaxResponse = response;
462
463 //var xml = $.parseXML(response);
464 //console.log(xml);
465
466 if(responseFunction != null)
467 {
468
469 responseFunction(response);
470 }
471 })
472 .error(function()
473 {
474 console.log("(" + callingFunction + ") Failed");
475 });
476
477 console.log("Finished ajax call to: " + url);
478
479 console.log("Got response: " + ajaxResponse);
480 return ajaxResponse;
481}
482
483
484// No function overloading in JavaScript. Can pass a custom object, however, see
485// http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
486function callMetadataServer(callingFunction, url, responseFunction, opts)
487{
488 var async_setting = true; // Internal processing of 'read' operations (get meta) is not order dependent
489
490 // If doing set- or remove- (not get-) metadata, then rewrite URLs to call GS2Construct's ModfiyMetadata service instead (which will ensure this only works when authenticated).
491 // From:
492 // <gs3server>/cgi-bin/metadata-server.pl?a=set-archives-metadata&c=smallcol&site=localsite&d=HASH01454f31011f6b6b26eaf8d7&metaname=Title&metavalue=Moo&prevmetavalue=Blabla&metamode=override
493 // To:
494 // <gs3server>/library?a=g&rt=r&ro=1&s=ModifyMetadata&s1.a=set-archives-metadata&s1.collection=smallcol&s1.site=localsite&s1.d=HASH01454f31011f6b6b26eaf8d7&s1.metaname=Title&s1.metavalue=Moo&s1.prevmetavalue=Blabla&s1.metamode=override
495
496 // if we're doing a set- or remove- metadata operations, then we'll be changing the URL to make sure we go through GS3's authentication
497 if(url.indexOf("set-") != -1 || url.indexOf("remove-") != -1) {
498
499 url = url.replace("&c=", "&collection="); // c is a special param name for GS2Construct
500 url = url.replace(/(&|\?)([^=]*=)/g, "$1"+"s1.$2"); // prefix param names with "s1."
501 url = url.replace("cgi-bin/metadata-server.pl?", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=ModifyMetadata&");
502
503 //console.log("@@@@@ URL is " + url);
504
505 async_setting = false; // for 'write' operations (set/remove meta), we force sequential processing of the internal operation.
506
507 } // otherwise, such as for get- metadata operation, we proceed as before, which will not require authentication
508
509 if (opts != null) {
510 if(opts["forceSync"] != null) {
511 async_setting = (!opts["forceSync"]);
512 }
513 }
514
515 console.log("Away to call: " + url);
516 var ajaxResponse = "No response received yet, async ajax request";
517
518 var splitURL = url.split("?");
519 url = splitURL[0];
520 var params = splitURL[1];
521 var gsapi = new GSAjaxAPI(url);
522
523 // ajax calls default to using method GET, we want to do POST operations for get-meta and set-meta requests
524 // since get-meta-array and especially set-meta-array can be large, e.g. for user comments.
525
526 if(async_setting) {
527 gsapi.urlPostAsync(url, params, responseFunction);
528 } else {
529 ajaxResponse = gsapi.urlPostSync(url, params);
530 }
531
532 console.log("(" + callingFunction + ") Response received from server: " + ajaxResponse);
533
534 console.log("Finished ajax call to: " + url);
535
536 console.log("Got response: " + ajaxResponse);
537 return ajaxResponse;
538}
539
540
541/*************************
542* SET METADATA FUNCTIONS *
543*************************/
544
545gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, prevMetadataValue, metamode, responseFunction)
546{
547 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);
548}
549
550gs.functions.setArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction)
551{
552 if(metadataPosition != null)
553 {
554 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);
555 }
556 else if(prevMetadataValue != null)
557 {
558 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);
559 }
560 else
561 {
562 callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
563 }
564}
565
566gs.functions.setIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction)
567{
568 if(metadataPosition != null)
569 {
570 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);
571 }
572 else if(prevMetadataValue != null)
573 {
574 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);
575 }
576}
577
578gs.functions.setMetadata = function(collection, site, documentID, metadataName, metadataValue, metamode, responseFunction)
579{
580 var nameArray = ["setImportMetadata", "setArchivesMetadata", "setIndexMetadata"];
581 var functionArray = ["set-import-metadata", "set-archives-metadata", "set-metadata"];
582
583 for(var i = 0; i < nameArray.length; i++)
584 {
585 callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue + "&metamode=" + metamode, responseFunction);
586 }
587}
588
589// New. Modified version of the GS2 version of this method in gsajaxapi.js.
590// The where parameter can be specified as one or more of: import, archives, index, live
591// separated by |. If null, it is assumed to be index which is the original default
592// behaviour of calling set-metadata-array. E.g. where=import|archives|index
593// THIS METHOD IS SYNCHRONOUS
594gs.functions.setMetadataArray = function(collection, site, docArray, metamode, where, responseFunction, forceSync)
595{
596 docArrayJSON = JSON.stringify(docArray);
597
598 var params = "a=" + escape("set-metadata-array"); //"a=set-metadata-array";
599 if(where != null) {
600 params += "&where=" + escape(where); // if where not specified, meta-server will default to setting index meta
601 //} else {
602 // params += "&where=import|archives|index";
603 }
604 params += "&c="+escape(collection);
605 params += "&site="+escape(site);
606 params += "&json="+escape(docArrayJSON);
607
608 if (metamode!=null) {
609 params += "&metamode=" + escape(metamode);
610 }
611
612 // set operations are generally synchronous, but allow calling function to force ajax call
613 // to be synchronous or not. Default is synchronous, as it was for GS2
614 if(forceSync == null) {
615 forceSync = true;
616 }
617
618 var response = callMetadataServer("Setting metadata in "+where, "cgi-bin/metadata-server.pl?"+params, responseFunction, {"forceSync": forceSync});
619
620 return response;
621 // return this.urlPostSync(mdserver,params); // gsajaxapi.js version for GS2
622}
623
624
625/*************************
626* GET METADATA FUNCTIONS *
627*************************/
628
629// New. Modified version of the GS2 version of this method in gsajaxapi.js.
630// See description for setMetadataArray above for information about the 'where' parameter.
631// THIS METHOD IS SYNCHRONOUS BY DEFAULT. Set forceSync to false to override this default behaviour
632gs.functions.getMetadataArray = function(collection, site, docArray, where, responseFunction, forceSync)
633{
634 docArrayJSON = JSON.stringify(docArray);
635
636 var params = "a=" + escape("get-metadata-array"); //"a=set-metadata-array";
637 if(where != null) {
638 params += "&where=" + escape(where); // if where not specified, meta-server will default to setting index meta
639 //} else {
640 // params += "&where=import|archives|index";
641 }
642 params += "&c="+escape(collection);
643 params += "&site="+escape(site);
644 params += "&json="+escape(docArrayJSON);
645
646 // get operations are generally asynchronous, but allow calling function to force ajax call
647 // to be synchronous or not. Default is synchronous, as it was for GS2
648 if(forceSync == null) {
649 forceSync = true;
650 }
651 // Objects/maps can use identifiers or strings for property names
652 // http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
653 // https://www.w3schools.com/js/js_objects.asp
654 var response = callMetadataServer("Getting metadata from "+where, "cgi-bin/metadata-server.pl?"+params, responseFunction, {"forceSync":forceSync});
655
656 return response;
657 //return this.urlPostSync(mdserver,params); // gsajaxapi.js version for GS2
658}
659
660
661gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction)
662{
663 var url = "cgi-bin/metadata-server.pl?a=get-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
664 callMetadataServer("getImportMetadata", url, function(responseText)
665 {
666 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, null, responseText);
667 if(responseFunction != null)
668 {
669 responseFunction(metadata);
670 }
671 });
672}
673
674gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
675{
676 var url = "cgi-bin/metadata-server.pl?a=get-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
677 if(metadataPosition != null)
678 {
679 url += "&metapos=" + metadataPosition;
680 }
681
682 callMetadataServer("getArchivesMetadata", url, function(responseText)
683 {
684 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, metadataPosition, responseText); // indexPos, archivesPos, metaval (responseText)
685 if(responseFunction != null)
686 {
687 responseFunction(metadata);
688 }
689 });
690}
691
692gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
693{
694 var url = "cgi-bin/metadata-server.pl?a=get-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
695 if(metadataPosition != null)
696 {
697 url += "&metapos=" + metadataPosition;
698 }
699
700 callMetadataServer("getIndexMetadata", url, function(responseText)
701 {
702 var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, null, responseText); // indexPos, archivesPos, metaval (responseText)
703
704 if(responseFunction != null)
705 {
706 responseFunction(metadata);
707 }
708 });
709}
710
711/****************************
712* REMOVE METADATA FUNCTIONS *
713****************************/
714
715gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
716{
717 callMetadataServer("removeImportMetadata", "cgi-bin/metadata-server.pl?a=remove-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metavalue=" + metadataValue + "&metaname=" + metadataName, responseFunction);
718}
719
720gs.functions.removeArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
721{
722 if(metadataPosition != null)
723 {
724 callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
725 }
726 else if(metadataValue != null)
727 {
728 callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metavalue=" + metadataValue + "&metaname=" + metadataName, responseFunction);
729 }
730}
731
732gs.functions.removeIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
733{
734 if(metadataPosition != null)
735 {
736 callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
737 }
738 else if(metadataValue != null)
739 {
740 callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metavalue=" + metadataValue + "&metaname=" + metadataName, responseFunction);
741 }
742}
743
744gs.functions.removeMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
745{
746 var nameArray = ["removeImportMetadata", "removeArchivesMetadata", "removeIndexMetadata"];
747 var functionArray = ["remove-import-metadata", "remove-archives-metadata", "remove-metadata"];
748
749 for(var i = 0; i < nameArray.length; i++)
750 {
751 callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metavalue=" + metadataValue + "&metaname=" + metadataName, responseFunction);
752 }
753}
Note: See TracBrowser for help on using the repository browser.