* that it is replaced instead of being removed.
*
* @param {HTMLElement} filterRow
+ * @param {Bool} refreshContent Whether to refresh the table content when removing
*/
- const removeOrReplaceFilterRow = filterRow => {
+ const removeOrReplaceFilterRow = (filterRow, refreshContent) => {
const filterCount = getFilterRegion().querySelectorAll(Selectors.filter.region).length;
if (filterCount === 1) {
- replaceFilterRow(filterRow);
+ replaceFilterRow(filterRow, refreshContent);
} else {
- removeFilterRow(filterRow);
+ removeFilterRow(filterRow, refreshContent);
}
};
* Remove the specified filter row and associated class.
*
* @param {HTMLElement} filterRow
+ * @param {Bool} refreshContent Whether to refresh the table content when removing
*/
- const removeFilterRow = async filterRow => {
+ const removeFilterRow = async(filterRow, refreshContent = true) => {
const filterType = filterRow.querySelector(Selectors.filter.fields.type);
const hasFilterValue = !!filterType.value;
// Update the list of available filter types.
updateFiltersOptions();
- if (hasFilterValue) {
+ if (hasFilterValue && refreshContent) {
// Refresh the table if there was any content in this row.
updateTableFromFilter();
}
* Replace the specified filter row with a new one.
*
* @param {HTMLElement} filterRow
+ * @param {Bool} refreshContent Whether to refresh the table content when removing
* @param {Number} rowNum The number used to label the filter fieldset legend (eg Row 1). Defaults to 1 (the first filter).
* @return {Promise}
*/
- const replaceFilterRow = (filterRow, rowNum = 1) => {
+ const replaceFilterRow = (filterRow, refreshContent = true, rowNum = 1) => {
// Remove the filter object.
removeFilterObject(filterRow.dataset.filterType);
})
.then(filterRow => {
// Refresh the table.
- updateTableFromFilter();
-
- return filterRow;
+ if (refreshContent) {
+ return updateTableFromFilter();
+ } else {
+ return filterRow;
+ }
})
.catch(Notification.exception);
};
const pendingPromise = new Pending('core_user/participantsfilter:setFilterFromConfig');
const filters = getFilterRegion().querySelectorAll(Selectors.filter.region);
- filters.forEach(filterRow => removeOrReplaceFilterRow(filterRow));
+ filters.forEach(filterRow => removeOrReplaceFilterRow(filterRow, false));
// Refresh the table.
return updateTableFromFilter()
filters.forEach(filterRow => {
const filterType = filterRow.querySelector(Selectors.filter.fields.type);
if (!filterType.value) {
- removeOrReplaceFilterRow(filterRow);
+ removeOrReplaceFilterRow(filterRow, false);
}
});
};
if (e.target.closest(Selectors.filter.actions.remove)) {
e.preventDefault();
- removeOrReplaceFilterRow(e.target.closest(Selectors.filter.region));
+ removeOrReplaceFilterRow(e.target.closest(Selectors.filter.region), true);
}
});