From b3151e0129e39c1f721b2a68ed7ab0f8ccab47ee Mon Sep 17 00:00:00 2001 From: HWFord <54360213+HWFord@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:30:44 +0200 Subject: [PATCH] fixes #2211 integrate new redesign for date posted filter filter on date_posted custom values (specific years, months or days) along side last 7, 30 days, 3 and 6 months following redesign by alice --- include/functions_search.inc.php | 59 ++++- include/ws_functions/pwg.images.php | 64 ++++- index.php | 57 +++-- themes/default/css/clear-search.css | 31 ++- themes/default/css/dark-search.css | 5 +- themes/default/css/search.css | 136 ++++++++-- themes/default/js/mcs.js | 236 +++++++++++++++--- .../template/include/search_filters.inc.tpl | 85 ++++++- ws.php | 8 +- 9 files changed, 589 insertions(+), 92 deletions(-) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index c31e10e11..81e081f1f 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -397,8 +397,9 @@ SELECT // // date_posted // - if (!empty($search['fields']['date_posted'])) + if (!empty($search['fields']['date_posted']['preset'])) { + $has_filters_filled = true; $options = array( @@ -407,17 +408,60 @@ SELECT '30d' => '30 DAY', '3m' => '3 MONTH', '6m' => '6 MONTH', - '1y' => '1 YEAR', ); - if (isset($options[ $search['fields']['date_posted'] ])) + if (isset($options[ $search['fields']['date_posted']['preset'] ]) and 'custom' != $search['fields']['date_posted']['preset']) { - $date_posted_clause = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted'] ].')'; + $date_posted_clause = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted']['preset'] ].')'; } - elseif (preg_match('/^y(\d+)$/', $search['fields']['date_posted'], $matches)) + elseif ('custom' == $search['fields']['date_posted']['preset'] and isset($search['fields']['date_posted']['custom'])) { - // that is for y2023 = all photos posted in 2023 - $date_posted_clause = 'YEAR(date_available) = '.$matches[1]; + $date_posted_subclauses = array(); + $custom_dates = array_flip($search['fields']['date_posted']['custom']); + + foreach (array_keys($custom_dates) as $custom_date) + { + // in real-life tests, we have determined "where year(date_available) = 2024" was + // far less (4 times less) than "where date_available between '2024-01-01 00:00:00' and '2024-12-31 23:59:59'" + // so let's find the begin/end for each custom date + // ... and also, no need to search for images of 2023-10-16 if 2023-10 is already requested + $begin = $end = null; + + $ymd = substr($custom_date, 0, 1); + if ('y' == $ymd) + { + $year = substr($custom_date, 1); + $begin = $year.'-01-01 00:00:00'; + $end = $year.'-12-31 23:59:59'; + } + elseif ('m' == $ymd) + { + list($year, $month) = explode('-', substr($custom_date, 1)); + + if (!isset($custom_dates['y'.$year])) + { + $begin = $year.'-'.$month.'-01 00:00:00'; + $end = $year.'-'.$month.'-'.cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year).' 23:59:59'; + } + } + elseif ('d' == $ymd) + { + list($year, $month, $day) = explode('-', substr($custom_date, 1)); + + if (!isset($custom_dates['y'.$year]) and !isset($custom_dates['m'.$year.'-'.$month])) + { + $begin = $year.'-'.$month.'-'.$day.' 00:00:00'; + $end = $year.'-'.$month.'-'.$day.' 23:59:59'; + } + } + + if (!empty($begin)) + { + $date_posted_subclauses[] = 'date_available BETWEEN "'.$begin.'" AND "'.$end.'"'; + } + } + + $date_posted_clause = '('.implode(' OR ', prepend_append_array_items($date_posted_subclauses, '(', ')')).')'; } $query = ' @@ -428,6 +472,7 @@ SELECT WHERE '.$date_posted_clause.' '.$forbidden.' ;'; + $image_ids_for_filter['date_posted'] = query2array($query, null, 'id'); } diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 45a4cdd68..8efe4515b 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -859,14 +859,70 @@ function ws_images_filteredSearch_create($params, $service) $search['fields']['added_by'] = $params['added_by']; } - if (isset($params['date_posted'])) + if (isset($params['date_posted_preset'])) { - if (!preg_match('/^(24h|7d|30d|3m|6m|y\d+|)$/', $params['date_posted'])) + if (!preg_match('/^(24h|7d|30d|3m|6m|custom|)$/', $params['date_posted_preset'])) { - return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted'); + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted_preset'); } - $search['fields']['date_posted'] = $params['date_posted']; + @$search['fields']['date_posted']['preset'] = $params['date_posted_preset']; + + if ('custom' == $search['fields']['date_posted']['preset'] and empty($params['date_posted_custom'])) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom is missing'); + } + } + + if (isset($params['date_posted_custom'])) + { + if (!isset($search['fields']['date_posted']['preset']) or $search['fields']['date_posted']['preset'] != 'custom') + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom provided date_posted_preset is not custom'); + } + + foreach ($params['date_posted_custom'] as $date) + { + $correct_format = false; + + $ymd = substr($date, 0, 1); + if ('y' == $ymd) + { + if (preg_match('/^y(\d{4})$/', $date, $matches)) + { + $correct_format = true; + } + } + elseif ('m' == $ymd) + { + if (preg_match('/^m(\d{4}-\d{2})$/', $date, $matches)) + { + list($year, $month) = explode('-', $matches[1]); + if ($month >= 1 and $month <= 12) + { + $correct_format = true; + } + } + } + elseif ('d' == $ymd) + { + if (preg_match('/^d(\d{4}-\d{2}-\d{2})$/', $date, $matches)) + { + list($year, $month, $day) = explode('-', $matches[1]); + if ($month >= 1 and $month <= 12 and $day >= 1 and $day <= cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year)) + { + $correct_format = true; + } + } + } + + if (!$correct_format) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom, invalid option '.$date); + } + + @$search['fields']['date_posted']['custom'][] = $date; + } } if (isset($params['ratios'])) diff --git a/index.php b/index.php index 054b0179d..0e81ab5e5 100644 --- a/index.php +++ b/index.php @@ -341,20 +341,6 @@ SELECT ); } - $pre_counters_keys = array_keys($pre_counters); - rsort($pre_counters_keys); // we want y2023 to come before y2022 in the list - - foreach ($pre_counters_keys as $key) - { - if (preg_match('/^y(\d+)$/', $key, $matches)) - { - $counters[$key] = array( - 'label' => l10n('year %d', $matches[1]), - 'counter' => count(array_keys($pre_counters[$key])) - ); - } - } - foreach ($counters as $key => $counter) { if (0 == $counter['counter']) @@ -364,6 +350,49 @@ SELECT } $template->assign('DATE_POSTED', $counters); + + + // Custom date + $query = ' +SELECT + DISTINCT id, + date_available as date + FROM '.IMAGES_TABLE.' AS i + JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id + WHERE '.$filter_clause.' +;'; + + $list_of_dates = array(); + + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + list($date_without_time) = explode(' ', $row['date']); + list($y, $m) = explode('-', $date_without_time); + + @$list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['count']++; + @$list_of_dates[$y]['months'][$y.'-'.$m]['count']++; + @$list_of_dates[$y]['count']++; + + // Benchmark if better to put the label in another array rather than keep in this array + + if (!isset($list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['label'])) + { + $list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['label'] = format_date($row['date']); + } + + if (!isset($list_of_dates[$y]['months'][$m]['label'])) + { + $list_of_dates[$y]['months'][$y.'-'.$m]['label'] = $lang['month'][(int)$m].' '.$y; + } + + if (!isset($list_of_dates[$y]['label'])) + { + $list_of_dates[$y]['label'] = l10n('year %d', $y); + } + } + + $template->assign('LIST_DATE_POSTED', $list_of_dates); } if (isset($my_search['fields']['added_by'])) diff --git a/themes/default/css/clear-search.css b/themes/default/css/clear-search.css index ebcd178e1..79f590e4f 100644 --- a/themes/default/css/clear-search.css +++ b/themes/default/css/clear-search.css @@ -109,15 +109,34 @@ color: #444; } +.date_posted-option label{ + background-color:white; + border-bottom:1px solid #f3f3f3; +} + +.date_posted-option i{ + background-color:white; +} .filetypes-option:nth-child(odd), .added_by-option:nth-child(odd), -.date_posted-option:nth-child(odd) label, +.preset_posted_date .date_posted-option:nth-child(odd) label, +.preset_posted_date .date_posted-option:nth-child(odd) i, +.custom_posted_date .date_posted-option:nth-child(odd) .year_input label, +.custom_posted_date .date_posted-option:nth-child(odd) .year_input i, +.custom_posted_date .date_posted-option:nth-child(even) .month_input label, +.custom_posted_date .date_posted-option:nth-child(even) .month_input i, +.custom_posted_date .days_container .date_posted-option:nth-child(odd) label, +.custom_posted_date .days_container .date_posted-option:nth-child(odd) i, .ratios-option:nth-child(odd), .ratings-option:nth-child(odd){ background: #f3f3f3; } +.date_posted-option label .checked-icon.grey-icon{ + color:#777; +} + .filetypes-option label .checked-icon, .added_by-option label .checked-icon, .date_posted-option label .checked-icon, @@ -128,7 +147,7 @@ .filetypes-option label .ext-badge, .added_by-option label .added_by-badge, -.date_posted-option label .date_posted-badge, +.date_posted-badge, .ratios-option label .ratio-badge, .ratings-option label .ratings-badge { background: #ff7700; @@ -149,14 +168,12 @@ .filetypes-option input:checked + label, .ratios-option input:checked + label, -.ratings-option input:checked + label { +.ratings-option input:checked + label, +.preset_posted_date .date_posted-option input:checked + label, +.custom_posted_date .selected input:checked { background: #fff5e8; } -.date_posted-option input:checked + label { - background: rgba(244, 171, 79, 0.17); -} - .head-button-2 { color: #777; } diff --git a/themes/default/css/dark-search.css b/themes/default/css/dark-search.css index 9df2b56c5..84c6cfe86 100644 --- a/themes/default/css/dark-search.css +++ b/themes/default/css/dark-search.css @@ -128,7 +128,7 @@ .filetypes-option label .ext-badge, .added_by-option label .added_by-badge, -.date_posted-option label .date_posted-badge, +.date_posted-badge, .ratios-option label .ratio-badge, .ratings-option label .ratings-badge { background: #ff7700bb; @@ -149,7 +149,8 @@ .added_by-option input:checked + label, .filetypes-option input:checked + label, -.date_posted-option input:checked + label, +.date_posted-option .selected label, +.date_posted-option .selected .accordion-toggle, .ratios-option input:checked + label, .ratings-option input:checked + label{ background: rgba(244, 171, 79, 0.17); diff --git a/themes/default/css/search.css b/themes/default/css/search.css index b849bc181..fbbb86d25 100644 --- a/themes/default/css/search.css +++ b/themes/default/css/search.css @@ -302,7 +302,6 @@ width: 200px; } -.filter-date_posted-form, .filter-ratings-form{ width: 250px; } @@ -339,7 +338,7 @@ .filetypes-option label, .added_by-option label, -.date_posted-option label, +.preset_posted_date .date_posted-option label, .ratios-option label, .ratings-option label{ display: flex; @@ -351,14 +350,20 @@ .filetypes-option label .checked-icon, .added_by-option label .checked-icon, -.date_posted-option label .checked-icon, .ratios-option label .checked-icon, -.ratings-option label .checked-icon{ +.ratings-option label .checked-icon, +.preset_posted_date .date_posted-option label .checked-icon{ display: none; position: absolute; - left: 0; + left: 3px; + top: 4px; +} + +.custom_posted_date .date_posted-option label .checked-icon{ + display: none; + position: absolute; + right: 3px; top: 4px; - margin: 5px; } .filetypes-option label .ext-name { @@ -367,8 +372,8 @@ .filetypes-option label .ext-name, .added_by-option label .added_by-name, -.date_posted-option label .date-period, .ratios-option label .ratio-name, +.preset_posted_date .date_posted-option .date-period, .ratings-option label .ratings-name { margin-left: 30px; } @@ -378,29 +383,36 @@ margin-right: 10px; } -.date_posted-option label .date-period{ - margin-left: 30px; +.custom_posted_date .date_posted-option label .date-period{ + margin-right: 30px; } .filetypes-option label .ext-badge, .added_by-option label .added_by-badge, -.date_posted-option label .date_posted-badge, .ratios-option label .ratio-badge, -.ratings-option label .ratings-badge { +.ratings-option label .ratings-badge, +.preset_posted_date .date_posted-option label .date_posted-badge { margin-left: auto; border-radius: 10px; padding: 0 5px; font-weight: 600; } +.custom_posted_date .date_posted-option label .date_posted-badge{ + border-radius: 10px; + padding: 0 5px; + font-weight: 600; +} + .filetypes-option input:checked + label .checked-icon, .added_by-option input:checked + label .checked-icon, -.date_posted-option input:checked + label .checked-icon, .ratios-option input:checked + label .checked-icon, -.ratings-option input:checked + label .checked-icon{ - display: flex; +.ratings-option input:checked + label .checked-icon, +.preset_posted_date .date_posted-option input:checked + label .checked-icon{ + display: block; } +.filter-date_posted-form, .filter-album-form { width: 400px; } @@ -422,6 +434,75 @@ .width-option-container{ margin-bottom:25px; } + +.year_input, +.month_input{ + display:flex +} + +.date_posted-option label{ + display: flex; + flex-direction: row; + align-items: baseline; + position: relative; + padding: 5px; + margin-left:-1px; +} + +.custom_posted_date .date_posted-option label{ + width:100%; +} + +.date_posted-option .accordion-toggle{ + padding:5px; + rotate:90deg; +} + +.date_posted-option .accordion-toggle:hover{ + color:#ff7700; + cursor:pointer; +} + +.date_posted-option.month{ + margin-left:15px; + display:none; +} +.date_posted-option.day{ + margin-left:30px; + margin-right:10px; + display:none; +} + +.date_posted-option .show-child .accordion-toggle::before { + transform: rotate(90deg); +} + +.custom_posted_date{ + display:none; +} + +.grey-icon{ + display:block!important; +} + +.custom_posted_date_toggle{ + cursor:pointer; +} + +.date_posted-option .custom_posted_date_toggle{ + padding: 5px 0; + border-top: .3px solid #aaa; + border-bottom: .3px solid #aaa; +} + +.custom_posted_date_toggle .gallery-icon-up-open:before{ + rotate: -90deg; +} + +.custom_posted_date.custom_posted_date_toggle{ + position:absolute; +} + /*_____________________________*/ .head-button-2 { @@ -778,8 +859,7 @@ .ui-slider-horizontal { - width: 280px; - margin: 10px 0 10px 9px; + margin: 10px; height: 2px; } @@ -846,4 +926,28 @@ .ui-slider-horizontal .ui-slider-handle:hover{ cursor:pointer; +} + +.mcs-container div .slider_input{ + display:flex; + justify-content: space-between; + margin-bottom:15px; +} + +.mcs-container div .slider_input .max_input{ + text-align:right; +} + +.mcs-container input[type="number"], +.mcs-container input[type="number"]:focus{ + border: none; + background: #eee; + color: #444; + border-radius:6px; +} + +.mcs-container div .slider_input p{ + margin:0; + color:#656565; + font-size:12px; } \ No newline at end of file diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 777745a29..dd89342a3 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -86,6 +86,7 @@ $(document).ready(function () { items: global_params.fields.tags ? global_params.fields.tags.words : null, }); }); + if (global_params.fields.tags) { $(".filter-tag").css("display", "flex"); $(".filter-manager-controller.tags").prop("checked", true); @@ -114,25 +115,165 @@ $(document).ready(function () { } // Setup Date post filter - if (global_params.fields.hasOwnProperty('date_posted')) { + if (global_params.fields.date_posted) { + $(".filter-date_posted").css("display", "flex"); $(".filter-manager-controller.date_posted").prop("checked", true); - if (global_params.fields.date_posted != null && global_params.fields.date_posted != "") { - $("#date_posted-" + global_params.fields.date_posted).prop("checked", true); + if (global_params.fields.date_posted.preset != null && global_params.fields.date_posted.preset != "") { + // If filter is used and not empty check preset date option + $("#date_posted-" + global_params.fields.date_posted.preset).prop("checked", true); + date_posted_str = $('.date_posted-option label#'+ global_params.fields.date_posted.preset +' .date-period').text(); - date_posted_str = $('.date_posted-option label#'+global_params.fields.date_posted+' .date-period').text(); + // if option is custom check custom dates + if ('custom' == global_params.fields.date_posted.preset && global_params.fields.date_posted.custom != null) + { + date_posted_str = ''; + var customArray = global_params.fields.date_posted.custom + + $(customArray).each(function( index ) { + var customValue = this.substring(1, $(this).length); + + $("#date_posted_"+customValue).prop("checked", true).addClass('selected'); + $("#date_posted_"+customValue).siblings('label').find('.checked-icon').show(); + + date_posted_str += $('.date_posted-option label#'+ customValue +' .date-period').text() + + if($(global_params.fields.date_posted.custom).length > 1 && index != $(customArray).length-1) + { + date_posted_str += ', '; + } + }); + } + + // change badge label if filter not empty $(".filter-date_posted").addClass("filter-filled"); $(".filter.filter-date_posted .search-words").text(date_posted_str); } $(".filter-date_posted .filter-actions .clear").on('click', function () { + updateFilters('date_posted', 'add'); $(".date_posted-option input").prop('checked', false); + $(".date_posted-option input").trigger('change'); + + // $('.date_posted-option input').removeAttr('disabled'); + // $('.date_posted-option input').removeClass('grey-icon'); }); - PS_params.date_posted = global_params.fields.date_posted.length > 0 ? global_params.fields.date_posted : ''; + // Disable possiblity for user to select custom option, its gets selected programtically later on + $("#date_posted_custom").attr('disabled', 'disabled'); - empty_filters_list.push(PS_params.date_posted); + // Handle toggle between preset and custom options + $(".custom_posted_date_toggle").on("click", function (e) { + $('.custom_posted_date').toggle() + $('.preset_posted_date').toggle() + }); + + // Handle accoridan features in custom options + $(".custom_posted_date .accordion-toggle").on("click", function (e) { + var clickedOption = $(this).parent(); + $(clickedOption).toggleClass('show-child'); + if('year' == $(this).data('type')) + { + $(clickedOption).parent().find('.date_posted-option.month').toggle(); + } + else if('month' == $(this).data('type')) + { + $(clickedOption).parent().find('.date_posted-option.day').toggle(); + } + }); + + // On custom date input select + $(".custom_posted_date .date_posted-option input").change(function() { + var parentOption = $(this).parent() + + if(true == $(this).prop("checked")){ + // Toggle tick icon on selected date in custom list + $(this).siblings('label').find('.checked-icon').show(); + + // Add class selected to selected option, + // We want to find which are selected to handle the others + $(this).addClass('selected') + $(parentOption).addClass('selected') + $(parentOption).find('.mcs-icon').addClass('selected') + } + else + { + // Toggle tick icon on selected date in custom list + $(this).siblings('label').find('.checked-icon').hide(); + + // Add class selected to selected option, + // We want to find which are selected to handle the others + $(this).removeClass('selected') + $(parentOption).removeClass('selected') + $(parentOption).find('.mcs-icon').removeClass('selected') + } + + // TODO finish handling grey tick on child options, and having specifi icon to show children are selected + + // if this is selected then disable selecting children, and display grey tick + // var selectedContainerID = $(this).parent().parent().attr('id'); + // if ($(this).is(":checked")) + // { + // $('#'+selectedContainerID+' .date_posted-option input').not('.selected').attr('disabled', 'disabled'); + // $('#'+selectedContainerID+' .date_posted-option .mcs-icon').not('.selected').addClass('grey-icon'); + + // if($(parentOption).hasClass('year')) + // { + // if($(parentOption).find('label .mcs-icon').hasClass('gallery-icon-menu')) + // { + // $(parentOption).find('label .mcs-icon').toggleClass('gallery-icon-menu gallery-icon-checkmark').show(); + // } + // } + // else if($(parentOption).hasClass('month')) + // { + // $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon'); + // } + // else if ($(parentOption).hasClass('day')) + // { + // $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark').show(); + // $(this).parents('.month').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark').show(); + // } + // } + // else + // { + // $('#'+selectedContainerID+' .date_posted-option input').not('.selected').removeAttr('disabled'); + // $('#'+selectedContainerID+' .date_posted-option .mcs-icon').not('.selected').removeClass('grey-icon'); + + // $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon'); + // $(this).parents('.month').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon'); + + // } + + // Used to select custom in preset list if dates are selected + if($('.custom_posted_date input:checked').length > 0) + { + $("#date_posted-custom").prop('checked', true); + $('.preset_posted_date input').attr('disabled', 'disabled'); + } + else{ + $("#date_posted-custom").prop('checked', false); + $('.preset_posted_date input').removeAttr('disabled'); + } + + }); + + // Used to select custom in preset list if dates are selected + if($('.custom_posted_date input:checked').length > 0) + { + $("#date_posted-custom").prop('checked', true); + $('.preset_posted_date input').attr('disabled', 'disabled'); + } + else{ + $("#date_posted-custom").prop('checked', false); + $('.preset_posted_date input').removeAttr('disabled'); + } + + PS_params.date_posted_preset = global_params.fields.date_posted.preset != '' ? global_params.fields.date_posted.preset : ''; + PS_params.date_posted_custom = global_params.fields.date_posted.custom != '' ? global_params.fields.date_posted.custom : ''; + + empty_filters_list.push(PS_params.date_posted_preset); + empty_filters_list.push(PS_params.date_posted_custom); } // Setup album filter @@ -351,6 +492,15 @@ $(document).ready(function () { $('[data-slider=filesizes]').pwgDoubleSlider(sliders.filesizes); + $('[data-slider=filesizes]').on("slidestop", function(event, ui) { + var min = $('[data-slider=filesizes]').find('[data-input=min]').val(); + var max = $('[data-slider=filesizes]').find('[data-input=max]').val(); + + $('input[name=filter_filesize_min_text]').val(min).trigger('change'); + $('input[name=filter_filesize_max_text]').val(max).trigger('change'); + + }); + if( global_params.fields.filesize_min != null && global_params.fields.filesize_max > 0) { $(".filter-filesize").addClass("filter-filled"); $(".filter.filter-filesize .search-words").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max,)); @@ -516,7 +666,6 @@ $(document).ready(function () { } } else { if ($(".filter.filter-" + $(this).data("wid")).is(':visible')) { - console.log($(this).data("wid")); updateFilters($(this).data("wid"), 'del'); } } @@ -658,14 +807,31 @@ $(document).ready(function () { return; } $(".filter-date_posted-form").toggle(0, function () { - if ($(this).is(':visible')) { + if ($(this).is(':visible')) + { $(".filter-date_posted").addClass("show-filter-dropdown"); - } else { + } + else + { $(".filter-date_posted").removeClass("show-filter-dropdown"); - global_params.fields.date_posted = $(".date_posted-option input:checked").val(); + var presetValue = $(".preset_posted_date .date_posted-option input:checked").val(); - PS_params.date_posted = $(".date_posted-option input:checked").length > 0 ? $(".date_posted-option input:checked").val() : ""; + global_params.fields.date_posted.preset = presetValue; + PS_params.date_posted_preset = presetValue != null ? presetValue : ""; + + if ('custom' == presetValue) + { + var customDates = []; + + $(".custom_posted_date .date_posted-option input:checked").each(function(){ + customDates.push($(this).val()); + }); + + global_params.fields.date_posted.custom = customDates; + PS_params.date_posted_custom = customDates.length > 0 ? customDates : ""; + } + } }); }); @@ -674,6 +840,7 @@ $(document).ready(function () { $(".filter-date_posted").trigger("click"); performSearch(PS_params, true); }); + $(".filter-date_posted .filter-actions .delete").on("click", function () { updateFilters('date_posted', 'del'); performSearch(PS_params, true); @@ -826,6 +993,7 @@ $(document).ready(function () { } }); }); + $(".filter-filetypes .filter-validate").on("click", function () { $(".filter-filetypes").trigger("click"); performSearch(PS_params, true); @@ -1041,26 +1209,6 @@ $(document).ready(function () { $(".filter-manager-controller.width").prop("checked", false); } }); - - - /* Close dropdowns if you click on the screen */ - // $(document).mouseup(function (e) { - // e.stopPropagation(); - // let option_is_clicked = false - // $(".mcs-container .filter").each(function () { - // console.log(($(this).hasClass("show-filter-dropdown"))); - // if (!($(this).has(e.target).length === 0)) { - // option_is_clicked = true; - // } - // }) - // if (!option_is_clicked) { - // $(".filter-form").hide(); - // if ($(".show-filter-dropdown").length != 0) { - // $(".show-filter-dropdown").removeClass("show-filter-dropdown"); - // performSearch(); - // } - // } - // }); }) function performSearch(params, reload = false) { @@ -1076,11 +1224,11 @@ function performSearch(params, reload = false) { }, error:function(e) { console.log(e); + $(".filter-form ").append('
Error
') + $(".filter-validate").find(".validate-text").css("display", "block"); + $(".filter-validate").find(".loading").hide(); + $(".remove-filter").removeClass(prefix_icon + 'spin6 animate-spin').addClass(prefix_icon + 'cancel'); }, - }).done(function () { - $(".filter-validate").find(".validate-text").css("display", "block"); - $(".filter-validate").find(".loading").hide(); - $(".remove-filter").removeClass(prefix_icon + 'spin6 animate-spin').addClass(prefix_icon + 'cancel'); }); } @@ -1159,6 +1307,24 @@ function updateFilters(filterName, mode) { } break; + case 'date_posted': + if (mode == 'add') { + global_params.fields['date_posted'] = {}; + global_params.fields.date_posted.preset = ''; + global_params.fields.date_posted.custom = []; + + PS_params.date_posted_preset = ''; + PS_params.date_posted_custom = []; + + } else if (mode == 'del') { + delete global_params.fields.date_posted.preset; + delete global_params.fields.date_posted.custom; + + delete PS_params.date_posted_preset; + delete PS_params.date_posted_custom; + } + break; + case 'filesize': if (mode == 'add') { global_params.fields.filesize_min = ''; diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index a6cc40d30..8bf6f6f1d 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -255,6 +255,7 @@ const prefix_icon = 'gallery-icon-'; {/if} +{* For pst date *} {if isset($DATE_POSTED)}