Looking to display or hide certain sections on a page based on specific conditions.
I want to only show the sections of the page that contain words from the conditionsToShow
array.
function hideWorkflowConditions() {
// initially hide the elements
$('#descriptors_table > tbody').children().css('display', 'none');
}
function showWorkflowConditions() {
let conditionsToShow = `
Block transition until approval
Category is not Empty
Code Committed
File Uploader is User
File Uploader is in Group
File Uploader is in Project Role
Has Attachments AM
Has Links AM
Hide transition from user
Limit By Status
No Open Reviews
Only Assignee
Only Reporter
Permission
SIL
Script [ScriptRunner]
Sub-Task Blocking
Unreviewed Code
User Is In Group
User Is In Group Custom Field
User Is In Project Role
Verify Number of Attachments in Category
`;
// split the conditions into an array, using line breaks
let conditionsArray = conditionsToShow.split(/\n/).filter(Boolean);
// remove whitespace from the array
let conditionsArrayTrimmed = conditionsArray.map(Function.prototype.call, String.prototype.trim);
conditionsArrayTrimmed.forEach(element => {
// try to show the section if it contains the specified element
$( "#descriptors_table > tbody > tr (:contains('"+ element +"'))" ).css('display', 'table-row');
});
}
hideWorkflowConditions();
showWorkflowConditions();
// code snippet to show a single hidden element
/*var elx = "Only Reporter";
$( "#descriptors_table > tbody > tr (:contains('"+ elx +"'))" ).css('display', 'table-row');
*/