[24930] | 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 | }
|
---|
[25008] | 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 | }
|
---|
| 199 |
|
---|
| 200 | /*************************
|
---|
| 201 | * SET METADATA FUNCTIONS *
|
---|
| 202 | *************************/
|
---|
| 203 |
|
---|
| 204 | gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
| 205 | {
|
---|
| 206 | callMetadataServer("setImportMetadata", "cgi-bin/metadata-server.pl?a=set-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | gs.functions.setArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
| 210 | {
|
---|
| 211 | if(metadataPosition != null)
|
---|
| 212 | {
|
---|
| 213 | callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
| 214 | }
|
---|
| 215 | else if(metadataValue != null)
|
---|
| 216 | {
|
---|
| 217 | callMetadataServer("setArchivesMetadata", "cgi-bin/metadata-server.pl?a=set-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | gs.functions.setIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
| 222 | {
|
---|
| 223 | if(metadataPosition != null)
|
---|
| 224 | {
|
---|
| 225 | callMetadataServer("setIndexMetadata", "cgi-bin/metadata-server.pl?a=set-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
| 226 | }
|
---|
| 227 | else if(metadataValue != null)
|
---|
| 228 | {
|
---|
| 229 | callMetadataServer("setIndexMetadata", "cgi-bin/metadata-server.pl?a=set-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | gs.functions.setMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
| 234 | {
|
---|
| 235 | var nameArray = ["setImportMetadata", "setArchivesMetadata", "setIndexMetadata"];
|
---|
| 236 | var functionArray = ["set-import-metadata", "set-archives-metadata", "set-metadata"];
|
---|
| 237 |
|
---|
| 238 | for(var i = 0; i < nameArray.length; i++)
|
---|
| 239 | {
|
---|
| 240 | callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | /*************************
|
---|
| 245 | * GET METADATA FUNCTIONS *
|
---|
| 246 | *************************/
|
---|
| 247 |
|
---|
| 248 | gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction)
|
---|
| 249 | {
|
---|
| 250 | var url = "cgi-bin/metadata-server.pl?a=get-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
| 251 | callMetadataServer("getImportMetadata", url, function(responseText)
|
---|
| 252 | {
|
---|
| 253 | var metadata = new GSMetadata(collection, site, documentID, metadataName, null, responseText);
|
---|
| 254 | if(responseFunction != null)
|
---|
| 255 | {
|
---|
| 256 | responseFunction(metadata);
|
---|
| 257 | }
|
---|
| 258 | });
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
|
---|
| 262 | {
|
---|
| 263 | var url = "cgi-bin/metadata-server.pl?a=get-archives-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
| 264 | if(metadataPosition != null)
|
---|
| 265 | {
|
---|
| 266 | url += "&metapos=" + metadataPosition;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | callMetadataServer("getArchivesMetadata", url, function(responseText)
|
---|
| 270 | {
|
---|
| 271 | var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, responseText);
|
---|
| 272 | if(responseFunction != null)
|
---|
| 273 | {
|
---|
| 274 | responseFunction(metadata);
|
---|
| 275 | }
|
---|
| 276 | });
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction)
|
---|
| 280 | {
|
---|
| 281 | var url = "cgi-bin/metadata-server.pl?a=get-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName;
|
---|
| 282 | if(metadataPosition != null)
|
---|
| 283 | {
|
---|
| 284 | url += "&metapos=" + metadataPosition;
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | callMetadataServer("getIndexMetadata", url, function(responseText)
|
---|
| 288 | {
|
---|
| 289 | var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, responseText);
|
---|
| 290 |
|
---|
| 291 | if(responseFunction != null)
|
---|
| 292 | {
|
---|
| 293 | responseFunction(metadata);
|
---|
| 294 | }
|
---|
| 295 | });
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | /****************************
|
---|
| 299 | * REMOVE METADATA FUNCTIONS *
|
---|
| 300 | ****************************/
|
---|
| 301 |
|
---|
| 302 | gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
| 303 | {
|
---|
| 304 | callMetadataServer("removeImportMetadata", "cgi-bin/metadata-server.pl?a=remove-import-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | gs.functions.removeArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
| 308 | {
|
---|
| 309 | if(metadataPosition != null)
|
---|
| 310 | {
|
---|
| 311 | callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archive-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
| 312 | }
|
---|
| 313 | else if(metadataValue != null)
|
---|
| 314 | {
|
---|
| 315 | callMetadataServer("removeArchiveMetadata", "cgi-bin/metadata-server.pl?a=remove-archive-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | gs.functions.removeIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction)
|
---|
| 320 | {
|
---|
| 321 | if(metadataPosition != null)
|
---|
| 322 | {
|
---|
| 323 | callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metapos=" + metadataPosition, responseFunction);
|
---|
| 324 | }
|
---|
| 325 | else if(metadataValue != null)
|
---|
| 326 | {
|
---|
| 327 | callMetadataServer("removeIndexMetadata", "cgi-bin/metadata-server.pl?a=remove-metadata&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | gs.functions.removeMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction)
|
---|
| 332 | {
|
---|
| 333 | var nameArray = ["removeImportMetadata", "removeArchivesMetadata", "removeIndexMetadata"];
|
---|
| 334 | var functionArray = ["remove-import-metadata", "remove-archives-metadata", "remove-metadata"];
|
---|
| 335 |
|
---|
| 336 | for(var i = 0; i < nameArray.length; i++)
|
---|
| 337 | {
|
---|
| 338 | callMetadataServer(nameArray[i], "cgi-bin/metadata-server.pl?a=" + functionArray[i] + "&c=" + collection + "&site=" + site + "&d=" + documentID + "&metaname=" + metadataName + "&metavalue=" + metadataValue, responseFunction);
|
---|
| 339 | }
|
---|
| 340 | }
|
---|