- Timestamp:
- 2017-03-31T19:42:22+13:00 (7 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.