Changeset 31542 for main/trunk/greenstone3/web/interfaces/default/js
- Timestamp:
- 2017-03-27T21:39:33+13:00 (7 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/gsajaxapi.js
r31527 r31542 167 167 // http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp 168 168 this.urlPostSync = function(scriptURL, params) { 169 170 171 // Firefox, Opera 8.0+, Safari172 xmlHttp=new XMLHttpRequest();173 174 175 // Internet Explorer176 try {177 178 }179 catch (e) {180 181 182 183 184 185 186 187 }188 189 190 191 192 193 194 195 params += "&un=" + un_;196 197 198 params += "&ky=" + ky_;199 200 201 202 203 204 205 206 }169 var xmlHttp=false; 170 try { 171 // Firefox, Opera 8.0+, Safari 172 xmlHttp=new XMLHttpRequest(); 173 } 174 catch (e) { 175 // Internet Explorer 176 try { 177 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 178 } 179 catch (e) { 180 try { 181 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 182 } 183 catch (e) { 184 alert("Your browser does not support AJAX!"); 185 return false; 186 } 187 } 188 } 189 190 // e.g. scriptURL: /greenstone/cgi-bin/metadata-server.pl 191 xmlHttp.open('POST', scriptURL, false); // false means synchronous 192 xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 193 194 if(un_ != null) { 195 params += "&un=" + un_; 196 } 197 if(ky_ != null) { 198 params += "&ky=" + ky_; 199 } 200 201 xmlHttp.send(params); // needs to be escaped/encoded 202 203 //alert(scriptURL + "?" + params); 204 //alert(xmlHttp.responseText); // if synchronous, process xmlHttp.responseText AFTER send() call 205 return xmlHttp.responseText; 206 } 207 207 208 208 // New, an Ajax Asynchronous Post method. 209 209 // For helpful links, see the urlPostSync() method above 210 210 this.urlPostAsync = function(scriptURL, params, callback) { 211 212 213 // Firefox, Opera 8.0+, Safari214 xmlHttp=new XMLHttpRequest();215 216 217 // Internet Explorer218 try {219 220 }221 catch (e) {222 223 224 225 226 227 228 229 }230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 211 var xmlHttp=false; 212 try { 213 // Firefox, Opera 8.0+, Safari 214 xmlHttp=new XMLHttpRequest(); 215 } 216 catch (e) { 217 // Internet Explorer 218 try { 219 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 220 } 221 catch (e) { 222 try { 223 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 224 } 225 catch (e) { 226 alert("Your browser does not support AJAX!"); 227 return false; 228 } 229 } 230 } 231 232 233 234 // e.g. scriptURL: /greenstone/cgi-bin/metadata-server.pl 235 xmlHttp.open('POST', scriptURL, true); // true means asynchronous 236 xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 237 238 239 // If asynchronous: 240 // If the callback param is a function, we will set it up to get called when 241 // the async post has finished (is ready) 242 // if the callback parameter isn't a function, the param represents a field 243 // that we want to dynamically update when the async post process has finished 244 245 245 var typeof_callback = typeof(callback); 246 246 if ((typeof_callback == "string") || (typeof_callback == "number") || (typeof_callback == "boolean")) { 247 247 var locid = callback; 248 248 249 249 xmlHttp.onreadystatechange=function() { 250 250 if(xmlHttp.readyState==4) { … … 267 267 alert("Unrecognized type of callback value: " + typeof_callback); 268 268 } 269 270 271 params += "&un=" + un_;272 273 274 params += "&ky=" + ky_;275 276 277 278 279 280 281 }269 270 if(un_ != null) { 271 params += "&un=" + un_; 272 } 273 if(ky_ != null) { 274 params += "&ky=" + ky_; 275 } 276 //alert("Posting Async: " + scriptURL + "?" + params); 277 278 xmlHttp.send(params); // needs to be escaped/encoded 279 // if synchronous, would process xmlHttp AFTER send() call, such as by 280 // accessing xmlHttp.responseText to return that to the caller at this point. 281 } 282 282 283 283 // New -
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r31537 r31542 424 424 // No function overloading in JavaScript. Can pass a custom object, however, see 425 425 // http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices 426 function callMetadataServer (callingFunction, url, responseFunction, opts)426 function callMetadataServerGET(callingFunction, url, responseFunction, opts) 427 427 { 428 428 var async_setting = true; // Internal processing of 'read' operations (get meta) is not order dependent … … 457 457 .success(function(response) 458 458 { 459 console.log("(" + callingFunction + ") Response received from server: " + response);459 console.log("(" + callingFunction + ") Response received from server: " + ajaxResponse); 460 460 461 461 ajaxResponse = response; … … 480 480 return ajaxResponse; 481 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 486 function 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 482 540 483 541 /*************************
Note:
See TracChangeset
for help on using the changeset viewer.