Ignore:
Timestamp:
2017-03-24T21:37:12+13:00 (7 years ago)
Author:
ak19
Message:

First commit for getting user comments working for GS3. It all works, but there's debugging statements still and haven't cleaned up commented out code. After that, would like to make POST rather than GET AJAX calls, so more refactoring required. 1. config_format.xsl is just minor spelling corrections. 2. header.xsl has a new function generateLogoutURL. 3. document.xsl imports and calls new usercomments.xsl to set up the user comments area. 4. New usercomments.js is imported by new usercomments.xsl, and sets up the interaction of the usercomments area. 5. javascript-global-functions.js now contains setMetadataArray and getMetadataArray functions to parallel what GS2 used in gsajaxapi.js, but for GS3 need to go through GS2Construct.processModifyMetadata() service in java code. 5. GS2Construct.java does different checking for users adding user comments versus users doing document editing. For the latter, the user needs to have editing permissions for the document. But any user is allowed to add comments on any accessible document. But ModifyMetadata should not allow any other metadata to be modified other than meta fields. 6. New language strings for usercomment area and GS2Construct errors in the 2 changed properties files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js

    r31529 r31537  
    422422}
    423423
    424 function callMetadataServer(callingFunction, url, responseFunction)
     424// No function overloading in JavaScript. Can pass a custom object, however, see
     425// http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
     426function callMetadataServer(callingFunction, url, responseFunction, opts)
    425427{
    426428    var async_setting = true; // Internal processing of 'read' operations (get meta) is not order dependent
     
    445447    } // otherwise, such as for get- metadata operation, we proceed as before, which will not require authentication
    446448
     449    if (opts != null && opts["forceSync"] != null) {
     450    async_setting = (!opts["forceSync"]);
     451    }
     452
     453    console.log("Away to call: " + url);
     454    var ajaxResponse = null;
    447455
    448456    $.ajax(url, {async: async_setting})
     
    451459        console.log("(" + callingFunction + ") Response received from server: " + response);
    452460
     461        ajaxResponse = response;
     462
    453463        //var xml = $.parseXML(response);
    454464        //console.log(xml);
     
    456466        if(responseFunction != null)
    457467        {
    458             responseFunction(response);
     468           
     469            responseFunction(response);
    459470        }
    460471    })
     
    463474        console.log("(" + callingFunction + ") Failed");
    464475    });
     476
     477    console.log("Finished ajax call to: " + url);
     478   
     479    console.log("Got response: " + ajaxResponse);
     480    return ajaxResponse;
    465481}
    466482
     
    513529}
    514530
     531// New. Modified version of the GS2 version of this method in gsajaxapi.js.
     532// The where parameter can be specified as one or more of: import, archives, index, live
     533// separated by |. If null, it is assumed to be index which is the original default
     534// behaviour of calling set-metadata-array. E.g. where=import|archives|index
     535// THIS METHOD IS SYNCHRONOUS
     536gs.functions.setMetadataArray = function(collection, site, docArray, metamode, where, responseFunction)
     537{
     538    docArrayJSON = JSON.stringify(docArray);
     539   
     540    var params = "a=" + escape("set-metadata-array"); //"a=set-metadata-array";
     541    if(where != null) {
     542    params += "&where=" + escape(where); // if where not specified, meta-server will default to setting index meta
     543    //} else {
     544    //    params += "&where=import|archives|index";
     545    }
     546    params += "&c="+escape(collection);
     547    params += "&site="+escape(site);
     548    params += "&json="+escape(docArrayJSON);
     549   
     550    if (metamode!=null) {
     551    params += "&metamode=" + escape(metamode);
     552    }
     553   
     554
     555    var response = callMetadataServer("Setting metadata in "+where, "cgi-bin/metadata-server.pl?"+params, responseFunction);
     556
     557    return response;
     558    // return this.urlPostSync(mdserver,params); // gsajaxapi.js version for GS2
     559}
     560
     561
    515562/*************************
    516563* GET METADATA FUNCTIONS *
    517564*************************/
    518565
     566// New. Modified version of the GS2 version of this method in gsajaxapi.js.
     567// See description for setMetadataArray above for information about the 'where' parameter.
     568// THIS METHOD IS SYNCHRONOUS BY DEFAULT. Set forceSync to false to override this default behaviour
     569gs.functions.getMetadataArray = function(collection, site, docArray, where, forceSync, responseFunction)
     570{
     571    docArrayJSON = JSON.stringify(docArray);
     572   
     573    var params = "a=" + escape("get-metadata-array"); //"a=set-metadata-array";
     574    if(where != null) {
     575    params += "&where=" + escape(where); // if where not specified, meta-server will default to setting index meta
     576    //} else {
     577    //    params += "&where=import|archives|index";
     578    }
     579    params += "&c="+escape(collection);
     580    params += "&site="+escape(site);
     581    params += "&json="+escape(docArrayJSON);
     582       
     583    // get operations are generally asynchronous, but allow calling function to force ajax call
     584    // to be synchronous or not. Default is synchronous, as it was for GS2
     585    if(forceSync == null) {
     586    forceSync = true;
     587    }
     588    // Objects/maps can use identifiers or strings for property names
     589    // http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
     590    // https://www.w3schools.com/js/js_objects.asp
     591    var response = callMetadataServer("Getting metadata from "+where, "cgi-bin/metadata-server.pl?"+params, responseFunction, {"forceSync":forceSync});
     592
     593    return response;
     594    //return this.urlPostSync(mdserver,params); // gsajaxapi.js version for GS2
     595}
     596
     597
    519598gs.functions.getImportMetadata = function(collection, site, documentID, metadataName, responseFunction)
    520599{
Note: See TracChangeset for help on using the changeset viewer.