Add toggle button for weekends

This commit is contained in:
Nathan Gray 2015-11-06 00:37:23 +00:00
parent f742d11d45
commit b4087292a8
6 changed files with 18 additions and 72 deletions

View File

@ -119,12 +119,6 @@ class calendar_hooks
'day4' => lang('Dayview').' & '.lang('Four days view'), 'day4' => lang('Dayview').' & '.lang('Four days view'),
'day' => lang('Dayview'), 'day' => lang('Dayview'),
); );
/* Select list with number of day by week */
$week_view = array(
'5' => lang('Weekview without weekend'),
'7' => lang('Weekview with weekend'),
);
$updates = array( $updates = array(
'no' => lang('Never'), 'no' => lang('Never'),
'add_cancel' => lang('on invitation / cancelation only'), 'add_cancel' => lang('on invitation / cancelation only'),
@ -235,16 +229,6 @@ class calendar_hooks
'admin' => False, 'admin' => False,
'default'=> '1', // 1 = week 'default'=> '1', // 1 = week
),*/ ),*/
'days_in_weekview' => array(
'type' => 'select',
'label' => 'default week view',
'name' => 'days_in_weekview',
'values' => $week_view,
'help' => 'Do you want a weekview with or without weekend?',
'xmlrpc' => True,
'admin' => False,
'default'=> '7',
),
'multiple_weeks' => array( 'multiple_weeks' => array(
'type' => 'select', 'type' => 'select',
'label' => 'Weeks in multiple week view', 'label' => 'Weeks in multiple week view',

View File

@ -127,7 +127,7 @@ class calendar_ui
/** /**
* @var array $states_to_save all states that will be saved to the user prefs * @var array $states_to_save all states that will be saved to the user prefs
*/ */
var $states_to_save = array('owner','filter','cat_id','view','sortby','planner_days'); var $states_to_save = array('owner','filter','cat_id','view','sortby','planner_days','weekend');
/** /**
* Constructor * Constructor
@ -420,30 +420,12 @@ class calendar_ui
// save defined states into the user-prefs // save defined states into the user-prefs
if(!empty($states) && is_array($states)) if(!empty($states) && is_array($states))
{ {
$saved_states = serialize(array_intersect_key($states,array_flip($this->states_to_save))); $saved_states = array_intersect_key($states,array_flip($this->states_to_save));
if ($saved_states != $this->cal_prefs['saved_states']) if ($saved_states != $this->cal_prefs['saved_states'])
{ {
$GLOBALS['egw']->preferences->add('calendar','saved_states',$saved_states); $GLOBALS['egw']->preferences->add('calendar','saved_states',$saved_states);
$GLOBALS['egw']->preferences->save_repository(false,'user',true); $GLOBALS['egw']->preferences->save_repository(false,'user',true);
} }
// store state in request for clientside favorites to use
// remove date and other states never stored in a favorite
$states = array_diff_key($states,array('date'=>false,'year'=>false,'month'=>false,'day'=>false,'save_owner'=>false));
if (strpos($_GET['menuaction'], 'ajax_sidebox') !== false)
{
// sidebox request is from top frame, which has app.calendar NOT loaded by time response arrives
}
elseif (egw_json_request::isJSONRequest())// && strpos($_GET['menuaction'], 'calendar_uiforms') === false)
{
$response = egw_json_response::get();
//$response->apply('app.calendar.set_state', array($states, $_GET['menuaction']));
}
else
{
egw_framework::set_extra('calendar', 'state', $states);
}
} }
} }
} }
@ -647,6 +629,7 @@ class calendar_ui
$sidebox = new etemplate_new('calendar.sidebox'); $sidebox = new etemplate_new('calendar.sidebox');
$content = $this->cal_prefs['saved_states'];
$content['view'] = $this->view ? $this->view : 'week'; $content['view'] = $this->view ? $this->view : 'week';
$content['date'] = $this->date ? $this->date : egw_time(); $content['date'] = $this->date ? $this->date : egw_time();
$owners = $this->owner ? is_array($this->owner) ? array($this->owner) : explode(',',$this->owner) : array($GLOBALS['egw_info']['user']['account_id']); $owners = $this->owner ? is_array($this->owner) ? array($this->owner) : explode(',',$this->owner) : array($GLOBALS['egw_info']['user']['account_id']);
@ -677,14 +660,9 @@ class calendar_ui
'selected' => $this->view == 'day4', 'selected' => $this->view == 'day4',
), ),
array( array(
'text' => lang('weekview with weekend'), 'text' => lang('weekview'),
'value' => '{"view":"week","days":7}', 'value' => '{"view":"week"}',
'selected' => $this->view == 'week' && $this->cal_prefs['days_in_weekview'] != 5, 'selected' => $this->view == 'week',
),
array(
'text' => lang('weekview without weekend'),
'value' => '{"view":"week","days":5}',
'selected' => $this->view == 'week' && $this->cal_prefs['days_in_weekview'] == 5,
), ),
array( array(
'text' => lang('Multiple week view'), 'text' => lang('Multiple week view'),

View File

@ -269,19 +269,6 @@ class calendar_uiviews extends calendar_ui
// List view in a separate file // List view in a separate file
$list_ui = new calendar_uilist(); $list_ui = new calendar_uilist();
$list_ui->listview(); $list_ui->listview();
// Set the current state
if (egw_json_request::isJSONRequest())// && strpos($_GET['menuaction'], 'calendar_uiforms') === false)
{
$states = array();
foreach(array('date','cat_id','filter','owner','view','sortby') as $state)
{
if($this->$state) $states[$state] = $this->$state;
}
$states['date'] = egw_time::to($states['date'],egw_time::ET2);
$response = egw_json_response::get();
$response->apply('app.calendar.set_state', array($states));
}
} }
/** /**

View File

@ -60,11 +60,10 @@ app.classes.calendar = AppJS.extend(
state: { state: {
date: new Date(), date: new Date(),
view: egw.preference('defaultcalendar','calendar') || 'day', view: egw.preference('defaultcalendar','calendar') || 'day',
owner: egw.user('account_id'), owner: egw.user('account_id')
days: egw.preference('days_in_weekview','calendar')
}, },
states_to_save: ['owner','filter','cat_id','view','sortby','planner_days'], states_to_save: ['owner','filter','cat_id','view','sortby','planner_days','weekend'],
// If you are in one of these views and select a date in the sidebox, the view // If you are in one of these views and select a date in the sidebox, the view
// will change as needed to show the date. Other views will only change the // will change as needed to show the date. Other views will only change the
@ -90,6 +89,7 @@ app.classes.calendar = AppJS.extend(
// Scroll // Scroll
jQuery(jQuery.proxy(this._scroll,this)); jQuery(jQuery.proxy(this._scroll,this));
jQuery.extend(this.state, this.egw.preference('saved_states','calendar'));
}, },
/** /**
@ -2553,7 +2553,7 @@ app.classes.calendar = AppJS.extend(
{ {
sidebox.parentsUntil('#calendar_sidebox_content') sidebox.parentsUntil('#calendar_sidebox_content')
.find('.egw_fw_ui_category_content').not(sidebox.parent()) .find('.egw_fw_ui_category_content').not(sidebox.parent())
.on('change.sidebox', 'select:not(.et2_selectbox),input', this, function(event) { .on('change.sidebox', 'select:not(.et2_selectbox),input[type!="checkbox"]', this, function(event) {
var state = {}; var state = {};
var name = this.name.replace('[]',''); var name = this.name.replace('[]','');
var value = $j(this).val(); var value = $j(this).val();
@ -2860,7 +2860,7 @@ app.classes.calendar = AppJS.extend(
*/ */
show_weekend: function(state) show_weekend: function(state)
{ {
return state.days ? parseInt(state.days) === 7 : parseInt(egw.preference('days_in_weekview','calendar')) == 7; return state.weekend;
}, },
/** /**
* How big or small are the displayed time chunks? * How big or small are the displayed time chunks?
@ -2947,7 +2947,7 @@ jQuery.extend(app.classes.calendar,{
}, },
show_weekend: function(state) { show_weekend: function(state) {
state.days = '1'; state.days = '1';
state.weekend = 'true';
return app.calendar.View.show_weekend.call(this,state); return app.calendar.View.show_weekend.call(this,state);
}, },
scroll: function(delta) scroll: function(delta)
@ -2971,6 +2971,7 @@ jQuery.extend(app.classes.calendar,{
return d; return d;
}, },
show_weekend: function(state) { show_weekend: function(state) {
state.weekend = 'true';
return true; return true;
}, },
scroll: function(delta) scroll: function(delta)
@ -3002,12 +3003,7 @@ jQuery.extend(app.classes.calendar,{
d.setUTCMinutes(59); d.setUTCMinutes(59);
d.setUTCSeconds(59); d.setUTCSeconds(59);
d.setUTCMilliseconds(0); d.setUTCMilliseconds(0);
state.days = '' + (state.days >= 5 ? state.days : egw.preference('days_in_weekview','calendar') || 7);
return d; return d;
},
show_weekend: function(state)
{
return parseInt(state.days) === 7;
} }
}), }),
weekN: app.classes.calendar.prototype.View.extend({ weekN: app.classes.calendar.prototype.View.extend({
@ -3060,10 +3056,6 @@ jQuery.extend(app.classes.calendar,{
var d = new Date(app.calendar.state.date); var d = new Date(app.calendar.state.date);
d.setUTCMonth(d.getUTCMonth() + delta); d.setUTCMonth(d.getUTCMonth() + delta);
return d; return d;
},
show_weekend: function(state)
{
return true;
} }
}), }),

View File

@ -25,6 +25,9 @@
#calendar-sidebox_buttons tbody { #calendar-sidebox_buttons tbody {
width: 100%; width: 100%;
} }
#calendar-sidebox_weekend {
/* Special css styling goes here */
}
#calendar-sidebox_date td.ui-datepicker-week-col { #calendar-sidebox_date td.ui-datepicker-week-col {
cursor: pointer; cursor: pointer;
} }

