2011-04-27 18:53:06 +02:00
/ * *
2013-10-31 15:51:19 +01:00
* EGroupware - Calendar - Javascript UI
2011-04-27 18:53:06 +02:00
*
* @ link http : //www.egroupware.org
* @ package calendar
2013-10-31 15:51:19 +01:00
* @ author Hadi Nategh < hn - AT - stylite . de >
2015-07-15 18:29:10 +02:00
* @ author Nathan Gray
2016-02-17 20:56:54 +01:00
* @ copyright ( c ) 2008 - 16 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2011-04-27 18:53:06 +02:00
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ version $Id$
* /
2013-11-05 19:08:07 +01:00
/ * e g w : u s e s
2015-05-06 21:03:45 +02:00
/ e t e m p l a t e / j s / e t e m p l a t e 2 . j s ;
2016-02-09 21:28:57 +01:00
/ c a l e n d a r / j s / e t 2 _ w i d g e t _ o w n e r . j s ;
2015-05-06 21:03:45 +02:00
/ c a l e n d a r / j s / e t 2 _ w i d g e t _ t i m e g r i d . j s ;
2015-06-25 19:44:28 +02:00
/ c a l e n d a r / j s / e t 2 _ w i d g e t _ p l a n n e r . j s ;
2016-06-14 17:26:50 +02:00
/ v e n d o r / b o w e r - a s s e t / j q u e r y - t o u c h s w i p e / j q u e r y . t o u c h S w i p e . j s ;
2013-11-05 19:08:07 +01:00
* /
2011-04-27 18:53:06 +02:00
/ * *
2013-10-31 15:51:19 +01:00
* UI for calendar
*
2015-07-01 00:26:59 +02:00
* Calendar has multiple different views of the same data . All the templates
* for the different view are loaded at the start , then the view objects
2015-07-15 15:16:31 +02:00
* in app . classes . calendar . views are used to manage the different views .
2015-07-15 18:29:10 +02:00
* update _state ( ) is used to change the state between the different views , as
* well as adjust only a single part of the state while keeping the rest unchanged .
2015-07-01 00:26:59 +02:00
*
2015-07-15 18:29:10 +02:00
* The event widgets ( and the nextmatch ) get the data from egw . data , and they
* register update callbacks to automatically update when the data changes . This
* means that when we update something on the server , to update the UI we just need
* to send back the new data and if the event widget still exists it will update
* itself . See calendar _uiforms - > ajax _status ( ) .
*
* To reduce server calls , we also keep a map of day => event IDs . This allows
* us to quickly change views ( week to day , for example ) without requesting additional
* data from the server . We keep that map as long as only the date ( and a few
* others - see update _state ( ) ) changes . If user or any of the other filters are
* changed , we discard the daywise cache and ask the server for the filtered events .
2015-07-01 00:26:59 +02:00
*
2013-10-31 15:51:19 +01:00
* @ augments AppJS
2011-04-27 18:53:06 +02:00
* /
2016-03-01 17:27:45 +01:00
app . classes . calendar = ( function ( ) { "use strict" ; return AppJS . extend (
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
/ * *
* application name
* /
appname : 'calendar' ,
2013-11-05 19:08:07 +01:00
2015-06-10 23:51:28 +02:00
/ * *
* etemplate for the sidebox filters
* /
sidebox _et2 : null ,
/ * *
* Current internal state
2015-07-15 18:29:10 +02:00
*
* If you need to change state , you can pass just the fields to change to
* update _state ( ) .
2015-06-10 23:51:28 +02:00
* /
state : {
date : new Date ( ) ,
2015-12-16 01:23:25 +01:00
view : egw . preference ( 'saved_states' , 'calendar' ) ? egw . preference ( 'saved_states' , 'calendar' ) . view : egw . preference ( 'defaultcalendar' , 'calendar' ) || 'day' ,
2015-11-06 01:37:23 +01:00
owner : egw . user ( 'account_id' )
2015-06-10 23:51:28 +02:00
} ,
2015-09-07 19:13:20 +02:00
2016-06-30 21:21:13 +02:00
/ * *
* These are the keys we keep to set & remember the status , others are discarded
* /
2016-02-03 19:27:52 +01:00
states _to _save : [ 'owner' , 'status_filter' , 'filter' , 'cat_id' , 'view' , 'sortby' , 'planner_view' , 'weekend' ] ,
2015-09-09 22:59:23 +02:00
2015-09-14 22:47:25 +02:00
// 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
// date in the current view.
sidebox _changes _views : [ 'day' , 'week' , 'month' ] ,
2015-12-14 23:08:12 +01:00
// Calendar allows other apps to hook into the sidebox. We keep these etemplates
// up to date as state is changed.
sidebox _hooked _templates : [ ] ,
2016-02-23 22:29:13 +01:00
// List of queries in progress, to prevent home from requesting the same thing
_queries _in _progress : [ ] ,
2016-05-10 21:41:28 +02:00
// Calendar-wide autorefresh
_autorefresh _timer : null ,
2013-10-31 15:51:19 +01:00
/ * *
* Constructor
*
* @ memberOf app . calendar
* /
init : function ( )
2011-04-27 18:53:06 +02:00
{
2016-06-13 18:03:52 +02:00
// categories have nothing to do with calendar, but eT2 objects loads calendars app.js
2016-06-25 12:28:52 +02:00
if ( window . framework && framework . applications . calendar . browser &&
2016-06-14 21:17:46 +02:00
framework . applications . calendar . browser . currentLocation . match ( 'menuaction=preferences\.preferences_categories_ui\.index' ) )
2016-06-13 18:03:52 +02:00
{
this . _super . apply ( this , arguments ) ;
return ;
}
else // make calendar object available, even if not running in top window, as sidebox does
2015-06-15 23:38:03 +02:00
if ( window . top !== window && ! egw ( window ) . is _popup ( ) && window . top . app . calendar )
2013-12-12 00:51:35 +01:00
{
2015-06-15 23:38:03 +02:00
window . app . calendar = window . top . app . calendar ;
return ;
2013-12-12 00:51:35 +01:00
}
2016-04-06 17:19:24 +02:00
else if ( window . top == window && ! egw ( window ) . is _popup ( ) )
{
// Show loading div
egw . loading _prompt (
this . appname , true , egw . lang ( 'please wait...' ) ,
2016-05-02 21:22:52 +02:00
typeof framework !== 'undefined' ? framework . applications . calendar . tab . contentDiv : false ,
2016-04-06 17:19:24 +02:00
egwIsMobile ( ) ? 'horizental' : 'spinner'
) ;
}
2014-08-26 18:29:12 +02:00
// call parent
this . _super . apply ( this , arguments ) ;
2015-06-25 19:44:28 +02:00
// Scroll
jQuery ( jQuery . proxy ( this . _scroll , this ) ) ;
2015-11-06 01:37:23 +01:00
jQuery . extend ( this . state , this . egw . preference ( 'saved_states' , 'calendar' ) ) ;
2013-10-31 15:51:19 +01:00
} ,
/ * *
* Destructor
* /
destroy : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
// call parent
this . _super . apply ( this , arguments ) ;
2013-12-12 00:51:35 +01:00
// remove top window reference
if ( window . top !== window && window . top . app . calendar === this )
{
2014-02-19 16:20:19 +01:00
delete window . top . app . calendar ;
2013-12-12 00:51:35 +01:00
}
2015-07-15 18:29:10 +02:00
jQuery ( 'body' ) . off ( '.calendar' ) ;
2015-11-10 21:04:17 +01:00
if ( this . sidebox _et2 )
{
var date = this . sidebox _et2 . getWidgetById ( 'date' ) ;
2016-06-02 16:51:15 +02:00
jQuery ( window ) . off ( 'resize.calendar' + date . dom _id ) ;
2015-11-10 21:04:17 +01:00
}
2015-12-14 23:08:12 +01:00
this . sidebox _hooked _templates = null ;
2015-10-27 17:45:37 +01:00
egw _unregisterGlobalShortcut ( jQuery . ui . keyCode . PAGE _UP , false , false , false ) ;
egw _unregisterGlobalShortcut ( jQuery . ui . keyCode . PAGE _DOWN , false , false , false ) ;
2016-05-10 21:41:28 +02:00
// Stop autorefresh
if ( this . _autorefresh _timer )
{
window . clearInterval ( this . _autorefresh _timer ) ;
this . _autorefresh _timer = null ;
}
2013-10-31 15:51:19 +01:00
} ,
2011-04-27 18:53:06 +02:00
2013-10-31 15:51:19 +01:00
/ * *
* This function is called when the etemplate2 object is loaded
* and ready . If you must store a reference to the et2 object ,
* make sure to clean it up in destroy ( ) .
*
2014-02-19 16:20:19 +01:00
* @ param { etemplate2 } _et2 newly ready et2 object
* @ param { string } _name name of template
2013-10-31 15:51:19 +01:00
* /
2014-02-19 16:20:19 +01:00
et2 _ready : function ( _et2 , _name )
2013-10-31 15:51:19 +01:00
{
// call parent
this . _super . apply ( this , arguments ) ;
2014-02-12 18:36:20 +01:00
2015-07-15 18:29:10 +02:00
// Avoid many problems with home
2016-06-13 18:03:52 +02:00
if ( _et2 . app !== 'calendar' || _name == 'admin.categories.index' )
2016-04-07 00:23:43 +02:00
{
egw . loading _prompt ( this . appname , false ) ;
return ;
}
2015-09-07 19:13:20 +02:00
2014-02-12 18:36:20 +01:00
// Re-init sidebox, since it was probably initialized too soon
var sidebox = jQuery ( '#favorite_sidebox_' + this . appname ) ;
if ( sidebox . length == 0 && egw _getFramework ( ) != null )
{
var egw _fw = egw _getFramework ( ) ;
2016-06-02 16:51:15 +02:00
sidebox = jQuery ( '#favorite_sidebox_' + this . appname , egw _fw . sidemenuDiv ) ;
2014-02-12 18:36:20 +01:00
}
2013-10-31 15:51:19 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) ;
2014-10-30 11:24:11 +01:00
2014-02-19 16:20:19 +01:00
switch ( _name )
2013-10-31 15:51:19 +01:00
{
2015-06-10 23:51:28 +02:00
case 'calendar.sidebox' :
this . sidebox _et2 = _et2 . widgetContainer ;
2015-12-14 23:08:12 +01:00
this . sidebox _hooked _templates . push ( this . sidebox _et2 ) ;
2016-06-02 16:51:15 +02:00
jQuery ( _et2 . DOMContainer ) . hide ( ) ;
2016-05-16 19:21:03 +02:00
// Set client side holiday cache for this year
egw . window . et2 _calendar _view . holiday _cache [ content . data . year ] = content . data . holidays ;
delete content . data . holidays ;
delete content . data . year ;
2015-06-10 23:51:28 +02:00
this . _setup _sidebox _filters ( ) ;
2016-05-18 15:08:05 +02:00
2016-01-27 18:35:25 +01:00
this . state = content . data ;
2014-02-19 16:20:19 +01:00
break ;
2015-07-15 15:16:31 +02:00
2014-02-19 16:20:19 +01:00
case 'calendar.edit' :
if ( typeof content . data [ 'conflicts' ] == 'undefined' )
2014-01-24 16:50:17 +01:00
{
2014-02-19 16:20:19 +01:00
//Check if it's fallback from conflict window or it's from edit window
if ( content . data [ 'button_was' ] != 'freetime' )
{
this . set _enddate _visibility ( ) ;
this . check _recur _type ( ) ;
2016-07-26 00:14:13 +02:00
this . edit _start _change ( ) ;
2014-10-30 11:24:11 +01:00
this . et2 . getWidgetById ( 'recur_exception' ) . set _disabled ( ! content . data . recur _exception ||
typeof content . data . recur _exception [ 0 ] == 'undefined' ) ;
2014-02-19 16:20:19 +01:00
}
else
{
this . freetime _search ( ) ;
}
//send Syncronus ajax request to the server to unlock the on close entry
//set onbeforeunload with json request to send request when the window gets close by X button
2015-08-31 12:49:58 +02:00
if ( content . data . lock _token )
{
window . onbeforeunload = function ( ) {
this . egw . json ( 'calendar.calendar_uiforms.ajax_unlock' ,
[ content . data . id , content . data . lock _token ] , null , true , null , null ) . sendRequest ( true ) ;
} ;
}
2014-01-24 16:50:17 +01:00
}
2014-05-27 17:02:56 +02:00
this . alarm _custom _date ( ) ;
2016-06-14 19:23:26 +02:00
// If title is pre-filled for a new (no ID) event, highlight it
if ( content . data && ! content . data . id && content . data . title )
{
this . et2 . getWidgetById ( 'title' ) . input . select ( ) ;
}
2014-02-19 16:20:19 +01:00
break ;
case 'calendar.freetimesearch' :
2013-10-31 15:51:19 +01:00
this . set _enddate _visibility ( ) ;
2014-02-19 16:20:19 +01:00
break ;
2015-06-10 23:51:28 +02:00
case 'calendar.list' :
2015-10-16 19:32:21 +02:00
// Wait until _et2_view_init is done
window . setTimeout ( jQuery . proxy ( function ( ) {
this . filter _change ( ) ;
} , this ) , 0 ) ;
break ;
2013-10-31 15:51:19 +01:00
}
2015-07-15 18:29:10 +02:00
// Record the templates for the views so we can switch between them
this . _et2 _view _init ( _et2 , _name ) ;
2013-10-31 15:51:19 +01:00
} ,
2014-08-21 14:43:14 +02:00
2014-06-25 17:39:58 +02:00
/ * *
* Observer method receives update notifications from all applications
*
* App is responsible for only reacting to "messages" it is interested in !
*
2015-11-11 00:31:55 +01:00
* Calendar binds listeners to the data cache , so if the data is updated , the widget
2016-02-17 20:56:54 +01:00
* will automatically update itself .
2015-11-11 00:31:55 +01:00
*
2014-06-25 17:39:58 +02:00
* @ param { string } _msg message ( already translated ) to show , eg . 'Entry deleted'
* @ param { string } _app application name
* @ param { ( string | number ) } _id id of entry to refresh or null
* @ param { string } _type either 'update' , 'edit' , 'delete' , 'add' or null
* - update : request just modified data from given rows . Sorting is not considered ,
* so if the sort field is changed , the row will not be moved .
* - edit : rows changed , but sorting may be affected . Requires full reload .
* - delete : just delete the given rows clientside ( no server interaction neccessary )
* - add : requires full reload for proper sorting
* @ param { string } _msg _type 'error' , 'warning' or 'success' ( default )
* @ param { object | null } _links app => array of ids of linked entries
* or null , if not triggered on server - side , which adds that info
* @ return { false | * } false to stop regular refresh , thought all observers are run
* /
observer : function ( _msg , _app , _id , _type , _msg _type , _links )
{
2014-06-26 14:39:20 +02:00
var do _refresh = false ;
2016-08-02 17:29:45 +02:00
if ( this . state . view === 'listview' )
{
app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) . refresh ( _id , _type ) ;
}
2014-06-26 14:39:20 +02:00
switch ( _app )
2014-06-25 17:39:58 +02:00
{
2014-06-26 14:39:20 +02:00
case 'infolog' :
jQuery ( '.calendar_calDayTodos' )
. find ( 'a' )
. each ( function ( i , a ) {
var match = a . href . split ( /&info_id=/ ) ;
if ( match && typeof match [ 1 ] != "undefined" )
2014-06-25 17:39:58 +02:00
{
2014-06-26 14:39:20 +02:00
if ( match [ 1 ] == _id ) do _refresh = true ;
2014-06-25 17:39:58 +02:00
}
2014-06-26 14:39:20 +02:00
} ) ;
2016-01-11 21:43:52 +01:00
// Unfortunately we do not know what type this infolog is here,
// but we can tell if it's turned off entirely
if ( egw . preference ( 'calendar_integration' , 'infolog' ) !== '0' )
2014-06-26 14:39:20 +02:00
{
2016-01-11 21:43:52 +01:00
if ( jQuery ( 'div [data-app="infolog"][data-app_id="' + _id + '"]' ) . length > 0 ) do _refresh = true ;
switch ( _type )
{
case 'add' :
do _refresh = true ;
break ;
}
2014-06-26 14:39:20 +02:00
}
if ( do _refresh )
{
2016-07-04 23:20:22 +02:00
// Discard cache
2016-02-22 16:43:03 +01:00
this . _clear _cache ( ) ;
2016-07-04 23:20:22 +02:00
// Calendar is the current application, refresh now
2016-07-15 16:24:57 +02:00
if ( framework . activeApp . appName === this . appname )
2016-07-04 23:20:22 +02:00
{
this . setState ( { state : this . state } ) ;
}
// Bind once to trigger a refresh when tab is activated again
else if ( framework . applications . calendar && framework . applications . calendar . tab &&
framework . applications . calendar . tab . contentDiv )
{
jQuery ( framework . applications . calendar . tab . contentDiv )
. off ( 'show.calendar' )
. one ( 'show.calendar' ,
jQuery . proxy ( function ( ) { this . setState ( { state : this . state } ) ; } , this )
) ;
}
2014-06-26 14:39:20 +02:00
}
2015-07-15 18:29:10 +02:00
break ;
case 'calendar' :
2015-10-27 17:45:37 +01:00
// Regular refresh
2015-11-05 21:56:13 +01:00
var event = false ;
2015-08-12 18:51:03 +02:00
if ( _id )
2015-07-15 18:29:10 +02:00
{
2015-11-05 21:56:13 +01:00
event = egw . dataGetUIDdata ( 'calendar::' + _id ) ;
}
2016-01-14 16:46:55 +01:00
if ( event && event . data && event . data . date || _type === 'delete' )
2015-11-05 21:56:13 +01:00
{
2016-01-14 16:46:55 +01:00
// Intelligent refresh without reloading everything
2016-06-13 18:03:52 +02:00
var recurrences = Object . keys ( egw . dataSearchUIDs ( new RegExp ( '^calendar::' + _id + ':' ) ) ) ;
2016-06-16 18:28:56 +02:00
var ids = event && event . data && event . data . recur _type && typeof _id === 'string' && _id . indexOf ( ':' ) < 0 || recurrences . length ?
2016-01-20 21:58:14 +01:00
recurrences :
[ 'calendar::' + _id ] ;
2016-01-14 16:46:55 +01:00
if ( _type === 'delete' )
2015-07-15 18:29:10 +02:00
{
2016-01-20 21:58:14 +01:00
for ( var i in ids )
{
egw . dataStoreUID ( ids [ i ] , null ) ;
}
2016-01-14 16:46:55 +01:00
}
// Updates are handled by events themselves through egw.data
else if ( _type !== 'update' )
{
2016-01-20 21:58:14 +01:00
this . _update _events ( this . state , ids ) ;
2015-11-05 21:56:13 +01:00
}
return false ;
2015-08-12 18:51:03 +02:00
}
else
{
2016-02-22 16:43:03 +01:00
this . _clear _cache ( ) ;
2015-10-14 16:32:33 +02:00
// Force redraw to current state
this . setState ( { state : this . state } ) ;
2016-04-28 00:50:56 +02:00
return false ;
2015-07-15 18:29:10 +02:00
}
break ;
2014-08-21 14:43:14 +02:00
}
2014-06-25 17:39:58 +02:00
} ,
2014-08-21 14:43:14 +02:00
2014-01-24 16:50:17 +01:00
/ * *
* Link hander for jDots template to just reload our iframe , instead of reloading whole admin app
*
* @ param { String } _url
* @ return { boolean | string } true , if linkHandler took care of link , false for default processing or url to navigate to
* /
linkHandler : function ( _url )
{
2016-06-13 18:03:52 +02:00
if ( _url == 'about:blank' || _url . match ( 'menuaction=preferences\.preferences_categories_ui\.index' ) )
2015-10-15 22:06:19 +02:00
{
return false ;
}
2015-08-12 00:30:50 +02:00
if ( _url . match ( 'menuaction=calendar\.calendar_uiviews\.' ) )
2014-01-24 16:50:17 +01:00
{
2015-08-12 00:30:50 +02:00
var view = _url . match ( /calendar_uiviews\.([^&?]+)/ ) ;
view = view && view . length > 1 ? view [ 1 ] : null ;
// Get query
var q = { } ;
_url . split ( '?' ) [ 1 ] . split ( '&' ) . forEach ( function ( i ) {
2015-10-15 22:06:19 +02:00
q [ i . split ( '=' ) [ 0 ] ] = unescape ( i . split ( '=' ) [ 1 ] ) ;
2015-08-12 00:30:50 +02:00
} ) ;
delete q . ajax ;
delete q . menuaction ;
2015-10-16 19:32:21 +02:00
if ( ! view && q . view || q . view != view && view == 'index' ) view = q . view ;
2016-06-13 18:03:52 +02:00
2016-06-09 00:02:54 +02:00
// No specific view requested, looks like a reload from framework
if ( this . sidebox _et2 && typeof view === 'undefined' )
{
this . _clear _cache ( ) ;
this . setState ( { state : this . state } ) ;
return false ;
}
2015-10-15 22:06:19 +02:00
if ( this . sidebox _et2 && typeof app . classes . calendar . views [ view ] == 'undefined' && view != 'index' )
2015-06-15 23:38:03 +02:00
{
2015-10-14 20:10:39 +02:00
if ( q . owner )
{
q . owner = q . owner . split ( ',' ) ;
q . owner = q . owner . reduce ( function ( p , c ) { if ( p . indexOf ( c ) < 0 ) p . push ( c ) ; return p ; } , [ ] ) ;
q . owner = q . owner . join ( ',' ) ;
}
q . menuaction = 'calendar.calendar_uiviews.index' ;
this . sidebox _et2 . getWidgetById ( 'iframe' ) . set _src ( egw . link ( '/index.php' , q ) ) ;
2016-06-02 16:51:15 +02:00
jQuery ( this . sidebox _et2 . parentNode ) . show ( ) ;
2015-06-15 23:38:03 +02:00
return true ;
}
2015-08-12 00:30:50 +02:00
// Known AJAX view
else if ( app . classes . calendar . views [ view ] )
2015-07-15 18:29:10 +02:00
{
2015-10-15 22:06:19 +02:00
// Reload of known view?
if ( view == 'index' )
{
var pref = this . egw . preference ( 'saved_states' , 'calendar' ) ;
view = pref . view || 'day' ;
}
// View etemplate not loaded
2015-08-12 00:30:50 +02:00
if ( typeof app . classes . calendar . views [ view ] . etemplates [ 0 ] == 'string' )
{
return _url + '&ajax=true' ;
}
// Already loaded, we'll just apply any variables to our current state
var set = jQuery . extend ( { view : view } , q ) ;
this . update _state ( set ) ;
return true ;
2015-07-15 18:29:10 +02:00
}
2015-06-15 23:38:03 +02:00
}
2015-10-15 22:06:19 +02:00
else if ( this . sidebox _et2 )
2015-06-15 23:38:03 +02:00
{
2015-07-15 18:29:10 +02:00
var iframe = this . sidebox _et2 . getWidgetById ( 'iframe' ) ;
2015-10-15 22:06:19 +02:00
if ( ! iframe ) return false ;
2015-07-15 18:29:10 +02:00
iframe . set _src ( _url ) ;
2016-06-02 16:51:15 +02:00
jQuery ( this . sidebox _et2 . parentNode ) . show ( ) ;
2015-07-15 18:29:10 +02:00
// Hide other views
for ( var _view in app . classes . calendar . views )
{
for ( var i = 0 ; i < app . classes . calendar . views [ _view ] . etemplates . length ; i ++ )
{
2016-06-02 16:51:15 +02:00
jQuery ( app . classes . calendar . views [ _view ] . etemplates [ i ] . DOMContainer ) . hide ( ) ;
2015-07-15 18:29:10 +02:00
}
}
this . state . view = '' ;
2015-06-15 23:38:03 +02:00
return true ;
2014-01-24 16:50:17 +01:00
}
// can not load our own index page, has to be done by framework
return false ;
} ,
2016-01-06 19:24:45 +01:00
/ * *
* Handle actions from the toolbar
*
* @ param { egwAction } action Action from the toolbar
* /
toolbar _action : function toolbar _action ( action )
{
// Most can just provide state change data
if ( action . data && action . data . state )
{
2016-02-03 19:27:52 +01:00
var state = jQuery . extend ( { } , action . data . state ) ;
if ( state . view == 'planner' && app . calendar . state . view != 'planner' ) {
state . planner _view = app . calendar . state . view ;
}
this . update _state ( state ) ;
2016-01-06 19:24:45 +01:00
}
// Special handling
switch ( action . id )
{
2016-01-06 21:37:29 +01:00
case 'add' :
return egw . open ( null , "calendar" , "add" ) ;
2016-01-06 19:24:45 +01:00
case 'weekend' :
this . update _state ( { weekend : action . checked } ) ;
break ;
2016-01-21 19:41:54 +01:00
case 'today' :
var tempDate = new Date ( ) ;
var today = new Date ( tempDate . getFullYear ( ) , tempDate . getMonth ( ) , tempDate . getDate ( ) , 0 , - tempDate . getTimezoneOffset ( ) , 0 ) ;
var change = { date : today . toJSON ( ) } ;
app . calendar . update _state ( change ) ;
break ;
2016-01-06 19:24:45 +01:00
case 'next' :
case 'previous' :
var delta = action . id == 'previous' ? - 1 : 1 ;
var view = app . classes . calendar . views [ app . calendar . state . view ] || false ;
var start = new Date ( app . calendar . state . date ) ;
if ( view )
{
start = view . scroll ( delta ) ;
app . calendar . update _state ( { date : app . calendar . date . toString ( start ) } ) ;
}
break ;
}
} ,
/ * *
* Set the app header
2016-02-17 20:56:54 +01:00
*
2016-01-06 19:24:45 +01:00
* Because the toolbar takes some vertical space and has some horizontal space ,
* we don ' t use the system app header , but our own that is in the toolbar
2016-02-17 20:56:54 +01:00
*
2016-01-06 19:24:45 +01:00
* @ param { string } header Text to display
* /
set _app _header : function ( header ) {
var template = etemplate2 . getById ( 'calendar-toolbar' ) ;
var widget = template ? template . widgetContainer . getWidgetById ( 'app_header' ) : false ;
if ( widget )
{
widget . set _value ( header ) ;
egw _app _header ( '' , 'calendar' ) ;
}
else
{
egw _app _header ( header , 'calendar' ) ;
}
} ,
2015-06-10 23:51:28 +02:00
/ * *
* Setup and handle sortable calendars .
*
* You can only sort calendars if there is more than one owner , and the calendars
* are not combined ( many owners , multi - week or month views )
* @ returns { undefined }
* /
_sortable : function ( ) {
2014-11-05 17:13:26 +01:00
// Calender current state
var state = this . getState ( ) ;
2016-01-08 23:38:11 +01:00
// Day / month sortables
var daily = jQuery ( '#calendar-view_view .calendar_calGridHeader > div:first' ) ;
var weekly = jQuery ( '#calendar-view_view tbody' ) ;
if ( state . view == 'day' )
{
var sortable = daily ;
if ( weekly . sortable ( 'instance' ) ) weekly . sortable ( 'disable' ) ;
}
else
{
2016-06-13 18:03:52 +02:00
var sortable = weekly ;
2016-01-08 23:38:11 +01:00
if ( daily . sortable ( 'instance' ) ) daily . sortable ( 'disable' ) ;
}
2015-07-15 18:29:10 +02:00
if ( ! sortable . sortable ( 'instance' ) )
2014-11-05 17:13:26 +01:00
{
2016-01-08 23:38:11 +01:00
sortable . sortable ( {
2016-06-30 21:21:13 +02:00
cancel : "#divAppboxHeader, .calendar_calWeekNavHeader, .calendar_calDayColHeader, .calendar_plannerHeader" ,
2015-06-10 23:51:28 +02:00
handle : '.calendar_calGridHeader' ,
//placeholder: "srotable_cal_wk_ph",
2014-11-05 17:13:26 +01:00
axis : "y" ,
revert : true ,
helper : "clone" ,
create : function ( )
{
var $sortItem = jQuery ( this ) ;
} ,
2015-07-22 01:45:38 +02:00
start : function ( event , ui )
2014-11-05 17:13:26 +01:00
{
2016-06-02 16:51:15 +02:00
jQuery ( '.calendar_calTimeGrid' , ui . helper ) . css ( 'position' , 'absolute' ) ;
2015-06-10 23:51:28 +02:00
// Put owners into row IDs
2015-08-12 00:30:50 +02:00
app . classes . calendar . views [ app . calendar . state . view ] . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
2016-01-08 23:38:11 +01:00
if ( widget . options . owner && ! widget . disabled )
{
widget . div . parents ( 'tr' ) . attr ( 'data-owner' , widget . options . owner ) ;
}
else
{
widget . div . parents ( 'tr' ) . removeAttr ( 'data-owner' ) ;
}
2015-07-15 15:16:31 +02:00
} , this , et2 _calendar _timegrid ) ;
2014-11-05 17:13:26 +01:00
} ,
stop : function ( )
{
} ,
update : function ( )
{
2015-08-12 00:30:50 +02:00
var state = app . calendar . getState ( ) ;
2014-11-05 17:13:26 +01:00
if ( state && typeof state . owner !== 'undefined' )
{
2015-06-10 23:51:28 +02:00
var sortedArr = sortable . sortable ( 'toArray' , { attribute : "data-owner" } ) ;
2016-01-08 23:38:11 +01:00
// No duplicates, no empties
sortedArr = sortedArr . filter ( function ( value , index , self ) {
return value !== '' && self . indexOf ( value ) === index ;
2016-06-13 18:03:52 +02:00
} ) ;
2016-01-08 23:38:11 +01:00
var parent = null ;
var children = [ ] ;
if ( state . view == 'day' )
{
// If in day view, the days need to be re-ordered, avoiding
// the current sort order
app . classes . calendar . views . day . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
var idx = sortedArr . indexOf ( widget . options . owner ) ;
// Move the event holding div
widget . set _left ( ( parseInt ( widget . options . width ) * idx ) + 'px' ) ;
// Re-order the children, or it won't stay
parent = widget . _parent ;
children . splice ( idx , 0 , widget ) ;
} , this , et2 _calendar _daycol ) ;
}
else
{
// Re-order the children, or it won't stay
app . classes . calendar . views . day . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
parent = widget . _parent ;
var idx = sortedArr . indexOf ( widget . options . owner ) ;
children . splice ( idx , 0 , widget ) ;
2016-01-22 01:22:08 +01:00
widget . resize ( ) ;
2016-01-08 23:38:11 +01:00
} , this , et2 _calendar _timegrid ) ;
}
parent . _children . sort ( function ( a , b ) {
return children . indexOf ( a ) - children . indexOf ( b ) ;
} ) ;
2015-06-10 23:51:28 +02:00
// Directly update, since there is no other changes needed,
// and we don't want the current sort order applied
app . calendar . state . owner = sortedArr ;
2014-11-05 17:13:26 +01:00
}
}
} ) ;
2015-06-10 23:51:28 +02:00
}
// Enable or disable
2015-12-23 00:34:53 +01:00
if ( state . owner . length > 1 && (
2015-12-28 17:55:51 +01:00
state . view == 'day' && state . owner . length < parseInt ( egw . preference ( 'day_consolidate' , 'calendar' ) ) ||
state . view == 'week' && state . owner . length < parseInt ( egw . preference ( 'week_consolidate' , 'calendar' ) )
2015-12-23 00:34:53 +01:00
) )
2015-07-15 18:29:10 +02:00
{
sortable . sortable ( 'enable' )
. sortable ( "refresh" )
. disableSelection ( ) ;
var options = { } ;
switch ( state . view )
{
case "day" :
options = {
placeholder : "srotable_cal_day_ph" ,
2016-01-08 23:38:11 +01:00
axis : "x" ,
handle : '> div:first' ,
helper : function ( event , element ) {
var scroll = element . parentsUntil ( '.calendar_calTimeGrid' ) . last ( ) . next ( ) ;
2016-06-02 16:51:15 +02:00
var helper = jQuery ( document . createElement ( 'div' ) )
2016-01-08 23:38:11 +01:00
. append ( element . clone ( ) )
. css ( 'height' , scroll . parent ( ) . css ( 'height' ) )
. css ( 'background-color' , 'white' )
. css ( 'width' , element . css ( 'width' ) ) ;
return helper ;
}
2015-07-15 18:29:10 +02:00
} ;
sortable . sortable ( 'option' , options ) ;
break ;
case "week" :
options = {
placeholder : "srotable_cal_wk_ph" ,
2016-01-08 23:38:11 +01:00
axis : "y" ,
handle : '.calendar_calGridHeader' ,
helper : 'clone'
2015-07-15 18:29:10 +02:00
} ;
sortable . sortable ( 'option' , options ) ;
break ;
}
2015-06-10 23:51:28 +02:00
}
else
{
2015-07-15 18:29:10 +02:00
sortable . sortable ( 'disable' ) ;
2015-06-10 23:51:28 +02:00
}
2013-12-13 19:18:56 +01:00
} ,
2014-01-30 19:24:24 +01:00
2015-06-25 19:44:28 +02:00
/ * *
* Bind scroll event
* When the user scrolls , we ' ll move enddate - startdate days
* /
_scroll : function ( ) {
2015-10-27 17:45:37 +01:00
/ * *
* Function we can pass all this off to
*
* @ param { String } direction up , down , left or right
* @ param { number } delta Integer for how many we ' re moving , should be + / - 1
* /
var scroll _animate = function ( direction , delta )
{
// Scrolling too fast?
if ( app . calendar . _scroll _disabled ) return ;
// Find the template
2016-06-02 16:51:15 +02:00
var id = jQuery ( this ) . closest ( '.et2_container' ) . attr ( 'id' ) ;
2015-10-27 17:45:37 +01:00
if ( id )
{
var template = etemplate2 . getById ( id ) ;
}
else
{
template = app . classes . calendar . views [ app . calendar . state . view ] . etemplates [ 0 ] ;
}
if ( ! template ) return ;
// Prevent scrolling too fast
app . calendar . _scroll _disabled = true ;
// Animate the transition, if possible
2016-06-13 18:03:52 +02:00
var widget = null ;
2015-10-27 17:45:37 +01:00
template . widgetContainer . iterateOver ( function ( w ) {
if ( w . getDOMNode ( ) == this ) widget = w ;
} , this , et2 _widget ) ;
if ( widget == null )
{
template . widgetContainer . iterateOver ( function ( w ) {
widget = w ;
} , this , et2 _calendar _timegrid ) ;
if ( widget == null ) return ;
}
2016-02-04 22:05:31 +01:00
/ * D i s a b l e d
2016-02-17 20:56:54 +01:00
*
2015-10-27 17:45:37 +01:00
// We clone the nodes so we can animate the transition
2016-06-02 16:51:15 +02:00
var original = jQuery ( widget . getDOMNode ( ) ) . closest ( '.et2_grid' ) ;
2015-10-27 17:45:37 +01:00
var cloned = original . clone ( true ) . attr ( "id" , "CLONE" ) ;
2015-11-04 22:47:52 +01:00
// Moving this stuff around scrolls things around too
// We need this later
2016-06-02 16:51:15 +02:00
var scrollTop = jQuery ( '.calendar_calTimeGridScroll' , original ) . scrollTop ( ) ;
2015-10-27 17:45:37 +01:00
2015-11-04 22:47:52 +01:00
// This is to hide the scrollbar
var wrapper = original . parent ( ) ;
2015-10-27 17:45:37 +01:00
if ( direction == "right" || direction == "left" )
{
original . css ( { "display" : "inline-block" , "width" : original . width ( ) + "px" } ) ;
cloned . css ( { "display" : "inline-block" , "width" : original . width ( ) + "px" } ) ;
}
2015-11-04 22:47:52 +01:00
else
{
original . css ( "height" , original . height ( ) + "px" ) ;
cloned . css ( "height" , original . height ( ) + "px" ) ;
}
2015-11-12 02:01:21 +01:00
var original _size = { height : wrapper . parent ( ) . css ( 'height' ) , width : wrapper . parent ( ) . css ( 'width' ) } ;
2015-11-04 22:47:52 +01:00
wrapper . parent ( ) . css ( { overflow : 'hidden' , height : original . outerHeight ( ) + "px" , width : original . outerWidth ( ) + "px" } ) ;
wrapper . height ( direction == "up" || direction == "down" ? 2 * original . outerHeight ( ) : original . outerHeight ( ) ) ;
wrapper . width ( direction == "left" || direction == "right" ? 2 * original . outerWidth ( ) : original . outerWidth ( ) ) ;
2015-10-27 17:45:37 +01:00
// Re-scroll to previous to avoid "jumping"
2016-06-02 16:51:15 +02:00
jQuery ( '.calendar_calTimeGridScroll' , original ) . scrollTop ( scrollTop ) ;
2015-10-27 17:45:37 +01:00
switch ( direction )
{
case "up" :
case "left" :
// Scrolling up
// Apply the reverse quickly, then let it animate as the changes are
// removed, leaving things where they should be.
2015-11-04 22:47:52 +01:00
2015-10-27 17:45:37 +01:00
original . parent ( ) . append ( cloned ) ;
// Makes it jump to destination
wrapper . css ( {
"transition-duration" : "0s" ,
2015-11-04 22:47:52 +01:00
"transition-delay" : "0s" ,
"transform" : direction == "up" ? "translateY(-50%)" : "translateX(-50%)"
2015-10-27 17:45:37 +01:00
} ) ;
2015-11-04 22:47:52 +01:00
// Stop browser from caching style by forcing reflow
2015-12-21 19:14:33 +01:00
if ( wrapper [ 0 ] ) wrapper [ 0 ] . offsetHeight ;
2015-11-05 00:05:22 +01:00
2015-10-27 17:45:37 +01:00
wrapper . css ( {
"transition-duration" : "" ,
"transition-delay" : ""
} ) ;
break ;
case "down" :
case "right" :
// Scrolling down
original . parent ( ) . prepend ( cloned ) ;
break ;
}
// Scroll clone to match to avoid "jumping"
2016-06-02 16:51:15 +02:00
jQuery ( '.calendar_calTimeGridScroll' , cloned ) . scrollTop ( scrollTop ) ;
2015-10-27 17:45:37 +01:00
// Remove
var remove = function ( ) {
// Starting animation
wrapper . addClass ( "calendar_slide" ) ;
var translate = direction == "down" ? "translateY(-50%)" : ( direction == "right" ? "translateX(-50%)" : "" ) ;
wrapper . css ( { "transform" : translate } ) ;
window . setTimeout ( function ( ) {
2015-11-04 22:47:52 +01:00
2015-10-27 17:45:37 +01:00
cloned . remove ( ) ;
2016-02-17 20:56:54 +01:00
2015-11-04 22:47:52 +01:00
// Makes it jump to destination
wrapper . css ( {
"transition-duration" : "0s" ,
"transition-delay" : "0s"
} ) ;
2016-02-17 20:56:54 +01:00
2015-11-04 22:47:52 +01:00
// Clean up from animation
wrapper
. removeClass ( "calendar_slide" )
. css ( { "transform" : '' , height : '' , width : '' , overflow : '' } ) ;
2015-11-12 02:01:21 +01:00
wrapper . parent ( ) . css ( { overflow : '' , width : original _size . width , height : original _size . height } ) ;
2015-10-27 17:45:37 +01:00
original . css ( "display" , "" ) ;
2015-12-22 21:07:40 +01:00
if ( wrapper . length )
{
wrapper [ 0 ] . offsetHeight ;
}
2015-11-04 22:47:52 +01:00
wrapper . css ( {
"transition-duration" : "" ,
"transition-delay" : ""
} ) ;
2015-10-27 17:45:37 +01:00
// Re-scroll to start of day
2015-11-13 00:10:16 +01:00
template . widgetContainer . iterateOver ( function ( w ) {
2015-12-09 21:54:01 +01:00
w . resizeTimes ( ) ;
2015-11-13 00:10:16 +01:00
} , this , et2 _calendar _timegrid ) ;
2015-10-27 17:45:37 +01:00
window . setTimeout ( function ( ) {
if ( app . calendar )
{
app . calendar . _scroll _disabled = false ;
}
} , 100 ) ;
} , 2000 ) ;
}
// If detecting the transition end worked, we wouldn't need to use a timeout.
window . setTimeout ( remove , 100 ) ;
2016-02-04 22:05:31 +01:00
* /
window . setTimeout ( function ( ) {
if ( app . calendar )
{
app . calendar . _scroll _disabled = false ;
}
} , 2000 ) ;
2015-10-27 17:45:37 +01:00
// Get the view to calculate - this actually loads the new data
// Using a timeout make it a little faster (in Chrome)
window . setTimeout ( function ( ) {
var view = app . classes . calendar . views [ app . calendar . state . view ] || false ;
var start = new Date ( app . calendar . state . date ) ;
if ( view && view . etemplates . indexOf ( template ) !== - 1 )
{
start = view . scroll ( delta ) ;
app . calendar . update _state ( { date : app . calendar . date . toString ( start ) } ) ;
}
else
{
// Home - always 1 week
// TODO
return false ;
}
} , 0 ) ;
} ;
2016-02-17 20:56:54 +01:00
2015-07-15 18:29:10 +02:00
// Bind only once, to the whole thing
2016-02-04 22:05:31 +01:00
/ * D i s a b l e d
2015-07-15 18:29:10 +02:00
jQuery ( 'body' ) . off ( '.calendar' )
//.on('wheel','.et2_container:#calendar-list,#calendar-sidebox)',
. on ( 'wheel.calendar' , '.et2_container .calendar_calTimeGrid, .et2_container .calendar_plannerWidget' ,
2015-06-25 19:44:28 +02:00
function ( e )
{
2015-10-27 17:45:37 +01:00
// Consume scroll if in the middle of something
if ( app . calendar . _scroll _disabled ) return false ;
2016-02-17 20:56:54 +01:00
2015-10-21 21:53:19 +02:00
// Ignore if they're going the other way
var direction = e . originalEvent . deltaY > 0 ? 1 : - 1 ;
var at _bottom = direction !== - 1 ;
var at _top = direction !== 1 ;
2016-02-17 20:56:54 +01:00
2016-06-02 16:51:15 +02:00
jQuery ( this ) . children ( ":not(.calendar_calGridHeader)" ) . each ( function ( ) {
2015-10-27 17:45:37 +01:00
// Check for less than 2px from edge, as sometimes we can't scroll anymore, but still have
// 2px left to go
at _bottom = at _bottom && Math . abs ( this . scrollTop - ( this . scrollHeight - this . offsetHeight ) ) <= 2 ;
2015-10-05 20:27:19 +02:00
} ) . each ( function ( ) {
at _top = at _top && this . scrollTop === 0 ;
} ) ;
if ( ! at _bottom && ! at _top ) return ;
2015-10-21 21:53:19 +02:00
2015-06-25 19:44:28 +02:00
e . preventDefault ( ) ;
2015-08-05 23:24:07 +02:00
2015-10-27 17:45:37 +01:00
scroll _animate . call ( this , direction > 0 ? "down" : "up" , direction ) ;
return false ;
}
2015-10-28 16:55:10 +01:00
) ;
2016-02-04 22:05:31 +01:00
* /
2016-03-18 16:49:11 +01:00
if ( typeof framework !== 'undefined' && framework . applications . calendar && framework . applications . calendar . tab )
2015-12-12 01:13:38 +01:00
{
2016-06-14 17:26:50 +02:00
jQuery ( framework . applications . calendar . tab . contentDiv )
. swipe ( 'destroy' ) ;
jQuery ( framework . applications . calendar . tab . contentDiv )
2015-12-12 01:13:38 +01:00
. swipe ( {
//Generic swipe handler for all directions
swipe : function ( event , direction , distance , duration , fingerCount ) {
if ( direction == "up" || direction == "down" )
{
2016-02-11 21:30:55 +01:00
if ( fingerCount <= 1 ) return ;
2015-12-12 01:13:38 +01:00
var at _bottom = direction !== - 1 ;
var at _top = direction !== 1 ;
2016-06-02 16:51:15 +02:00
jQuery ( this ) . children ( ":not(.calendar_calGridHeader)" ) . each ( function ( ) {
2015-12-12 01:13:38 +01:00
// Check for less than 2px from edge, as sometimes we can't scroll anymore, but still have
// 2px left to go
at _bottom = at _bottom && Math . abs ( this . scrollTop - ( this . scrollHeight - this . offsetHeight ) ) <= 2 ;
} ) . each ( function ( ) {
at _top = at _top && this . scrollTop === 0 ;
} ) ;
}
2015-06-25 19:44:28 +02:00
2015-12-12 01:13:38 +01:00
var delta = direction == "down" || direction == "right" ? - 1 : 1 ;
// But we animate in the opposite direction to the swipe
var opposite = { "down" : "up" , "up" : "down" , "left" : "right" , "right" : "left" } ;
direction = opposite [ direction ] ;
2016-06-13 18:03:52 +02:00
scroll _animate . call ( jQuery ( event . target ) . closest ( '.calendar_calTimeGrid, .calendar_plannerWidget' ) [ 0 ] , direction , delta ) ;
2015-12-12 01:13:38 +01:00
return false ;
} ,
allowPageScroll : jQuery . fn . swipe . pageScroll . VERTICAL ,
threshold : 100 ,
fallbackToMouseEvents : false ,
triggerOnTouchEnd : false
} ) ;
// Page up & page down
egw _registerGlobalShortcut ( jQuery . ui . keyCode . PAGE _UP , false , false , false , function ( ) {
if ( app . calendar . state . view == 'listview' )
{
2016-06-13 18:03:52 +02:00
return false ;
2015-12-12 01:13:38 +01:00
}
scroll _animate . call ( this , "up" , - 1 ) ;
return true ;
2015-10-27 17:45:37 +01:00
} ) ;
2015-12-12 01:13:38 +01:00
egw _registerGlobalShortcut ( jQuery . ui . keyCode . PAGE _DOWN , false , false , false , function ( ) {
if ( app . calendar . state . view == 'listview' )
{
2016-06-13 18:03:52 +02:00
return false ;
2015-12-12 01:13:38 +01:00
}
scroll _animate . call ( this , "down" , 1 ) ;
return true ;
} ) ;
}
2015-06-25 19:44:28 +02:00
} ,
2015-06-10 23:51:28 +02:00
/ * *
2015-07-15 15:16:31 +02:00
* Handler for changes generated by internal user interactions , like
2015-06-10 23:51:28 +02:00
* drag & drop inside calendar and resize .
2015-07-15 15:16:31 +02:00
*
2015-06-10 23:51:28 +02:00
* @ param { Event } event
* @ param { et2 _calendar _event } widget Widget for the event
* @ param { string } dialog _button - 'single' , 'series' , or 'exception' , based on the user ' s answer
* in the popup
* @ returns { undefined }
* /
event _change : function ( event , widget , dialog _button )
{
2015-08-24 19:28:19 +02:00
// Add loading spinner - not visible if the body / gradient is there though
widget . div . addClass ( 'loading' ) ;
2015-11-05 21:56:13 +01:00
// Integrated infolog event
//Get infologID if in case if it's an integrated infolog event
2015-12-01 23:02:47 +01:00
if ( widget . options . value . app == 'infolog' )
2015-11-05 21:56:13 +01:00
{
// If it is an integrated infolog event we need to edit infolog entry
egw ( ) . json (
'stylite_infolog_calendar_integration::ajax_moveInfologEvent' ,
2015-12-01 23:02:47 +01:00
[ widget . options . value . app _id , widget . options . value . start , widget . options . value . duration ] ,
2015-11-05 21:56:13 +01:00
// Remove loading spinner
function ( ) { if ( widget . div ) widget . div . removeClass ( 'loading' ) ; }
) . sendRequest ( ) ;
}
else
{
2015-12-04 18:37:26 +01:00
var _send = function ( ) {
egw ( ) . json (
'calendar.calendar_uiforms.ajax_moveEvent' ,
[
dialog _button == 'exception' ? widget . options . value . app _id : widget . options . value . id ,
widget . options . value . owner ,
widget . options . value . start ,
widget . options . value . owner ,
widget . options . value . duration ,
dialog _button == 'series' ? widget . options . value . start : null
] ,
// Remove loading spinner
function ( ) { if ( widget && widget . div ) widget . div . removeClass ( 'loading' ) ; }
) . sendRequest ( true ) ;
2016-06-13 18:03:52 +02:00
} ;
2015-12-04 18:37:26 +01:00
if ( dialog _button == 'series' && widget . options . value . recur _type )
2014-08-21 13:20:37 +02:00
{
2015-12-04 18:37:26 +01:00
widget . series _split _prompt ( function ( _button _id )
{
if ( _button _id == et2 _dialog . OK _BUTTON )
{
_send ( ) ;
}
}
) ;
2014-08-21 13:20:37 +02:00
}
else
{
2015-12-04 18:37:26 +01:00
_send ( ) ;
2014-08-21 13:20:37 +02:00
}
2014-01-24 13:50:20 +01:00
}
2013-12-13 19:18:56 +01:00
} ,
2014-01-30 19:24:24 +01:00
2013-10-31 15:51:19 +01:00
/ * *
* open the freetime search popup
*
2013-11-05 19:08:07 +01:00
* @ param { string } _link
2013-10-31 15:51:19 +01:00
* /
2013-11-05 19:08:07 +01:00
freetime _search _popup : function ( _link )
{
2013-10-31 15:51:19 +01:00
this . egw . open _link ( _link , 'ft_search' , '700x500' ) ;
2013-11-05 19:08:07 +01:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* send an ajax request to server to set the freetimesearch window content
*
* /
freetime _search : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
content [ 'start' ] = this . et2 . getWidgetById ( 'start' ) . get _value ( ) ;
content [ 'end' ] = this . et2 . getWidgetById ( 'end' ) . get _value ( ) ;
content [ 'duration' ] = this . et2 . getWidgetById ( 'duration' ) . get _value ( ) ;
var request = this . egw . json ( 'calendar.calendar_uiforms.ajax_freetimesearch' , [ content ] , null , null , null , null ) ;
request . sendRequest ( ) ;
} ,
/ * *
* Function for disabling the recur _data multiselect box
*
* /
check _recur _type : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
var recurType = this . et2 . getWidgetById ( 'recur_type' ) ;
var recurData = this . et2 . getWidgetById ( 'recur_data' ) ;
2011-04-27 18:53:06 +02:00
2013-10-31 15:51:19 +01:00
if ( recurType && recurData )
2011-04-27 18:53:06 +02:00
{
2016-05-13 13:20:38 +02:00
recurData . set _disabled ( recurType . get _value ( ) != 2 && recurType . get _value ( ) != 4 ) ;
2011-04-27 18:53:06 +02:00
}
2013-10-31 15:51:19 +01:00
} ,
2016-07-26 00:14:13 +02:00
/ * *
* Actions for when the user changes the event start date in edit dialog
2016-09-08 12:30:42 +02:00
*
2016-07-26 00:14:13 +02:00
* @ returns { undefined }
* /
edit _start _change : function ( input , widget )
{
if ( ! widget )
{
widget = etemplate2 . getById ( 'calendar-edit' ) . widgetContainer . getWidgetById ( 'start' ) ;
}
2016-09-08 12:30:42 +02:00
2016-07-26 00:14:13 +02:00
// Update settings for querying participants
this . edit _update _participant ( widget ) ;
// Update recurring date limit, if not set it can't be before start
if ( widget )
{
var recur _end = widget . getRoot ( ) . getWidgetById ( 'recur_enddate' ) ;
if ( recur _end && ! recur _end . getValue ( ) )
{
recur _end . set _min ( widget . getValue ( ) ) ;
}
}
2016-09-12 18:58:15 +02:00
// Update currently selected alarm time
this . alarm _custom _date ( ) ;
2016-07-26 00:14:13 +02:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* Show / Hide end date , for both edit and freetimesearch popups ,
* based on if "use end date" selected or not .
*
* /
set _enddate _visibility : function ( )
{
var duration = this . et2 . getWidgetById ( 'duration' ) ;
2014-11-14 10:37:49 +01:00
var start = this . et2 . getWidgetById ( 'start' ) ;
2013-10-31 15:51:19 +01:00
var end = this . et2 . getWidgetById ( 'end' ) ;
2014-11-14 10:37:49 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
2014-11-27 18:37:18 +01:00
2013-10-31 15:51:19 +01:00
if ( typeof duration != 'undefined' && typeof end != 'undefined' )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
end . set _disabled ( duration . get _value ( ) !== '' ) ;
2016-02-17 20:56:54 +01:00
2015-09-28 21:31:01 +02:00
// Only set end date if not provided, adding seconds fails with DST
if ( ! end . disabled && ! content . end )
2014-11-14 10:37:49 +01:00
{
end . set _value ( start . get _value ( ) ) ;
if ( typeof content . duration != 'undefined' ) end . set _value ( "+" + content . duration ) ;
}
2011-04-27 18:53:06 +02:00
}
2016-04-29 20:01:17 +02:00
this . edit _update _participant ( start ) ;
} ,
/ * *
* Update query parameters for participants
*
* This allows for resource conflict checking
*
* @ param { DOMNode | et2 _widget } input Either the input node , or the widget
* @ param { et2 _widget } [ widget ] If input is an input node , widget will have
* the widget , otherwise it will be undefined .
* /
edit _update _participant : function ( input , widget )
{
if ( typeof widget === 'undefined' ) widget = input ;
var content = widget . getInstanceManager ( ) . getValues ( widget . getRoot ( ) ) ;
var participant = widget . getRoot ( ) . getWidgetById ( 'participant' ) ;
participant . set _autocomplete _params ( { exec : {
start : content . start ,
end : content . end ,
duration : content . duration ,
2016-06-23 15:49:44 +02:00
whole _day : content . whole _day ,
2016-04-29 20:01:17 +02:00
} } ) ;
2013-10-31 15:51:19 +01:00
} ,
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
/ * *
* handles actions selectbox in calendar edit popup
*
2013-11-05 19:08:07 +01:00
* @ param { mixed } _event
2014-01-24 10:47:33 +01:00
* @ param { et2 _base _widget } widget "actions selectBox" in edit popup window
2013-10-31 15:51:19 +01:00
* /
2013-11-05 19:08:07 +01:00
actions _change : function ( _event , widget )
{
2013-10-31 15:51:19 +01:00
var event = this . et2 . getArrayMgr ( 'content' ) . data ;
if ( widget )
{
var id = this . et2 . getArrayMgr ( 'content' ) . data [ 'id' ] ;
switch ( widget . get _value ( ) )
{
case 'print' :
this . egw . open _link ( 'calendar.calendar_uiforms.edit&cal_id=' + id + '&print=1' , '_blank' , '700x700' ) ;
break ;
case 'mail' :
this . egw . json ( 'calendar.calendar_uiforms.ajax_custom_mail' , [ event , ! event [ 'id' ] , false ] , null , null , null , null ) . sendRequest ( ) ;
this . et2 . _inst . submit ( ) ;
break ;
case 'sendrequest' :
this . egw . json ( 'calendar.calendar_uiforms.ajax_custom_mail' , [ event , ! event [ 'id' ] , true ] , null , null , null , null ) . sendRequest ( ) ;
this . et2 . _inst . submit ( ) ;
break ;
case 'infolog' :
2016-06-02 16:51:15 +02:00
this . egw . open _link ( 'infolog.infolog_ui.edit&action=calendar&action_id=' + ( jQuery . isPlainObject ( event ) ? event [ 'id' ] : event ) , '_blank' , '700x600' , 'infolog' ) ;
2013-10-31 15:51:19 +01:00
this . et2 . _inst . submit ( ) ;
break ;
2014-02-10 13:45:57 +01:00
case 'ical' :
this . et2 . _inst . postSubmit ( ) ;
break ;
2013-10-31 15:51:19 +01:00
default :
this . et2 . _inst . submit ( ) ;
}
}
2013-11-05 19:08:07 +01:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* open mail compose popup window
*
2013-11-05 19:08:07 +01:00
* @ param { Array } vars
2013-10-31 15:51:19 +01:00
* @ todo need to provide right mail compose from server to custom _mail function
* /
2013-11-05 19:08:07 +01:00
custom _mail : function ( vars )
{
2014-01-29 19:47:49 +01:00
this . egw . open _link ( this . egw . link ( "/index.php" , vars ) , '_blank' , '700x700' ) ;
2013-11-05 19:08:07 +01:00
} ,
2014-08-21 14:43:14 +02:00
2013-10-31 15:51:19 +01:00
/ * *
* control delete _series popup visibility
*
2014-01-24 10:47:33 +01:00
* @ param { et2 _widget } widget
2013-11-05 19:08:07 +01:00
* @ param { Array } exceptions an array contains number of exception entries
2013-10-31 15:51:19 +01:00
*
* /
2014-01-23 11:27:18 +01:00
delete _btn : function ( widget , exceptions )
2013-11-05 19:08:07 +01:00
{
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
2013-10-31 15:51:19 +01:00
2013-11-05 19:08:07 +01:00
if ( exceptions )
{
2014-06-16 18:49:45 +02:00
var buttons = [
{
button _id : 'keep' ,
2015-10-26 16:10:39 +01:00
title : this . egw . lang ( 'All exceptions are converted into single events.' ) ,
text : this . egw . lang ( 'Keep exceptions' ) ,
2014-06-16 18:49:45 +02:00
id : 'button[delete_keep_exceptions]' ,
image : 'keep' , "default" : true
} ,
{
button _id : 'delete' ,
2015-10-26 16:10:39 +01:00
title : this . egw . lang ( 'The exceptions are deleted together with the series.' ) ,
text : this . egw . lang ( 'Delete exceptions' ) ,
2014-06-16 18:49:45 +02:00
id : 'button[delete_exceptions]' ,
image : 'delete'
} ,
{
button _id : 'cancel' ,
2015-10-26 16:10:39 +01:00
text : this . egw . lang ( 'Cancel' ) ,
2014-06-16 18:49:45 +02:00
id : 'dialog[cancel]' ,
image : 'cancel'
}
2014-08-21 14:43:14 +02:00
2014-06-16 18:49:45 +02:00
] ;
var self = this ;
et2 _dialog . show _dialog
(
function ( _button _id )
{
if ( _button _id != 'dialog[cancel]' )
{
2015-11-16 17:45:02 +01:00
widget . getRoot ( ) . getWidgetById ( 'delete_exceptions' ) . set _value ( _button _id == 'button[delete_exceptions]' ) ;
widget . getInstanceManager ( ) . submit ( 'button[delete]' ) ;
2014-06-16 18:49:45 +02:00
return true ;
}
else
{
return false ;
}
} ,
this . egw . lang ( "Do you want to keep the series exceptions in your calendar?" ) ,
this . egw . lang ( "This event is part of a series" ) , { } , buttons , et2 _dialog . WARNING _MESSAGE
) ;
2013-11-05 19:08:07 +01:00
}
else if ( content [ 'recur_type' ] !== 0 )
{
2014-01-23 11:27:18 +01:00
et2 _dialog . confirm ( widget , 'Delete this series of recuring events' , 'Delete Series' ) ;
2013-11-05 19:08:07 +01:00
}
else
{
2014-01-23 11:27:18 +01:00
et2 _dialog . confirm ( widget , 'Delete this event' , 'Delete' ) ;
2013-11-05 19:08:07 +01:00
}
} ,
2013-10-31 15:51:19 +01:00
2016-04-18 15:56:47 +02:00
/ * *
2016-04-29 10:40:55 +02:00
* On change participant event , try to set add button status based on
* participant field value . Additionally , disable / enable quantity field
* if there ' s none resource value or there are more than one resource selected .
2016-04-18 15:56:47 +02:00
*
* /
2016-04-29 10:40:55 +02:00
participantOnChange : function ( )
{
2016-04-18 15:56:47 +02:00
var add = this . et2 . getWidgetById ( 'add' ) ;
2016-04-29 10:40:55 +02:00
var quantity = this . et2 . getWidgetById ( 'quantity' ) ;
2016-04-18 15:56:47 +02:00
var participant = this . et2 . getWidgetById ( 'participant' ) ;
2016-04-29 10:40:55 +02:00
// array of participants
var value = participant . get _value ( ) ;
add . set _readonly ( value . length <= 0 ) ;
quantity . set _readonly ( false ) ;
// number of resources
var nRes = 0 ;
for ( var i = 0 ; i < value . length ; i ++ )
{
if ( ! value [ i ] . match ( /\D/ig ) || nRes )
{
quantity . set _readonly ( true ) ;
quantity . set _value ( 1 ) ;
}
nRes ++ ;
}
2016-04-18 15:56:47 +02:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* print _participants _status ( egw , widget )
* Handle to apply changes from status in print popup
*
2013-11-05 19:08:07 +01:00
* @ param { mixed } _event
* @ param { et2 _base _widget } widget widget "status" in print popup window
2013-10-31 15:51:19 +01:00
*
* /
2013-11-05 19:08:07 +01:00
print _participants _status : function ( _event , widget )
{
2013-10-31 15:51:19 +01:00
if ( widget && window . opener )
{
//Parent popup window
var editPopWindow = window . opener ;
if ( editPopWindow )
{
//Update paretn popup window
editPopWindow . etemplate2 . getByApplication ( 'calendar' ) [ 0 ] . widgetContainer . getWidgetById ( widget . id ) . set _value ( widget . get _value ( ) ) ;
}
this . et2 . _inst . submit ( ) ;
editPopWindow . opener . egw _refresh ( 'status changed' , 'calendar' ) ;
}
else if ( widget )
{
window . egw _refresh ( this . egw . lang ( 'The original popup edit window is closed! You need to close the print window and reopen the entry again.' ) , 'calendar' ) ;
}
2013-11-05 19:08:07 +01:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* Handles to select freetime , and replace the selected one on Start ,
* and End date & time in edit calendar entry popup .
*
2013-11-05 19:08:07 +01:00
* @ param { mixed } _event
* @ param { et2 _base _widget } _widget widget "select button" in freetime search popup window
2013-10-31 15:51:19 +01:00
*
* /
2013-11-05 19:08:07 +01:00
freetime _select : function ( _event , _widget )
{
2013-10-31 15:51:19 +01:00
if ( _widget )
{
var content = this . et2 . _inst . widgetContainer . getArrayMgr ( 'content' ) . data ;
// Make the Id from selected button by checking the index
var selectedId = _widget . id . match ( /^select\[([0-9])\]$/i ) [ 1 ] ;
var sTime = this . et2 . getWidgetById ( selectedId + 'start' ) ;
//check the parent window is still open before to try to access it
2014-09-04 15:03:48 +02:00
if ( window . opener && sTime )
2013-10-31 15:51:19 +01:00
{
var editWindowObj = window . opener . etemplate2 . getByApplication ( 'calendar' ) [ 0 ] ;
if ( typeof editWindowObj != "undefined" )
{
var startTime = editWindowObj . widgetContainer . getWidgetById ( 'start' ) ;
var endTime = editWindowObj . widgetContainer . getWidgetById ( 'end' ) ;
if ( startTime && endTime )
{
2014-09-04 15:03:48 +02:00
startTime . set _value ( sTime . get _value ( ) ) ;
endTime . set _value ( sTime . get _value ( ) ) ;
endTime . set _value ( '+' + content [ 'duration' ] ) ;
2013-10-31 15:51:19 +01:00
}
}
}
else
{
alert ( this . egw . lang ( 'The original calendar edit popup is closed!' ) ) ;
}
}
2014-12-12 15:21:04 +01:00
egw ( window ) . close ( ) ;
2013-11-05 19:08:07 +01:00
} ,
2013-10-31 15:51:19 +01:00
/ * *
* show / hide the filter of nm list in calendar listview
*
* /
filter _change : function ( )
2013-01-09 22:45:55 +01:00
{
2015-10-16 19:32:21 +02:00
var view = app . classes . calendar . views [ 'listview' ] . etemplates [ 0 ] . widgetContainer || false ;
2015-12-10 01:40:04 +01:00
var filter = view ? view . getWidgetById ( 'nm' ) . getWidgetById ( 'filter' ) : null ;
2015-10-16 19:32:21 +02:00
var dates = view ? view . getWidgetById ( 'calendar.list.dates' ) : null ;
2013-10-31 15:51:19 +01:00
2015-12-16 21:41:54 +01:00
// Update state when user changes it
if ( filter )
{
app . calendar . state . filter = filter . getValue ( ) ;
2016-04-20 18:52:52 +02:00
// Change sort order for before - this is just the UI, server does the query
if ( app . calendar . state . filter == 'before' )
{
view . getWidgetById ( 'nm' ) . sortBy ( 'cal_start' , false , false ) ;
}
else
{
view . getWidgetById ( 'nm' ) . sortBy ( 'cal_start' , true , false ) ;
}
2015-12-16 21:41:54 +01:00
}
else
{
delete app . calendar . state . filter ;
}
2013-10-31 15:51:19 +01:00
if ( filter && dates )
2013-01-09 22:45:55 +01:00
{
2013-10-31 15:51:19 +01:00
dates . set _disabled ( filter . value !== "custom" ) ;
2016-04-25 17:56:23 +02:00
if ( filter . value == "custom" && ! this . state _update _in _progress )
2016-02-17 20:56:54 +01:00
{
2016-04-25 17:56:23 +02:00
// Copy state dates over, without causing [another] state update
var actual = this . state _update _in _progress ;
this . state _update _in _progress = true ;
view . getWidgetById ( 'startdate' ) . set _value ( app . calendar . state . first ) ;
view . getWidgetById ( 'enddate' ) . set _value ( app . calendar . state . last ) ;
this . state _update _in _progress = actual ;
2016-02-22 23:45:48 +01:00
jQuery ( view . getWidgetById ( 'startdate' ) . getDOMNode ( ) ) . find ( 'input' ) . focus ( ) ;
2016-02-17 20:56:54 +01:00
}
2013-01-09 22:45:55 +01:00
}
2013-10-31 15:51:19 +01:00
} ,
2015-07-01 00:26:59 +02:00
/ * *
* Application links from non - list events
2015-07-15 15:16:31 +02:00
*
2015-07-01 00:26:59 +02:00
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _events
* /
action _open : function ( _action , _events )
{
var id = _events [ 0 ] . id . split ( '::' ) ;
if ( _action . data . open )
{
var open = JSON . parse ( _action . data . open ) || { } ;
var extra = open . extra || '' ;
extra = extra . replace ( /(\$|%24)app/ , id [ 0 ] ) . replace ( /(\$|%24)id/ , id [ 1 ] ) ;
2016-01-18 23:48:38 +01:00
// Get a little smarter with the context
2016-01-19 16:37:15 +01:00
if ( ! extra )
2016-01-18 23:48:38 +01:00
{
2016-03-09 19:10:43 +01:00
var context = { } ;
2016-01-19 16:37:15 +01:00
if ( egw . dataGetUIDdata ( _events [ 0 ] . id ) && egw . dataGetUIDdata ( _events [ 0 ] . id ) . data )
{
// Found data in global cache
context = egw . dataGetUIDdata ( _events [ 0 ] . id ) . data ;
extra = { } ;
}
else if ( _events [ 0 ] . iface . getWidget ( ) && _events [ 0 ] . iface . getWidget ( ) . instanceOf ( et2 _valueWidget ) )
{
// Able to extract something from the widget
context = _events [ 0 ] . iface . getWidget ( ) . getValue ?
_events [ 0 ] . iface . getWidget ( ) . getValue ( ) :
2016-06-13 18:03:52 +02:00
_events [ 0 ] . iface . getWidget ( ) . options . value || { } ;
2016-01-19 16:37:15 +01:00
extra = { } ;
}
2016-03-09 19:10:43 +01:00
// Try to pull whatever we can from the event
else if ( jQuery . isEmptyObject ( context ) && _action . menu _context && ( _action . menu _context . event . target ) )
{
var target = _action . menu _context . event . target ;
while ( target != null && target . parentNode && jQuery . isEmptyObject ( target . dataset ) )
{
target = target . parentNode ;
}
2016-08-18 23:33:24 +02:00
context = extra = jQuery . extend ( { } , target . dataset ) ;
var owner = jQuery ( target ) . closest ( '[data-owner]' ) . get ( 0 ) ;
if ( owner && owner . dataset . owner && owner . dataset . owner != this . state . owner )
{
extra . owner = owner . dataset . owner . split ( ',' ) ;
}
2016-03-09 19:10:43 +01:00
}
2016-01-19 16:37:15 +01:00
if ( context . date ) extra . date = context . date ;
if ( context . app ) extra . app = context . app ;
if ( context . app _id ) extra . app _id = context . app _id ;
2016-01-18 23:48:38 +01:00
}
this . egw . open ( open . id _data || '' , open . app , open . type , extra ? extra : context ) ;
2015-07-01 00:26:59 +02:00
}
else if ( _action . data . url )
{
var url = _action . data . url ;
url = url . replace ( /(\$|%24)app/ , id [ 0 ] ) . replace ( /(\$|%24)id/ , id [ 1 ] ) ;
this . egw . open _link ( url ) ;
}
} ,
2016-04-27 21:28:31 +02:00
/ * *
* Context menu action ( on a single event ) in non - listview to generate ical
*
* Since nextmatch is all ready to handle that , we pass it through
*
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _events
* /
ical : function ( _action , _events )
{
// Send it through nextmatch
_action . data . nextmatch = etemplate2 . getById ( 'calendar-list' ) . widgetContainer . getWidgetById ( 'nm' ) ;
var ids = { ids : [ ] } ;
for ( var i = 0 ; i < _events . length ; i ++ )
{
ids . ids . push ( _events [ i ] . id ) ;
}
nm _action ( _action , _events , null , ids ) ;
} ,
2015-06-10 23:51:28 +02:00
/ * *
* Change status ( via AJAX )
*
* @ param { egwAction } _action
* @ param { egwActionObject } _events
* /
status : function ( _action , _events )
{
// Should be a single event, but we'll do it for all
for ( var i = 0 ; i < _events . length ; i ++ )
{
var event _widget = _events [ i ] . iface . getWidget ( ) || false ;
if ( ! event _widget ) continue ;
event _widget . recur _prompt ( jQuery . proxy ( function ( button _id , event _data ) {
switch ( button _id )
{
case 'exception' :
2015-07-01 00:26:59 +02:00
egw ( ) . json (
'calendar.calendar_uiforms.ajax_status' ,
[ event _data . app _id , egw . user ( 'account_id' ) , _action . data . id ]
) . sendRequest ( true ) ;
2015-06-10 23:51:28 +02:00
break ;
case 'series' :
case 'single' :
2015-07-01 00:26:59 +02:00
egw ( ) . json (
'calendar.calendar_uiforms.ajax_status' ,
[ event _data . id , egw . user ( 'account_id' ) , _action . data . id ]
) . sendRequest ( true ) ;
2015-06-10 23:51:28 +02:00
break ;
case 'cancel' :
default :
break ;
}
} , this ) ) ;
}
} ,
2013-10-31 15:51:19 +01:00
/ * *
* this function try to fix ids which are from integrated apps
*
2015-07-15 18:29:10 +02:00
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _senders
2013-10-31 15:51:19 +01:00
* /
cal _fix _app _id : function ( _action , _senders )
2013-01-09 22:38:18 +01:00
{
2013-10-31 15:51:19 +01:00
var app = 'calendar' ;
var id = _senders [ 0 ] . id ;
2013-11-04 11:23:08 +01:00
var matches = id . match ( /^(?:calendar::)?([0-9]+)(:([0-9]+))?$/ ) ;
2013-10-31 15:51:19 +01:00
if ( matches )
{
id = matches [ 1 ] ;
}
2014-01-24 10:47:33 +01:00
else
2013-10-31 15:51:19 +01:00
{
2014-01-24 10:47:33 +01:00
matches = id . match ( /^([a-z_-]+)([0-9]+)/i ) ;
if ( matches )
{
app = matches [ 1 ] ;
id = matches [ 2 ] ;
}
2013-10-31 15:51:19 +01:00
}
var backup _url = _action . data . url ;
2013-11-05 14:30:41 +01:00
_action . data . url = _action . data . url . replace ( /(\$|%24)id/ , id ) ;
_action . data . url = _action . data . url . replace ( /(\$|%24)app/ , app ) ;
2013-10-31 15:51:19 +01:00
2015-07-01 00:26:59 +02:00
nm _action ( _action , _senders , false , { ids : [ id ] } ) ;
2013-11-05 14:30:41 +01:00
2013-10-31 15:51:19 +01:00
_action . data . url = backup _url ; // restore url
} ,
/ * *
* Open calendar entry , taking into accout the calendar integration of other apps
*
* calendar _uilist : : get _rows sets var js _calendar _integration object
*
* @ param _action
* @ param _senders
*
* /
cal _open : function ( _action , _senders )
{
2015-12-07 19:32:59 +01:00
// Try for easy way - find a widget
if ( _senders [ 0 ] . iface . getWidget )
{
var widget = _senders [ 0 ] . iface . getWidget ( ) ;
return widget . recur _prompt ( ) ;
}
2016-02-17 20:56:54 +01:00
2015-12-07 19:32:59 +01:00
// Nextmatch in list view does not have a widget, but we can pull
// the data by ID
2015-10-07 17:34:37 +02:00
// Check for series
2013-10-31 15:51:19 +01:00
var id = _senders [ 0 ] . id ;
2015-12-07 19:32:59 +01:00
var data = egw . dataGetUIDdata ( id ) ;
if ( data && data . data )
2013-10-31 15:51:19 +01:00
{
2015-12-07 19:32:59 +01:00
et2 _calendar _event . recur _prompt ( data . data ) ;
2013-10-31 15:51:19 +01:00
return ;
}
2015-12-07 19:32:59 +01:00
var matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
2015-10-07 17:34:37 +02:00
// Check for other app integration data sent from server
var backup = _action . data ;
if ( _action . parent . data && _action . parent . data . nextmatch )
{
var js _integration _data = _action . parent . data . nextmatch . options . settings . js _integration _data || this . et2 . getArrayMgr ( 'content' ) . data . nm . js _integration _data ;
if ( typeof js _integration _data == 'string' )
{
js _integration _data = JSON . parse ( js _integration _data ) ;
}
}
matches = id . match ( /^calendar::([a-z_-]+)([0-9]+)/i ) ;
if ( matches && js _integration _data && js _integration _data [ matches [ 1 ] ] )
2013-10-31 15:51:19 +01:00
{
var app = matches [ 1 ] ;
_action . data . url = window . egw _webserverUrl + '/index.php?' ;
var get _params = js _integration _data [ app ] . edit ;
get _params [ js _integration _data [ app ] . edit _id ] = matches [ 2 ] ;
for ( var name in get _params )
_action . data . url += name + "=" + encodeURIComponent ( get _params [ name ] ) + "&" ;
2013-01-09 22:38:18 +01:00
2014-01-24 10:47:33 +01:00
if ( js _integration _data [ app ] . edit _popup )
2013-10-31 15:51:19 +01:00
{
2015-10-07 17:34:37 +02:00
egw . open _link ( _action . data . url , '_blank' , js _integration _data [ app ] . edit _popup , app ) ;
_action . data = backup ; // restore url, width, height, nm_action
return ;
}
}
else
{
// Other app integration using link registry
var data = egw . dataGetUIDdata ( _senders [ 0 ] . id ) ;
if ( data && data . data )
{
return egw . open ( data . data . app _id , data . data . app , 'edit' ) ;
2013-10-31 15:51:19 +01:00
}
}
2015-10-07 17:34:37 +02:00
// Regular, single event
2013-10-31 15:51:19 +01:00
egw . open ( id . replace ( /^calendar::/g , '' ) , 'calendar' , 'edit' ) ;
} ,
2013-01-09 22:38:18 +01:00
2015-07-15 18:29:10 +02:00
/ * *
* Delete ( a single ) calendar entry over ajax .
*
* Used for the non - list views
*
* @ param { egwAction } _action
* @ param { egwActionObject } _events
* /
delete : function ( _action , _events )
{
// Should be a single event, but we'll do it for all
for ( var i = 0 ; i < _events . length ; i ++ )
{
var event _widget = _events [ i ] . iface . getWidget ( ) || false ;
if ( ! event _widget ) continue ;
event _widget . recur _prompt ( jQuery . proxy ( function ( button _id , event _data ) {
switch ( button _id )
{
case 'exception' :
egw ( ) . json (
'calendar.calendar_uiforms.ajax_delete' ,
[ event _data . app _id ]
) . sendRequest ( true ) ;
break ;
case 'series' :
case 'single' :
egw ( ) . json (
'calendar.calendar_uiforms.ajax_delete' ,
[ event _data . id ]
) . sendRequest ( true ) ;
break ;
case 'cancel' :
default :
break ;
}
} , this ) ) ;
}
} ,
2013-10-31 15:51:19 +01:00
/ * *
* Delete calendar entry , asking if you want to delete series or exception
*
2015-07-15 18:29:10 +02:00
* Used for nextmatch
2013-10-31 15:51:19 +01:00
*
* @ param _action
* @ param _senders
* /
cal _delete : function ( _action , _senders )
{
var backup = _action . data ;
var matches = false ;
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
// Loop so we ask if any of the selected entries is part of a series
for ( var i = 0 ; i < _senders . length ; i ++ )
2013-01-09 22:38:18 +01:00
{
2013-10-31 15:51:19 +01:00
var id = _senders [ i ] . id ;
if ( ! matches )
{
matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
}
}
if ( matches )
{
2014-06-17 11:44:15 +02:00
var popup = jQuery ( '#calendar-list_delete_popup' ) . get ( 0 ) ;
if ( typeof popup != 'undefined' )
2013-11-05 19:08:07 +01:00
{
2014-06-17 11:44:15 +02:00
// nm action - show popup
nm _open _popup ( _action , _senders ) ;
2014-08-21 14:43:14 +02:00
}
2013-01-09 22:38:18 +01:00
return ;
}
2013-10-31 15:51:19 +01:00
2013-11-05 17:02:21 +01:00
nm _action ( _action , _senders ) ;
2013-10-31 15:51:19 +01:00
} ,
2014-01-23 18:15:49 +01:00
/ * *
2014-01-24 16:50:17 +01:00
* Confirmation dialog for moving a series entry
2014-01-23 18:15:49 +01:00
*
2014-01-24 16:50:17 +01:00
* @ param { object } _DOM
* @ param { et2 _widget } _button button Save | Apply
2014-01-23 18:15:49 +01:00
* /
move _edit _series : function ( _DOM , _button )
{
2015-11-30 19:12:26 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var start _date = this . et2 . getWidgetById ( 'start' ) . get _value ( ) ;
2015-12-04 18:37:26 +01:00
var end _date = this . et2 . getWidgetById ( 'end' ) . get _value ( ) ;
2015-11-30 19:12:26 +01:00
var whole _day = this . et2 . getWidgetById ( 'whole_day' ) ;
2015-12-04 18:37:26 +01:00
var duration = '' + this . et2 . getWidgetById ( 'duration' ) . get _value ( ) ;
2014-09-10 12:24:40 +02:00
var is _whole _day = whole _day && whole _day . get _value ( ) == whole _day . options . selected _value ;
2014-01-23 18:15:49 +01:00
var button = _button ;
var that = this ;
2015-12-04 18:37:26 +01:00
var instance _date = window . location . search . match ( /date=(\d{4}-\d{2}-\d{2}(?:.+Z)?)/ ) ;
if ( instance _date && instance _date . length && instance _date [ 1 ] )
{
instance _date = new Date ( unescape ( instance _date [ 1 ] ) ) ;
instance _date . setUTCMinutes ( instance _date . getUTCMinutes ( ) + instance _date . getTimezoneOffset ( ) ) ;
}
2014-03-25 16:04:14 +01:00
if ( typeof content != 'undefined' && content . id != null &&
typeof content . recur _type != 'undefined' && content . recur _type != null && content . recur _type != 0
)
2014-01-23 18:15:49 +01:00
{
2016-02-17 20:56:54 +01:00
if ( content . start != start _date ||
2015-12-04 18:37:26 +01:00
content . whole _day != is _whole _day ||
2015-12-08 18:19:15 +01:00
( duration && '' + content . duration != duration ||
// End date might ignore seconds, and be 59 seconds off for all day events
! duration && Math . abs ( new Date ( end _date ) - new Date ( content . end ) ) > 60000 )
2015-12-04 18:37:26 +01:00
)
2014-01-23 18:15:49 +01:00
{
2015-12-04 18:37:26 +01:00
et2 _calendar _event . series _split _prompt (
content , instance _date , function ( _button _id )
2014-01-23 18:15:49 +01:00
{
if ( _button _id == et2 _dialog . OK _BUTTON )
{
that . et2 . _inst . submit ( button ) ;
}
2015-12-04 18:37:26 +01:00
}
) ;
2014-01-23 18:15:49 +01:00
}
else
{
return true ;
}
}
else
{
return true ;
}
} ,
2015-12-15 17:36:54 +01:00
/ * *
* Sidebox merge
*
* Manage the state and pass the request to the correct place . Since the nextmatch
* and the sidebox have different ideas of the 'current' timespan ( sidebox
* always has a start and end date ) we need to call merge on the nextmatch
* if the current view is listview , so the user gets the results they expect .
*
2016-06-13 18:03:52 +02:00
* @ param { Event } event UI event
* @ param { et2 _widget } widget Should be the merge selectbox
2015-12-15 17:36:54 +01:00
* /
sidebox _merge : function ( event , widget )
{
if ( ! widget || ! widget . getValue ( ) ) return false ;
if ( this . state . view == 'listview' )
{
// If user is looking at the list, pretend they used the context
// menu and process it through the nextmatch
var nm = etemplate2 . getById ( 'calendar-list' ) . widgetContainer . getWidgetById ( 'nm' ) || false ;
var selected = nm ? nm . controller . _objectManager . getSelectedLinks ( ) : [ ] ;
2016-06-13 18:03:52 +02:00
var action = nm . controller . _actionManager . getActionById ( 'document_' + widget . getValue ( ) ) ;
2015-12-15 17:36:54 +01:00
if ( nm && ( ! selected || ! selected . length ) )
{
nm . controller . _selectionMgr . selectAll ( true ) ;
}
if ( action && selected )
{
action . execute ( selected ) ;
}
}
else
{
// Set the hidden inputs to the current time span & submit
widget . getRoot ( ) . getWidgetById ( 'first' ) . set _value ( app . calendar . state . first ) ;
widget . getRoot ( ) . getWidgetById ( 'last' ) . set _value ( app . calendar . state . last ) ;
widget . getInstanceManager ( ) . postSubmit ( ) ;
}
window . setTimeout ( function ( ) { widget . set _value ( '' ) ; } , 100 ) ;
return false ;
} ,
2014-01-24 10:47:33 +01:00
/ * *
* Method to set state for JSON requests ( jdots ajax _exec or et2 submits can NOT use egw . js script tag )
*
* @ param { object } _state
* /
set _state : function ( _state )
{
if ( typeof _state == 'object' )
{
2015-06-10 23:51:28 +02:00
// If everything is loaded, handle the changes
if ( this . sidebox _et2 !== null )
{
this . update _state ( _state ) ;
}
else
{
// Things aren't loaded yet, just set it
this . state = _state ;
}
}
} ,
/ * *
* Change only part of the current state .
2015-07-15 15:16:31 +02:00
*
2015-06-10 23:51:28 +02:00
* The passed state options ( filters ) are merged with the current state , so
* this is the one that should be used for most calls , as setState ( ) requires
* the complete state .
2015-07-15 15:16:31 +02:00
*
2015-06-10 23:51:28 +02:00
* @ param { Object } _set New settings
* /
2016-01-05 21:43:19 +01:00
update _state : function update _state ( _set )
2015-06-10 23:51:28 +02:00
{
2015-06-15 23:38:03 +02:00
// Make sure we're running in top window
2016-03-18 16:49:11 +01:00
if ( window !== window . top && window . top . app . calendar )
2015-06-15 23:38:03 +02:00
{
return window . top . app . calendar . update _state ( _set ) ;
}
2015-07-15 18:29:10 +02:00
if ( this . state _update _in _progress ) return ;
2015-06-10 23:51:28 +02:00
var changed = [ ] ;
var new _state = jQuery . extend ( { } , this . state ) ;
2015-07-01 00:26:59 +02:00
if ( typeof _set === 'object' )
2015-06-10 23:51:28 +02:00
{
for ( var s in _set )
{
2015-12-07 19:32:59 +01:00
if ( new _state [ s ] !== _set [ s ] && ( typeof new _state [ s ] == 'string' || typeof new _state [ s ] !== 'string' && new _state [ s ] + '' !== _set [ s ] + '' ) )
2015-06-10 23:51:28 +02:00
{
changed . push ( s + ': ' + new _state [ s ] + ' -> ' + _set [ s ] ) ;
new _state [ s ] = _set [ s ] ;
}
}
}
if ( changed . length && ! this . state _update _in _progress )
{
2016-03-15 17:51:10 +01:00
// This activates calendar app if you call setState from a different app
// such as home. If we change state while not active, sizing is wrong.
2016-03-18 16:49:11 +01:00
if ( typeof framework !== 'undefined' && framework . applications . calendar && framework . applications . calendar . hasSideboxMenuContent )
2016-03-15 17:51:10 +01:00
{
framework . setActiveApp ( framework . applications . calendar ) ;
}
2015-06-10 23:51:28 +02:00
console . log ( 'Calendar state changed' , changed . join ( "\n" ) ) ;
// Log
this . egw . debug ( 'navigation' , 'Calendar state changed' , changed . join ( "\n" ) ) ;
this . setState ( { state : new _state } ) ;
2014-01-24 10:47:33 +01:00
}
} ,
2013-12-05 00:28:31 +01:00
/ * *
* Return state object defining current view
*
* Called by favorites to query current state .
*
* @ return { object } description
* /
2016-01-05 21:43:19 +01:00
getState : function getState ( )
2013-12-05 00:28:31 +01:00
{
2015-07-15 18:29:10 +02:00
var state = jQuery . extend ( { } , this . state ) ;
2013-12-06 22:26:55 +01:00
2014-01-24 10:47:33 +01:00
if ( ! state )
{
var egw _script _tag = document . getElementById ( 'egw_script_id' ) ;
state = egw _script _tag . getAttribute ( 'data-calendar-state' ) ;
state = state ? JSON . parse ( state ) : { } ;
}
2013-12-05 00:28:31 +01:00
2015-01-08 16:51:36 +01:00
// Don't store current user in state to allow admins to create favourites for all
// Should make no difference for normal users.
if ( state . owner == egw . user ( 'account_id' ) )
{
// 0 is always the current user, so if an admin creates a default favorite,
// it will work for other users too.
state . owner = 0 ;
}
2016-02-17 20:56:54 +01:00
2015-12-14 21:46:25 +01:00
// Keywords are only for list view
if ( state . view == 'listview' )
{
var listview = app . classes . calendar . views . listview . etemplates [ 0 ] &&
app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer &&
app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
if ( listview && listview . activeFilters && listview . activeFilters . search )
{
state . keywords = listview . activeFilters . search ;
}
}
2015-11-24 17:17:00 +01:00
// Don't store date or first and last
delete state . date ;
2015-06-29 21:16:56 +02:00
delete state . first ;
delete state . last ;
2015-11-24 18:21:37 +01:00
delete state . startdate ;
delete state . enddate ;
delete state . start _date ;
delete state . end _date ;
2016-02-17 20:56:54 +01:00
2013-12-06 22:26:55 +01:00
return state ;
2013-12-05 00:28:31 +01:00
} ,
/ * *
* Set a state previously returned by getState
*
* Called by favorites to set a state saved as favorite .
*
* @ param { object } state containing "name" attribute to be used as "favorite" GET parameter to a nextmatch
* /
2016-01-05 21:43:19 +01:00
setState : function setState ( state )
2013-12-05 00:28:31 +01:00
{
2013-12-06 19:24:29 +01:00
// State should be an object, not a string, but we'll parse
if ( typeof state == "string" )
{
if ( state . indexOf ( '{' ) != - 1 || state == 'null' )
{
state = JSON . parse ( state ) ;
}
}
2015-07-01 00:26:59 +02:00
if ( typeof state . state !== 'object' || ! state . state . view )
2015-06-10 23:51:28 +02:00
{
state . state = { view : 'week' } ;
}
2015-12-22 00:03:42 +01:00
// States with no name (favorites other than No filters) default to
// today. Applying a favorite should keep the current date.
2015-06-10 23:51:28 +02:00
if ( ! state . state . date )
{
2015-12-22 00:03:42 +01:00
state . state . date = state . name ? this . state . date : new Date ( ) ;
2015-06-10 23:51:28 +02:00
}
2015-11-06 19:42:39 +01:00
if ( typeof state . state . weekend == 'undefined' )
{
state . state . weekend = true ;
}
2015-06-15 23:38:03 +02:00
// Hide other views
2015-10-21 21:53:19 +02:00
var view = app . classes . calendar . views [ state . state . view ] ;
2015-07-01 00:26:59 +02:00
for ( var _view in app . classes . calendar . views )
2015-06-15 23:38:03 +02:00
{
2015-07-01 00:26:59 +02:00
if ( state . state . view != _view && app . classes . calendar . views [ _view ] )
2015-06-15 23:38:03 +02:00
{
2015-07-01 00:26:59 +02:00
for ( var i = 0 ; i < app . classes . calendar . views [ _view ] . etemplates . length ; i ++ )
2015-06-15 23:38:03 +02:00
{
2015-10-21 21:53:19 +02:00
if ( typeof app . classes . calendar . views [ _view ] . etemplates [ i ] !== 'string' &&
view . etemplates . indexOf ( app . classes . calendar . views [ _view ] . etemplates [ i ] ) == - 1 )
2015-07-15 18:29:10 +02:00
{
2016-06-02 16:51:15 +02:00
jQuery ( app . classes . calendar . views [ _view ] . etemplates [ i ] . DOMContainer ) . hide ( ) ;
2015-07-15 18:29:10 +02:00
}
2015-06-15 23:38:03 +02:00
}
}
}
2015-06-29 21:16:56 +02:00
if ( this . sidebox _et2 )
{
2016-06-02 16:51:15 +02:00
jQuery ( this . sidebox _et2 . getInstanceManager ( ) . DOMContainer ) . hide ( ) ;
2015-06-29 21:16:56 +02:00
}
2015-07-15 15:16:31 +02:00
2015-10-14 16:32:33 +02:00
// Check for valid cache
2016-02-03 19:27:52 +01:00
var cachable _changes = [ 'date' , 'weekend' , 'view' , 'days' , 'planner_view' , 'sortby' ] ;
2015-11-23 23:57:05 +01:00
var keys = jQuery . unique ( Object . keys ( this . state ) . concat ( Object . keys ( state . state ) ) ) ;
for ( var i = 0 ; i < keys . length ; i ++ )
2015-10-14 16:32:33 +02:00
{
2015-11-23 23:57:05 +01:00
var s = keys [ i ] ;
2015-10-14 16:32:33 +02:00
if ( this . state [ s ] !== state . state [ s ] )
{
if ( cachable _changes . indexOf ( s ) === - 1 )
{
// Expire daywise cache
var daywise = egw . dataKnownUIDs ( app . classes . calendar . DAYWISE _CACHE _ID ) ;
// Can't delete from here, as that would disconnect the existing widgets listening
for ( var i = 0 ; i < daywise . length ; i ++ )
{
egw . dataStoreUID ( app . classes . calendar . DAYWISE _CACHE _ID + '::' + daywise [ i ] , null ) ;
}
break ;
}
}
}
2015-06-10 23:51:28 +02:00
// Check for a supported client-side view
2015-07-01 00:26:59 +02:00
if ( app . classes . calendar . views [ state . state . view ] &&
2015-06-15 23:38:03 +02:00
// Check that the view is instanciated
2015-07-01 00:26:59 +02:00
typeof app . classes . calendar . views [ state . state . view ] . etemplates [ 0 ] !== 'string' && app . classes . calendar . views [ state . state . view ] . etemplates [ 0 ] . widgetContainer
2015-06-15 23:38:03 +02:00
)
2015-06-10 23:51:28 +02:00
{
// Doing an update - this includes the selected view, and the sidebox
// We set a flag to ignore changes from the sidebox which would
// cause infinite loops.
this . state _update _in _progress = true ;
2015-07-15 15:16:31 +02:00
2015-07-15 18:29:10 +02:00
// Sanitize owner so it's always an array
2015-12-08 23:17:44 +01:00
if ( state . state . owner === null || ! state . state . owner ||
( typeof state . state . owner . length != 'undefined' && state . state . owner . length == 0 )
)
2015-08-12 00:30:50 +02:00
{
state . state . owner = undefined ;
}
2015-06-10 23:51:28 +02:00
switch ( typeof state . state . owner )
{
case 'undefined' :
2015-08-12 00:30:50 +02:00
state . state . owner = [ this . egw . user ( 'account_id' ) ] ;
2015-06-10 23:51:28 +02:00
break ;
case 'string' :
state . state . owner = state . state . owner . split ( ',' ) ;
break ;
case 'number' :
state . state . owner = [ state . state . owner ] ;
break ;
2015-07-15 18:29:10 +02:00
case 'object' :
// An array-like Object or an Array?
if ( ! state . state . owner . filter )
{
state . state . owner = jQuery . map ( state . state . owner , function ( owner ) { return owner ; } ) ;
}
2015-06-10 23:51:28 +02:00
}
2016-01-08 23:38:11 +01:00
// Remove duplicates
state . state . owner = state . state . owner . filter ( function ( value , index , self ) {
return self . indexOf ( value ) === index ;
2016-06-13 18:03:52 +02:00
} ) ;
2016-02-11 18:02:06 +01:00
// Make sure they're all strings
state . state . owner = state . state . owner . map ( function ( owner ) { return '' + owner ; } ) ;
2015-06-10 23:51:28 +02:00
// Keep sort order
if ( typeof this . state . owner === 'object' )
{
var owner = [ ] ;
this . state . owner . forEach ( function ( key ) {
var found = false ;
state . state . owner = state . state . owner . filter ( function ( item ) {
if ( ! found && item == key ) {
owner . push ( item ) ;
found = true ;
return false ;
} else
return true ;
} ) ;
} ) ;
// Add in any new owners
state . state . owner = owner . concat ( state . state . owner ) ;
}
2016-01-08 23:38:11 +01:00
if ( state . state . owner . indexOf ( '0' ) >= 0 )
2015-11-20 19:05:27 +01:00
{
2016-01-08 23:38:11 +01:00
state . state . owner [ state . state . owner . indexOf ( '0' ) ] = this . egw . user ( 'account_id' ) ;
2015-11-20 19:05:27 +01:00
}
2013-12-05 00:28:31 +01:00
2015-06-10 23:51:28 +02:00
// Show the correct number of grids
2015-12-23 00:34:53 +01:00
var grid _count = 0 ;
switch ( state . state . view )
{
case 'day' :
2016-06-13 18:03:52 +02:00
grid _count = 1 ;
2015-12-23 00:34:53 +01:00
break ;
2016-03-29 16:52:40 +02:00
case 'day4' :
2015-12-23 00:34:53 +01:00
case 'week' :
2015-12-28 17:55:51 +01:00
grid _count = state . state . owner . length >= parseInt ( this . egw . preference ( 'week_consolidate' , 'calendar' ) ) ? 1 : state . state . owner . length ;
2015-12-23 00:34:53 +01:00
break ;
case 'weekN' :
grid _count = parseInt ( this . egw . preference ( 'multiple_weeks' , 'calendar' ) ) || 3 ;
break ;
// Month is calculated individually for the month
}
2016-02-17 20:56:54 +01:00
2015-07-01 00:26:59 +02:00
var grid = view . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'view' ) ;
2015-06-10 23:51:28 +02:00
2016-04-21 21:00:21 +02:00
// Show the templates for the current view
// Needs to be visible while updating so sizing works
for ( var i = 0 ; i < view . etemplates . length ; i ++ )
{
2016-06-02 16:51:15 +02:00
jQuery ( view . etemplates [ i ] . DOMContainer ) . show ( ) ;
2016-04-21 21:00:21 +02:00
}
2016-04-27 12:36:59 +02:00
2015-06-10 23:51:28 +02:00
/ *
2016-01-05 21:43:19 +01:00
If the count is different , we need to have the correct number
2015-06-10 23:51:28 +02:00
If the count is > 1 , it ' s either because there are multiple date spans ( weekN , month ) and we need the correct span
per row , or there are multiple owners and we need the correct owner per row .
* /
2016-01-05 21:43:19 +01:00
if ( grid )
2015-06-10 23:51:28 +02:00
{
2016-06-22 17:56:16 +02:00
// Show loading div to hide redrawing
egw . loading _prompt (
this . appname , true , egw . lang ( 'please wait...' ) ,
typeof framework !== 'undefined' ? framework . applications . calendar . tab . contentDiv : false ,
egwIsMobile ( ) ? 'horizental' : 'spinner'
) ;
var loading = false ;
2016-06-25 12:28:52 +02:00
2016-06-22 17:56:16 +02:00
2015-06-10 23:51:28 +02:00
var value = [ ] ;
2015-07-01 00:26:59 +02:00
state . state . first = view . start _date ( state . state ) . toJSON ( ) ;
2015-06-25 19:44:28 +02:00
// We'll modify this one, so it needs to be a new object
var date = new Date ( state . state . first ) ;
2015-06-10 23:51:28 +02:00
2016-01-22 01:22:08 +01:00
// Hide all but the first day header
2016-06-02 16:51:15 +02:00
jQuery ( grid . getDOMNode ( ) ) . toggleClass (
2016-03-29 16:52:40 +02:00
'hideDayColHeader' ,
state . state . view == 'week' || state . state . view == 'day4'
) ;
2016-02-17 20:56:54 +01:00
2016-01-05 21:43:19 +01:00
// Determine the different end date & varying values
2015-06-10 23:51:28 +02:00
switch ( state . state . view )
{
case 'month' :
2015-07-01 00:26:59 +02:00
var end = state . state . last = view . end _date ( state . state ) ;
2015-06-10 23:51:28 +02:00
grid _count = Math . ceil ( ( end - date ) / ( 1000 * 60 * 60 * 24 ) / 7 ) ;
// fall through
case 'weekN' :
for ( var week = 0 ; week < grid _count ; week ++ )
{
var val = {
2016-01-05 21:43:19 +01:00
id : app . classes . calendar . _daywise _cache _id ( date , state . state . owner ) ,
2015-10-29 20:47:01 +01:00
start _date : date . toJSON ( ) ,
end _date : new Date ( date . toJSON ( ) ) ,
2015-06-10 23:51:28 +02:00
owner : state . state . owner
} ;
val . end _date . setUTCHours ( 24 * 7 - 1 ) ;
2016-01-05 21:43:19 +01:00
val . end _date . setUTCMinutes ( 59 ) ;
val . end _date . setUTCSeconds ( 59 ) ;
2015-10-29 20:47:01 +01:00
val . end _date = val . end _date . toJSON ( ) ;
2015-06-10 23:51:28 +02:00
value . push ( val ) ;
date . setUTCHours ( 24 * 7 ) ;
}
2015-07-15 18:29:10 +02:00
state . state . last = val . end _date ;
2015-06-10 23:51:28 +02:00
break ;
2016-01-05 21:43:19 +01:00
case 'day' :
var end = state . state . last = view . end _date ( state . state ) . toJSON ( ) ;
2016-01-15 23:43:59 +01:00
value . push ( {
2016-01-05 21:43:19 +01:00
id : app . classes . calendar . _daywise _cache _id ( date , state . state . owner ) ,
2016-01-15 23:43:59 +01:00
start _date : state . state . first ,
end _date : state . state . last ,
owner : view . owner ( state . state )
} ) ;
2016-01-05 21:43:19 +01:00
break ;
2015-06-10 23:51:28 +02:00
default :
2015-10-29 20:47:01 +01:00
var end = state . state . last = view . end _date ( state . state ) . toJSON ( ) ;
2015-06-10 23:51:28 +02:00
for ( var owner = 0 ; owner < grid _count && owner < state . state . owner . length ; owner ++ )
{
2016-06-13 18:03:52 +02:00
var _owner = grid _count > 1 ? state . state . owner [ owner ] || 0 : state . state . owner ;
2015-06-10 23:51:28 +02:00
value . push ( {
2016-01-05 21:43:19 +01:00
id : app . classes . calendar . _daywise _cache _id ( date , _owner ) ,
2015-06-10 23:51:28 +02:00
start _date : date ,
end _date : end ,
2016-01-05 21:43:19 +01:00
owner : _owner
2015-06-10 23:51:28 +02:00
} ) ;
}
break ;
}
2015-07-15 18:29:10 +02:00
// If we have cached data for the timespan, pass it along
2016-01-15 23:43:59 +01:00
// Single day with multiple owners still needs owners split to satisfy
// caching keys, otherwise they'll fetch & cache consolidated
if ( state . state . view == 'day' && state . state . owner . length < parseInt ( this . egw . preference ( 'day_consolidate' , 'calendar' ) ) )
{
2016-03-01 17:27:45 +01:00
var day _value = [ ] ;
2016-01-15 23:43:59 +01:00
for ( var i = 0 ; i < state . state . owner . length ; i ++ )
{
day _value . push ( {
start _date : state . state . first ,
end _date : state . state . last ,
owner : state . state . owner [ i ]
} ) ;
}
2016-06-22 17:56:16 +02:00
loading = this . _need _data ( day _value , state . state ) ;
2016-01-15 23:43:59 +01:00
}
else
{
2016-06-22 17:56:16 +02:00
loading = this . _need _data ( value , state . state ) ;
2016-01-15 23:43:59 +01:00
}
2015-08-06 19:12:34 +02:00
2016-01-05 21:43:19 +01:00
var row _index = 0 ;
2016-02-17 20:56:54 +01:00
2016-01-05 21:43:19 +01:00
// Find any matching, existing rows - they can be kept
grid . iterateOver ( function ( widget ) {
for ( var i = 0 ; i < value . length ; i ++ )
{
if ( widget . id == value [ i ] . id )
2015-08-06 19:12:34 +02:00
{
2016-01-05 21:43:19 +01:00
// Keep it, but move it
if ( i > row _index )
{
for ( var j = i - row _index ; j > 0 ; j -- )
{
// Move from the end to the start
grid . _children . unshift ( grid . _children . pop ( ) ) ;
2015-08-19 02:08:22 +02:00
2016-01-05 21:43:19 +01:00
// Swap DOM nodes
var a = grid . _children [ 0 ] . getDOMNode ( ) . parentNode . parentNode ;
2016-06-02 16:51:15 +02:00
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( ) ;
2016-01-05 21:43:19 +01:00
var b = grid . _children [ 1 ] . getDOMNode ( ) . parentNode . parentNode ;
a . parentNode . insertBefore ( a , b ) ;
2016-04-27 12:36:59 +02:00
2016-04-21 21:00:21 +02:00
// Moving nodes changes scrolling, so set it back
2016-06-02 16:51:15 +02:00
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( a _scroll ) ;
2016-01-05 21:43:19 +01:00
}
}
else if ( row _index > i )
{
2016-01-08 23:38:11 +01:00
// Swap DOM nodes
var a = grid . _children [ row _index ] . getDOMNode ( ) . parentNode . parentNode ;
2016-06-02 16:51:15 +02:00
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( ) ;
2016-01-08 23:38:11 +01:00
var b = grid . _children [ i ] . getDOMNode ( ) . parentNode . parentNode ;
2016-04-21 21:00:21 +02:00
// Simple scroll forward, put top on the bottom
// This makes it faster if they scroll back next
if ( i == 0 && row _index == 1 )
{
2016-06-02 16:51:15 +02:00
jQuery ( b ) . appendTo ( b . parentNode ) ;
2016-04-21 21:00:21 +02:00
grid . _children . push ( grid . _children . shift ( ) ) ;
}
else
{
grid . _children . splice ( i , 0 , widget ) ;
grid . _children . splice ( row _index + 1 , 1 ) ;
a . parentNode . insertBefore ( a , b ) ;
}
// Moving nodes changes scrolling, so set it back
2016-06-02 16:51:15 +02:00
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( a _scroll ) ;
2016-01-05 21:43:19 +01:00
}
break ;
2015-08-19 02:08:22 +02:00
}
2016-01-05 21:43:19 +01:00
}
row _index ++ ;
} , this , et2 _calendar _view ) ;
row _index = 0 ;
// Set rows that need it
grid . iterateOver ( function ( widget ) {
if ( row _index < value . length )
{
widget . set _disabled ( false ) ;
}
else
{
widget . set _disabled ( true ) ;
return ;
}
if ( widget . set _show _weekend )
{
widget . set _show _weekend ( view . show _weekend ( state . state ) ) ;
}
2016-01-13 00:55:59 +01:00
if ( widget . set _granularity )
{
2016-04-26 00:09:57 +02:00
if ( widget . loader ) widget . loader . show ( ) ;
2016-01-13 00:55:59 +01:00
widget . set _granularity ( view . granularity ( state . state ) ) ;
}
2016-01-05 21:43:19 +01:00
if ( widget . id == value [ row _index ] . id &&
2016-04-21 21:00:21 +02:00
widget . get _end _date ( ) . getUTCFullYear ( ) == value [ row _index ] . end _date . substring ( 0 , 4 ) &&
widget . get _end _date ( ) . getUTCMonth ( ) + 1 == value [ row _index ] . end _date . substring ( 5 , 7 ) &&
widget . get _end _date ( ) . getUTCDate ( ) == value [ row _index ] . end _date . substring ( 8 , 10 )
2016-01-05 21:43:19 +01:00
)
{
// Do not need to re-set this row, but we do need to re-do
// the times, as they may have changed
2016-04-21 21:00:21 +02:00
widget . resizeTimes ( ) ;
2016-09-01 18:36:43 +02:00
window . setTimeout ( jQuery . proxy ( widget . set _header _classes , widget ) , 0 ) ;
2016-04-27 12:36:59 +02:00
2016-04-21 21:00:21 +02:00
// Hide loader
widget . loader . hide ( ) ;
2016-01-05 21:43:19 +01:00
row _index ++ ;
return ;
}
if ( widget . set _value )
{
widget . set _value ( value [ row _index ++ ] ) ;
}
} , this , et2 _calendar _view ) ;
2015-06-10 23:51:28 +02:00
}
2016-04-28 00:50:56 +02:00
else if ( state . state . view !== 'listview' )
2015-06-10 23:51:28 +02:00
{
2016-01-05 21:43:19 +01:00
// Simple, easy case - just one widget for the selected time span. (planner)
2015-06-10 23:51:28 +02:00
// Update existing view's special attribute filters, defined in the view list
for ( var updater in view )
{
if ( typeof view [ updater ] === 'function' )
{
var value = view [ updater ] . call ( this , state . state ) ;
2015-07-01 00:26:59 +02:00
if ( updater === 'start_date' ) state . state . first = this . date . toString ( value ) ;
if ( updater === 'end_date' ) state . state . last = this . date . toString ( value ) ;
2015-06-10 23:51:28 +02:00
// Set value
for ( var i = 0 ; i < view . etemplates . length ; i ++ )
{
view . etemplates [ i ] . widgetContainer . iterateOver ( function ( widget ) {
2015-07-01 00:26:59 +02:00
if ( typeof widget [ 'set_' + updater ] === 'function' )
2015-06-10 23:51:28 +02:00
{
2016-02-11 18:02:06 +01:00
widget [ 'set_' + updater ] ( value ) ;
2015-06-10 23:51:28 +02:00
}
2015-12-28 23:21:47 +01:00
} , this , et2 _calendar _view ) ;
2015-06-10 23:51:28 +02:00
}
}
}
2015-07-15 18:29:10 +02:00
var value = [ { start _date : state . state . first , end _date : state . state . last } ] ;
2016-06-22 17:56:16 +02:00
loading = this . _need _data ( value , state . state ) ;
2015-06-10 23:51:28 +02:00
}
2015-06-15 23:38:03 +02:00
// Include first & last dates in state, mostly for server side processing
2015-07-15 15:16:31 +02:00
if ( state . state . first && state . state . first . toJSON ) state . state . first = state . state . first . toJSON ( ) ;
if ( state . state . last && state . state . last . toJSON ) state . state . last = state . state . last . toJSON ( ) ;
2015-06-10 23:51:28 +02:00
// Toggle todos
2016-06-02 16:51:15 +02:00
if ( ( state . state . view == 'day' || this . state . view == 'day' ) && jQuery ( view . etemplates [ 0 ] . DOMContainer ) . is ( ':visible' ) )
2015-06-10 23:51:28 +02:00
{
2016-04-18 16:05:24 +02:00
if ( state . state . view == 'day' && state . state . owner . length === 1 && ! isNaN ( state . state . owner ) && state . state . owner [ 0 ] >= 0 && ! egwIsMobile ( ) )
2015-06-10 23:51:28 +02:00
{
2016-05-04 18:45:42 +02:00
view . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( w ) {
2016-06-02 16:51:15 +02:00
w . set _width ( jQuery ( view . etemplates [ 0 ] . DOMContainer ) . width ( ) * 0.69 ) ;
2016-05-04 18:45:42 +02:00
} , this , et2 _calendar _timegrid ) ;
2016-06-02 16:51:15 +02:00
jQuery ( view . etemplates [ 1 ] . DOMContainer ) . css ( { "left" : "69%" , "height" : ( jQuery ( framework . tabsUi . activeTab . contentDiv ) . height ( ) - 30 ) + 'px' } ) ;
2016-05-04 18:45:42 +02:00
// TODO: Maybe some caching here
this . egw . jsonq ( 'calendar_uiviews::ajax_get_todos' , [ state . state . date , state . state . owner [ 0 ] ] , function ( data ) {
this . getWidgetById ( 'label' ) . set _value ( data . label || '' ) ;
this . getWidgetById ( 'todos' ) . set _value ( { content : data . todos || '' } ) ;
} , view . etemplates [ 1 ] . widgetContainer ) ;
view . etemplates [ 0 ] . resize ( ) ;
2015-06-10 23:51:28 +02:00
}
2015-08-12 18:37:02 +02:00
else
{
2016-06-02 16:51:15 +02:00
jQuery ( app . classes . calendar . views . day . etemplates [ 1 ] . DOMContainer ) . css ( "left" , "100%" ) ;
2016-07-04 17:17:34 +02:00
jQuery ( app . classes . calendar . views . day . etemplates [ 1 ] . DOMContainer ) . hide ( ) ;
2016-06-02 16:51:15 +02:00
jQuery ( app . classes . calendar . views . day . etemplates [ 0 ] . DOMContainer ) . css ( "width" , "100%" ) ;
2015-11-13 00:10:16 +01:00
view . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( w ) {
w . set _width ( '100%' ) ;
} , this , et2 _calendar _timegrid ) ;
2015-08-12 18:37:02 +02:00
}
2015-06-10 23:51:28 +02:00
}
2016-06-02 16:51:15 +02:00
else if ( jQuery ( view . etemplates [ 0 ] . DOMContainer ) . is ( ':visible' ) )
2015-06-10 23:51:28 +02:00
{
2016-06-02 16:51:15 +02:00
jQuery ( view . etemplates [ 0 ] . DOMContainer ) . css ( "width" , "" ) ;
2015-12-23 22:09:02 +01:00
view . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( w ) {
w . set _width ( '100%' ) ;
} , this , et2 _calendar _timegrid ) ;
2015-06-10 23:51:28 +02:00
}
2015-11-13 00:10:16 +01:00
2015-07-15 18:29:10 +02:00
// List view (nextmatch) has slightly different fields
2015-06-10 23:51:28 +02:00
if ( state . state . view === 'listview' )
{
state . state . startdate = state . state . date ;
2015-11-24 18:21:37 +01:00
if ( state . state . startdate . toJSON )
{
state . state . startdate = state . state . startdate . toJSON ( ) ;
}
2015-10-05 20:27:19 +02:00
if ( state . state . end _date )
{
state . state . enddate = state . state . end _date ;
}
2015-11-24 18:21:37 +01:00
if ( state . state . enddate && state . state . enddate . toJSON )
{
state . state . enddate = state . state . enddate . toJSON ( ) ;
}
2015-06-10 23:51:28 +02:00
state . state . col _filter = { participant : state . state . owner } ;
2016-03-30 01:34:45 +02:00
state . state . search = state . state . keywords ? state . state . keywords : state . state . search ;
2015-07-15 18:29:10 +02:00
2015-09-07 19:13:20 +02:00
2015-07-01 00:26:59 +02:00
var nm = view . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
2015-11-24 18:21:37 +01:00
// 'Custom' filter needs an end date
if ( nm . activeFilters . filter === 'custom' && ! state . state . end _date )
{
state . state . enddate = state . state . last ;
}
if ( state . state . enddate && state . state . startdate && state . state . startdate > state . state . enddate )
{
state . state . enddate = state . state . startdate ;
}
2015-06-10 23:51:28 +02:00
nm . applyFilters ( state . state ) ;
2015-12-02 18:34:06 +01:00
2015-12-10 01:40:04 +01:00
// Try to keep last value up to date with what's in nextmatch
if ( nm . activeFilters . enddate )
{
this . state . last = nm . activeFilters . enddate ;
}
2015-10-16 19:32:21 +02:00
// Updates the display of start & end date
this . filter _change ( ) ;
2015-06-10 23:51:28 +02:00
}
2015-11-23 16:51:13 +01:00
else
{
// Turn off nextmatch's automatic stuff - it won't work while it
// is hidden, and can cause an infinite loop as it tries to layout.
// (It will automatically re-start when shown)
try
{
var nm = app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
nm . controller . _grid . doInvalidate = false ;
} catch ( e ) { }
2016-01-15 00:23:22 +01:00
// Other views do not search
delete state . state . keywords ;
2015-11-23 16:51:13 +01:00
}
2015-12-14 21:46:25 +01:00
this . state = jQuery . extend ( { } , state . state ) ;
2015-06-10 23:51:28 +02:00
/* Update re-orderable calendars */
this . _sortable ( ) ;
2015-07-15 15:16:31 +02:00
2015-06-10 23:51:28 +02:00
/* Update sidebox widgets to show current value*/
2015-12-14 23:08:12 +01:00
if ( this . sidebox _hooked _templates . length )
2015-07-15 18:29:10 +02:00
{
2015-12-14 23:08:12 +01:00
for ( var j = 0 ; j < this . sidebox _hooked _templates . length ; j ++ )
{
var sidebox = this . sidebox _hooked _templates [ j ] ;
// Remove any destroyed or not valid templates
if ( ! sidebox . getInstanceManager || ! sidebox . getInstanceManager ( ) )
2015-06-10 23:51:28 +02:00
{
2015-12-14 23:08:12 +01:00
this . sidebox _hooked _templates . splice ( j , 1 , 0 ) ;
continue ;
}
sidebox . iterateOver ( function ( widget ) {
if ( widget . id == 'view' )
2015-06-10 23:51:28 +02:00
{
2015-12-14 23:08:12 +01:00
// View widget has a list of state settings, which require special handling
for ( var i = 0 ; i < widget . options . select _options . length ; i ++ )
2015-07-15 18:29:10 +02:00
{
2015-12-14 23:08:12 +01:00
var option _state = JSON . parse ( widget . options . select _options [ i ] . value ) || [ ] ;
var match = true ;
for ( var os _key in option _state )
{
// Sometimes an optional state variable is not yet defined (sortby, days, etc)
match = match && ( option _state [ os _key ] == this . state [ os _key ] || typeof this . state [ os _key ] == 'undefined' ) ;
}
if ( match )
{
widget . set _value ( widget . options . select _options [ i ] . value ) ;
return ;
}
2015-07-15 18:29:10 +02:00
}
2015-06-10 23:51:28 +02:00
}
2015-12-14 23:08:12 +01:00
else if ( widget . id == 'keywords' )
{
widget . set _value ( '' ) ;
}
else if ( typeof state . state [ widget . id ] !== 'undefined' && state . state [ widget . id ] != widget . getValue ( ) )
2015-10-16 19:32:21 +02:00
{
2015-12-14 23:08:12 +01:00
// Update widget. This may trigger an infinite loop of
// updates, so we do it after changing this.state and set a flag
try
{
widget . set _value ( state . state [ widget . id ] ) ;
}
catch ( e )
{
widget . set _value ( '' ) ;
}
2015-10-16 19:32:21 +02:00
}
2015-12-14 23:08:12 +01:00
else if ( widget . instanceOf ( et2 _inputWidget ) && typeof state . state [ widget . id ] == 'undefined' )
2015-10-16 19:32:21 +02:00
{
2015-12-14 23:08:12 +01:00
// No value, clear it
2015-10-16 19:32:21 +02:00
widget . set _value ( '' ) ;
}
2015-12-14 23:08:12 +01:00
} , this , et2 _valueWidget ) ;
}
2015-07-15 18:29:10 +02:00
}
2015-06-10 23:51:28 +02:00
2015-06-29 21:16:56 +02:00
// If current state matches a favorite, hightlight it
this . highlight _favorite ( ) ;
2015-10-20 01:08:16 +02:00
// Update app header
2016-01-06 19:24:45 +01:00
this . set _app _header ( view . header ( state . state ) ) ;
2015-10-20 01:08:16 +02:00
2016-05-10 21:41:28 +02:00
// Reset auto-refresh timer
this . _set _autorefresh ( ) ;
2015-06-10 23:51:28 +02:00
// Sidebox is updated, we can clear the flag
this . state _update _in _progress = false ;
2015-09-09 22:59:23 +02:00
// Update saved state in preferences
var save = { } ;
for ( var i = 0 ; i < this . states _to _save . length ; i ++ )
{
save [ this . states _to _save [ i ] ] = this . state [ this . states _to _save [ i ] ] ;
}
egw . set _preference ( 'calendar' , 'saved_states' , save ) ;
2016-06-22 17:56:16 +02:00
// Trigger resize to get correct sizes, as they may have sized while
// hidden
for ( var i = 0 ; i < view . etemplates . length ; i ++ )
{
view . etemplates [ i ] . resize ( ) ;
}
2016-06-25 12:28:52 +02:00
2016-06-22 17:56:16 +02:00
// If we need to fetch data from the server, it will hide the loader
// when done but if everything is in the cache, hide from here.
if ( ! loading )
{
window . setTimeout ( jQuery . proxy ( function ( ) {
egw . loading _prompt ( this . appname , false ) ;
} , this ) , 500 ) ;
}
2016-06-25 12:28:52 +02:00
2015-06-10 23:51:28 +02:00
return ;
}
2013-12-05 00:28:31 +01:00
// old calendar state handling on server-side (incl. switching to and from listview)
var menuaction = 'calendar.calendar_uiviews.index' ;
2014-02-25 00:50:51 +01:00
if ( typeof state . state != 'undefined' && ( typeof state . state . view == 'undefined' || state . state . view == 'listview' ) )
2013-12-05 00:28:31 +01:00
{
2014-02-26 14:35:27 +01:00
if ( state . name )
{
// 'blank' is the special name for no filters, send that instead of the nice translated name
state . state . favorite = jQuery . isEmptyObject ( state ) || jQuery . isEmptyObject ( state . state || state . filter ) ? 'blank' : state . name . replace ( /[^A-Za-z0-9-_]/g , '_' ) ;
2014-02-28 11:51:33 +01:00
// set date for "No Filter" (blank) favorite to todays date
if ( state . state . favorite == 'blank' )
state . state . date = jQuery . datepicker . formatDate ( 'yymmdd' , new Date ) ;
2014-02-26 14:35:27 +01:00
}
menuaction = 'calendar.calendar_uilist.listview' ;
state . state . ajax = 'true' ;
2014-01-24 10:47:33 +01:00
// check if we already use et2 / are in listview
2014-01-30 19:24:24 +01:00
if ( this . et2 || etemplate2 && etemplate2 . getByApplication ( 'calendar' ) )
2014-01-24 10:47:33 +01:00
{
// current calendar-code can set regular calendar states only via a server-request :(
// --> check if we only need to set something which can be handeled by nm internally
// or we need a redirect
// ToDo: pass them via nm's get_rows call to server (eg. by passing state), so we dont need a redirect
var current _state = this . getState ( ) ;
var need _redirect = false ;
for ( var attr in current _state )
{
switch ( attr )
{
case 'cat_id' :
case 'owner' :
case 'filter' :
if ( state . state [ attr ] != current _state [ attr ] )
{
need _redirect = true ;
2014-02-26 14:35:27 +01:00
// reset of attributes managed on server-side
if ( state . state . favorite === 'blank' )
{
switch ( attr )
{
case 'cat_id' :
state . state . cat _id = 0 ;
break ;
case 'owner' :
state . state . owner = egw . user ( 'account_id' ) ;
break ;
case 'filter' :
state . state . filter = 'default' ;
break ;
}
}
2014-01-24 10:47:33 +01:00
break ;
}
break ;
2014-02-26 14:35:27 +01:00
case 'view' :
// "No filter" (blank) favorite: if not in listview --> stay in that view
if ( state . state . favorite === 'blank' && current _state . view != 'listview' )
{
menuaction = 'calendar.calendar_uiviews.index' ;
delete state . state . ajax ;
need _redirect = true ;
}
2014-01-24 10:47:33 +01:00
}
}
if ( ! need _redirect )
{
return this . _super . apply ( this , [ state ] ) ;
}
}
2013-12-05 00:28:31 +01:00
}
2014-01-30 17:55:02 +01:00
// setting internal state now, that linkHandler does not intercept switching from listview to any old view
2015-06-15 23:38:03 +02:00
this . state = jQuery . extend ( { } , state . state ) ;
2015-07-01 00:26:59 +02:00
if ( this . sidebox _et2 )
{
2016-06-02 16:51:15 +02:00
jQuery ( this . sidebox _et2 . getInstanceManager ( ) . DOMContainer ) . show ( ) ;
2015-07-01 00:26:59 +02:00
}
2014-01-30 17:55:02 +01:00
2013-12-12 00:51:35 +01:00
var query = jQuery . extend ( { menuaction : menuaction } , state . state || { } ) ;
2013-12-12 04:42:08 +01:00
2013-12-12 00:51:35 +01:00
// prepend an owner 0, to reset all owners and not just set given resource type
if ( typeof query . owner != 'undefined' )
2013-12-05 00:28:31 +01:00
{
2015-10-16 19:32:21 +02:00
query . owner = '0,' + ( typeof query . owner == 'object' ? query . owner . join ( ',' ) : ( '' + query . owner ) . replace ( '0,' , '' ) ) ;
2013-12-05 00:28:31 +01:00
}
2013-12-12 00:51:35 +01:00
2013-12-12 04:42:08 +01:00
this . egw . open _link ( this . egw . link ( '/index.php' , query ) , 'calendar' ) ;
2013-12-12 00:51:35 +01:00
// Stop the normal bubbling if this is called on click
return false ;
2014-03-11 11:45:02 +01:00
} ,
2014-06-06 13:59:20 +02:00
2015-06-10 23:51:28 +02:00
/ * *
* Check to see if any of the selected is an event widget
* Used to separate grid actions from event actions
2015-07-15 15:16:31 +02:00
*
* @ param { egwAction } _action
* @ param { egwActioObject [ ] } _selected
2015-06-10 23:51:28 +02:00
* @ returns { boolean } Is any of the selected an event widget
* /
is _event : function ( _action , _selected )
{
var is _widget = false ;
for ( var i = 0 ; i < _selected . length ; i ++ )
{
if ( _selected [ i ] . iface . getWidget ( ) && _selected [ i ] . iface . getWidget ( ) . instanceOf ( et2 _calendar _event ) )
{
is _widget = true ;
}
2015-06-25 19:44:28 +02:00
// Also check classes, usually indicating permission
if ( _action . data && _action . data . enableClass )
{
2016-06-02 16:51:15 +02:00
is _widget = is _widget && ( jQuery ( _selected [ i ] . iface . getDOMNode ( ) ) . hasClass ( _action . data . enableClass ) ) ;
2015-06-25 19:44:28 +02:00
}
if ( _action . data && _action . data . disableClass )
{
2016-06-02 16:51:15 +02:00
is _widget = is _widget && ! ( jQuery ( _selected [ i ] . iface . getDOMNode ( ) ) . hasClass ( _action . data . disableClass ) ) ;
2015-06-25 19:44:28 +02:00
}
2015-06-10 23:51:28 +02:00
}
return is _widget ;
} ,
2014-05-27 17:02:56 +02:00
/ * *
* Enable / Disable custom Date - time for set Alarm
*
2014-06-06 13:59:20 +02:00
* @ param { egw object } _egw
2014-05-27 17:02:56 +02:00
* @ param { widget object } _widget new _alarm [ options ] selectbox
* /
alarm _custom _date : function ( _egw , _widget )
{
var alarm _date = this . et2 . getWidgetById ( 'new_alarm[date]' ) ;
var alarm _options = _widget || this . et2 . getWidgetById ( 'new_alarm[options]' ) ;
var start = this . et2 . getWidgetById ( 'start' ) ;
2014-06-06 13:59:20 +02:00
if ( alarm _date && alarm _options
2014-05-27 17:02:56 +02:00
&& start )
{
if ( alarm _options . get _value ( ) != '0' )
{
alarm _date . set _class ( 'calendar_alarm_date_display' ) ;
}
else
{
alarm _date . set _class ( '' ) ;
}
2014-09-23 15:49:22 +02:00
var startDate = typeof start . get _value != 'undefined' ? start . get _value ( ) : start . value ;
2014-05-27 17:02:56 +02:00
if ( startDate )
{
2014-08-21 14:43:14 +02:00
var date = new Date ( startDate ) ;
2014-08-21 15:31:10 +02:00
date . setTime ( date . getTime ( ) - 1000 * parseInt ( alarm _options . get _value ( ) ) ) ;
2014-05-27 17:02:56 +02:00
alarm _date . set _value ( date ) ;
}
}
2014-05-28 17:04:06 +02:00
} ,
2014-06-06 13:59:20 +02:00
2014-05-28 17:04:06 +02:00
/ * *
2014-06-06 13:59:20 +02:00
* Set alarm options based on WD / Regular event user preferences
2014-05-28 17:04:06 +02:00
* Gets fired by wholeday checkbox
2014-06-06 13:59:20 +02:00
*
* @ param { egw object } _egw
2014-05-28 17:04:06 +02:00
* @ param { widget object } _widget whole _day checkbox
* /
set _alarmOptions _WD : function ( _egw , _widget )
{
2014-06-06 13:59:20 +02:00
var alarm = this . et2 . getWidgetById ( 'alarm' ) ;
if ( ! alarm ) return ; // no default alarm
2014-06-05 18:07:59 +02:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var start = this . et2 . getWidgetById ( 'start' ) ;
var self = this ;
var time = alarm . cells [ 1 ] [ 0 ] . widget ;
var event = alarm . cells [ 1 ] [ 1 ] . widget ;
2014-05-28 17:04:06 +02:00
// Convert a seconds of time to a translated label
var _secs _to _label = function ( _secs )
{
var label = '' ;
if ( _secs <= 3600 )
{
label = self . egw . lang ( '%1 minutes' , _secs / 60 ) ;
}
else if ( _secs <= 86400 )
{
label = self . egw . lang ( '%1 hours' , _secs / 3600 ) ;
}
return label ;
2014-06-06 13:59:20 +02:00
} ;
if ( typeof content [ 'alarm' ] [ 1 ] [ 'default' ] == 'undefined' )
2014-05-28 17:04:06 +02:00
{
2014-06-06 13:59:20 +02:00
// user deleted alarm --> nothing to do
2014-05-28 17:04:06 +02:00
}
else
{
2014-06-06 13:59:20 +02:00
var def _alarm = this . egw . preference ( _widget . get _value ( ) === "true" ?
'default-alarm-wholeday' : 'default-alarm' , 'calendar' ) ;
if ( ! def _alarm && def _alarm !== 0 ) // no alarm
{
jQuery ( '#calendar-edit_alarm > tbody :nth-child(1)' ) . hide ( ) ;
}
else
{
jQuery ( '#calendar-edit_alarm > tbody :nth-child(1)' ) . show ( ) ;
2014-09-05 12:34:37 +02:00
start . set _hours ( 0 ) ;
start . set _minutes ( 0 ) ;
time . set _value ( start . get _value ( ) ) ;
time . set _value ( '-' + ( 60 * def _alarm ) ) ;
2014-06-06 13:59:20 +02:00
event . set _value ( _secs _to _label ( 60 * def _alarm ) ) ;
}
2014-05-28 17:04:06 +02:00
}
2015-06-10 23:51:28 +02:00
} ,
2016-02-22 16:43:03 +01:00
/ * *
* Clear all calendar data from egw . data cache
* /
_clear _cache : function ( ) {
// Full refresh, clear the caches
var events = egw . dataKnownUIDs ( 'calendar' ) ;
for ( var i = 0 ; i < events . length ; i ++ )
{
egw . dataDeleteUID ( 'calendar::' + events [ i ] ) ;
}
var daywise = egw . dataKnownUIDs ( app . classes . calendar . DAYWISE _CACHE _ID ) ;
for ( var i = 0 ; i < daywise . length ; i ++ )
{
// Empty to clear existing widgets
egw . dataStoreUID ( app . classes . calendar . DAYWISE _CACHE _ID + '::' + daywise [ i ] , null ) ;
}
} ,
2015-07-15 18:29:10 +02:00
/ * *
* Take the date range ( s ) in the value and decide if we need to fetch data
* for the date ranges , or if they ' re already cached fill them in .
*
2015-12-28 23:21:47 +01:00
* @ param { Object } value
* @ param { Object } state
2016-06-22 17:56:16 +02:00
*
* @ return { boolean } Data was requested
2015-07-15 18:29:10 +02:00
* /
_need _data : function ( value , state )
{
var need _data = false ;
// Determine if we're showing multiple owners seperate or consolidated
var seperate _owners = false ;
2015-08-25 02:00:45 +02:00
var last _owner = value . length ? value [ 0 ] . owner || 0 : 0 ;
2015-07-15 18:29:10 +02:00
for ( var i = 0 ; i < value . length && ! seperate _owners ; i ++ )
{
2016-06-13 18:03:52 +02:00
seperate _owners = seperate _owners || ( last _owner !== value [ i ] . owner ) ;
2015-07-15 18:29:10 +02:00
}
for ( var i = 0 ; i < value . length ; i ++ )
{
var t = new Date ( value [ i ] . start _date ) ;
var end = new Date ( value [ i ] . end _date ) ;
do
{
// Cache is by date (and owner, if seperate)
var date = t . getUTCFullYear ( ) + sprintf ( '%02d' , t . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , t . getUTCDate ( ) ) ;
2015-11-18 18:44:22 +01:00
var cache _id = app . classes . calendar . _daywise _cache _id ( date , seperate _owners && value [ i ] . owner ? value [ i ] . owner : state . owner || false ) ;
2015-07-15 18:29:10 +02:00
if ( egw . dataHasUID ( cache _id ) )
{
var c = egw . dataGetUIDdata ( cache _id ) ;
if ( c . data && c . data !== null )
{
// There is data, pass it along now
value [ i ] [ date ] = [ ] ;
for ( var j = 0 ; j < c . data . length ; j ++ )
{
if ( egw . dataHasUID ( 'calendar::' + c . data [ j ] ) )
{
value [ i ] [ date ] . push ( egw . dataGetUIDdata ( 'calendar::' + c . data [ j ] ) . data ) ;
}
else
{
need _data = true ;
}
}
}
else
{
need _data = true ;
// Assume it's empty, if there is data it will be filled later
egw . dataStoreUID ( cache _id , [ ] ) ;
}
}
else
{
need _data = true ;
// Assume it's empty, if there is data it will be filled later
egw . dataStoreUID ( cache _id , [ ] ) ;
}
t . setUTCDate ( t . getUTCDate ( ) + 1 ) ;
}
while ( t < end ) ;
2015-09-07 19:13:20 +02:00
2015-07-15 18:29:10 +02:00
// Some data is missing for the current owner, go get it
if ( need _data && seperate _owners )
{
2015-12-03 21:44:52 +01:00
this . _fetch _data (
jQuery . extend ( { } , state , { owner : value [ i ] . owner } ) ,
this . sidebox _et2 ? null : this . et2 . getInstanceManager ( )
) ;
2016-07-06 21:18:36 +02:00
need _data = false ;
2015-07-15 18:29:10 +02:00
}
}
// Some data was missing, go get it
if ( need _data && ! seperate _owners )
{
2015-12-03 21:44:52 +01:00
this . _fetch _data (
state ,
this . sidebox _et2 ? null : this . et2 . getInstanceManager ( )
) ;
2015-07-15 18:29:10 +02:00
}
2016-06-22 17:56:16 +02:00
return need _data ;
2015-07-15 18:29:10 +02:00
} ,
/ * *
* Use the egw . data system to get data from the calendar list for the
* selected time span .
*
* As long as the other filters are the same ( category , owner , status ) we
* cache the data .
2015-08-06 19:12:34 +02:00
*
* @ param { Object } state
* @ param { etemplate2 } [ instance ] If the full calendar app isn ' t loaded
* ( home app ) , pass a different instance to use it to get the data
2015-08-26 01:30:32 +02:00
* @ param { number } [ start ] Result offset . Internal use only
2015-07-15 18:29:10 +02:00
* /
2015-08-26 01:30:32 +02:00
_fetch _data : function ( state , instance , start )
2015-07-15 18:29:10 +02:00
{
2015-12-03 21:44:52 +01:00
if ( ! this . sidebox _et2 && ! instance )
{
return ;
}
2015-07-15 18:29:10 +02:00
2015-08-26 01:30:32 +02:00
if ( typeof start === 'undefined' )
{
start = 0 ;
}
2015-11-23 18:36:21 +01:00
// Category needs to be false if empty, not an empty array or string
var cat _id = state . cat _id ? state . cat _id : false ;
if ( cat _id && typeof cat _id . join != 'undefined' )
{
if ( cat _id . join ( '' ) == '' ) cat _id = false ;
}
2016-09-08 12:30:42 +02:00
// Make sure cat_id reaches to server in array format
2016-09-08 14:03:05 +02:00
if ( cat _id && typeof cat _id == 'string' && cat _id != "0" ) cat _id = cat _id . split ( ',' ) ;
2015-11-23 18:36:21 +01:00
2015-08-26 01:30:32 +02:00
var query = jQuery . extend ( { } , {
get _rows : 'calendar.calendar_uilist.get_rows' ,
row _id : 'row_id' ,
startdate : state . first || state . date ,
enddate : state . last ,
// Participant must be an array or it won't work
col _filter : { participant : ( typeof state . owner == 'string' || typeof state . owner == 'number' ? [ state . owner ] : state . owner ) } ,
filter : 'custom' , // Must be custom to get start & end dates
2015-12-16 20:54:22 +01:00
status _filter : state . status _filter ,
2015-11-23 18:36:21 +01:00
cat _id : cat _id ,
2015-11-10 19:35:24 +01:00
csv _export : false
2015-08-26 01:30:32 +02:00
} ) ;
// Show ajax loader
2016-03-18 16:49:11 +01:00
if ( typeof framework !== 'undefined' )
{
framework . applications . calendar . sidemenuEntry . showAjaxLoader ( ) ;
}
2015-08-26 01:30:32 +02:00
2016-02-23 22:29:13 +01:00
// Already in progress?
var query _string = JSON . stringify ( query ) ;
if ( this . _queries _in _progress . indexOf ( query _string ) != - 1 )
{
return ;
}
this . _queries _in _progress . push ( query _string ) ;
2015-07-15 18:29:10 +02:00
this . egw . dataFetch (
2015-08-06 19:12:34 +02:00
instance ? instance . etemplate _exec _id :
this . sidebox _et2 . getInstanceManager ( ) . etemplate _exec _id ,
2016-01-28 22:35:22 +01:00
{ start : start , num _rows : 400 } ,
2015-08-26 01:30:32 +02:00
query ,
2015-07-15 18:29:10 +02:00
this . id ,
2016-01-05 21:43:19 +01:00
function calendar _handleResponse ( data ) {
2016-02-23 22:29:13 +01:00
var idx = this . _queries _in _progress . indexOf ( query _string ) ;
if ( idx >= 0 )
{
this . _queries _in _progress . splice ( idx , 1 ) ;
}
//console.log(data);
2016-03-01 17:27:45 +01:00
2015-10-14 16:32:33 +02:00
// Look for any updated select options
if ( data . rows && data . rows . sel _options && this . sidebox _et2 )
{
for ( var field in data . rows . sel _options )
{
var widget = this . sidebox _et2 . getWidgetById ( field ) ;
if ( widget && widget . set _select _options )
{
// Merge in new, update label of existing
for ( var i in data . rows . sel _options [ field ] )
{
2015-12-14 19:38:53 +01:00
var found = false ;
2015-10-14 16:32:33 +02:00
var option = data . rows . sel _options [ field ] [ i ] ;
for ( var j in widget . options . select _options )
{
if ( option . value == widget . options . select _options [ j ] . value )
{
widget . options . select _options [ j ] . label = option . label ;
2015-12-14 19:38:53 +01:00
found = true ;
2015-10-14 16:32:33 +02:00
break ;
}
2015-12-14 19:38:53 +01:00
}
if ( ! found )
{
2016-02-09 21:28:57 +01:00
if ( ! widget . options . select _options . push )
{
widget . options . select _options = [ ] ;
}
2015-12-14 19:38:53 +01:00
widget . options . select _options . push ( option ) ;
2015-10-14 16:32:33 +02:00
}
}
2015-12-08 01:22:50 +01:00
var in _progress = app . calendar . state _update _in _progress ;
app . calendar . state _update _in _progress = true ;
2015-10-14 16:32:33 +02:00
widget . set _select _options ( widget . options . select _options ) ;
widget . set _value ( widget . getValue ( ) ) ;
2015-12-14 19:38:53 +01:00
// If updating owner, update listview participants as well
// This lets us _add_ to the options, normal nm behaviour will replace.
if ( field == 'owner' )
{
try {
var participant = app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) . getWidgetById ( 'participant' ) ;
if ( participant )
{
participant . options . select _options = widget . options . select _options ;
participant . set _select _options ( widget . options . select _options ) ;
}
} catch ( e ) { debugger ; }
}
2015-12-28 23:21:47 +01:00
2015-12-08 01:22:50 +01:00
app . calendar . state _update _in _progress = in _progress ;
2015-10-14 16:32:33 +02:00
}
}
}
2015-11-14 00:21:16 +01:00
2016-01-14 16:46:55 +01:00
if ( data . order && data . total )
2015-07-15 18:29:10 +02:00
{
2016-01-14 16:46:55 +01:00
this . _update _events ( state , data . order ) ;
2015-07-15 18:29:10 +02:00
}
2015-09-07 19:13:20 +02:00
2015-08-26 01:30:32 +02:00
// More rows?
if ( data . order . length + start < data . total )
{
// Wait a bit, let UI do something.
window . setTimeout ( function ( ) {
app . calendar . _fetch _data ( state , instance , start + data . order . length ) ;
} , 100 ) ;
}
// Hide AJAX loader
2016-05-27 22:57:31 +02:00
else if ( typeof framework !== 'undefined' )
2016-03-18 16:49:11 +01:00
{
framework . applications . calendar . sidemenuEntry . hideAjaxLoader ( ) ;
2016-06-25 00:29:40 +02:00
egw . loading _prompt ( 'calendar' , false )
2016-03-18 16:49:11 +01:00
}
2015-07-15 18:29:10 +02:00
} , this , null
) ;
} ,
2016-01-14 16:46:55 +01:00
/ * *
* We have a list of calendar UIDs of events that need updating .
*
* The event data should already be in the egw . data cache , we just need to
* figure out where they need to go , and update the needed parent objects .
*
* Already existing events will have already been updated by egw . data
* callbacks .
*
* @ param { Object } state Current state for update , used to determine what to update
2016-06-13 18:03:52 +02:00
* @ param data
2016-01-14 16:46:55 +01:00
* /
_update _events : function ( state , data ) {
var updated _days = { } ;
// Events can span for longer than we are showing
var first = new Date ( state . first ) ;
var last = new Date ( state . last ) ;
var bounds = {
first : '' + first . getUTCFullYear ( ) + sprintf ( '%02d' , first . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , first . getUTCDate ( ) ) ,
last : '' + last . getUTCFullYear ( ) + sprintf ( '%02d' , last . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , last . getUTCDate ( ) )
} ;
// Seperate owners, or consolidated?
var multiple _owner = typeof state . owner != 'string' &&
state . owner . length > 1 &&
( state . view == 'day' && state . owner . length < parseInt ( this . egw . preference ( 'day_consolidate' , 'calendar' ) ) ||
state . view == 'week' && state . owner . length < parseInt ( this . egw . preference ( 'week_consolidate' , 'calendar' ) ) ) ;
for ( var i = 0 ; i < data . length ; i ++ )
{
var record = this . egw . dataGetUIDdata ( data [ i ] ) ;
if ( record && record . data )
{
if ( typeof updated _days [ record . data . date ] === 'undefined' )
{
// Check to make sure it's in range first, record.data.date is start date
// and could be before our start
if ( record . data . date >= bounds . first && record . data . date <= bounds . last )
{
updated _days [ record . data . date ] = [ ] ;
}
}
if ( typeof updated _days [ record . data . date ] != 'undefined' )
{
// Copy, to avoid unwanted changes by reference
updated _days [ record . data . date ] . push ( record . data . row _id ) ;
}
// Check for multi-day events listed once
// Date must stay a string or we might cause problems with nextmatch
var dates = {
start : typeof record . data . start === 'string' ? record . data . start : record . data . start . toJSON ( ) ,
2016-06-13 18:03:52 +02:00
end : typeof record . data . end === 'string' ? record . data . end : record . data . end . toJSON ( )
2016-01-14 16:46:55 +01:00
} ;
if ( dates . start . substr ( 0 , 10 ) !== dates . end . substr ( 0 , 10 ) )
{
var end = new Date ( Math . min ( new Date ( record . data . end ) , new Date ( state . last ) ) ) ;
end . setUTCHours ( 23 ) ;
end . setUTCMinutes ( 59 ) ;
end . setUTCSeconds ( 59 ) ;
var t = new Date ( Math . max ( new Date ( record . data . start ) , new Date ( state . first ) ) ) ;
do
{
var expanded _date = '' + t . getUTCFullYear ( ) + sprintf ( '%02d' , t . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , t . getUTCDate ( ) ) ;
if ( typeof ( updated _days [ expanded _date ] ) === 'undefined' )
{
// Check to make sure it's in range first, expanded_date could be after our end
if ( expanded _date >= bounds . first && expanded _date <= bounds . last )
{
updated _days [ expanded _date ] = [ ] ;
}
}
if ( record . data . date !== expanded _date && typeof updated _days [ expanded _date ] !== 'undefined' )
{
// Copy, to avoid unwanted changes by reference
updated _days [ expanded _date ] . push ( record . data . row _id ) ;
}
t . setUTCDate ( t . getUTCDate ( ) + 1 ) ;
}
while ( end >= t )
}
}
}
// Now we know which days changed, so we pass it on
for ( var day in updated _days )
{
// Might be split by user, so we have to check that too
2016-02-10 01:35:54 +01:00
for ( var i = 0 ; i < ( typeof state . owner == 'object' ? state . owner . length : 1 ) ; i ++ )
2016-01-14 16:46:55 +01:00
{
var owner = multiple _owner ? state . owner [ i ] : state . owner ;
var cache _id = app . classes . calendar . _daywise _cache _id ( day , owner ) ;
if ( egw . dataHasUID ( cache _id ) )
{
// Don't lose any existing data, just append
var c = egw . dataGetUIDdata ( cache _id ) ;
if ( c . data && c . data !== null )
{
// Avoid duplicates
var data = c . data . concat ( updated _days [ day ] ) . filter ( function ( value , index , self ) {
return self . indexOf ( value ) === index ;
} ) ;
this . egw . dataStoreUID ( cache _id , data ) ;
}
}
else
{
this . egw . dataStoreUID ( cache _id , updated _days [ day ] ) ;
}
if ( ! multiple _owner ) break ;
}
}
2016-04-05 23:57:10 +02:00
egw . loading _prompt ( this . appname , false ) ;
2016-01-14 16:46:55 +01:00
} ,
2015-06-10 23:51:28 +02:00
/ * *
* Some handy date calculations
* All take either a Date object or full date with timestamp ( Z )
* /
date : {
2015-07-01 00:26:59 +02:00
toString : function ( date )
{
// Ensure consistent formatting using UTC, avoids problems with comparison
// and timezones
if ( typeof date === 'string' ) date = new Date ( date ) ;
return date . getUTCFullYear ( ) + '-' +
sprintf ( "%02d" , date . getUTCMonth ( ) + 1 ) + '-' +
sprintf ( "%02d" , date . getUTCDate ( ) ) + 'T' +
sprintf ( "%02d" , date . getUTCHours ( ) ) + ':' +
sprintf ( "%02d" , date . getUTCMinutes ( ) ) + ':' +
sprintf ( "%02d" , date . getUTCSeconds ( ) ) + 'Z' ;
} ,
2015-09-07 19:13:20 +02:00
2015-08-19 02:08:22 +02:00
/ * *
* Formats one or two dates ( range ) as long date ( full monthname ) , optionaly with a time
*
* Take care of any timezone issues before you pass the dates in .
*
* @ param { Date } first first date
2016-06-13 18:03:52 +02:00
* @ param { Date } last = 0 last date for range , or false for a single date
* @ param { boolean } display _time = false should a time be displayed too
* @ param { boolean } display _day = false should a day - name prefix the date , eg . monday June 20 , 2006
2015-08-19 02:08:22 +02:00
* @ return string with formatted date
* /
long _date : function ( first , last , display _time , display _day )
{
if ( ! first ) return '' ;
if ( typeof first === 'string' )
{
first = new Date ( first ) ;
}
2016-07-14 19:30:04 +02:00
var first _format = new Date ( first . valueOf ( ) + first . getTimezoneOffset ( ) * 60 * 1000 ) ;
2015-08-19 02:08:22 +02:00
if ( typeof last == 'string' && last )
{
last = new Date ( last ) ;
}
if ( ! last || typeof last !== 'object' )
{
last = false ;
}
2016-07-14 19:30:04 +02:00
if ( last )
{
var last _format = new Date ( last . valueOf ( ) + last . getTimezoneOffset ( ) * 60 * 1000 ) ;
}
2015-08-19 02:08:22 +02:00
if ( ! display _time ) display _time = false ;
if ( ! display _day ) display _day = false ;
var range = '' ;
var datefmt = egw . preference ( 'dateformat' ) ;
2015-11-17 21:19:47 +01:00
var timefmt = egw . preference ( 'timeformat' ) === '12' ? 'h:i a' : 'H:i' ;
2015-08-19 02:08:22 +02:00
var month _before _day = datefmt [ 0 ] . toLowerCase ( ) == 'm' ||
datefmt [ 2 ] . toLowerCase ( ) == 'm' && datefmt [ 4 ] == 'd' ;
if ( display _day )
{
2016-07-14 19:30:04 +02:00
range = jQuery . datepicker . formatDate ( 'DD' , first _format ) + ( datefmt [ 0 ] != 'd' ? ' ' : ', ' ) ;
2015-08-19 02:08:22 +02:00
}
for ( var i = 0 ; i < 5 ; i += 2 )
{
switch ( datefmt [ i ] )
{
case 'd' :
range += first . getUTCDate ( ) + ( datefmt [ 1 ] == '.' ? '.' : '' ) ;
2016-07-14 19:30:04 +02:00
if ( last && ( first . getUTCMonth ( ) != last . getUTCMonth ( ) || first . getUTCFullYear ( ) != last . getUTCFullYear ( ) ) )
2015-08-19 02:08:22 +02:00
{
if ( ! month _before _day )
{
2016-07-14 19:30:04 +02:00
range += jQuery . datepicker . formatDate ( 'MM' , first _format ) ;
2015-08-19 02:08:22 +02:00
}
if ( first . getFullYear ( ) != last . getFullYear ( ) && datefmt [ 0 ] != 'Y' )
{
2015-11-30 18:31:59 +01:00
range += ( datefmt [ 0 ] != 'd' ? ', ' : ' ' ) + first . getFullYear ( ) ;
2015-08-19 02:08:22 +02:00
}
if ( display _time )
{
2016-07-14 19:30:04 +02:00
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , first _format ) ;
2015-08-19 02:08:22 +02:00
}
if ( ! last )
{
return range ;
}
range += ' - ' ;
if ( first . getFullYear ( ) != last . getFullYear ( ) && datefmt [ 0 ] == 'Y' )
{
2016-07-14 19:30:04 +02:00
range += last . getUTCFullYear ( ) + ', ' ;
2015-08-19 02:08:22 +02:00
}
if ( month _before _day )
{
2016-07-14 19:30:04 +02:00
range += jQuery . datepicker . formatDate ( 'MM' , last _format ) ;
2015-08-19 02:08:22 +02:00
}
}
else
{
if ( display _time )
{
2016-07-14 19:30:04 +02:00
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , last _format ) ;
2015-08-19 02:08:22 +02:00
}
if ( last )
{
range += ' - ' ;
}
}
if ( last )
{
range += ' ' + last . getUTCDate ( ) + ( datefmt [ 1 ] == '.' ? '.' : '' ) ;
}
break ;
case 'm' :
case 'M' :
2016-07-14 19:30:04 +02:00
range += ' ' + jQuery . datepicker . formatDate ( 'MM' , month _before _day ? first _format : last _format ) + ' ' ;
2015-08-19 02:08:22 +02:00
break ;
case 'Y' :
if ( datefmt [ 0 ] != 'm' )
{
2016-07-14 19:30:04 +02:00
range += ' ' + ( datefmt [ 0 ] == 'Y' ? first . getUTCFullYear ( ) + ( datefmt [ 2 ] == 'd' ? ', ' : ' ' ) : last . getUTCFullYear ( ) + ' ' ) ;
2015-08-19 02:08:22 +02:00
}
break ;
}
}
if ( display _time && last )
{
2016-07-14 19:30:04 +02:00
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , last _format ) ;
2015-08-19 02:08:22 +02:00
}
if ( datefmt [ 4 ] == 'Y' && datefmt [ 0 ] == 'm' )
{
2016-07-14 19:30:04 +02:00
range += ', ' + last . getUTCFullYear ( ) ;
2015-08-19 02:08:22 +02:00
}
return range ;
} ,
/ * *
* Calculate iso8601 week - number , which is defined for Monday as first day of week only
*
* We adjust the day , if user prefs want a different week - start - day
*
2016-06-13 18:03:52 +02:00
* @ param { string | Date } _date
2015-08-19 02:08:22 +02:00
* @ return string
* /
week _number : function ( _date )
{
var d = new Date ( _date ) ;
var day = d . getUTCDay ( ) ;
// if week does not start Monday and date is Sunday --> add one day
if ( egw . preference ( 'weekdaystarts' , 'calendar' ) != 'Monday' && ! day )
{
d . setUTCDate ( d . getUTCDate ( ) + 1 ) ;
}
// if week does start Saturday and $time is Saturday --> add two days
else if ( egw . preference ( 'weekdaystarts' , 'calendar' ) == 'Saturday' && day == 6 )
{
d . setUTCDate ( d . getUTCDate ( ) + 2 ) ;
}
return jQuery . datepicker . iso8601Week ( new Date ( d . valueOf ( ) + d . getTimezoneOffset ( ) * 60 * 1000 ) ) ;
} ,
2015-06-10 23:51:28 +02:00
start _of _week : function ( date )
{
var d = new Date ( date ) ;
var day = d . getUTCDay ( ) ;
var diff = 0 ;
switch ( egw . preference ( 'weekdaystarts' , 'calendar' ) )
{
case 'Saturday' :
2015-08-19 02:08:22 +02:00
diff = day === 6 ? 0 : day === 0 ? - 1 : - ( day + 1 ) ;
2015-06-10 23:51:28 +02:00
break ;
case 'Monday' :
2015-11-30 18:55:21 +01:00
diff = day === 0 ? - 6 : 1 - day ;
2015-06-10 23:51:28 +02:00
break ;
case 'Sunday' :
default :
diff = - day ;
}
2015-07-15 18:29:10 +02:00
d . setUTCDate ( d . getUTCDate ( ) + diff ) ;
2015-06-10 23:51:28 +02:00
return d ;
} ,
end _of _week : function ( date )
{
var d = app . calendar . date . start _of _week ( date ) ;
2015-07-15 18:29:10 +02:00
d . setUTCDate ( d . getUTCDate ( ) + 6 ) ;
2015-06-10 23:51:28 +02:00
return d ;
}
} ,
/ * *
* The sidebox filters use some non - standard and not - exposed options . They
* are set up here .
*
* /
_setup _sidebox _filters : function ( )
{
// Further date customizations
2015-12-02 00:49:14 +01:00
var date _widget = this . sidebox _et2 . getWidgetById ( 'date' ) ;
if ( date _widget )
2015-06-10 23:51:28 +02:00
{
2016-04-01 17:12:27 +02:00
// Dynamic resize of sidebox calendar to fill sidebox
2016-06-02 16:51:15 +02:00
var preferred _width = jQuery ( '#calendar-sidebox_date .ui-datepicker-inline' ) . outerWidth ( ) ;
var font _ratio = 12 / parseFloat ( jQuery ( '#calendar-sidebox_date .ui-datepicker-inline' ) . css ( 'font-size' ) ) ;
2016-04-01 17:12:27 +02:00
var calendar _resize = function ( ) {
try {
2016-06-02 16:51:15 +02:00
var percent = 1 + ( ( jQuery ( date _widget . getDOMNode ( ) ) . width ( ) - preferred _width ) / preferred _width ) ;
2016-04-01 17:12:27 +02:00
percent *= font _ratio ;
2016-06-02 16:51:15 +02:00
jQuery ( '#calendar-sidebox_date .ui-datepicker-inline' )
2016-04-01 17:12:27 +02:00
. css ( 'font-size' , ( percent * 100 ) + '%' ) ;
// Position go and today
2016-06-02 16:51:15 +02:00
var buttons = jQuery ( '#calendar-sidebox_date .ui-datepicker-header a span' ) ;
2016-04-01 17:12:27 +02:00
if ( today . length && go _button . length )
{
2016-06-03 10:41:03 +02:00
go _button . position ( { my : 'left+8px center' , at : 'right center-1' , of : jQuery ( '#calendar-sidebox_date .ui-datepicker-year' ) } ) ;
2016-04-01 17:12:27 +02:00
today . css ( {
'left' : ( buttons . first ( ) . offset ( ) . left + buttons . last ( ) . offset ( ) . left ) / 2 - Math . ceil ( today . outerWidth ( true ) / 2 ) ,
'top' : go _button . css ( 'top' )
} ) ;
buttons . position ( { my : 'center' , at : 'center' , of : go _button } )
. css ( 'left' , '' ) ;
}
} catch ( e ) {
// Resize didn't work
}
} ;
2015-12-02 00:49:14 +01:00
var datepicker = date _widget . input _date . datepicker ( "option" , {
2015-11-03 00:21:59 +01:00
showButtonPanel : false ,
2016-02-01 21:52:53 +01:00
onChangeMonthYear : function ( year , month , inst )
{
// Update month button label
var go _button = date _widget . getRoot ( ) . getWidgetById ( 'header_go' ) ;
if ( go _button )
{
var temp _date = new Date ( year , month - 1 , 1 , 0 , 0 , 0 ) ;
//temp_date.setUTCMinutes(temp_date.getUTCMinutes() + temp_date.getTimezoneOffset());
2016-02-03 17:52:28 +01:00
go _button . btn . attr ( 'title' , egw . lang ( date ( 'F' , temp _date ) ) ) ;
2016-02-01 21:52:53 +01:00
// Store current _displayed_ date in date button for clicking
temp _date . setUTCMinutes ( temp _date . getUTCMinutes ( ) - temp _date . getTimezoneOffset ( ) ) ;
go _button . btn . attr ( 'data-date' , temp _date . toJSON ( ) ) ;
}
2016-04-01 17:12:27 +02:00
window . setTimeout ( calendar _resize , 0 ) ;
2016-02-01 21:52:53 +01:00
} ,
2015-08-24 19:28:19 +02:00
// Mark holidays
beforeShowDay : function ( date )
{
2016-01-13 23:07:09 +01:00
var holidays = et2 _calendar _view . get _holidays ( { day _class _holiday : function ( ) { } } , date . getFullYear ( ) ) ;
2015-12-01 23:53:13 +01:00
var day _holidays = holidays [ '' + date . getFullYear ( ) +
sprintf ( "%02d" , date . getMonth ( ) + 1 ) +
sprintf ( "%02d" , date . getDate ( ) ) ] ;
2015-08-24 19:28:19 +02:00
var css _class = '' ;
var tooltip = '' ;
if ( typeof day _holidays !== 'undefined' && day _holidays . length )
{
for ( var i = 0 ; i < day _holidays . length ; i ++ )
{
if ( typeof day _holidays [ i ] [ 'birthyear' ] !== 'undefined' )
{
css _class += 'calendar_calBirthday ' ;
}
else
{
css _class += 'calendar_calHoliday ' ;
}
tooltip += day _holidays [ i ] [ 'name' ] + "\n" ;
}
}
return [ true , css _class , tooltip ] ;
}
2015-06-10 23:51:28 +02:00
} ) ;
2015-07-15 15:16:31 +02:00
2015-08-24 19:28:19 +02:00
// Clickable week numbers
2015-12-02 00:49:14 +01:00
date _widget . input _date . on ( 'mouseenter' , '.ui-datepicker-week-col' , function ( ) {
2016-06-02 16:51:15 +02:00
jQuery ( this ) . siblings ( ) . find ( 'a' ) . addClass ( 'ui-state-hover' ) ;
2015-08-24 19:28:19 +02:00
} )
. on ( 'mouseleave' , '.ui-datepicker-week-col' , function ( ) {
2016-06-02 16:51:15 +02:00
jQuery ( this ) . siblings ( ) . find ( 'a' ) . removeClass ( 'ui-state-hover' ) ;
2015-08-24 19:28:19 +02:00
} )
. on ( 'click' , '.ui-datepicker-week-col' , function ( ) {
2015-09-14 22:47:25 +02:00
var view = app . calendar . state . view ;
2015-09-29 18:50:49 +02:00
var days = app . calendar . state . days ;
2016-02-17 20:56:54 +01:00
2015-12-18 18:18:05 +01:00
// Avoid a full state update, we just want the calendar to update
// Directly update to avoid change event from the sidebox calendar
var date = new Date ( this . nextSibling . dataset . year , this . nextSibling . dataset . month , this . nextSibling . firstChild . textContent , 0 , 0 , 0 ) ;
2015-12-21 19:14:33 +01:00
date . setUTCMinutes ( date . getUTCMinutes ( ) - date . getTimezoneOffset ( ) ) ;
2015-12-18 18:18:05 +01:00
date = app . calendar . date . toString ( date ) ;
2015-08-24 19:28:19 +02:00
2015-09-14 22:47:25 +02:00
// Set to week view, if in one of the views where we change view
if ( app . calendar . sidebox _changes _views . indexOf ( view ) >= 0 )
{
2015-12-18 18:18:05 +01:00
app . calendar . update _state ( { view : 'week' , date : date , days : days } ) ;
2015-09-14 22:47:25 +02:00
}
2015-10-05 20:27:19 +02:00
else if ( view == 'planner' )
2015-09-14 22:47:25 +02:00
{
// Clicked a week, show just a week
2016-02-03 19:27:52 +01:00
app . calendar . update _state ( { date : date , planner _view : 'week' } ) ;
2015-09-14 22:47:25 +02:00
}
2015-10-05 20:27:19 +02:00
else if ( view == 'listview' )
{
app . calendar . update _state ( {
2015-12-18 18:18:05 +01:00
date : date ,
end _date : app . calendar . date . toString ( app . classes . calendar . views . week . end _date ( { date : date } ) ) ,
2015-12-16 21:41:54 +01:00
filter : 'week'
2015-10-05 20:27:19 +02:00
} ) ;
}
2015-12-21 19:16:32 +01:00
else
{
app . calendar . update _state ( { date : date } ) ;
}
2015-08-24 19:28:19 +02:00
} ) ;
2016-02-01 21:52:53 +01:00
// Set today button
2016-06-02 16:51:15 +02:00
var today = jQuery ( '#calendar-sidebox_header_today' ) ;
2016-02-03 17:52:28 +01:00
today . attr ( 'title' , egw . lang ( 'today' ) ) ;
2016-02-01 21:52:53 +01:00
// Set go button
var go _button = date _widget . getRoot ( ) . getWidgetById ( 'header_go' ) ;
if ( go _button && go _button . btn )
{
go _button = go _button . btn ;
var temp _date = new Date ( date _widget . get _value ( ) ) ;
temp _date . setUTCDate ( 1 ) ;
temp _date . setUTCMinutes ( temp _date . getUTCMinutes ( ) + temp _date . getTimezoneOffset ( ) ) ;
2016-02-03 17:52:28 +01:00
go _button . attr ( 'title' , egw . lang ( date ( 'F' , temp _date ) ) ) ;
2016-02-01 21:52:53 +01:00
// Store current _displayed_ date in date button for clicking
temp _date . setUTCMinutes ( temp _date . getUTCMinutes ( ) - temp _date . getTimezoneOffset ( ) ) ;
go _button . attr ( 'data-date' , temp _date . toJSON ( ) ) ;
2016-02-03 17:52:28 +01:00
2016-02-01 21:52:53 +01:00
}
2015-08-24 19:28:19 +02:00
}
2015-11-23 23:01:02 +01:00
2016-06-02 16:51:15 +02:00
jQuery ( window ) . on ( 'resize.calendar' + date _widget . dom _id , calendar _resize ) . trigger ( 'resize' ) ;
2016-04-01 17:12:27 +02:00
2015-11-23 23:01:02 +01:00
// Avoid wrapping owner icons if user has group + search
2016-06-02 16:51:15 +02:00
var button = jQuery ( '#calendar-sidebox_owner ~ span.et2_clickable' ) ;
2015-11-23 23:01:02 +01:00
if ( button . length == 1 )
{
2015-11-23 23:44:16 +01:00
button . parent ( ) . css ( 'margin-right' , button . outerWidth ( true ) + 2 ) ;
2015-11-23 23:01:02 +01:00
button . parent ( ) . parent ( ) . css ( 'white-space' , 'nowrap' ) ;
}
2016-06-02 16:51:15 +02:00
jQuery ( window ) . on ( 'resize.calendar-owner' , function ( ) {
var preferred _width = jQuery ( '#calendar-et2_target' ) . children ( ) . first ( ) . outerWidth ( ) || 0 ;
2016-02-24 19:04:40 +01:00
if ( app . calendar && app . calendar . sidebox _et2 )
2016-02-09 21:28:57 +01:00
{
2016-02-24 19:04:40 +01:00
var owner = app . calendar . sidebox _et2 . getWidgetById ( 'owner' ) ;
if ( preferred _width && owner . input . hasClass ( "chzn-done" ) )
{
owner . input . next ( ) . css ( 'width' , preferred _width ) ;
}
2016-02-09 21:28:57 +01:00
}
} ) ;
2015-07-01 00:26:59 +02:00
} ,
2015-09-07 19:13:20 +02:00
2015-07-15 18:29:10 +02:00
/ * *
* Record view templates so we can quickly switch between them .
2015-09-07 19:13:20 +02:00
*
2015-07-15 18:29:10 +02:00
* @ param { etemplate2 } _et2 etemplate2 template that was just loaded
* @ param { String } _name Name of the template
* /
_et2 _view _init : function ( _et2 , _name )
{
var hidden = typeof this . state . view !== 'undefined' ;
2015-12-23 01:42:39 +01:00
var all _loaded = this . sidebox _et2 !== null ;
2015-07-15 18:29:10 +02:00
2015-08-05 23:24:07 +02:00
// Avoid home portlets using our templates, and get them right
if ( _et2 . uniqueId . indexOf ( 'portlet' ) === 0 ) return ;
2015-09-07 19:13:20 +02:00
2015-07-15 18:29:10 +02:00
// Flag to make sure we don't hide non-view templates
var view _et2 = false ;
2015-09-07 19:13:20 +02:00
2015-07-15 18:29:10 +02:00
for ( var view in app . classes . calendar . views )
{
var index = app . classes . calendar . views [ view ] . etemplates . indexOf ( _name ) ;
if ( index > - 1 )
{
view _et2 = true ;
app . classes . calendar . views [ view ] . etemplates [ index ] = _et2 ;
// If a template disappears, we want to release it
2016-06-02 16:51:15 +02:00
jQuery ( _et2 . DOMContainer ) . one ( 'clear' , jQuery . proxy ( function ( ) {
2015-10-15 22:06:19 +02:00
this . view . etemplates [ this . index ] = _name ;
2015-08-05 23:24:07 +02:00
} , jQuery . extend ( { } , { view : app . classes . calendar . views [ view ] , index : "" + index , name : _name } ) ) ) ;
2015-07-15 18:29:10 +02:00
if ( this . state . view === view )
{
hidden = false ;
}
}
app . classes . calendar . views [ view ] . etemplates . forEach ( function ( et ) { all _loaded = all _loaded && typeof et !== 'string' ; } ) ;
}
2015-12-11 20:38:52 +01:00
// Add some extras to the nextmatch so it can keep the dates in sync with
// those in the sidebox calendar. Care must be taken to not trigger any
// sort of refresh or update, as that may resulte in infinite loops so these
// are only used for the 'week' and 'month' filters, and we just update the
// date range
if ( _name == 'calendar.list' )
{
var nm = _et2 . widgetContainer . getWidgetById ( 'nm' ) ;
if ( nm )
{
2015-12-29 23:12:30 +01:00
// Avoid unwanted refresh immediately after load
nm . controller . _grid . doInvalidate = false ;
2016-02-17 20:56:54 +01:00
2016-03-30 01:34:45 +02:00
// Preserve pre-set search
if ( nm . activeFilters . search )
{
this . state . keywords = nm . activeFilters . search ;
}
2016-08-03 18:53:37 +02:00
// Bind to keep search up to date
jQuery ( nm . getWidgetById ( 'search' ) . getDOMNode ( ) ) . on ( 'change' , function ( ) {
app . calendar . state . search = jQuery ( 'input' , this ) . val ( ) ;
} ) ;
2015-12-11 20:38:52 +01:00
nm . set _startdate = jQuery . proxy ( function ( date ) {
this . state . first = this . date . toString ( new Date ( date ) ) ;
} , this ) ;
nm . set _enddate = jQuery . proxy ( function ( date ) {
this . state . last = this . date . toString ( new Date ( date ) ) ;
} , this ) ;
}
}
2015-07-15 18:29:10 +02:00
// Start hidden, except for current view
if ( view _et2 )
{
if ( hidden )
{
2016-06-02 16:51:15 +02:00
jQuery ( _et2 . DOMContainer ) . hide ( ) ;
2015-07-15 18:29:10 +02:00
}
}
2015-12-14 23:08:12 +01:00
else
{
var app _name = _name . split ( '.' ) [ 0 ] ;
if ( app _name && app _name != 'calendar' && egw . app ( app _name ) )
{
// A template from another application? Keep it up to date as state changes
this . sidebox _hooked _templates . push ( _et2 . widgetContainer ) ;
// If it leaves (or reloads) remove it
2016-06-02 16:51:15 +02:00
jQuery ( _et2 . DOMContainer ) . one ( 'clear' , jQuery . proxy ( function ( ) {
2015-12-14 23:08:12 +01:00
if ( app . calendar )
{
app . calendar . sidebox _hooked _templates . splice ( this , 1 , 0 ) ;
}
} , this . sidebox _hooked _templates . length - 1 ) ) ;
}
}
2015-12-23 19:15:23 +01:00
if ( all _loaded )
{
2016-06-02 16:51:15 +02:00
jQuery ( window ) . trigger ( 'resize' ) ;
2015-12-23 19:15:23 +01:00
this . setState ( { state : this . state } ) ;
2016-04-18 15:56:47 +02:00
2016-04-05 23:57:10 +02:00
// Hide loader after 1 second as a fallback, it will also be hidden
// after loading is complete.
window . setTimeout ( jQuery . proxy ( function ( ) {
egw . loading _prompt ( this . appname , false ) ;
} , this ) , 1000 ) ;
2016-04-18 15:56:47 +02:00
2016-05-10 21:41:28 +02:00
// Start calendar-wide autorefresh timer to include more than just nm
this . _set _autorefresh ( ) ;
}
} ,
/ * *
* Set a refresh timer that works for the current view .
* The nextmatch goes into an infinite loop if we let it autorefresh while
* hidden .
* /
_set _autorefresh : function ( ) {
2016-05-16 22:32:03 +02:00
// Listview not loaded
if ( typeof app . classes . calendar . views . listview . etemplates [ 0 ] == 'string' ) return ;
2016-05-18 15:08:05 +02:00
2016-05-10 21:41:28 +02:00
var nm = app . classes . calendar . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
2016-05-16 22:32:03 +02:00
// nextmatch missing
2016-05-10 21:41:28 +02:00
if ( ! nm ) return ;
2016-05-13 13:20:38 +02:00
2016-05-10 21:41:28 +02:00
var refresh _preference = "nextmatch-" + nm . options . settings . columnselection _pref + "-autorefresh" ;
var time = this . egw . preference ( refresh _preference , 'calendar' ) ;
if ( this . state . view == 'listview' && time )
{
nm . _set _autorefresh ( time ) ;
return ;
}
else
{
window . clearInterval ( nm . _autorefresh _timer ) ;
}
2016-05-18 15:08:05 +02:00
var self = this ;
2016-05-10 21:41:28 +02:00
var refresh = function ( ) {
// Deleted events are not coming properly, so clear it all
2016-05-18 15:08:05 +02:00
self . _clear _cache ( ) ;
2016-05-10 21:41:28 +02:00
// Force redraw to current state
2016-05-18 15:08:05 +02:00
self . setState ( { state : self . state } ) ;
2016-05-10 21:41:28 +02:00
// This is a fast update, but misses deleted events
//app.calendar._fetch_data(app.calendar.state);
} ;
2016-05-13 13:20:38 +02:00
2016-05-10 21:41:28 +02:00
// Start / update timer
if ( this . _autorefresh _timer )
{
window . clearInterval ( this . _autorefresh _timer ) ;
this . _autorefresh _timer = null ;
2015-12-23 19:15:23 +01:00
}
2016-05-10 21:41:28 +02:00
if ( time > 0 )
{
this . _autorefresh _timer = setInterval ( jQuery . proxy ( refresh , this ) , time * 1000 ) ;
}
// Bind to tab show/hide events, so that we don't bother refreshing in the background
2016-06-02 16:51:15 +02:00
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'hide.calendar' , jQuery . proxy ( function ( e ) {
2016-05-10 21:41:28 +02:00
// Stop
window . clearInterval ( this . _autorefresh _timer ) ;
2016-06-02 16:51:15 +02:00
jQuery ( e . target ) . off ( e ) ;
2016-05-10 21:41:28 +02:00
2016-05-24 23:28:22 +02:00
if ( ! time ) return ;
2016-06-03 10:41:03 +02:00
2016-05-10 21:41:28 +02:00
// If the autorefresh time is up, bind once to trigger a refresh
// (if needed) when tab is activated again
this . _autorefresh _timer = setTimeout ( jQuery . proxy ( function ( ) {
// Check in case it was stopped / destroyed since
if ( ! this . _autorefresh _timer ) return ;
2016-06-02 16:51:15 +02:00
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . one ( 'show.calendar' ,
2016-05-10 21:41:28 +02:00
// Important to use anonymous function instead of just 'this.refresh' because
// of the parameters passed
jQuery . proxy ( function ( ) { refresh ( ) ; } , this )
) ;
} , this ) , time * 1000 ) ;
} , this ) ) ;
2016-06-02 16:51:15 +02:00
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'show.calendar' , jQuery . proxy ( function ( e ) {
2016-05-10 21:41:28 +02:00
// Start normal autorefresh timer again
this . _set _autorefresh ( this . egw . preference ( refresh _preference , 'calendar' ) ) ;
2016-06-02 16:51:15 +02:00
jQuery ( e . target ) . off ( e ) ;
2016-05-10 21:41:28 +02:00
} , this ) ) ;
2015-07-15 18:29:10 +02:00
} ,
2015-09-14 22:47:25 +02:00
/ * *
* Super class for the different views .
*
* Each separate view overrides what it needs
* /
2015-07-01 00:26:59 +02:00
View : {
// List of etemplates to show for this view
etemplates : [ 'calendar.view' ] ,
/ * *
* Translated label for header
* @ param { Object } state
* @ returns { string }
* /
header : function ( state ) {
var formatDate = new Date ( state . date ) ;
formatDate = new Date ( formatDate . valueOf ( ) + formatDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
2015-10-15 22:06:19 +02:00
return app . calendar . View . _owner ( state ) + date ( egw . preference ( 'dateformat' ) , formatDate ) ;
} ,
/ * *
* If one owner , get the owner text
2016-06-13 18:03:52 +02:00
*
* @ param { object } state
2015-10-15 22:06:19 +02:00
* /
_owner : function ( state ) {
var owner = '' ;
2015-10-15 23:34:07 +02:00
if ( state . owner . length && state . owner . length == 1 && app . calendar . sidebox _et2 )
2015-10-15 22:06:19 +02:00
{
var own = app . calendar . sidebox _et2 . getWidgetById ( 'owner' ) . getDOMNode ( ) ;
if ( own . selectedIndex >= 0 )
{
owner = own . options [ own . selectedIndex ] . innerHTML + ": " ;
}
}
return owner ;
2015-07-01 00:26:59 +02:00
} ,
/ * *
* Get the start date for this view
* @ param { Object } state
* @ returns { Date }
* /
start _date : function ( state ) {
var d = state . date ? new Date ( state . date ) : new Date ( ) ;
d . setUTCHours ( 0 ) ;
d . setUTCMinutes ( 0 ) ;
d . setUTCSeconds ( 0 ) ;
d . setUTCMilliseconds ( 0 ) ;
return d ;
} ,
/ * *
* Get the end date for this view
* @ param { Object } state
* @ returns { Date }
* /
end _date : function ( state ) {
var d = state . date ? new Date ( state . date ) : new Date ( ) ;
d . setUTCHours ( 23 ) ;
d . setUTCMinutes ( 59 ) ;
d . setUTCSeconds ( 59 ) ;
d . setUTCMilliseconds ( 0 ) ;
return d ;
} ,
2015-07-22 01:45:38 +02:00
/ * *
* Get the owner for this view
*
* This is always the owner from the given state , we use a function
* to trigger setting the widget value .
*
2016-06-13 18:03:52 +02:00
* @ param { number [ ] | String } state state . owner List of owner IDs , or a comma seperated list
2015-07-22 01:45:38 +02:00
* @ returns { number [ ] | String }
* /
2015-07-01 00:26:59 +02:00
owner : function ( state ) {
return state . owner || 0 ;
} ,
2015-07-22 01:45:38 +02:00
/ * *
* Should the view show the weekends
*
2016-06-13 18:03:52 +02:00
* @ param { object } state
2015-07-22 01:45:38 +02:00
* @ returns { boolean } Current preference to show 5 or 7 days in weekview
* /
2015-07-01 00:26:59 +02:00
show _weekend : function ( state )
{
2015-11-06 01:37:23 +01:00
return state . weekend ;
2015-07-01 00:26:59 +02:00
} ,
2015-09-03 00:40:38 +02:00
/ * *
* How big or small are the displayed time chunks ?
2016-06-13 18:03:52 +02:00
*
* @ param { object } state
2015-09-03 00:40:38 +02:00
* /
2015-08-19 02:08:22 +02:00
granularity : function ( state ) {
2016-02-04 20:47:57 +01:00
var list = egw . preference ( 'use_time_grid' , 'calendar' ) ;
2016-05-18 19:30:02 +02:00
if ( list === 0 || typeof list === 'undefined' )
{
return parseInt ( egw . preference ( 'interval' , 'calendar' ) ) || 30 ;
}
2016-01-13 01:27:10 +01:00
if ( typeof list == 'string' ) list = list . split ( ',' ) ;
2016-01-13 01:24:19 +01:00
if ( ! list . indexOf && jQuery . isPlainObject ( list ) )
{
2016-06-13 18:03:52 +02:00
list = jQuery . map ( list , function ( el ) { return el ; } ) ;
2016-01-13 01:24:19 +01:00
}
2016-01-13 00:55:59 +01:00
return list . indexOf ( state . view ) >= 0 ?
0 :
parseInt ( egw . preference ( 'interval' , 'calendar' ) ) || 30 ;
2015-08-19 02:08:22 +02:00
} ,
2015-07-01 00:26:59 +02:00
extend : function ( sub )
{
return jQuery . extend ( { } , this , { _super : this } , sub ) ;
2015-07-22 01:45:38 +02:00
} ,
/ * *
* Determines the new date after scrolling . The default is 1 week .
*
* @ param { number } delta Integer for how many 'ticks' to move , positive for
* forward , negative for backward
* @ returns { Date }
* /
scroll : function ( delta )
{
var d = new Date ( app . calendar . state . date ) ;
d . setUTCDate ( d . getUTCDate ( ) + ( 7 * delta ) ) ;
return d ;
2015-07-01 00:26:59 +02:00
}
2014-06-06 13:59:20 +02:00
}
2016-03-01 17:27:45 +01:00
} ) ; } ) . call ( this ) ;
2015-07-01 00:26:59 +02:00
jQuery . extend ( app . classes . calendar , {
2015-08-05 23:24:07 +02:00
/ * *
* This is the data cache prefix for the daywise event index cache
* Daywise cache IDs look like : calendar _daywise : : 20150101 and
* contain a list of event IDs for that day ( or empty array )
* /
DAYWISE _CACHE _ID : 'calendar_daywise' ,
/ * *
* Create a cache ID for the daywise cache
*
2016-01-27 18:35:25 +01:00
* @ param { String | Date } date If a string , date should be in Ymd format
2015-08-05 23:24:07 +02:00
* @ param { String | integer | String [ ] } owner
* @ returns { String } Cache ID
* /
_daywise _cache _id : function ( date , owner )
{
if ( typeof date === 'object' )
{
date = date . getUTCFullYear ( ) + sprintf ( '%02d' , date . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , date . getUTCDate ( ) ) ;
}
2016-06-24 18:44:33 +02:00
// If the owner is not set, 0, or the current user, don't bother adding it
var _owner = ( owner && owner . toString ( ) != '0' ) ? owner . toString ( ) : '' ;
2015-08-05 23:24:07 +02:00
if ( _owner == egw . user ( 'account_id' ) )
{
_owner = '' ;
}
return app . classes . calendar . DAYWISE _CACHE _ID + '::' + date + ( _owner ? '-' + _owner : '' ) ;
} ,
/ * *
* Etemplates and settings for the different views . Some ( day view )
* use more than one template , some use the same template as others ,
* most need different handling for their various attributes .
*
* Not using the standard Class . extend here because it hides the members ,
* and we want to be able to look inside them . This is done seperately instead
* of inside the normal object to allow access to the View object .
* /
2015-07-01 00:26:59 +02:00
views : {
day : app . classes . calendar . prototype . View . extend ( {
header : function ( state ) {
2016-01-21 19:35:53 +01:00
return app . calendar . View . header . call ( this , state ) ;
2015-07-01 00:26:59 +02:00
} ,
etemplates : [ 'calendar.view' , 'calendar.todo' ] ,
start _date : function ( state ) {
var d = app . calendar . View . start _date . call ( this , state ) ;
state . date = app . calendar . date . toString ( d ) ;
return d ;
} ,
show _weekend : function ( state ) {
state . days = '1' ;
2015-11-06 01:37:23 +01:00
state . weekend = 'true' ;
2015-07-01 00:26:59 +02:00
return app . calendar . View . show _weekend . call ( this , state ) ;
2015-07-22 01:45:38 +02:00
} ,
scroll : function ( delta )
{
var d = new Date ( app . calendar . state . date ) ;
d . setUTCDate ( d . getUTCDate ( ) + ( delta ) ) ;
return d ;
2015-07-01 00:26:59 +02:00
}
} ) ,
day4 : app . classes . calendar . prototype . View . extend ( {
header : function ( state ) {
2016-01-21 19:35:53 +01:00
return app . calendar . View . header . call ( this , state ) ;
2015-07-01 00:26:59 +02:00
} ,
end _date : function ( state ) {
var d = app . calendar . View . end _date . call ( this , state ) ;
state . days = '4' ;
d . setUTCHours ( 24 * 4 - 1 ) ;
d . setUTCMinutes ( 59 ) ;
d . setUTCSeconds ( 59 ) ;
d . setUTCMilliseconds ( 0 ) ;
return d ;
2015-08-19 02:08:22 +02:00
} ,
show _weekend : function ( state ) {
2015-11-06 01:37:23 +01:00
state . weekend = 'true' ;
2015-08-19 02:08:22 +02:00
return true ;
2015-09-14 22:47:25 +02:00
} ,
scroll : function ( delta )
{
var d = new Date ( app . calendar . state . date ) ;
d . setUTCDate ( d . getUTCDate ( ) + ( 4 * delta ) ) ;
return d ;
2015-07-01 00:26:59 +02:00
}
} ) ,
week : app . classes . calendar . prototype . View . extend ( {
header : function ( state ) {
2015-10-16 19:32:21 +02:00
var end _date = state . last ;
if ( ! app . classes . calendar . views . week . show _weekend ( state ) )
{
end _date = new Date ( state . last ) ;
end _date . setUTCDate ( end _date . getUTCDate ( ) - 2 ) ;
}
2016-01-21 19:35:53 +01:00
return app . calendar . View . _owner ( state ) + app . calendar . egw . lang ( 'Week' ) + ' ' +
2015-08-19 02:08:22 +02:00
app . calendar . date . week _number ( state . first ) + ': ' +
2016-06-13 18:03:52 +02:00
app . calendar . date . long _date ( state . first , end _date ) ;
2015-07-01 00:26:59 +02:00
} ,
start _date : function ( state ) {
2015-07-15 18:29:10 +02:00
return app . calendar . date . start _of _week ( app . calendar . View . start _date . call ( this , state ) ) ;
2015-07-01 00:26:59 +02:00
} ,
end _date : function ( state ) {
var d = app . calendar . date . start _of _week ( state . date || new Date ( ) ) ;
// Always 7 days, we just turn weekends on or off
d . setUTCHours ( 24 * 7 - 1 ) ;
d . setUTCMinutes ( 59 ) ;
d . setUTCSeconds ( 59 ) ;
d . setUTCMilliseconds ( 0 ) ;
return d ;
}
} ) ,
weekN : app . classes . calendar . prototype . View . extend ( {
header : function ( state ) {
2016-01-21 19:35:53 +01:00
return app . calendar . View . _owner ( state ) + app . calendar . egw . lang ( 'Week' ) + ' ' +
2015-08-19 02:08:22 +02:00
app . calendar . date . week _number ( state . first ) + ' - ' +
app . calendar . date . week _number ( state . last ) + ': ' +
2016-06-13 18:03:52 +02:00
app . calendar . date . long _date ( state . first , state . last ) ;
2015-07-01 00:26:59 +02:00
} ,
start _date : function ( state ) {
2015-12-03 21:44:52 +01:00
return app . calendar . date . start _of _week ( app . calendar . View . start _date . call ( this , state ) ) ;
2015-07-01 00:26:59 +02:00
} ,
end _date : function ( state ) {
state . days = '' + ( state . days >= 5 ? state . days : egw . preference ( 'days_in_weekview' , 'calendar' ) || 7 ) ;
2015-12-03 21:44:52 +01:00
var d = app . calendar . date . start _of _week ( app . calendar . View . start _date . call ( this , state ) ) ;
2015-07-01 00:26:59 +02:00
// Always 7 days, we just turn weekends on or off
2016-02-03 19:27:52 +01:00
d . setUTCHours ( 24 * 7 * ( parseInt ( this . egw . preference ( 'multiple_weeks' , 'calendar' ) ) || 3 ) - 1 ) ;
2015-07-01 00:26:59 +02:00
return d ;
2015-07-15 15:16:31 +02:00
}
2015-07-01 00:26:59 +02:00
} ) ,
month : app . classes . calendar . prototype . View . extend ( {
header : function ( state )
{
var formatDate = new Date ( state . date ) ;
formatDate = new Date ( formatDate . valueOf ( ) + formatDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
2016-01-21 19:35:53 +01:00
return app . calendar . View . _owner ( state ) + app . calendar . egw . lang ( date ( 'F' , formatDate ) ) + ' ' + date ( 'Y' , formatDate ) ;
2015-07-01 00:26:59 +02:00
} ,
start _date : function ( state ) {
2015-07-15 15:16:31 +02:00
var d = app . calendar . View . start _date . call ( this , state ) ;
2015-07-01 00:26:59 +02:00
d . setUTCDate ( 1 ) ;
return app . calendar . date . start _of _week ( d ) ;
} ,
end _date : function ( state ) {
2015-07-15 15:16:31 +02:00
var d = app . calendar . View . end _date . call ( this , state ) ;
2016-01-21 16:40:32 +01:00
d = new Date ( d . getFullYear ( ) , d . getUTCMonth ( ) + 1 , 1 , 0 , - d . getTimezoneOffset ( ) , 0 ) ;
d . setUTCSeconds ( d . getUTCSeconds ( ) - 1 ) ;
return app . calendar . date . end _of _week ( d ) ;
2015-07-22 01:45:38 +02:00
} ,
2015-08-19 02:08:22 +02:00
granularity : function ( state ) {
2016-01-13 00:55:59 +01:00
// Always a list, not a grid
return 0 ;
2015-08-19 02:08:22 +02:00
} ,
2015-07-22 01:45:38 +02:00
scroll : function ( delta )
{
var d = new Date ( app . calendar . state . date ) ;
d . setUTCMonth ( d . getUTCMonth ( ) + delta ) ;
return d ;
2015-07-15 15:16:31 +02:00
}
2015-07-01 00:26:59 +02:00
} ) ,
planner : app . classes . calendar . prototype . View . extend ( {
header : function ( state ) {
var startDate = new Date ( state . first ) ;
startDate = new Date ( startDate . valueOf ( ) + startDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
var endDate = new Date ( state . last ) ;
endDate = new Date ( endDate . valueOf ( ) + endDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
2016-01-21 19:35:53 +01:00
return app . calendar . View . _owner ( state ) + date ( egw . preference ( 'dateformat' ) , startDate ) +
2015-08-11 17:35:54 +02:00
( startDate == endDate ? '' : ' - ' + date ( egw . preference ( 'dateformat' ) , endDate ) ) ;
2015-07-01 00:26:59 +02:00
} ,
etemplates : [ 'calendar.planner' ] ,
group _by : function ( state ) {
2015-11-10 01:56:31 +01:00
return state . sortby ? state . sortby : 0 ;
2015-07-01 00:26:59 +02:00
} ,
2016-02-03 19:27:52 +01:00
// Note: Planner uses the additional value of planner_view to determine
// the start & end dates using other view's functions
2015-07-01 00:26:59 +02:00
start _date : function ( state ) {
2016-01-15 01:05:02 +01:00
// Start here, in case we can't find anything better
2015-07-01 00:26:59 +02:00
var d = app . calendar . View . start _date . call ( this , state ) ;
2016-01-15 01:05:02 +01:00
2016-01-19 00:26:19 +01:00
if ( state . sortby && state . sortby === 'month' )
{
d . setUTCDate ( 1 ) ;
}
2016-02-03 19:27:52 +01:00
else if ( state . planner _view && app . classes . calendar . views [ state . planner _view ] )
2015-12-23 21:50:33 +01:00
{
2016-02-03 19:27:52 +01:00
d = app . classes . calendar . views [ state . planner _view ] . start _date . call ( this , state ) ;
2015-12-23 21:50:33 +01:00
}
2016-02-03 19:27:52 +01:00
else
2015-07-01 00:26:59 +02:00
{
2015-12-21 19:14:33 +01:00
d = app . calendar . date . start _of _week ( d ) ;
d . setUTCHours ( 0 ) ;
d . setUTCMinutes ( 0 ) ;
d . setUTCSeconds ( 0 ) ;
d . setUTCMilliseconds ( 0 ) ;
return d ;
2015-07-01 00:26:59 +02:00
}
return d ;
} ,
end _date : function ( state ) {
2016-02-17 20:56:54 +01:00
2015-07-01 00:26:59 +02:00
var d = app . calendar . View . end _date . call ( this , state ) ;
if ( state . sortby && state . sortby === 'month' )
{
d . setUTCDate ( 0 ) ;
d . setUTCFullYear ( d . getUTCFullYear ( ) + 1 ) ;
}
2016-02-03 19:27:52 +01:00
else if ( state . planner _view && app . classes . calendar . views [ state . planner _view ] )
2015-07-01 00:26:59 +02:00
{
2016-02-03 19:27:52 +01:00
d = app . classes . calendar . views [ state . planner _view ] . end _date . call ( this , state ) ;
2015-07-01 00:26:59 +02:00
}
2015-12-23 21:50:33 +01:00
else if ( state . days )
{
// This one comes from a grid view, but we'll use it
d . setUTCDate ( d . getUTCDate ( ) + parseInt ( state . days ) - 1 ) ;
delete state . days ;
}
2016-02-03 19:27:52 +01:00
else
2015-07-01 00:26:59 +02:00
{
2015-12-22 21:07:40 +01:00
d = app . calendar . date . end _of _week ( d ) ;
2015-07-01 00:26:59 +02:00
}
return d ;
2015-08-06 19:12:34 +02:00
} ,
scroll : function ( delta )
{
2016-02-03 19:27:52 +01:00
if ( app . calendar . state . planner _view )
{
return app . classes . calendar . views [ app . calendar . state . planner _view ] . scroll . call ( this , delta ) ;
}
2015-08-19 18:17:55 +02:00
var d = new Date ( app . calendar . state . date ) ;
// Yearly view, grouped by month - scroll 1 month
if ( app . calendar . state . sortby === 'month' )
{
2016-06-13 18:03:52 +02:00
d . setUTCMonth ( d . getUTCMonth ( ) + delta ) ;
2015-08-19 18:17:55 +02:00
d . setUTCDate ( 1 ) ;
d . setUTCHours ( 0 ) ;
d . setUTCMinutes ( 0 ) ;
return d ;
}
2015-08-06 19:12:34 +02:00
// Need to set the day count, or auto date ranging takes over and
// makes things buggy
if ( app . calendar . state . first && app . calendar . state . last )
{
var diff = new Date ( app . calendar . state . last ) - new Date ( app . calendar . state . first ) ;
2016-02-03 19:27:52 +01:00
var days = Math . round ( diff / ( 1000 * 3600 * 24 ) ) ;
2015-08-06 19:12:34 +02:00
}
2016-02-03 19:27:52 +01:00
d . setUTCDate ( d . getUTCDate ( ) + ( days * delta ) ) ;
if ( days > 8 )
2015-08-06 19:12:34 +02:00
{
d = app . calendar . date . start _of _week ( d ) ;
}
return d ;
2015-07-01 00:26:59 +02:00
}
} ) ,
listview : app . classes . calendar . prototype . View . extend ( {
2015-10-16 19:32:21 +02:00
header : function ( state )
{
2016-07-26 17:51:36 +02:00
var startDate = new Date ( state . first || state . date ) ;
2015-10-16 19:32:21 +02:00
startDate = new Date ( startDate . valueOf ( ) + startDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
2015-11-24 17:04:44 +01:00
var start _check = '' + startDate . getFullYear ( ) + startDate . getMonth ( ) + startDate . getDate ( ) ;
2015-10-16 19:32:21 +02:00
2016-07-26 17:51:36 +02:00
var endDate = new Date ( state . last || state . date ) ;
2015-10-16 19:32:21 +02:00
endDate = new Date ( endDate . valueOf ( ) + endDate . getTimezoneOffset ( ) * 60 * 1000 ) ;
2015-11-24 17:04:44 +01:00
var end _check = '' + endDate . getFullYear ( ) + endDate . getMonth ( ) + endDate . getDate ( ) ;
2016-01-21 19:35:53 +01:00
return app . calendar . View . _owner ( state ) +
2015-10-16 19:32:21 +02:00
date ( egw . preference ( 'dateformat' ) , startDate ) +
2015-11-24 17:04:44 +01:00
( start _check == end _check ? '' : ' - ' + date ( egw . preference ( 'dateformat' ) , endDate ) ) ;
2015-10-16 19:32:21 +02:00
} ,
2015-12-10 01:40:04 +01:00
etemplates : [ 'calendar.list' ]
2015-07-01 00:26:59 +02:00
} )
} }
2015-10-26 16:10:39 +01:00
) ;