Ignore:
Timestamp:
2013-05-02T17:43:31+12:00 (11 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.