Changeset 38188 for main/trunk/greenstone3/web
- Timestamp:
- 2023-09-21T21:46:13+12:00 (9 months ago)
- 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 601 601 602 602 // 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 of603 // These next 2 functions prepare both the URL version of the payload and the data object version 604 604 // of the payload. Then calling functions, and the _callMetadataServer() function they call, will control 605 605 // and determine which of the two forms ultimately gets used. … … 610 610 { 611 611 // if we're doing set- or remove- metadata operations, 612 // then we need change the data params that will make up the query string612 // then we need to change the data params that will make up the query string 613 613 // to make sure we go through GS3's authentication 614 614 // 1. prefix meta names with s1, -
main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
r37704 r38188 95 95 } 96 96 97 97 98 gs.usercomments.loadedUserComments = function(data) 98 99 { … … 119 120 var i = 0; 120 121 var looping = true; 122 123 var canDeleteComments = gs.variables["userCanDeleteComments"]; 124 //alert("canDeleteComments: " + canDeleteComments); 121 125 122 126 … … 153 157 154 158 // 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); 156 160 157 161 i++; 158 162 } 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 159 174 } 160 175 … … 168 183 169 184 170 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment ) {185 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment, canDeleteComments) { 171 186 172 187 var divgroup=document.createElement("div"); … … 178 193 var divtime=document.createElement("div"); 179 194 var divcomment=document.createElement("div"); 180 195 181 196 182 197 divgroup.appendChild(divuser); 183 198 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 } 184 208 divuser.appendChild(txt); 185 209 … … 200 224 201 225 } 226 227 228 gs.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 /* 247 gs.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 */ 202 308 203 309 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc, … … 268 374 var docArray = [doc_rec]; 269 375 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 271 378 document.getElementById("usercommentSubmitButton").disabled = true; 272 379 var delCommentsButton = document.getElementById("delCommentsButton"); 380 if(delCommentsButton != undefined) { 381 delCommentsButton.disabled = true; 382 } 273 383 274 384 //var result = gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index"); … … 329 439 // that the set-meta-array operation has completed. 330 440 document.getElementById("usercommentSubmitButton").disabled = false; 441 var delCommentsButton = document.getElementById("delCommentsButton"); 442 if(delCommentsButton != undefined) { 443 delCommentsButton.disabled = false; 444 } 445 331 446 } 332 447 -
main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl
r37704 r38188 42 42 <gsf:variable name="textcommentsubmitted"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submitted')"/></gsf:variable> 43 43 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 44 52 <!-- 2. Load the javascript, which will do stuff on window load/ready for which it needs the above gs.variables --> 45 53 <script type="text/javascript" src="interfaces/{$interface_name}/js/gsajaxapi.js"><xsl:text> </xsl:text></script> … … 53 61 previously submitted comments exist, or if the form#usercommentform to add 54 62 a new comment is displayed. Otherwise only the "Add Comments" link is shown. --> 55 <xsl:comment>Existing comments will be loadeddynamically loaded into this div#usercomments</xsl:comment>63 <xsl:comment>Existing comments will be dynamically loaded into this div#usercomments</xsl:comment> 56 64 </div> 57 65
Note:
See TracChangeset
for help on using the changeset viewer.