Changeset 27293

Show
Ignore:
Timestamp:
02.05.2013 17:43:31 (6 years ago)
Author:
ak19
Message:

Some bugfixes and improvements to the existing Add User Comment form before committing changes for the authentication. Fixes like checking for empty strings entered for the comment which shouldn't go in the database. And after a comment is submitted, it needs to be added to the existing list of displayed user comments, instead of reloading them all.

Location:
main/trunk/greenstone2/macros
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/macros/document.dm

    r27281 r27293  
    166166 
    167167    function addUserComment(_username, _comment, _docid, doc) \{ 
     168 
     169        // don't add empty strings for name/comment      
     170 
     171        // http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript 
     172        var trimmed_username=_username.replace(/^\s+|\s+$/g, ''); 
     173        var trimmed_comment = _comment.replace(/^\s+|\s+$/g, ''); 
     174         
     175        if(!trimmed_username || !trimmed_comment) \{ 
     176              doc.AddUserCommentForm.comment.value = ""; 
     177              doc.AddUserCommentForm.username.value = ""; 
     178              doc.getElementById("usercommentfeedback").innerHTML = "_text-is-empty_"; 
     179              return; 
     180        \} 
     181 
    168182        // Need to the add user comment meta of username, timestamp and comment to the 
    169183        // topmost section of the document. So only get the docId up to any period mark: 
     
    241255 
    242256        // update display of existing user comments to show the newly added comment 
    243         loadUserComments(); 
     257        var usercommentdiv = document.getElementById("usercomments"); 
     258        if(usercommentdiv != undefined) \{ 
     259             displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment); 
     260        \} 
    244261    \} 
    245262</script> 
  • main/trunk/greenstone2/macros/english.dm

    r27259 r27293  
    340340_textaddcomment_ {add comment} 
    341341_textcommentsubmitted_ {Comment Submitted} 
     342_text-is-empty_ {Can't add empty values} 
    342343 
    343344_textgoto_ {go to page} 
  • main/trunk/greenstone2/macros/style.dm

    r27282 r27293  
    244244    // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss 
    245245    // Call as: alert(timestamp.printTime()); 
    246     String.prototype.printTime = function () \{ 
    247       var timestamp    = parseInt(this, 10); // don't forget the second param 
    248       var date = new Date(timestamp); 
     246    function formatTime(timestamp) \{ 
     247      var int_timestamp    = parseInt(timestamp, 10); // don't forget the second param 
     248      var date = new Date(int_timestamp); 
    249249      return date.toLocaleDateString() + " " + date.toLocaleTimeString();    
    250250   \} 
     
    313313             
    314314        metapos++; 
    315         username = gsapi.getArchivesMetadata(doc_id, "username", metapos); 
     315        username = gsapi.getArchivesMetadata(doc_id, "username", metapos);//, "_cgiargun_", "_cgiargpw_"); 
    316316    \} 
    317317 
    318318    // No need to sort by time,  
    319     // as the array is already stored sorted and hence retrieved in the right order by using metapost counter 
     319    // as the array is already stored sorted and hence retrieved in the right order by using metapos counter 
    320320    // If sorting the array of comment records, which would be by timestamp, see 
    321321    // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort 
     
    328328     
    329329    // create the output HTML for all comments in one go now 
    330     // (we do this here altogether to hopefully avoid reloading the page for each comment) 
     330    // (we do this here for all values together to hopefully avoid reloading the page for each comment) 
    331331 
    332332    for(var i = 0; i < metapos; i++) \{ 
     
    339339 
    340340        // for each usercomment, create a child div with the username, timestamp and comment 
    341  
    342         var divgroup=document.createElement("div"); 
    343         var attr=document.createAttribute("class"); 
    344         attr.nodeValue="usercomment"; 
    345         divgroup.setAttributeNode(attr); 
    346  
    347         var divuser=document.createElement("div"); 
    348         var divtime=document.createElement("div"); 
    349         var divcomment=document.createElement("div"); 
    350  
    351      
    352         divgroup.appendChild(divuser); 
    353         var txt=document.createTextNode(username); 
    354         divuser.appendChild(txt); 
    355  
    356         divgroup.appendChild(divtime); 
    357         txt=document.createTextNode(timestamp.printTime()); // formate timestamp for date/time display 
    358         divtime.appendChild(txt); 
    359  
    360         divgroup.appendChild(divcomment); 
    361         txt=document.createTextNode(comment); 
    362         divcomment.appendChild(txt); 
    363  
    364         usercommentdiv.appendChild(divgroup); 
     341        displayInUserCommentList(usercommentdiv, username, timestamp, comment); 
    365342    \} 
    366343 
     
    368345    \} 
    369346 
     347    function displayInUserCommentList(usercommentdiv, username, timestamp, comment) \{ 
     348 
     349        var divgroup=document.createElement("div"); 
     350    var attr=document.createAttribute("class"); 
     351    attr.nodeValue="usercomment"; 
     352    divgroup.setAttributeNode(attr); 
     353 
     354    var divuser=document.createElement("div"); 
     355    var divtime=document.createElement("div"); 
     356    var divcomment=document.createElement("div"); 
     357 
     358     
     359    divgroup.appendChild(divuser); 
     360    var txt=document.createTextNode(username); 
     361    divuser.appendChild(txt); 
     362 
     363    divgroup.appendChild(divtime); 
     364    txt=document.createTextNode(formatTime(timestamp)); // format timestamp for date/time display 
     365    divtime.appendChild(txt); 
     366 
     367    divgroup.appendChild(divcomment); 
     368    txt=document.createTextNode(comment); 
     369    divcomment.appendChild(txt); 
     370 
     371    usercommentdiv.appendChild(divgroup); 
     372              
     373    \} 
    370374 
    371375    // http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load