diff --git a/app/assets/javascripts/projects/show.js b/app/assets/javascripts/projects/show.js index d5fd2aaee..59ef938b9 100644 --- a/app/assets/javascripts/projects/show.js +++ b/app/assets/javascripts/projects/show.js @@ -192,13 +192,13 @@ // Clear filters $filterDropdown.on('filter:clear', function() { + $(this).find('input').val(''); if ($startedOnFromFilter.data('DateTimePicker')) $startedOnFromFilter.data('DateTimePicker').clear(); if ($startedOnToFilter.data('DateTimePicker')) $startedOnToFilter.data('DateTimePicker').clear(); if ($modifiedOnFromFilter.data('DateTimePicker')) $modifiedOnFromFilter.data('DateTimePicker').clear(); if ($modifiedOnToFilter.data('DateTimePicker')) $modifiedOnToFilter.data('DateTimePicker').clear(); if ($archivedOnFromFilter.data('DateTimePicker')) $archivedOnFromFilter.data('DateTimePicker').clear(); if ($archivedOnToFilter.data('DateTimePicker')) $archivedOnToFilter.data('DateTimePicker').clear(); - $textFilter.val(''); }); } diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index b1c614663..50ab82143 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -127,6 +127,8 @@ var ProtocolsIndex = (function() { $filterDropdown.on('filter:clear', function() { dropdownSelector.clearData($publishedByFilter); dropdownSelector.clearData($accessByFilter); + + $(this).find('input').val(''); if ($publishedOnFromFilter.data('DateTimePicker')) $publishedOnFromFilter.data('DateTimePicker').clear(); if ($publishedOnToFilter.data('DateTimePicker')) $publishedOnToFilter.data('DateTimePicker').clear(); if ($modifiedOnFromFilter.data('DateTimePicker')) $modifiedOnFromFilter.data('DateTimePicker').clear(); diff --git a/app/assets/javascripts/sitewide/date_time_picker.js b/app/assets/javascripts/sitewide/date_time_picker.js index 31e1d37c6..329a1b1ac 100644 --- a/app/assets/javascripts/sitewide/date_time_picker.js +++ b/app/assets/javascripts/sitewide/date_time_picker.js @@ -5,26 +5,39 @@ ev.preventDefault(); ev.stopPropagation(); - let dt = $(this); - let selectedDate = {}; + const dt = $(this); - $('.calendar-input').slice(0, 2).each(function(index, element) { - if ($(element).val().length > 0 ) { - selectedDate.index = index; - selectedDate.date = moment($(element).val(), element.dataset.dateFormat).toDate(); - } - }); + if (dt.data('DateTimePicker')) { + dt.data('DateTimePicker').show(); + return; + } + + const linkedMin = dt.data('linked-min'); + const linkedMax = dt.data('linked-max'); let options = { - ignoreReadonly: true - }; + ignoreReadonly: true, + useCurrent: false + } - if (selectedDate.date) { - if (selectedDate.index == 0) { - options.minDate = selectedDate.date; - } else if (selectedDate.index == 1) { - options.maxDate = selectedDate.date; + if (linkedMin) { + if ($(linkedMin).val()) { + options.minDate = moment($(linkedMin).val(), $(linkedMin).data('dateFormat')).toDate(); } + + $(linkedMin).on("dp.change", function (e) { + dt.data("DateTimePicker").minDate(e.date); + }); + } + + if (linkedMax) { + if ($(linkedMax).val()) { + options.maxDate = moment($(linkedMax).val(), $(linkedMax).data('dateFormat')).toDate(); + } + + $(linkedMax).on("dp.change", function (e) { + dt.data("DateTimePicker").maxDate(e.date); + }); } if (dt.data('DateTimePicker')) { diff --git a/app/assets/javascripts/sitewide/filter_dropdown.js b/app/assets/javascripts/sitewide/filter_dropdown.js index 8c4184526..42b9c9523 100644 --- a/app/assets/javascripts/sitewide/filter_dropdown.js +++ b/app/assets/javascripts/sitewide/filter_dropdown.js @@ -26,6 +26,10 @@ var filterDropdown = (function() { var $textFilter = $('#textSearchFilterInput', $filterContainer); $filterContainer.on('show.bs.dropdown', function() { + if (!$(this).hasClass('filters-applied')) { + $(this).find('input').val(''); + } + let $filterDropdown = $filterContainer.find('.dropdown-menu'); let teamId = $filterDropdown.data('team-id'); $('#textSearchFilterHistory').find('li').remove(); diff --git a/app/views/shared/filter_dropdown/_datetime_search.html.erb b/app/views/shared/filter_dropdown/_datetime_search.html.erb index 04626aa9d..f757f3f61 100644 --- a/app/views/shared/filter_dropdown/_datetime_search.html.erb +++ b/app/views/shared/filter_dropdown/_datetime_search.html.erb @@ -6,6 +6,8 @@