mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-20 22:03:03 +08:00
Working on project filter not saved, red dot missing [SCI-9463]
Fixed project filters not saved/red dot not showing when applied [SCI-9463] PR fix 01 [SCI-9463]
This commit is contained in:
parent
ab1eae1bd2
commit
7c7c0b0d88
1 changed files with 29 additions and 11 deletions
|
@ -1,12 +1,15 @@
|
|||
var filterDropdown = (function() {
|
||||
var $filterContainer = '';
|
||||
var $filtersEnabled = false;
|
||||
let filtersEnabled = null;
|
||||
let textFilterVal = null;
|
||||
|
||||
function initClearButton() {
|
||||
$('.clear-button', $filterContainer).click(function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
$filterContainer.trigger('filter:clear');
|
||||
$filterContainer.removeClass('filters-applied');
|
||||
textFilterVal = null;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,22 +40,35 @@ var filterDropdown = (function() {
|
|||
let storagePath = `${$filterDropdown.data('search-field-history-key')}/${teamId}/recent_search_keywords`;
|
||||
let recentSearchKeywords = JSON.parse(localStorage.getItem(storagePath));
|
||||
$.each(recentSearchKeywords, function(i, keyword) {
|
||||
$('#textSearchFilterHistory').append(
|
||||
$(`<li class="dropdown-item">
|
||||
const listItem = $(`<li class="dropdown-item">
|
||||
<a class="projects-search-keyword" href="#" data-keyword="${keyword}">
|
||||
<i class="fas fa-history"></i>
|
||||
<span class="keyword-text">${keyword}</span>
|
||||
</a>
|
||||
</li>`)
|
||||
);
|
||||
</li>`);
|
||||
|
||||
listItem.find('.projects-search-keyword').click(function(e) {
|
||||
e.preventDefault();
|
||||
const clickedKeyword = $(this).data('keyword');
|
||||
if (clickedKeyword?.trim().length > 0) {
|
||||
textFilterVal = clickedKeyword;
|
||||
}
|
||||
else {
|
||||
textFilterVal = null;
|
||||
}
|
||||
});
|
||||
$('#textSearchFilterHistory').append(listItem);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
if (textFilterVal) {
|
||||
$('#textSearchFilterInput').val(textFilterVal);
|
||||
}
|
||||
}).on('hide.bs.dropdown', function(e) {
|
||||
if (e.target === e.currentTarget) {
|
||||
$('#textSearchFilterHistory').hide();
|
||||
if (filtersEnabledFunction() || $filtersEnabled) {
|
||||
if (filtersEnabledFunction() || filtersEnabled) {
|
||||
$('.apply-filters', $filterContainer).click();
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +112,11 @@ var filterDropdown = (function() {
|
|||
}
|
||||
recentSearchKeywords.unshift(projectsViewSearch);
|
||||
localStorage.setItem(storagePath, JSON.stringify(recentSearchKeywords));
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
$filterContainer.trigger('filter:apply');
|
||||
$(this).closest('.dropdown').removeClass('open');
|
||||
});
|
||||
|
@ -113,22 +131,22 @@ var filterDropdown = (function() {
|
|||
return {
|
||||
init: function(filtersEnabledFunction) {
|
||||
$filterContainer = $('.filter-container');
|
||||
$filtersEnabled = false;
|
||||
initClearButton();
|
||||
preventDropdownClose();
|
||||
initApplyButton();
|
||||
initCloseButton();
|
||||
initSearchField(filtersEnabledFunction);
|
||||
this.toggleFilterMark($filterContainer, filtersEnabled)
|
||||
return $filterContainer;
|
||||
},
|
||||
toggleFilterMark: function(filterContainer, filtersEnabled) {
|
||||
$filtersEnabled = filtersEnabled;
|
||||
if (filtersEnabled) {
|
||||
toggleFilterMark: function(filterContainer, filtersEnabledArg) {
|
||||
if (filtersEnabledArg) {
|
||||
filterContainer.addClass('filters-applied');
|
||||
filtersEnabled = filtersEnabledArg;
|
||||
} else {
|
||||
filterContainer.removeClass('filters-applied');
|
||||
filtersEnabled = null;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue