Changeset 37704 for main


Ignore:
Timestamp:
2023-04-23T22:33:27+12:00 (12 months ago)
Author:
davidb
Message:

Code/Syntax upgraded to provide better generality as to the metadata names used for usercomments; primarily done to allow a gs. prefix so it is easier to edit in GLI

Location:
main/trunk/greenstone3/web/interfaces/default
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/user_comments.js

    r31559 r37704  
    2020gs.usercomments = {};
    2121
     22gs.usercomments.defaults = {
     23    "metaname_username"     : "username",
     24    "metaname_usertimestamp": "usertimestamp",
     25    "metaname_usercomment"  : "usercomment"
     26}
     27
    2228// http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss
    2329// Call as: alert(timestamp.printTime());
     
    2834}
    2935
    30 gs.usercomments.loadUserComments = function() {
     36gs.usercomments.loadUserComments = function(opt_metaname_username, opt_metaname_usertimestamp, opt_metaname_usercomment) {
    3137
    3238    // don't bother loading comments if we're not on a document page (in which case there's no docid)
     
    5460    doc_id = doc_id.substring(0, period);
    5561    }
    56    
     62
     63    /* The current pattern of use (from usercomments.xsl) is to globally override/redefine
     64       the metadata names in gs.usercomments.defaults{ values }.  However, anticipating
     65       future, more general use, loadUserComments() and addUserComment() have been written
     66       with the ability to have optional parameters passed in the supersede the values in
     67       gs.usercomments.defaults{} */
     68
    5769    var username_rec = {
    58     metaname: "username",
     70    metaname: opt_metaname_username || gs.usercomments.defaults.metaname_username,  // e.g. "username"
    5971    metapos: "all"
    6072    };
    6173   
    6274    var timestamp_rec = {
    63     metaname: "usertimestamp",
     75    metaname: opt_metaname_usertimestamp || gs.usercomments.defaults.metaname_usertimestamp, // e.g. "usertimestamp"
    6476    metapos: "all"
    6577    };
    6678   
    6779    var comment_rec = {
    68     metaname: "usercomment",
     80    metaname: opt_metaname_usercomment || gs.usercomments.defaults.metaname_usercomment, // e.g. "usercomment"
    6981    metapos: "all"
    7082    };
     
    7991    //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index");
    8092
    81     gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index", gs.usercomments.loadedUserComments, false); // false for asynchronous
     93    gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index",
     94                  gs.usercomments.loadedUserComments, false); // false for asynchronous
    8295}
    8396
     
    132145            var username = metaval_rec.metavalue;
    133146        var timestamp = metatable[1].metavals[i].metavalue; 
    134         var comment = metatable[2].metavals[i].metavalue;
     147        var comment   = metatable[2].metavals[i].metavalue;
    135148       
    136149        // No need to sort by time, as the meta are already stored sorted
     
    188201}
    189202
    190 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) {
     203gs.usercomments.addUserComment = function(_username, _comment, _docid, doc,
     204                      opt_metaname_username, opt_metaname_usertimestamp, opt_metaname_usercomment) {
    191205   
    192206    // don't add empty strings for name/comment     
     
    232246   
    233247    var username_rec = {
    234     metaname: "username",
     248    metaname: opt_metaname_username || gs.usercomments.defaults.metaname_username, // e.g. "username"
    235249    metavals: [_username]
    236250    };
    237251   
    238252    var timestamp_rec = {
    239     metaname: "usertimestamp",
     253    metaname: opt_metaname_usertimestamp || gs.usercomments.defaults.metaname_usertimestamp, // e.g. "usertimestamp"
    240254    metavals: [_timestamp]
    241255    };
    242256   
    243257    var comment_rec = {
    244     metaname: "usercomment",
     258    metaname: opt_metaname_usercomment || gs.usercomments.defaults.metaname_usercomment, // e.g. "usercomment"
    245259    metavals: [_comment]
    246260    };
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl

    r33755 r37704  
    99    exclude-result-prefixes="java util gsf">
    1010
     11<xsl:template name="userCommentsDefineMetanames">
     12  <gsf:script>
     13    <!-- Older Greenstone3 installations did not use metadata namespace/prefix for usercomment metadata
     14
     15     From GS3.11 onwards, this is now part of the Greenstone metadata set (gs.), allowing usercomments
     16     to be edited and managed from GLI.
     17
     18     If you want the older way of doing things, replace the JS syntax below the commented out block
     19    -->
     20   
     21    <!--
     22    gs.usercomments.defaults.metaname_username      = "username";
     23    gs.usercomments.defaults.metaname_usertimestamp = "usertimestamp";
     24    gs.usercomments.defaults.metaname_usercomment   = "usercomment";   
     25    -->
     26   
     27    gs.usercomments.defaults.metaname_username      = "gs.username";
     28    gs.usercomments.defaults.metaname_usertimestamp = "gs.usertimestamp";
     29    gs.usercomments.defaults.metaname_usercomment   = "gs.usercomment";   
     30  </gsf:script>
     31</xsl:template>
     32 
    1133<xsl:template name="userCommentsSection">
    1234 <xsl:if test="/page/pageResponse/format[@type='display']/gsf:option[@name='allowUserComments']/@value='true'">
     
    2345  <script type="text/javascript" src="interfaces/{$interface_name}/js/gsajaxapi.js"><xsl:text> </xsl:text></script>
    2446  <script type="text/javascript" src="interfaces/{$interface_name}/js/user_comments.js"><xsl:text> </xsl:text></script>
    25 
     47  <xsl:call-template name="userCommentsDefineMetanames"/>
    2648 
    2749  <!-- 3. Set up the User comments section in the HTML -->
Note: See TracChangeset for help on using the changeset viewer.