Ignore:
Timestamp:
2023-09-21T21:46:13+12:00 (8 months ago)
Author:
anupama
Message:

GUI infrastructure for admin to delete user comments is now in place. Actual remove operations not yet implemented, but to be done in 2 phases. In first phase, call the basic remove-metadata(index/archives/index) for each username, comment and timestamp in turn. In second phase, need to add remove-metadata-array functions, so it can be called on all metadata to be removed in one go, as with set-metadata-array called by addUserComments.

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

Legend:

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

    r36027 r38188  
    601601
    602602// Prepare the payload (data package) to transmit to metadataserver.pl over AJAX.
    603 // These next 2 functions prepare both the URL version of the payload and the data object version of
     603// These next 2 functions prepare both the URL version of the payload and the data object version
    604604// of the payload. Then calling functions, and the _callMetadataServer() function they call, will control
    605605// and determine which of the two forms ultimately gets used.
     
    610610{
    611611    // if we're doing set- or remove- metadata operations,
    612     // then we need change the data params that will make up the query string
     612    // then we need to change the data params that will make up the query string
    613613    // to make sure we go through GS3's authentication
    614614    // 1. prefix meta names with s1,
  • main/trunk/greenstone3/web/interfaces/default/js/user_comments.js

    r37704 r38188  
    9595}
    9696
     97
    9798gs.usercomments.loadedUserComments = function(data)
    9899{
     
    119120    var i = 0;
    120121    var looping = true;
     122
     123    var canDeleteComments = gs.variables["userCanDeleteComments"];
     124    //alert("canDeleteComments: " + canDeleteComments);
    121125   
    122126   
     
    153157       
    154158        // for each usercomment, create a child div with the username, timestamp and comment
    155         gs.usercomments.displayInUserCommentList(usercommentdiv, username, timestamp, comment);
     159        gs.usercomments.displayInUserCommentList(usercommentdiv, username, timestamp, comment, canDeleteComments);
    156160       
    157161        i++;
    158162    }       
     163    }
     164   
     165    if(canDeleteComments) {
     166    var delCommentsButton = document.createElement("button");
     167    delCommentsButton.innerHTML = "Delete selected";
     168    delCommentsButton.setAttribute("id", "del-selected-comments-button");   
     169    //delCommentsButton.setAttribute("onclick", gs.usercomments.deleteSelectedComments);
     170    // alternatively: https://www.w3schools.com/jsref/met_element_addeventlistener.asp
     171    delCommentsButton.addEventListener("click", gs.usercomments.deleteSelectedComments);
     172    usercommentdiv.appendChild(delCommentsButton);
     173   
    159174    }
    160175   
     
    168183
    169184
    170 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) {
     185gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment, canDeleteComments) {
    171186   
    172187    var divgroup=document.createElement("div");
     
    178193    var divtime=document.createElement("div");
    179194    var divcomment=document.createElement("div");
    180    
     195
    181196   
    182197    divgroup.appendChild(divuser);
    183198    var txt=document.createTextNode(username);
     199    if(canDeleteComments) {
     200    var deleteCheckBox = document.createElement("input");
     201    deleteCheckBox.setAttribute("type", "checkbox");
     202    deleteCheckBox.setAttribute("class", "del-me-comment");
     203    deleteCheckBox.setAttribute("data-user", username);
     204    deleteCheckBox.setAttribute("data-timestamp", timestamp);
     205    deleteCheckBox.setAttribute("data-comment", comment);
     206    divuser.appendChild(deleteCheckBox);
     207    }   
    184208    divuser.appendChild(txt);
    185209   
     
    200224   
    201225}
     226
     227
     228gs.usercomments.deleteSelectedComments = function() {
     229    // https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array
     230    // https://stackoverflow.com/questions/6166763/jquery-multiple-checkboxes-array
     231
     232    //var selectedComments = document.getElementsByClassName("del-me-comment");
     233    // var selectedComments = document.querySelectorAll('input[class=del-me-comment]:checked');
     234    var selectedComments = document.querySelectorAll('input[class=del-me-comment][type=checkbox]:checked');
     235
     236    if(selectedComments.length==0) {   
     237    alert("Delete pressed, but nothing selected");
     238    } else {
     239    //alert("Delete pressed " + selectedComments.length);
     240    alert("Delete pressed for docID: " + gs.variables["docID"]
     241          + " on num comments: " + selectedComments.length);
     242    }   
     243}
     244
     245
     246/*
     247gs.usercomments.removeUserComment = function (_usernames, _timestamps, _comments, _docid, doc,
     248          opt_metaname_username, opt_metaname_usertimestamp, opt_metaname_usercomment)
     249{
     250    // Want to remove usernames, timestamps and comments from import/metadata.xml,
     251    // archives/doc.xml and index/col.gdb.
     252   
     253    // Need to the add user comment meta of username, timestamp and comment to the
     254    // topmost section of the document. So only get the docId up to any period mark:
     255    var period = _docid.indexOf(".");
     256    if(period != -1) {
     257    _docid = _docid.substring(0, period);
     258    }
     259   
     260    // Use the new JSON metatable format to remove list of usernames, their matching timestamps and comments meta for docid in one go
     261    // For creating the JSON object that gets turned into a string, see
     262    // http://msdn.microsoft.com/en-us/library/ie/cc836459%28v=vs.94%29.aspx
     263    // http://jsfiddle.net/qmacro/W54hy/
     264   
     265    var username_rec = {
     266    metaname: opt_metaname_username || gs.usercomments.defaults.metaname_username, // e.g. "username"
     267    metavals: _usernames
     268    };
     269   
     270    var timestamp_rec = {
     271    metaname: opt_metaname_usertimestamp || gs.usercomments.defaults.metaname_usertimestamp, // e.g. "usertimestamp"
     272    metavals: _timestamps
     273    };
     274   
     275    var comment_rec = {
     276    metaname: opt_metaname_usercomment || gs.usercomments.defaults.metaname_usercomment, // e.g. "usercomment"
     277    metavals: _comments
     278    };
     279   
     280    var doc_rec = {
     281    docid: _docid,
     282    metatable: [username_rec, timestamp_rec, comment_rec],
     283    metamode: "accumulate" // TODO
     284    };
     285   
     286    var docArray = [doc_rec];
     287   
     288    // Don't allow the user to submit further comments or delete comments
     289    // until the metadata has been updated
     290    document.getElementById("usercommentSubmitButton").disabled = true;
     291    var delCommentsButton = document.getElementById("delCommentsButton");
     292    if(delCommentsButton != undefined) {// should be defined when in this function
     293    delCommentsButton.disabled = true;
     294    }
     295
     296    // There is no remove array version yet!!!
     297   
     298    //var result = gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index");
     299    gs.functions.removeMetadataArray(gs.variables["c"],
     300    gs.variables["site"],
     301    docArray, "accumulate",
     302    "import|archives|index",
     303    function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); },
     304    true); // true for synchronous, meaning is opposite to explanation for addUserComment() function below   
     305   
     306}
     307*/
    202308
    203309gs.usercomments.addUserComment = function(_username, _comment, _docid, doc,
     
    268374    var docArray = [doc_rec];
    269375   
    270     // Don't allow the user to submit further comments until the metadata has been updated
     376    // Don't allow the user to submit further comments or delete any
     377    // until the metadata has been updated
    271378    document.getElementById("usercommentSubmitButton").disabled = true;
    272 
     379    var delCommentsButton = document.getElementById("delCommentsButton");
     380    if(delCommentsButton != undefined) {
     381    delCommentsButton.disabled = true;
     382    }
    273383   
    274384    //var result = gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index");
     
    329439    // that the set-meta-array operation has completed.
    330440    document.getElementById("usercommentSubmitButton").disabled = false;
     441    var delCommentsButton = document.getElementById("delCommentsButton");
     442    if(delCommentsButton != undefined) {
     443    delCommentsButton.disabled = false;
     444    }
     445   
    331446}
    332447
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl

    r37704 r38188  
    4242  <gsf:variable name="textcommentsubmitted"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submitted')"/></gsf:variable>
    4343
     44
     45  <gsf:variable name="userCanDeleteComments">
     46    <xsl:choose>
     47      <xsl:when test="/page/pageRequest/userInformation and (util:csvContains(/page/pageRequest/userInformation/@groups, 'administrator'))">1</xsl:when><xsl:otherwise>0</xsl:otherwise>
     48    </xsl:choose>
     49  </gsf:variable>
     50  <gsf:variable name="docID"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></gsf:variable>
     51 
    4452  <!-- 2. Load the javascript, which will do stuff on window load/ready for which it needs the above gs.variables -->
    4553  <script type="text/javascript" src="interfaces/{$interface_name}/js/gsajaxapi.js"><xsl:text> </xsl:text></script>
     
    5361       previously submitted comments exist, or if the form#usercommentform to add
    5462       a new comment is displayed. Otherwise only the "Add Comments" link is shown. -->
    55       <xsl:comment>Existing comments will be loaded dynamically loaded into this div#usercomments</xsl:comment>
     63      <xsl:comment>Existing comments will be dynamically loaded into this div#usercomments</xsl:comment>
    5664    </div>
    5765
Note: See TracChangeset for help on using the changeset viewer.