- Timestamp:
- 2017-03-31T19:42:22+13:00 (7 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r31555 r31558 6 6 var HALTED = 12; 7 7 8 gs.functions = new Array();8 gs.functions = {}; 9 9 10 10 gs.jqGet = function(id) … … 436 436 // - opts param: No function overloading in JavaScript. Can pass a custom object, however can pass opts, 437 437 // see http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices 438 function callMetadataServer(callingFunction, payload, responseFunction, opts)438 gs.functions.callMetadataServer = function(callingFunction, payload, responseFunction, opts) 439 439 { 440 440 … … 443 443 // Set/remove operations will switch to synchronous AJAX, unless opt["forceSync"] is set otherwise 444 444 var async_setting = true; 445 var method = " GET"; // GET was the default before445 var method = "POST"; // GET was the default before 446 446 447 447 // Set to false if you wish to use the regular JavaScript AJAX way in gsajaxapi.js (will use payload.url) … … 457 457 // set method = "GET" (above, but also in calling functions that specify this optional parameter!) 458 458 // and set the default here below for _use_payload_in_data_not_url_form to false. 459 var _use_payload_in_data_not_url_form = false;459 var _use_payload_in_data_not_url_form = true; // code will anyway set this to true for jQuery $.ajax() with POST 460 460 461 461 var _modifyingMeta = false; … … 481 481 async_setting = false; // for 'write' operations (set/remove meta), we force sequential processing of the internal operation. 482 482 483 // for meta modification operatons, should we make the method=POST??????484 // method = "POST";485 483 } 486 484 // check for any overrides by calling code that knows what it's doing … … 580 578 // of the payload. Then calling functions, and the callMetadataServer() function they call, will control 581 579 // and determine which of the two forms ultimately gets used. 582 // UNUSED: http://stackoverflow.com/questions/8648892/convert-url-parameters-to-a-javascript-object 583 function getBasicDataForMetadataServer(metaServerCommand, collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition) { 584 580 // (Constructing both URL and data structure, as I could not successfully convert old URL way to data structure 581 // http://stackoverflow.com/questions/8648892/convert-url-parameters-to-a-javascript-object) 582 gs.functions.getBasicDataForMetadataServer = function(metaServerCommand, collection, site, documentID, metadataName, 583 metamode, metadataValue, prevMetadataValue, metadataPosition) 584 { 585 585 // if we're doing set- or remove- metadata operations, 586 586 // then we need change the data params that will make up the query string … … 665 665 666 666 // See description for getBasicDataForMetadataServer() 667 function getComplexDataForMetadataServer(metaServerCommand, collection, site, docArray, metamode, where) { 668 667 gs.functions.getComplexDataForMetadataServer = function(metaServerCommand, collection, site, docArray, metamode, where) 668 { 669 669 var docArrayJSON = JSON.stringify(docArray); 670 670 … … 746 746 *************************/ 747 747 748 // callMetadataServerURLMode("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);749 750 748 gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, prevMetadataValue, metamode, responseFunction) 751 749 { 752 750 753 callMetadataServer(751 gs.functions.callMetadataServer( 754 752 "setImportMetadata", 755 g etBasicDataForMetadataServer("set-import-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, null /*metapos*/),753 gs.functions.getBasicDataForMetadataServer("set-import-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, null /*metapos*/), 756 754 responseFunction); 757 755 … … 764 762 } 765 763 766 callMetadataServer(764 gs.functions.callMetadataServer( 767 765 "setArchivesMetadata", 768 g etBasicDataForMetadataServer("set-archives-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition),766 gs.functions.getBasicDataForMetadataServer("set-archives-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition), 769 767 responseFunction); 770 768 … … 781 779 if(metadataPosition != null || prevMetadataValue != null) { 782 780 783 callMetadataServer(781 gs.functions.callMetadataServer( 784 782 "setIndexMetadata", 785 g etBasicDataForMetadataServer("set-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition),783 gs.functions.getBasicDataForMetadataServer("set-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition), 786 784 responseFunction); 787 785 } … … 797 795 // previous version of this function did not allow setting metapos or prevMetavalue 798 796 // so leaving the behaviour the same along with function signature. 799 callMetadataServer(797 gs.functions.callMetadataServer( 800 798 nameArray[i], 801 g etBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, metamode, metadataValue, null /*prevMetadataValue*/, null /*metadataPosition*/),799 gs.functions.getBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, metamode, metadataValue, null /*prevMetadataValue*/, null /*metadataPosition*/), 802 800 responseFunction); 803 801 } … … 812 810 { 813 811 814 var payload = g etComplexDataForMetadataServer("set-metadata-array", collection, site, docArray, metamode, where);812 var payload = gs.functions.getComplexDataForMetadataServer("set-metadata-array", collection, site, docArray, metamode, where); 815 813 816 814 // set operations are generally synchronous, but allow calling function to force ajax call … … 822 820 //console.log("cgi-bin/metadata-server.pl?"+params); 823 821 824 var response = callMetadataServer("Setting metadata in "+where, payload, responseFunction, {"forceSync": forceSync, "requestMethod": "POST"});822 var response = gs.functions.callMetadataServer("Setting metadata in "+where, payload, responseFunction, {"forceSync": forceSync, "requestMethod": "POST"}); 825 823 826 824 return response; … … 837 835 gs.functions.getMetadataArray = function(collection, site, docArray, where, responseFunction, forceSync) 838 836 { 839 var payload = g etComplexDataForMetadataServer("get-metadata-array", collection, site, docArray, null /*metamode*/, where);837 var payload = gs.functions.getComplexDataForMetadataServer("get-metadata-array", collection, site, docArray, null /*metamode*/, where); 840 838 841 839 // get operations are generally asynchronous, but allow calling function to force ajax call … … 847 845 // http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices 848 846 // https://www.w3schools.com/js/js_objects.asp 849 var response = callMetadataServer("Getting metadata from "+where, payload, responseFunction, {"forceSync":forceSync, "requestMethod": "POST"});847 var response = gs.functions.callMetadataServer("Getting metadata from "+where, payload, responseFunction, {"forceSync":forceSync, "requestMethod": "POST"}); 850 848 851 849 return response; … … 855 853 gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction) 856 854 { 857 var payload = g etBasicDataForMetadataServer("get-import-metadata", collection, site, documentID, metadataName);858 callMetadataServer("getImportMetadata", payload, function(responseText) {855 var payload = gs.functions.getBasicDataForMetadataServer("get-import-metadata", collection, site, documentID, metadataName); 856 gs.functions.callMetadataServer("getImportMetadata", payload, function(responseText) { 859 857 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, null, responseText); 860 858 if(responseFunction != null) … … 867 865 gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction) 868 866 { 869 var payload = g etBasicDataForMetadataServer("get-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition);870 871 callMetadataServer("getArchivesMetadata", payload, function(responseText) {867 var payload = gs.functions.getBasicDataForMetadataServer("get-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition); 868 869 gs.functions.callMetadataServer("getArchivesMetadata", payload, function(responseText) { 872 870 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, metadataPosition, responseText); // indexPos, archivesPos, metaval (responseText) 873 871 if(responseFunction != null) … … 880 878 gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction) 881 879 { 882 var payload = g etBasicDataForMetadataServer("get-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition);883 884 callMetadataServer("getIndexMetadata", payload, function(responseText) {880 var payload = gs.functions.getBasicDataForMetadataServer("get-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition); 881 882 gs.functions.callMetadataServer("getIndexMetadata", payload, function(responseText) { 885 883 var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, null, responseText); // indexPos, archivesPos, metaval (responseText) 886 884 … … 898 896 gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction) 899 897 { 900 callMetadataServer(898 gs.functions.callMetadataServer( 901 899 "removeImportMetadata", 902 g etBasicDataForMetadataServer("remove-import-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/),900 gs.functions.getBasicDataForMetadataServer("remove-import-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/), 903 901 responseFunction); 904 902 } … … 910 908 } 911 909 912 callMetadataServer(910 gs.functions.callMetadataServer( 913 911 "removeArchiveMetadata", 914 g etBasicDataForMetadataServer("remove-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition),912 gs.functions.getBasicDataForMetadataServer("remove-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition), 915 913 responseFunction); 916 914 } … … 922 920 } 923 921 924 callMetadataServer(922 gs.functions.callMetadataServer( 925 923 "removeIndexMetadata", 926 g etBasicDataForMetadataServer("remove-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition),924 gs.functions.getBasicDataForMetadataServer("remove-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition), 927 925 responseFunction); 928 926 } … … 935 933 for(var i = 0; i < nameArray.length; i++) 936 934 { 937 callMetadataServer(935 gs.functions.callMetadataServer( 938 936 nameArray[i], 939 g etBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/),937 gs.functions.getBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/), 940 938 responseFunction); 941 939 } 942 940 } 941 -
main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
r31547 r31558 5 5 // http://stackoverflow.com/questions/8714472/cant-pass-event-to-addeventlistener-closure-issue 6 6 // https://www.sitepoint.com/demystifying-javascript-closures-callbacks-iifes/ 7 // http://stackoverflow.com/questions/4869712/new-without-delete-on-same-variable-in-javascript 8 // http://stackoverflow.com/questions/7375120/why-is-arr-faster-than-arr-new-array 9 // http://stackoverflow.com/questions/874205/what-is-the-difference-between-an-array-and-an-object 10 // http://stackoverflow.com/questions/33514915/what-s-the-difference-between-and-while-declaring-a-javascript-array 11 // http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ 7 12 8 13 /*************** 9 14 * USER COMMENTS 10 15 ****************/ 16 17 gs.usercomments = {}; 18 11 19 // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss 12 20 // Call as: alert(timestamp.printTime()); 13 function formatTime(timestamp) {21 gs.usercomments.formatTime = function(timestamp) { 14 22 var int_timestamp = parseInt(timestamp, 10); // don't forget the second param 15 23 var date = new Date(int_timestamp); … … 17 25 } 18 26 19 function loadUserComments() {27 gs.usercomments.loadUserComments = function() { 20 28 21 29 // don't bother loading comments if we're not on a document page (in which case there's no docid) … … 74 82 //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index"); 75 83 76 gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index", loadedUserComments, false); // false for asynchronous77 } 78 79 function loadedUserComments(data)84 gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index", gs.usercomments.loadedUserComments, false); // false for asynchronous 85 } 86 87 gs.usercomments.loadedUserComments = function(data) 80 88 { 81 89 // don't bother displaying comments if we're not on a document page … … 141 149 142 150 // for each usercomment, create a child div with the username, timestamp and comment 143 displayInUserCommentList(usercommentdiv, username, timestamp, comment);151 gs.usercomments.displayInUserCommentList(usercommentdiv, username, timestamp, comment); 144 152 145 153 i++; … … 155 163 156 164 157 function displayInUserCommentList(usercommentdiv, username, timestamp, comment) {165 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) { 158 166 159 167 //alert("Comment: " + username + " " + timestamp + " " + comment); … … 174 182 175 183 divgroup.appendChild(divtime); 176 txt=document.createTextNode( formatTime(timestamp)); // format timestamp for date/time display184 txt=document.createTextNode(gs.usercomments.formatTime(timestamp)); // format timestamp for date/time display 177 185 divtime.appendChild(txt); 178 186 … … 193 201 // Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync 194 202 // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 195 function safeHTML(str) {203 gs.usercomments.safeHTML = function(str) { 196 204 return str.replace("&", "&").replace("<", "<").replace(">", ">").replace('"',""").replace("'","'").replace("/", "/"); //"\\"" 197 } 198 199 200 function addUserComment(_username, _comment, _docid, doc) {205 } 206 207 208 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) { 201 209 202 210 // don't add empty strings for name/comment … … 287 295 288 296 //var result = gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index"); 289 gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index", function(ajaxResult) { return doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, false); // false for asynchronous, 297 gs.functions.setMetadataArray(gs.variables["c"], 298 gs.variables["site"], 299 docArray, "accumulate", 300 "import|archives|index", 301 function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, 302 false); // false for asynchronous, 290 303 // this is ok since we're disabling the comment submit button, so no further set-meta-array calls can be 291 304 // made until the ajax call returns and the callback is called which re-enables the submit button … … 296 309 } 297 310 298 function doneUpdatingMetatada(data, _username, _timestamp, _comment)311 gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment) 299 312 { 300 313 … … 339 352 var usercommentdiv = document.getElementById("usercomments"); 340 353 if(usercommentdiv != undefined) { 341 displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment);354 gs.usercomments.displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment); 342 355 } 343 356 } … … 348 361 } 349 362 350 function commentAreaSetup() {351 loadUserComments();363 gs.usercomments.commentAreaSetup = function() { 364 gs.usercomments.loadUserComments(); 352 365 353 366 //$("div#commentarea").html("<textarea required=\"required\" name=\"comment\" rows=\"10\" cols=\"64\" placeholder=\"Add your comment here...\"></textarea>"); … … 361 374 // This way we ensure we don't replace any other onLoad() functions, but append the loadUserComments() 362 375 // function to the existing set of eventhandlers called onDocReady 363 $(document).ready( commentAreaSetup);364 376 $(document).ready(gs.usercomments.commentAreaSetup); 377 -
main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl
r31557 r31558 48 48 </div> 49 49 50 <input type="submit" id="usercommentSubmitButton" onclick=" addUserComment(document.AddUserCommentForm.username.value, document.AddUserCommentForm.comment.value, document.AddUserCommentForm.d.value, document); return false;"><xsl:attribute name="value"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submit')"/></xsl:attribute></input>50 <input type="submit" id="usercommentSubmitButton" onclick="gs.usercomments.addUserComment(document.AddUserCommentForm.username.value, document.AddUserCommentForm.comment.value, document.AddUserCommentForm.d.value, document); return false;"><xsl:attribute name="value"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submit')"/></xsl:attribute></input> 51 51 <label id="usercommentfeedback"><xsl:comment>Text to prevent empty tags from becoming self-closing tags</xsl:comment></label> 52 52
Note:
See TracChangeset
for help on using the changeset viewer.