- Timestamp:
- 2019-03-07T20:51:46+13:00 (5 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js
r32871 r32873 285 285 var resultArray = new Array(); 286 286 287 console.log("**** changesToUpdate::editableElementsInitialisationProgress = " + editableElementsInitialisationProgress);287 //console.log("**** changesToUpdate::editableElementsInitialisationProgress = " + editableElementsInitialisationProgress); 288 288 289 289 // Only want to check for valid edited states if the editableInitStates has been fully set up: -
main/trunk/greenstone3/web/interfaces/default/js/gsajaxapi.js
r31542 r32873 243 243 // that we want to dynamically update when the async post process has finished 244 244 245 // NOTE: if passing in an error callback function *separate* from success callback (i.e. if current callback param won't check xmlHttp.status == 200) 246 // then see https://stackoverflow.com/questions/1442425/detect-xhr-error-is-really-due-to-browser-stop-or-click-to-new-page 247 // and https://stackoverflow.com/questions/8866761/xmlhttprequest-ajax-error 248 245 249 var typeof_callback = typeof(callback); 246 250 if ((typeof_callback == "string") || (typeof_callback == "number") || (typeof_callback == "boolean")) { -
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r31559 r32873 432 432 // 433 433 // - payload param: contains both the URL form and the data object form of the package to transmit over 434 // AJAX to metadataserver.pl. Based on the parameters and some internal variables, callMetadataServer()434 // AJAX to metadataserver.pl. Based on the parameters and some internal variables, _callMetadataServer() 435 435 // determines which to use. 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 gs.functions.callMetadataServer = function(callingFunction, payload, responseFunction, opts) 438 // 439 // BEWARE: 440 // errorResponseFunction is at present only called on error if using jQuery ajax (sync/async) and not if using gsajaxapi (sync/async). 441 gs.functions._callMetadataServer = function(callingFunction, payload, successResponseFunction, errorResponseFunction, opts) 439 442 { 440 443 … … 529 532 //console.log(xml); 530 533 531 if( responseFunction != null) {534 if(successResponseFunction != null) { 532 535 533 responseFunction(response);536 successResponseFunction(response); 534 537 } 535 538 }) 536 539 .error(function() { 537 console.log("(" + callingFunction + ") Failed"); 540 if(errorResponseFunction != null) { 541 errorResponseFunction(response); 542 } else { 543 console.log("(" + callingFunction + ") Failed"); 544 } 538 545 }); 539 546 } … … 553 560 554 561 if(async_setting) { 555 gsapi.urlPostAsync(url, params, responseFunction);562 gsapi.urlPostAsync(url, params, successResponseFunction); 556 563 } else { 557 564 ajaxResponse = gsapi.urlPostSync(url, params); … … 571 578 // Prepare the payload (data package) to transmit to metadataserver.pl over AJAX. 572 579 // These next 2 functions prepare both the URL version of the payload and the data object version of 573 // of the payload. Then calling functions, and the callMetadataServer() function they call, will control580 // of the payload. Then calling functions, and the _callMetadataServer() function they call, will control 574 581 // and determine which of the two forms ultimately gets used. 575 582 // (Constructing both URL and data structure, as I could not successfully convert old URL way to data structure … … 741 748 *************************/ 742 749 743 gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, prevMetadataValue, metamode, responseFunction)750 gs.functions.setImportMetadata = function(collection, site, documentID, metadataName, metadataValue, prevMetadataValue, metamode, successResponseFunction, errorResponseFunction) 744 751 { 745 746 gs.functions.callMetadataServer( 752 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 753 754 gs.functions._callMetadataServer( 747 755 "setImportMetadata", 748 756 gs.functions.getBasicDataForMetadataServer("set-import-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, null /*metapos*/), 749 responseFunction); 750 751 } 752 753 gs.functions.setArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction) 754 { 757 successResponseFunction, 758 errorResponseFunction); 759 760 } 761 762 gs.functions.setArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, successResponseFunction, errorResponseFunction) 763 { 764 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 765 755 766 if(metadataPosition != null) { 756 767 prevMetadataValue = null; // to force the same ultimate behaviour as in the old version of this code 757 768 } 758 769 759 gs.functions. callMetadataServer(770 gs.functions._callMetadataServer( 760 771 "setArchivesMetadata", 761 772 gs.functions.getBasicDataForMetadataServer("set-archives-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition), 762 responseFunction); 763 764 } 765 766 gs.functions.setIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction) 767 { 773 successResponseFunction, 774 errorResponseFunction); 775 776 } 777 778 gs.functions.setIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, successResponseFunction, errorResponseFunction) 779 { 780 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 781 768 782 if(metadataPosition != null) { 769 783 prevMetadataValue = null; // to force the same ultimate behaviour as in the old version of this code 770 784 } 771 785 772 // old version of this function would only call callMetadataServer if either metapos786 // old version of this function would only call _callMetadataServer if either metapos 773 787 // or prevMetaValue had a value. So sticking to the same behaviour in rewriting this function. 774 788 if(metadataPosition != null || prevMetadataValue != null) { 775 789 776 gs.functions. callMetadataServer(790 gs.functions._callMetadataServer( 777 791 "setIndexMetadata", 778 792 gs.functions.getBasicDataForMetadataServer("set-metadata", collection, site, documentID, metadataName, metamode, metadataValue, prevMetadataValue, metadataPosition), 779 responseFunction); 780 } 781 } 782 783 gs.functions.setMetadata = function(collection, site, documentID, metadataName, metadataValue, metamode, responseFunction) 784 { 793 successResponseFunction, 794 errorResponseFunction); 795 } 796 } 797 798 gs.functions.setMetadata = function(collection, site, documentID, metadataName, metadataValue, metamode, successResponseFunction, errorResponseFunction) 799 { 800 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 801 785 802 var nameArray = ["setImportMetadata", "setArchivesMetadata", "setIndexMetadata"]; 786 803 var functionArray = ["set-import-metadata", "set-archives-metadata", "set-metadata"]; … … 790 807 // previous version of this function did not allow setting metapos or prevMetavalue 791 808 // so leaving the behaviour the same along with function signature. 792 gs.functions. callMetadataServer(809 gs.functions._callMetadataServer( 793 810 nameArray[i], 794 811 gs.functions.getBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, metamode, metadataValue, null /*prevMetadataValue*/, null /*metadataPosition*/), 795 responseFunction); 812 successResponseFunction, 813 errorResponseFunction); 796 814 } 797 815 } … … 802 820 // behaviour of calling set-metadata-array. E.g. where=import|archives|index 803 821 // THIS METHOD IS SYNCHRONOUS by default. Set forceSync to false to override this default behaviour 804 gs.functions.setMetadataArray = function(collection, site, docArray, metamode, where, responseFunction, forceSync)822 gs.functions.setMetadataArray = function(collection, site, docArray, metamode, where, successResponseFunction, forceSync, errorResponseFunction) 805 823 { 824 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 806 825 807 826 var payload = gs.functions.getComplexDataForMetadataServer("set-metadata-array", collection, site, docArray, metamode, where); … … 815 834 //console.log("cgi-bin/metadata-server.pl?"+params); 816 835 817 var response = gs.functions. callMetadataServer("Setting metadata in "+where, payload, responseFunction, {"forceSync": forceSync, "requestMethod": "POST"});836 var response = gs.functions._callMetadataServer("Setting metadata in "+where, payload, successResponseFunction, errorResponseFunction, {"forceSync": forceSync, "requestMethod": "POST"}); 818 837 819 838 return response; … … 828 847 // See description for setMetadataArray above for information about the 'where' parameter. 829 848 // THIS METHOD IS SYNCHRONOUS BY DEFAULT. Set forceSync to false to override this default behaviour 830 gs.functions.getMetadataArray = function(collection, site, docArray, where, responseFunction, forceSync) 831 { 849 gs.functions.getMetadataArray = function(collection, site, docArray, where, successResponseFunction, forceSync, errorResponseFunction) 850 { 851 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 852 832 853 var payload = gs.functions.getComplexDataForMetadataServer("get-metadata-array", collection, site, docArray, null /*metamode*/, where); 833 854 … … 840 861 // http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices 841 862 // https://www.w3schools.com/js/js_objects.asp 842 var response = gs.functions. callMetadataServer("Getting metadata from "+where, payload, responseFunction, {"forceSync":forceSync, "requestMethod": "POST"});863 var response = gs.functions._callMetadataServer("Getting metadata from "+where, payload, successResponseFunction, errorResponseFunction, {"forceSync":forceSync, "requestMethod": "POST"}); 843 864 844 865 return response; … … 846 867 847 868 848 gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction) 849 { 869 gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, successResponseFunction, errorResponseFunction) 870 { 871 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 872 850 873 var payload = gs.functions.getBasicDataForMetadataServer("get-import-metadata", collection, site, documentID, metadataName); 851 gs.functions. callMetadataServer("getImportMetadata", payload, function(responseText) {874 gs.functions._callMetadataServer("getImportMetadata", payload, function(responseText) { 852 875 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, null, responseText); 853 if(responseFunction != null) 854 { 855 responseFunction(metadata); 856 } 857 }); 858 } 859 860 gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction) 861 { 876 if(successResponseFunction != null) 877 { 878 successResponseFunction(metadata); 879 } 880 }, 881 errorResponseFunction); 882 } 883 884 gs.functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, successResponseFunction, errorResponseFunction) 885 { 886 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 887 862 888 var payload = gs.functions.getBasicDataForMetadataServer("get-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition); 863 889 864 gs.functions.callMetadataServer("getArchivesMetadata", payload, function(responseText) { 865 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, metadataPosition, responseText); // indexPos, archivesPos, metaval (responseText) 866 if(responseFunction != null) 867 { 868 responseFunction(metadata); 869 } 870 }); 871 } 872 873 gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction) 874 { 890 gs.functions._callMetadataServer("getArchivesMetadata", payload, function(responseText) { 891 var metadata = new GSMetadata(collection, site, documentID, metadataName, null, metadataPosition, responseText); // indexPos, archivesPos, metaval (responseText) 892 if(successResponseFunction != null) 893 { 894 successResponseFunction(metadata); 895 } 896 }, 897 errorResponseFunction); 898 } 899 900 gs.functions.getIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, successResponseFunction, errorResponseFunction) 901 { 902 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 903 875 904 var payload = gs.functions.getBasicDataForMetadataServer("get-metadata", collection, site, documentID, metadataName, null /*metamode*/, null /*metavalue*/, null /*prevmetavalue*/, metadataPosition); 876 905 877 gs.functions. callMetadataServer("getIndexMetadata", payload, function(responseText) {878 var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, null, responseText); // indexPos, archivesPos, metaval (responseText)879 880 if(responseFunction != null)881 {882 responseFunction(metadata);883 } 884 });906 gs.functions._callMetadataServer("getIndexMetadata", payload, function(responseText) { 907 var metadata = new GSMetadata(collection, site, documentID, metadataName, metadataPosition, null, responseText); // indexPos, archivesPos, metaval (responseText) 908 if(successResponseFunction != null) 909 { 910 successResponseFunction(metadata); 911 } 912 }, 913 errorResponseFunction); 885 914 } 886 915 … … 889 918 ****************************/ 890 919 891 gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction) 892 { 893 gs.functions.callMetadataServer( 920 gs.functions.removeImportMetadata = function(collection, site, documentID, metadataName, metadataValue, successResponseFunction, errorResponseFunction) 921 { 922 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 923 924 gs.functions._callMetadataServer( 894 925 "removeImportMetadata", 895 926 gs.functions.getBasicDataForMetadataServer("remove-import-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/), 896 responseFunction); 897 } 898 899 gs.functions.removeArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction) 900 { 927 successResponseFunction, 928 errorResponseFunction); 929 } 930 931 gs.functions.removeArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, successResponseFunction, errorResponseFunction) 932 { 933 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 934 901 935 if(metadataPosition != null) { 902 936 metadataValue = null; // retaining behaviour of previous version of this function removeArchivesMetadata() 903 937 } 904 938 905 gs.functions. callMetadataServer(939 gs.functions._callMetadataServer( 906 940 "removeArchiveMetadata", 907 941 gs.functions.getBasicDataForMetadataServer("remove-archives-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition), 908 responseFunction); 909 } 910 911 gs.functions.removeIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, responseFunction) 912 { 942 successResponseFunction, 943 errorResponseFunction); 944 } 945 946 gs.functions.removeIndexMetadata = function(collection, site, documentID, metadataName, metadataPosition, metadataValue, successResponseFunction, errorResponseFunction) 947 { 948 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 949 913 950 if(metadataPosition != null) { 914 951 metadataValue = null; // retaining behaviour of previous version of this function removeIndexMetadata() 915 952 } 916 953 917 gs.functions. callMetadataServer(954 gs.functions._callMetadataServer( 918 955 "removeIndexMetadata", 919 956 gs.functions.getBasicDataForMetadataServer("remove-metadata", collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, metadataPosition), 920 responseFunction); 921 } 922 923 gs.functions.removeMetadata = function(collection, site, documentID, metadataName, metadataValue, responseFunction) 924 { 957 successResponseFunction, 958 errorResponseFunction); 959 } 960 961 gs.functions.removeMetadata = function(collection, site, documentID, metadataName, metadataValue, successResponseFunction, errorResponseFunction) 962 { 963 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 964 925 965 var nameArray = ["removeImportMetadata", "removeArchivesMetadata", "removeIndexMetadata"]; 926 966 var functionArray = ["remove-import-metadata", "remove-archives-metadata", "remove-metadata"]; … … 928 968 for(var i = 0; i < nameArray.length; i++) 929 969 { 930 gs.functions. callMetadataServer(970 gs.functions._callMetadataServer( 931 971 nameArray[i], 932 972 gs.functions.getBasicDataForMetadataServer(functionArray[i], collection, site, documentID, metadataName, null /*metamode*/, metadataValue, null /*prevmetavalue*/, null /*metapos*/), 933 responseFunction); 934 } 935 } 936 973 successResponseFunction, 974 errorResponseFunction); 975 } 976 } 977
Note:
See TracChangeset
for help on using the changeset viewer.