View File

@ -23,6 +23,7 @@ Egroupware
<column/> <column/>
<column/> <column/>
<column/> <column/>
<column/>
</columns> </columns>
<rows><row width="100%"> <rows><row width="100%">
<buttononly align="center" class="sideboxstar" id="add" onclick="egw.open(null,'calendar','add');" image="new" label="Add"/> <buttononly align="center" class="sideboxstar" id="add" onclick="egw.open(null,'calendar','add');" image="new" label="Add"/>
@ -32,6 +33,7 @@ Egroupware
<buttononly align="center" class="sideboxstar" id="month" image="month" label="Month view" onclick="app.calendar.update_state({view:'month'});"/> <buttononly align="center" class="sideboxstar" id="month" image="month" label="Month view" onclick="app.calendar.update_state({view:'month'});"/>
<buttononly align="center" class="sideboxstar" id="planner" image="planner" label="Group planner" onclick="app.calendar.update_state({view:'planner',planner_days:0});"/> <buttononly align="center" class="sideboxstar" id="planner" image="planner" label="Group planner" onclick="app.calendar.update_state({view:'planner',planner_days:0});"/>
<buttononly align="center" class="sideboxstar" id="listview" image="list" label="Listview" onclick="app.calendar.update_state({view:'listview'});"/> <buttononly align="center" class="sideboxstar" id="listview" image="list" label="Listview" onclick="app.calendar.update_state({view:'listview'});"/>
<checkbox class="sideboxstar" id="weekend" label="Toggle weekend" onchange="app.calendar.update_state({weekend: widget.getValue()}); return false;"/>
</row> </row>
</rows> </rows>
</grid> </grid>