Ignore:
Timestamp:
2023-10-20T17:01:06+13:00 (8 months ago)
Author:
anupama
Message:
  1. Confirmation dialog when deleting selected user comments. 2. The Delete Selected button should be unavailable if no user comments are checked.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/user_comments.js

    r38251 r38326  
    171171    // Arduous way: deletes each metadata individually
    172172    //delCommentsButton.addEventListener("click", gs.usercomments.deleteSelectedComments);
    173    
     173    delCommentsButton.disabled = true;
    174174    delButtonDiv.appendChild(delCommentsButton);
    175175
     
    217217    //deleteCheckBox.setAttribute("data-comment", comment);
    218218    divgroup.appendChild(deleteCheckBox);
     219
     220    //deleteCheckBox.setAttribute("checked", false); // why does this check the box?
     221    deleteCheckBox.addEventListener('change', function() {
     222        var delCommentsButton = document.getElementById("del-selected-comments-button");
     223        if(delCommentsButton.disabled && this.checked) {
     224        delCommentsButton.disabled = false;
     225        } else if(!this.checked) { //if we just unchecked current checkbox
     226        // only disable DeleteSelected button if all other checkboxes are all unchecked
     227        var selectedComments = document.querySelectorAll('input[class=del-me-comment][type=checkbox]:checked');
     228        if(selectedComments.length <= 0) {
     229             delCommentsButton.disabled = true;
     230        }
     231        }
     232    });
    219233    }
    220234   
     
    244258gs.usercomments.removeSelectedComments = function(eventObject, opt_metaname_username, opt_metaname_usertimestamp, opt_metaname_usercomment)
    245259{
     260    // https://sabe.io/blog/javascript-yes-no-confirmation-box
     261    var confirmResponse = confirm("Are you sure you want to delete the selected user comment(s)?");
     262    if (!confirmResponse) { // user cancelled
     263    return;
     264    }
     265
     266   
    246267    // https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array
    247268    // https://stackoverflow.com/questions/6166763/jquery-multiple-checkboxes-array
     
    497518   
    498519    // whether there was an error or not, re-enable the submit button now
    499     // that the removeMetada ajax operations have completed.
     520    // that the removeMetadata ajax operations have completed.
    500521    document.getElementById("usercommentSubmitButton").disabled = false;
     522   
    501523    var delCommentsButton = document.getElementById("del-selected-comments-button");
    502524    if(delCommentsButton != undefined) {
    503     delCommentsButton.disabled = false;
    504     }
    505    
     525    var delCheckboxes = document.querySelectorAll('input[class=del-me-comment][type=checkbox]');
     526    if(delCheckboxes.length <= 0) {
     527        delCommentsButton.disabled = true;
     528    }
     529    }   
    506530}
    507531
     
    641665    var delCommentsButton = document.getElementById("del-selected-comments-button");
    642666    if(delCommentsButton != undefined) {
    643     delCommentsButton.disabled = false;
    644     }
    645    
     667    var selectedComments = document.querySelectorAll('input[class=del-me-comment][type=checkbox]:checked');
     668    if(selectedComments.length <= 0) {
     669        delCommentsButton.disabled = true;
     670    } else {
     671        delCommentsButton.disabled = false;
     672    }
     673    }
    646674}
    647675
Note: See TracChangeset for help on using the changeset viewer.