Changeset 25008 for main/trunk
- Timestamp:
- 2012-01-26T14:24:46+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/oran/js/javascript-global-functions.js
r24930 r25008 60 60 } 61 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 }
Note:
See TracChangeset
for help on using the changeset viewer.