Changeset 38218 for main/trunk/greenstone3/web
- Timestamp:
- 2023-09-25T23:04:59+13:00 (9 months ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r38194 r38218 1020 1020 } 1021 1021 1022 // metamode (such as accumulate) has no meaning when removingMetadata, 1023 // so best not make it an option to avoid confusing callers? 1024 gs.functions.removeMetadataArray = function(collection, site, docArray, /*metamode,*/ 1022 // metamode=override is in theory supported by remove_archives and remove_import metadata 1023 // but not by remove_index and remove_live metadata. However, even in the former 2 cases, 1024 // passing in metamode=override still appears to be ineffective, see recent svn revision 38193. 1025 // And metamode accumulate prevents all removal. 1026 // So for now, this function forces metamode to null, regardless of what is passed in. 1027 // At least this ensures a more consistent effect with remove_index (and remove_live) functions. 1028 gs.functions.removeMetadataArray = function(collection, site, docArray, metamode, 1025 1029 where, successResponseFunction, forceSync, errorResponseFunction) 1026 { 1030 { 1031 alert("in gs.functions.removeMetaArray START"); 1032 1027 1033 if( typeof errorResponseFunction === 'undefined' ) { errorResponseFunction = null; } // force error callback to be defined: either null or has value 1028 1034 … … 1038 1044 1039 1045 var response = gs.functions._callMetadataServer("Removing metadata from "+where, payload, successResponseFunction, errorResponseFunction, {"forceSync": forceSync, "requestMethod": "POST"}); 1040 1046 1047 console.log("in gs.functions.removeMetaArray: " + JSON.stringify(payload)); 1048 1041 1049 return response; 1042 1050 } -
main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
r38189 r38218 167 167 //delCommentsButton.setAttribute("onclick", gs.usercomments.deleteSelectedComments); 168 168 // alternatively: https://www.w3schools.com/jsref/met_element_addeventlistener.asp 169 delCommentsButton.addEventListener("click", gs.usercomments.deleteSelectedComments); 169 170 delCommentsButton.addEventListener("click", gs.usercomments.removeSelectedComments); 171 // Arduous way: deletes each metadata individually 172 //delCommentsButton.addEventListener("click", gs.usercomments.deleteSelectedComments); 170 173 171 174 delButtonDiv.appendChild(delCommentsButton); … … 238 241 } 239 242 243 // Uses remove array to remove multiple metadata in one ajax call 244 gs.usercomments.removeSelectedComments = function(eventObject, opt_metaname_username, opt_metaname_usertimestamp, opt_metaname_usercomment) 245 { 246 // https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array 247 // https://stackoverflow.com/questions/6166763/jquery-multiple-checkboxes-array 248 249 var selectedComments = document.querySelectorAll('input[class=del-me-comment][type=checkbox]:checked'); 250 251 if(selectedComments.length > 0) { 252 253 // Don't allow the user to submit further comments or delete comments 254 // until the metadata has been updated 255 document.getElementById("usercommentSubmitButton").disabled = true; 256 var delCommentsButton = document.getElementById("delCommentsButton"); 257 if(delCommentsButton != undefined) {// should be defined when in this function 258 delCommentsButton.disabled = true; 259 } 260 261 // User comment meta are at topmost section of the document. 262 // So only get the docId up to any period mark: 263 var _docid = document.AddUserCommentForm.d.value; 264 var period = _docid.indexOf("."); 265 if(period != -1) { 266 _docid = _docid.substring(0, period); 267 } 268 269 //document.querySelectorAll('input[class=del-me-comment][type=checkbox]:checked').forEach(elem => console.log(elem.getAttribute('data-username'))); 270 271 var metadataPositions = []; 272 var failure = false; 273 274 // start deleting from end of metadata list, so we don't have to recalculate metapos each time 275 for (var i = 0; i < selectedComments.length; i++) { 276 277 var metapos = selectedComments[i].getAttribute("data-metapos"); 278 metadataPositions.push(metapos); // add metapos to end of array 279 } 280 } 281 282 // now we have all the metapositions we need to delete 283 // create a JSON of indicating the username, timestamp and comment metadata need to be deleted 284 // at all those metapositions 285 286 // removeMetadataArray escapes the entire JSON, so we don't individually escape the fields here 287 288 // For creating the JSON object that gets turned into a string, see 289 // http://msdn.microsoft.com/en-us/library/ie/cc836459%28v=vs.94%29.aspx 290 // http://jsfiddle.net/qmacro/W54hy/ 291 292 var username_rec = { 293 metaname: opt_metaname_username || gs.usercomments.defaults.metaname_username, // e.g. "username" 294 metapositions: metadataPositions 295 }; 296 297 var timestamp_rec = { 298 metaname: opt_metaname_usertimestamp || gs.usercomments.defaults.metaname_usertimestamp, // e.g. "usertimestamp" 299 metavals: metadataPositions 300 }; 301 302 var comment_rec = { 303 metaname: opt_metaname_usercomment || gs.usercomments.defaults.metaname_usercomment, // e.g. "usercomment" 304 metavals: metadataPositions 305 }; 306 307 var doc_rec = { 308 docid: _docid, 309 metatable: [username_rec, timestamp_rec, comment_rec], 310 //metamode: "accumulate" 311 }; 312 313 var docArray = [doc_rec]; 314 315 // Don't allow the user to submit further comments or delete any 316 // until the metadata has been updated 317 document.getElementById("usercommentSubmitButton").disabled = true; 318 var delCommentsButton = document.getElementById("delCommentsButton"); 319 if(delCommentsButton != undefined) { 320 delCommentsButton.disabled = true; 321 } 322 323 324 gs.functions.removeMetadataArray( 325 gs.variables["c"], 326 gs.variables["site"], 327 docArray, 328 null, //metamode 329 "import|archives|index", 330 function(ajaxResult) { return gs.usercomments.doneRemovingMetadata(ajaxResult, metadataPositions); }, 331 false, // false for asynchronous, see comment in gs.usercomments.addUserComment() 332 function(ajaxError) { return gs.usercomments.removeMultipleCommentsFailed(ajaxError); } 333 ); 334 335 336 //console.log("username: " + opt_metaname_username + " - " + gs.usercomments.defaults.metaname_username); 337 console.log("metapositions to remove: " + metadataPositions); 338 console.log("docArray:\n" + JSON.stringify(docArray)); 339 } 340 341 gs.usercomments.removeMultipleCommentsFailed = function(data) { 342 var result = (data.responseText) ? data.responseText : data; 343 alert("Remove failed. Got: " + result); 344 failure = true; 345 346 // TODO, force a page reload so that the usercomments' state somewhat better reflects what's in DBs 347 } 348 349 350 // Removes single metadata at a time 240 351 gs.usercomments.deleteSelectedComments = function() { 241 352 // https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array … … 282 393 gs.variables["site"], 283 394 _docid, 284 "gs.username",395 gs.usercomments.defaults.metaname_username, 285 396 metapos, 286 397 //"import|archives|index", … … 295 406 gs.variables["site"], 296 407 _docid, 297 "gs.usertimestamp",408 gs.usercomments.defaults.metaname_usertimestamp, 298 409 metapos, 299 410 //"import|archives|index", … … 308 419 gs.variables["site"], 309 420 _docid, 310 "gs.usercomment",421 gs.usercomments.defaults.metaname_usercomment, 311 422 metapos, 312 423 //"import|archives|index", … … 322 433 //console.log("modifiedMetapos: " + modifiedMetapos); 323 434 324 gs.usercomments.doneRemovingMetadata( modifiedMetapos);435 gs.usercomments.doneRemovingMetadata(null, modifiedMetapos); 325 436 } 326 437 } … … 337 448 } 338 449 339 gs.usercomments.doneRemovingMetadata = function(modifiedMetapos) { 450 gs.usercomments.doneRemovingMetadata = function(data, modifiedMetapos) { 451 452 // data is xmlHttpRequest Object if gsajaxapi is used for the ajax call. 453 // And data is a string if jQuery AJAX was used. 454 // Using JavaScript's feature sensing to detect which of the two we're dealing with: 455 var result = (data.responseText) ? data.responseText : data; 456 457 //alert(result); 458 console.log("@@@ Done removing metadata:\n" + result); 459 340 460 var userCommentsDiv = document.getElementById("usercomments"); 341 461 … … 524 644 525 645 gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment) 526 { 646 { 527 647 // data is xmlHttpRequest Object if gsajaxapi is used for the ajax call. 528 648 // And data is a string if jQuery AJAX was used.
Note:
See TracChangeset
for help on using the changeset viewer.