From: Anthony Talarico Date: Fri, 12 May 2017 13:45:43 +0000 (-0400) Subject: changing the date dropdown in calendar view to reflect the current view X-Git-Tag: v1.6.38^2~2^2~8 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=456f9304742be5f27a211c6efac7712f3e36db6b;p=WP-Plugins%2Fglm-member-db-events.git changing the date dropdown in calendar view to reflect the current view after change. limiting the dropdown to only hold 18 dates from the current date limiting the array that holds the dates for the date dropdown in calendar view for events list to only have 18 dates to keep the dropdown clean. setting the dropdown to reflect the selected dates as the views are changed --- diff --git a/models/front/events/list.php b/models/front/events/list.php index 3299651..b60e934 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -755,7 +755,9 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $years = array('current' => $current_year = date("Y"), 'next' => date('Y') +1 ); $months = []; + $count = 0; foreach($years as $key=>$year){ + if($current_year == $year){ $sql = 'SELECT MONTH(start_time) as month FROM '. GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX .'times '; $sql .= "WHERE YEAR(start_time) = $year AND MONTH(start_time) >= MONTH(CURDATE()) GROUP BY month"; @@ -765,20 +767,22 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $sql .= "WHERE YEAR(start_time) = $year GROUP BY month"; $results[$year] = $wpdb->get_results($sql, ARRAY_A); } - } - foreach($results as $year => $month){ foreach($month as $key=>$value){ - $month_string = $year .'-'. $value['month'] . '-01'; - $date = strtotime($month_string); - $month_date = date('m', $date); - $month_display = date('M', $date); - $months[$year][] = array('name'=> $month_display, 'date'=>$month_date); + if($count < 18){ + $month_string = $year .'-'. $value['month'] . '-01'; + $date = strtotime($month_string); + $month_date = date('m', $date); + $month_display = date('M', $date); + $months[$year][] = array('name'=> $month_display, 'date'=>$month_date); + } + $count++; } } $json_months = json_encode($months); ksort($months); + // Compile template data $templateData = array( 'eventDays' => $eventDays, diff --git a/views/front/events/agenda.html b/views/front/events/agenda.html index f119320..fa28a2c 100644 --- a/views/front/events/agenda.html +++ b/views/front/events/agenda.html @@ -142,6 +142,13 @@ var current_year = $('{$current_year}'); var retain_date; + function get_current_view(){ + var retain_date; + var calCurrDate = $('#eventCalendar').fullCalendar('getView').start; + var d = moment(calCurrDate).add(7, 'days').format('YYYY-MM-01'); + + return retain_date = d; + } months = JSON.parse(months); // console.log(sessionStorage.view + " : " + sessionStorage.override); @@ -228,10 +235,8 @@ handleWindowResize: true, lazyFetching: true, eventClick : function (event){ - var calCurrDate = $('#eventCalendar').fullCalendar('getView').start; - var d = moment(calCurrDate).add(7, 'days').format('YYYY-MM-01'); - retain_date = d; - sessionStorage.current_calendar_view = retain_date; + + sessionStorage.current_calendar_view = get_current_view(); location.href = event.url + '?glm_event_from=' + event.start.format(); @@ -313,49 +318,14 @@ $('#eventCalendar').find('.fc-today-button').on("click", function(){ eventsCalMonthAJAX(month_obj); - }); - - $(document).on("click", '.month-nav',function(){ - if(sessionStorage.current_calendar_view){ - sessionStorage.current_calendar_view = ''; - } - - $('.month-nav').removeClass("date-highlight"); - $(this).addClass("date-highlight"); - var new_date = $(this).attr('data-month'); - $('#eventCalendar').fullCalendar('gotoDate', new_date); - eventsCalMonthAJAX(month_obj); - - }); - $('.year-nav').on("click", function(){ - if(sessionStorage.current_calendar_view){ - sessionStorage.current_calendar_view = ''; - } - - $('.year-nav').removeClass("date-highlight"); - $(this).addClass("date-highlight"); - - var year = $(this).attr('data-year'); - - var new_months = months[year]; - - option = {}; - $('#month-nav-container').empty(); - - $.each(new_months, function(index, value){ - - if(value.date == current_month.selector && year === current_year.selector ){ - {literal} var option = $('
', {class: 'month-nav date-highlight current-date',text: value.name}); {/literal} - } else { - {literal} var option = $('
', {class: 'month-nav',text: value.name}); {/literal} - } - - option.attr('data-month', year + '-' + value.date +'-01'); - $('#month-nav-container').append(option); + var current_view = get_current_view(); + $('#event-date-toggle option').each(function(){ + if( $(this).val() === current_view){ + $(this).prop('selected', true); + } }); }); - - + var dates = $(".agenda-event-recur-dates"); dates.each( function (){ if( $(this).text().indexOf('-') < 0 ){