Changeset 31559

Show
Ignore:
Timestamp:
31.03.2017 20:51:11 (2 years ago)
Author:
ak19
Message:

Clean up phase for GS3 add user comments. Removed unwanted code, but only commenting out debug statements. Will get rid of debug statements after user comments tested to work successfully on GS3 Windows.

Location:
main/trunk/greenstone3/web/interfaces/default
Files:
3 modified

Legend:

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

    r31558 r31559  
    467467    // check for any caller overrides 
    468468    if(opts != null) { 
    469     //if(opts["use_payload_in_data_not_url_form"] != null) { 
    470       //  _use_payload_in_data_not_url_form = opts["use_payload_in_data_not_url_form"]; 
    471     //} 
    472469    if(opts["requestMethod"] != null) { 
    473470        method = opts["requestMethod"]; 
     
    502499    if(_use_payload_in_data_not_url_form) { // using data payload to do AJAX (regardless of request method) 
    503500     
    504     //method = "POST"; 
    505  
    506501    // for get-meta operations, go directly through metadata-server.pl 
    507502    // for set-meta ops, should go via GS3 authentication, which is off the GS3 library servlet 
     
    519514    // finally, can do the AJAX call 
    520515 
    521     console.log("*** Away to call: " + url); 
     516    //console.log("*** Away to call: " + url); 
    522517    var ajaxResponse = async_setting ? "*** No response received yet, async ajax request" : null; 
    523518 
     
    529524        .success(function(response) { 
    530525        ajaxResponse = response; 
    531         console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse); 
     526//      console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse); 
    532527         
    533528        //var xml = $.parseXML(response); 
     
    564559    } 
    565560     
    566     console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse); 
    567  
    568     } 
    569      
    570     console.log("*** Finished ajax call to: " + url);     
    571     console.log("*** Got response: " + ajaxResponse); 
     561//  console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse); 
     562 
     563    } 
     564     
     565//    console.log("*** Finished ajax call to: " + url);     
     566//    console.log("*** Got response: " + ajaxResponse); 
    572567 
    573568    return ajaxResponse; 
  • main/trunk/greenstone3/web/interfaces/default/js/user_comments.js

    r31558 r31559  
    1010// http://stackoverflow.com/questions/33514915/what-s-the-difference-between-and-while-declaring-a-javascript-array 
    1111// http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ 
     12// stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript 
     13// http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript 
    1214 
    1315/*************** 
     
    1517****************/ 
    1618 
     19// avoid making usercomments js functions global (which attaches them as properties to the window object) 
    1720gs.usercomments = {}; 
    1821 
     
    2831 
    2932    // don't bother loading comments if we're not on a document page (in which case there's no docid) 
    30     var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_"; //escape("cgiargd"); 
    31  
    32     // stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript 
    33     if(!doc_id) { // vs http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript 
    34      
     33    var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_" in GS2 
     34 
     35    if(!doc_id) {    
    3536    return; 
    3637    } 
     
    4041    // asynchronously, this is to help prevent any overlap in these functions' access of meta files in 
    4142    // index|archives|import. 
     43    // Prevent users from adding comments by disabling the submit button 
     44    // until existing comments have been retrieved and displayed 
    4245    var submitButton = document.getElementById("usercommentSubmitButton");     
    4346    if(submitButton) { // there'll be no submitButton if the comment form is not displayed (user not logged in) 
     
    4548    } 
    4649 
    47      
    48     // don't allow users to add comments (disable the submit button) 
    49     // until existing comments have been retrieved and displayed 
    50     //document.getElementById("usercommentSubmitButton").disabled = true; 
    51  
    5250    // Since we have a docid, get toplevel section of the docid 
    5351     
     
    7876 
    7977    var docArray = [doc_rec]; 
    80     //alert(JSON.stringify(docArray)); 
    8178 
    8279    //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index"); 
     
    10097    // Using JavaScript's feature sensing to detect which of the two we're dealing with: 
    10198    var json_result_str = (data.responseText) ? data.responseText : data;  
    102         // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript 
    103         //var json_result_str = (typeof data !== 'string') ? data.responseText : data; 
    104         //alert("Type of ajax get result: " + typeof (data)); 
    105  
    106     //  alert(json_result_str); 
    107     console.log("Got to display: " + json_result_str); 
     99 
     100    //console.log("Got user comments to display: " + json_result_str); 
     101 
    108102    var result = JSON.parse(json_result_str); 
    109103    // result contains only one docrec (result[0]), since we asked for the usercomments of one docid 
    110104    var metatable = result[0].metatable; 
    111     //  alert(JSON.stringify(metatable)); 
    112105     
    113106    var i = 0; 
     
    122115    attr.nodeValue="usercommentheading"; 
    123116    heading.setAttributeNode(attr); 
    124     var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_"); 
     117    var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_" in GS2 
    125118    heading.appendChild(txt); 
    126119    usercommentdiv.appendChild(heading); 
     
    141134        var comment = metatable[2].metavals[i].metavalue;  
    142135         
    143         //alert("Comment: " + username + " " + timestamp + " " + comment); 
    144          
    145136        // No need to sort by time, as the meta are already stored sorted  
    146137        // and hence retrieved in the right order by using the i (metapos) counter 
     
    156147     
    157148    var submitButton = document.getElementById("usercommentSubmitButton"); 
    158     // Now we've finished loading all user comments, allow the user to add a comment 
     149    // Now we've finished loading all user comments, 
     150    // allow the user to add a comment by enabling the submit button again 
    159151    if(submitButton) { 
    160152    submitButton.disabled = false; 
     
    165157gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) { 
    166158     
    167     //alert("Comment: " + username + " " + timestamp + " " + comment); 
    168  
    169159    var divgroup=document.createElement("div"); 
    170160    var attr=document.createAttribute("class"); 
     
    198188} 
    199189 
    200  
    201 // Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync 
    202 // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 
    203 gs.usercomments.safeHTML = function(str) { 
    204     return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"',"&quot;").replace("'","&#x27;").replace("/", "&#x2F;"); //"\\"" 
    205 } 
    206  
    207  
    208190gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) { 
    209191     
     
    214196    var trimmed_comment = _comment.replace(/^\s+|\s+$/g, ''); 
    215197     
    216     if(!trimmed_comment) { // || !trimmed_username 
     198    if(!trimmed_comment) { 
    217199    doc.AddUserCommentForm.comment.value = "";             
    218200    //document.AddUserCommentForm.username.value = ""; 
    219     document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_"; 
     201    document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_" in GS2 
    220202    return; 
    221203    } 
     
    236218    var _timestamp = new Date().getTime(); // div by 1000 to get seconds. valueOf() may return string 
    237219     
    238     //alert("username:" + _username 
    239     //+ "\\ncomment: " + _comment 
    240     //+ "\\ncollection: " + collection  
    241     //+ "\\ndocid: " + _docid 
    242     //+ "\\ntimestamp: " + _timestamp);  
    243      
    244      
    245     // Entity encode the values before storing (at least <, >, forward slash. 
    246     // And single and double quote, ampersand) 
    247     // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 
    248     // setMetadataArray escapes the entire JSON, is that better than escaping individually here? 
    249     //_docid = escape(_docid); 
    250     //_timestamp = escape(_timestamp); 
    251     //_username = escape(_username); //safeHTML(_username); 
    252     //_comment = escape(_comment); //safeHTML(_comment); 
    253      
    254     // Use this if making individual api calls to set username meta, then timestamp then comment meta 
    255     // GSAPI already knows the collection 
    256     //gsapi.setMetadata(_docid, "username", null, _username, "accumulate", "import|archives|index"); 
    257     //gsapi.setMetadata(_docid, "usertimestamp", null, _timestamp, "accumulate", "import|archives|index"); 
    258     //gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index"); 
     220    // setMetadataArray escapes the entire JSON, so we don't individually escape the fields here 
     221    // If we did, and called gsapi.setMetadata or gs.functions (in javascript-global-functions.js) instead, 
     222    // then resort to escaping first, e.g. 
     223    // _comment = escape(_comment); 
     224    // gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index"); 
    259225     
    260226     
     
    287253     
    288254    var docArray = [doc_rec]; 
    289      
    290     //alert(JSON.stringify(docArray)); 
    291255     
    292256    // Don't allow the user to submit further comments until the metadata has been updated 
     
    301265    function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, 
    302266    false); // false for asynchronous,  
    303     // this is ok since we're disabling the comment submit button, so no further set-meta-array calls can be 
    304     // made until the ajax call returns and the callback is called which re-enables the submit button 
     267    // async here is ok since we're disabling the comment submit button, so no further set-meta-array calls 
     268    // can be made until the ajax call returns and the callback is called which re-enables the submit button 
    305269    // But disabling submit does not protect against concurrent access such as someone else editing the  
    306270    // document (doing set-meta operations, updating archives/index/import) at the same time as someone else 
     
    311275gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment) 
    312276{ 
    313  
    314277    // data is xmlHttpRequest Object if gsajaxapi is used for the ajax call. 
    315278    // And data is a string if jQuery AJAX was used. 
    316279    // Using JavaScript's feature sensing to detect which of the two we're dealing with: 
    317280    var result = (data.responseText) ? data.responseText : data;         
    318         // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript 
    319         //var result = (typeof data !== 'string') ? data.responseText : data; 
    320         // alert("Type of ajax set result: " + typeof(data)); 
    321  
    322     //alert("Received post response to setMeta: " + result); // just the HTML page 
    323281 
    324282    // clear the comment field as it has now been submitted, but not the username field 
     
    336294    errormessage="ERROR: Unable to add comment. " + error; 
    337295    document.getElementById("usercommentfeedback").innerHTML = errormessage; 
    338     //alert("Result: " + result); 
    339296    }  
    340297    else if (responseErrorIndex != -1) { 
     
    344301    errormessage="ERROR: Unable to add comment. " + error; 
    345302    document.getElementById("usercommentfeedback").innerHTML = errormessage; 
    346     //alert("Result: " + result); 
    347303    } 
    348304    else { // success! 
    349     document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_";        
     305    document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_" in GS2 
    350306     
    351307    // update display of existing user comments to show the newly added comment 
     
    364320    gs.usercomments.loadUserComments(); 
    365321 
    366     //$("div#commentarea").html("<textarea required=\"required\" name=\"comment\" rows=\"10\" cols=\"64\" placeholder=\"Add your comment here...\"></textarea>"); 
    367322    $("div#commentarea").html('<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>'); 
    368323 
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl

    r31558 r31559  
    4242      <div> 
    4343        <p><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></p> 
    44         <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML --> 
     44        <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML. It will look like: --> 
    4545        <!--<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>--> 
    4646        <div id="commentarea">Comment area to appear here</div>