From 9460e1a2f938d249c0cd5d496cee8704fa3bbe36 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 22 Feb 2016 22:45:48 +0000 Subject: [PATCH] Home improvements - Weekend toggle, weekN & month support --- .../class.calendar_favorite_portlet.inc.php | 18 ++- ...calendar_timegrid_etemplate_widget.inc.php | 1 + calendar/inc/class.calendar_ui.inc.php | 2 + calendar/inc/class.calendar_uiviews.inc.php | 138 ++++++++---------- calendar/js/app.js | 2 +- calendar/js/et2_widget_timegrid.js | 2 +- 6 files changed, 77 insertions(+), 86 deletions(-) diff --git a/calendar/inc/class.calendar_favorite_portlet.inc.php b/calendar/inc/class.calendar_favorite_portlet.inc.php index 71ae534202..87731a90b9 100644 --- a/calendar/inc/class.calendar_favorite_portlet.inc.php +++ b/calendar/inc/class.calendar_favorite_portlet.inc.php @@ -81,6 +81,7 @@ class calendar_favorite_portlet extends home_favorite_portlet } if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter']; if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby']; + $ui->search_params['weekend'] = $this->favorite['state']['weekend']; } $etemplate->read('home.legacy'); @@ -114,15 +115,18 @@ class calendar_favorite_portlet extends home_favorite_portlet $ui->planner_view = $this->favorite['state']['planner_view']; $ui->planner(array(), $etemplate); return; - case 'year': - $content = array('legacy' => $ui->year(true)); - break; case 'month': - $content = array('legacy' => $ui->month(0,true)); - break; case 'weekN': - $content = array('legacy' => $ui->weekN(true)); - break; + $etemplate->read('calendar.view'); + $etemplate->set_dom_id($id); + $this->actions =& $etemplate->getElementAttribute('view', 'actions'); + + $ui->month($this->favorite['state']['view'] == 'month' ? + 0 : + (int)$ui->cal_prefs['multiple_weeks'], + $etemplate + ); + return; case 'week': $etemplate->read('calendar.view'); $etemplate->set_dom_id($id); diff --git a/calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php b/calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php index 44442ac895..d7426eeb41 100644 --- a/calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php +++ b/calendar/inc/class.calendar_timegrid_etemplate_widget.inc.php @@ -31,6 +31,7 @@ { $form_name = self::form_name($cname, $this->id, $expand); $value =& self::get_array(self::$request->content, $form_name, true); + if(!is_array($value)) $value = array(); foreach($value as $day => &$events) { diff --git a/calendar/inc/class.calendar_ui.inc.php b/calendar/inc/class.calendar_ui.inc.php index 16f53adcb3..f85b87d01d 100644 --- a/calendar/inc/class.calendar_ui.inc.php +++ b/calendar/inc/class.calendar_ui.inc.php @@ -714,6 +714,8 @@ class calendar_ui */ public function to_client(&$event) { + if(!$event || !is_array($event)) return false; + if (!$this->bo->check_perms(EGW_ACL_EDIT,$event)) { $event['class'] .= 'rowNoEdit '; diff --git a/calendar/inc/class.calendar_uiviews.inc.php b/calendar/inc/class.calendar_uiviews.inc.php index 62dd25b66d..13bf009ae2 100644 --- a/calendar/inc/class.calendar_uiviews.inc.php +++ b/calendar/inc/class.calendar_uiviews.inc.php @@ -540,7 +540,7 @@ class calendar_uiviews extends calendar_ui /** * Displays a multiple week-view * - * @param boolean $home = false if true return content suitable for home-page + * @param boolean|etemplate2 $home = false if not false return content suitable for home-page */ function &weekN($home=false) { @@ -553,42 +553,36 @@ class calendar_uiviews extends calendar_ui * Displays the monthview or a multiple week-view * * @param int $weeks = 0 number of weeks to show, if 0 (default) all weeks of one month are shown - * @param boolean $home = false if true return content suitable for home-page + * @param boolean|etemplate2 $home = false if not false return content suitable for home-page */ function &month($weeks=0,$home=false) { if ($this->debug > 0) $this->bo->debug_message('uiviews::month(weeks=%1) date=%2',True,$weeks,$this->date); - $this->use_time_grid = !$this->use_time_grid_pref || $this->use_time_grid_pref == 'all'; // all views + if (!$home) + { + trigger_error(__METHOD__ .' only used by home app', E_USER_DEPRECATED); + return; + } - // Merge print + $this->use_time_grid = !$this->use_time_grid_pref || $this->use_time_grid_pref == 'all'; // all views + $granularity = 0; if($weeks) { - // Split up span into multiple weeks - $timespan = array(); - $this->first = $this->datetime->get_weekday_start($this->year,$this->month,$this->day); - for($i = 0; $i < $weeks; $i++) - { - $timespan[] = array( - 'start' => strtotime("+$i weeks", $this->first), - 'end' => strtotime('+' . ($i+1).' weeks', $this->first) -1 - ); - } - } else { - $timespan[] = array( - 'start' => mktime(0,0,0,$this->month,1,$this->year), - 'end' => mktime(0,0,0,$this->month+1,1,$this->year)-1 - ); - } - $merge = $this->merge($timespan); - if($merge) - { - egw::redirect_link('/index.php',array( - 'menuaction' => 'calendar.calendar_uiviews.index', - 'msg' => $merge, - )); - } + $granularity = ($this->cal_prefs['interval'] ? (int)$this->cal_prefs['interval'] : 30); + $list = $this->cal_prefs['use_time_grid']; + if(!is_array($list)) + { + $list = explode(',',$list); + } + if(is_array($list)) + { + $granularity = in_array('weekN',$list) ? 0 : $granularity; + } + } + $content = array('view' => array()); + if ($weeks) { $this->first = $this->datetime->get_weekday_start($this->year,$this->month,$this->day); @@ -605,55 +599,27 @@ class calendar_uiviews extends calendar_ui } if ($this->debug > 0) $this->bo->debug_message('uiviews::month(%1) date=%2: first=%3, last=%4',False,$weeks,$this->date,$this->bo->date2string($this->first),$this->bo->date2string($this->last)); - $GLOBALS['egw_info']['flags']['app_header'] .= ': '.$navHeader; - - $days =& $this->bo->search(array( - 'start' => $this->first, - 'end' => $this->last, - )+$this->search_params); - - // we add DAY_s/2 to $this->first (using 12h), to deal with daylight saving changes - for ($week_start = $this->first; $week_start < $this->last; $week_start = strtotime("+1 week",$week_start)) + // Loop through, using egw_time to handle DST + $week = 0; + $week_start = new egw_time($this->first); + $week_start->setTime(0,0,0); + $week_end = new egw_time($week_start); + $week_end->add(new DateInterval('P6DT23H59M59S')); + $last = new egw_time($this->last); + for ($week_start; $week_start < $last; $week_start->add('1 week'), $week_end->add('1 week')) { - $week = array(); - for ($i = 0; $i < 7; ++$i) - { - $day_ymd = $this->bo->date2string($i ? strtotime("+$i days",$week_start) : $week_start); - $week[$day_ymd] = array_shift($days); - } - $week_view = array( - 'menuaction' => 'calendar.calendar_uiviews.week', - 'date' => $this->bo->date2string($week_start), - ); - $title = lang('Wk').' '.$this->week_number($week_start); - if ($this->allowEdit) - { - $title = html::a_href($title,$week_view,'',' title="'.lang('Weekview').'"'); - } - - $content .= $this->timeGridWidget($this->tagWholeDayOnTop($week),$weeks == 2 ? 30 : 60,200,'',$title,0,$week_start+WEEK_s >= $this->last); + $search_params = $this->search_params; + $search_params['start'] = $week_start->format('ts'); + $search_params['end'] = $week_end->format('ts'); + + $content['view'][] = (array)$this->tagWholeDayOnTop($this->bo->search($search_params)); + $home->setElementAttribute("view[$week]",'onchange',false); + $home->setElementAttribute("view[$week]",'granularity',$granularity); + $home->setElementAttribute("view[$week]",'show_weekend', $this->search_params['weekend']); + $week++; } - - $navHeader = '
' - .html::a_href(html::image('phpgwapi','left',lang('previous'),$options=' alt="<<"'),array( - 'menuaction' => $this->view_menuaction, - 'date' => date('Ymd',strtotime("-".$weekNavH, $weeks? $this->first: $this->bo->date2ts($this->date))), - )). ' '.$navHeader; - - $navHeader = $navHeader.' '.html::a_href(html::image('phpgwapi','right',lang('next'),$options=' alt=">>"'),array( - 'menuaction' => $this->view_menuaction, - 'date' => date('Ymd',strtotime("+".$weekNavH, $weeks? $this->first: $this->bo->date2ts($this->date))), - )).'
'; - $content = $navHeader.$content; - if (!$home) - { - $this->do_header(); - - echo $content; - } - - - return $content; + + $home->exec(__METHOD__, $content); } /** @@ -736,7 +702,7 @@ class calendar_uiviews extends calendar_ui * Displays the weekview, with 5 or 7 days * * @param int $days = 0 number of days to show, if 0 (default) the value from the URL or the prefs is used - * @param boolean $home = false if true return content suitable for home-page + * @param boolean|etemplate2 $home = false if not false return content suitable for home-page */ function week($days=0,$home=false) { @@ -757,6 +723,7 @@ class calendar_uiviews extends calendar_ui { $wd_start = $this->first = $this->bo->date2ts($this->date); $this->last = strtotime("+$days days",$this->first) - 1; + $view = $days == 1 ? 'day' : 'day4'; } else { @@ -774,6 +741,19 @@ class calendar_uiviews extends calendar_ui } } $this->last = strtotime("+$days days",$this->first) - 1; + $view = 'week'; + } + + $granularity = ($this->cal_prefs['interval'] ? (int)$this->cal_prefs['interval'] : 30); + + $list = $this->cal_prefs['use_time_grid']; + if(!is_array($list)) + { + $list = explode(',',$list); + } + if(is_array($list)) + { + $granularity = in_array($view,$list) ? 0 : $granularity; } $search_params = array( @@ -821,7 +801,11 @@ class calendar_uiviews extends calendar_ui } } $tmpl = $home ? $home :new etemplate_new('calendar.view'); - $tmpl->setElementAttribute('view','show_weekend', $days == 7); + foreach($content['view'] as $index => $week) + { + $tmpl->setElementAttribute("view[$index]",'granularity',$granularity); + $tmpl->setElementAttribute("view[$index]",'show_weekend',$this->search_params['weekend']); + } // Get the actions $tmpl->setElementAttribute('view','actions',$this->get_actions()); diff --git a/calendar/js/app.js b/calendar/js/app.js index 8f4c3f9437..51f2f8ef3e 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -1294,7 +1294,7 @@ app.classes.calendar = AppJS.extend( dates.set_disabled(filter.value !== "custom"); if (filter.value == "custom") { - jQuery(this.et2.getWidgetById('startdate').getDOMNode()).find('input').focus(); + jQuery(view.getWidgetById('startdate').getDOMNode()).find('input').focus(); } } }, diff --git a/calendar/js/et2_widget_timegrid.js b/calendar/js/et2_widget_timegrid.js index b8db7f8639..4494ec944a 100644 --- a/calendar/js/et2_widget_timegrid.js +++ b/calendar/js/et2_widget_timegrid.js @@ -1781,7 +1781,7 @@ var et2_calendar_timegrid = et2_calendar_view.extend([et2_IDetachedDOM, et2_IRes { this.options.height = Math.max(this.options.height, needed); // Set all others to match - if(!_too_small) + if(!_too_small && rowCount > 1) { window.setTimeout(jQuery.proxy(function() { this._parent.iterateOver(function(widget) {