changing the date dropdown in calendar view to reflect the current view
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 12 May 2017 13:45:43 +0000 (09:45 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 12 May 2017 13:45:43 +0000 (09:45 -0400)
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

models/front/events/list.php
views/front/events/agenda.html

index 3299651..b60e934 100644 (file)
@@ -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,
index f119320..fa28a2c 100644 (file)
         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);
             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();
 
        $('#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 = $('<div>', {class: 'month-nav date-highlight current-date',text: value.name}); {/literal}
-               } else {
-                   {literal} var option = $('<div>', {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 ){