2020-03-05 13:21:02 +01:00
"use strict" ;
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$
* /
2020-03-05 13:21:02 +01:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2013-11-05 19:08:07 +01:00
/ * e g w : u s e s
2020-03-05 13:21:02 +01:00
/ a p i / j s / j s a p i / e g w _ a p p . j s ;
/ e t e m p l a t e / j s / e t e m p l a t e 2 . j s ;
/ c a l e n d a r / j s / V i e w . j s ;
/ 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 ;
/ 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 ;
/ 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 ;
/ 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
* /
2020-03-05 13:21:02 +01:00
var egw _app _1 = require ( "../../api/js/jsapi/egw_app" ) ;
var etemplate2 _1 = require ( "../../api/js/etemplate/etemplate2" ) ;
var View _1 = require ( "./View" ) ;
var et2 _widget _view _1 = require ( "./et2_widget_view" ) ;
var et2 _widget _timegrid _1 = require ( "./et2_widget_timegrid" ) ;
var et2 _widget _daycol _1 = require ( "./et2_widget_daycol" ) ;
var et2 _widget _planner _row _1 = require ( "./et2_widget_planner_row" ) ;
var et2 _widget _event _1 = require ( "./et2_widget_event" ) ;
2020-09-22 19:33:20 +02:00
var et2 _widget _dialog _1 = require ( "../../api/js/etemplate/et2_widget_dialog" ) ;
var et2 _core _valueWidget _1 = require ( "../../api/js/etemplate/et2_core_valueWidget" ) ;
var et2 _core _widget _1 = require ( "../../api/js/etemplate/et2_core_widget" ) ;
var et2 _core _inputWidget _1 = require ( "../../api/js/etemplate/et2_core_inputWidget" ) ;
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
2020-03-05 13:21:02 +01:00
* in CalendarApp . 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
*
2011-04-27 18:53:06 +02:00
* /
2020-03-05 13:21:02 +01:00
var CalendarApp = /** @class */ ( function ( _super ) {
_ _extends ( CalendarApp , _super ) ;
/ * *
* Constructor
*
* /
function CalendarApp ( ) {
var _this =
/ *
// categories have nothing to do with calendar, but eT2 objects loads calendars app.js
if ( window . framework && framework . applications . calendar . browser &&
framework . applications . calendar . browser . currentLocation . match ( 'menuaction=preferences\.preferences_categories_ui\.index' ) )
{
this . _super . apply ( this , arguments ) ;
return ;
}
else // make calendar object available, even if not running in top window, as sidebox does
if ( window . top !== window && ! egw ( window ) . is _popup ( ) && window . top . app . calendar )
{
window . app . calendar = window . top . app . calendar ;
return ;
}
else if ( window . top == window && ! egw ( window ) . is _popup ( ) )
{
// Show loading div
egw . loading _prompt (
this . appname , true , egw . lang ( 'please wait...' ) ,
typeof framework !== 'undefined' ? framework . applications . calendar . tab . contentDiv : false ,
egwIsMobile ( ) ? 'horizental' : 'spinner'
) ;
}
* /
2020-04-03 18:59:53 +02:00
// call parent
_super . call ( this , 'calendar' ) || this ;
2020-03-05 13:21:02 +01:00
/ * *
* Needed for JSON callback
* /
_this . prefix = 'calendar' ;
/ * *
* etemplate for the sidebox filters
* /
_this . sidebox _et2 = null ;
/ * *
* Current internal state
*
* If you need to change state , you can pass just the fields to change to
* update _state ( ) .
* /
_this . state = {
date : new Date ( ) ,
view : egw . preference ( 'saved_states' , 'calendar' ) ?
// @ts-ignore
egw . preference ( 'saved_states' , 'calendar' ) . view :
egw . preference ( 'defaultcalendar' , 'calendar' ) || 'day' ,
owner : egw . user ( 'account_id' ) ,
keywords : '' ,
2020-07-14 21:39:45 +02:00
last : undefined ,
first : undefined
2020-03-05 13:21:02 +01: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.
_this . sidebox _changes _views = [ 'day' , 'week' , 'month' ] ;
// Calendar allows other apps to hook into the sidebox. We keep these etemplates
// up to date as state is changed.
_this . sidebox _hooked _templates = [ ] ;
// List of queries in progress, to prevent home from requesting the same thing
_this . _queries _in _progress = [ ] ;
// Calendar-wide autorefresh
_this . _autorefresh _timer = null ;
// Flag if the state is being updated
_this . state _update _in _progress = false ;
/ * *
* Some handy date calculations
* All take either a Date object or full date with timestamp ( Z )
* /
_this . date = {
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' ;
} ,
/ * *
* 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
* @ 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
* @ 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 ) ;
}
var first _format = new Date ( first . valueOf ( ) + first . getTimezoneOffset ( ) * 60 * 1000 ) ;
if ( typeof last == 'string' && last ) {
last = new Date ( last ) ;
}
if ( ! last || typeof last !== 'object' ) {
last = false ;
}
if ( last ) {
var last _format = new Date ( last . valueOf ( ) + last . getTimezoneOffset ( ) * 60 * 1000 ) ;
}
if ( ! display _time )
display _time = false ;
if ( ! display _day )
display _day = false ;
var range = '' ;
var datefmt = egw . preference ( 'dateformat' ) ;
var timefmt = egw . preference ( 'timeformat' ) === '12' ? 'h:i a' : 'H:i' ;
var month _before _day = datefmt [ 0 ] . toLowerCase ( ) == 'm' ||
datefmt [ 2 ] . toLowerCase ( ) == 'm' && datefmt [ 4 ] == 'd' ;
if ( display _day ) {
range = jQuery . datepicker . formatDate ( 'DD' , first _format ) + ( datefmt [ 0 ] != 'd' ? ' ' : ', ' ) ;
}
for ( var i = 0 ; i < 5 ; i += 2 ) {
switch ( datefmt [ i ] ) {
case 'd' :
range += first . getUTCDate ( ) + ( datefmt [ 1 ] == '.' ? '.' : '' ) ;
if ( last && ( first . getUTCMonth ( ) != last . getUTCMonth ( ) || first . getUTCFullYear ( ) != last . getUTCFullYear ( ) ) ) {
if ( ! month _before _day ) {
range += jQuery . datepicker . formatDate ( 'MM' , first _format ) ;
}
if ( first . getFullYear ( ) != last . getFullYear ( ) && datefmt [ 0 ] != 'Y' ) {
range += ( datefmt [ 0 ] != 'd' ? ', ' : ' ' ) + first . getFullYear ( ) ;
}
if ( display _time ) {
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , first _format ) ;
}
if ( ! last ) {
return range ;
}
range += ' - ' ;
if ( first . getFullYear ( ) != last . getFullYear ( ) && datefmt [ 0 ] == 'Y' ) {
range += last . getUTCFullYear ( ) + ', ' ;
}
if ( month _before _day ) {
range += jQuery . datepicker . formatDate ( 'MM' , last _format ) ;
}
}
else if ( last ) {
if ( display _time ) {
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , last _format ) ;
}
if ( last ) {
range += ' - ' ;
}
}
if ( last ) {
range += ' ' + last . getUTCDate ( ) + ( datefmt [ 1 ] == '.' ? '.' : '' ) ;
}
break ;
case 'm' :
case 'M' :
range += ' ' + jQuery . datepicker . formatDate ( 'MM' , month _before _day || ! last ? first _format : last _format ) + ' ' ;
break ;
case 'Y' :
if ( datefmt [ 0 ] != 'm' ) {
range += ' ' + ( datefmt [ 0 ] == 'Y' ? first . getUTCFullYear ( ) + ( datefmt [ 2 ] == 'd' ? ', ' : ' ' ) : last . getUTCFullYear ( ) + ' ' ) ;
}
break ;
}
}
if ( display _time && last ) {
range += ' ' + jQuery . datepicker . formatDate ( dateTimeFormat ( timefmt ) , last _format ) ;
}
if ( datefmt [ 4 ] == 'Y' && datefmt [ 0 ] == 'm' ) {
range += ', ' + last . getUTCFullYear ( ) ;
}
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
*
* @ param { string | Date } _date
* @ 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 ) ) ;
} ,
start _of _week : function ( date ) {
var d = new Date ( date ) ;
var day = d . getUTCDay ( ) ;
var diff = 0 ;
switch ( egw . preference ( 'weekdaystarts' , 'calendar' ) ) {
case 'Saturday' :
diff = day === 6 ? 0 : day === 0 ? - 1 : - ( day + 1 ) ;
break ;
case 'Monday' :
diff = day === 0 ? - 6 : 1 - day ;
break ;
case 'Sunday' :
default :
diff = - day ;
}
d . setUTCDate ( d . getUTCDate ( ) + diff ) ;
return d ;
} ,
end _of _week : function ( date ) {
2020-07-30 21:00:53 +02:00
var d = this . start _of _week ( date ) ;
2020-03-05 13:21:02 +01:00
d . setUTCDate ( d . getUTCDate ( ) + 6 ) ;
return d ;
}
} ;
// Scroll
jQuery ( jQuery . proxy ( _this . _scroll , _this ) ) ;
jQuery . extend ( _this . state , _this . egw . preference ( 'saved_states' , 'calendar' ) ) ;
// Set custom color for events without category
if ( _this . egw . preference ( 'no_category_custom_color' , 'calendar' ) ) {
_this . egw . css ( '.calendar_calEvent:not([class*="cat_"])' , 'background-color: ' + _this . egw . preference ( 'no_category_custom_color' , 'calendar' ) + ' !important' ) ;
}
return _this ;
}
/ * *
* Destructor
* /
CalendarApp . prototype . destroy = function ( ) {
// call parent
_super . prototype . destroy . call ( this , this . appname ) ;
// remove top window reference
// @ts-ignore
if ( window . top !== window && window . top . app . calendar === this ) {
// @ts-ignore
delete window . top . app . calendar ;
}
jQuery ( 'body' ) . off ( '.calendar' ) ;
if ( this . sidebox _et2 ) {
var date = this . sidebox _et2 . getWidgetById ( 'date' ) ;
jQuery ( window ) . off ( 'resize.calendar' + date . dom _id ) ;
}
2020-07-20 22:54:15 +02:00
this . sidebox _hooked _templates = [ ] ;
2020-03-05 13:21:02 +01:00
egw _unregisterGlobalShortcut ( jQuery . ui . keyCode . PAGE _UP , false , false , false ) ;
egw _unregisterGlobalShortcut ( jQuery . ui . keyCode . PAGE _DOWN , false , false , false ) ;
// Stop autorefresh
if ( this . _autorefresh _timer ) {
window . clearInterval ( this . _autorefresh _timer ) ;
this . _autorefresh _timer = null ;
}
} ;
/ * *
* 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 ( ) .
*
* @ param { etemplate2 } _et2 newly ready et2 object
* @ param { string } _name name of template
* /
CalendarApp . prototype . et2 _ready = function ( _et2 , _name ) {
// call parent
_super . prototype . et2 _ready . call ( this , _et2 , _name ) ;
// Avoid many problems with home
if ( _et2 . app !== 'calendar' || _name == 'admin.categories.index' ) {
egw . loading _prompt ( this . appname , false ) ;
return ;
}
// 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 ( ) ;
sidebox = jQuery ( '#favorite_sidebox_' + this . appname , egw _fw . sidemenuDiv ) ;
}
var content = this . et2 . getArrayMgr ( 'content' ) ;
switch ( _name ) {
case 'calendar.sidebox' :
this . sidebox _et2 = _et2 . widgetContainer ;
this . sidebox _hooked _templates . push ( this . sidebox _et2 ) ;
jQuery ( _et2 . DOMContainer ) . hide ( ) ;
// Set client side holiday cache for this year
// @ts-ignore
if ( egw . window . et2 _calendar _view ) {
// @ts-ignore
egw . window . et2 _calendar _view . holiday _cache [ content . data . year ] = content . data . holidays ;
delete content . data . holidays ;
delete content . data . year ;
}
this . _setup _sidebox _filters ( ) ;
this . state = content . data ;
break ;
case 'calendar.add' :
this . et2 . getWidgetById ( 'title' ) . input . select ( ) ;
// Fall through to get all the edit stuff too
case 'calendar.edit' :
if ( typeof content . data [ 'conflicts' ] == 'undefined' ) {
//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 ( ) ;
this . edit _start _change ( null , this . et2 . getWidgetById ( 'start' ) ) ;
if ( this . et2 . getWidgetById ( 'recur_exception' ) ) {
this . et2 . getWidgetById ( 'recur_exception' ) . set _disabled ( ! content . data . recur _exception ||
typeof content . data . recur _exception [ 0 ] == 'undefined' ) ;
}
}
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
if ( content . data . lock _token ) {
2020-06-19 21:27:41 +02:00
window . addEventListener ( "beforeunload" , this . _unlock . bind ( this ) ) ;
2020-03-05 13:21:02 +01:00
}
}
this . alarm _custom _date ( ) ;
// 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 ( ) ;
}
// Disable loading prompt (if loaded nopopup)
egw . loading _prompt ( this . appname , false ) ;
break ;
case 'calendar.freetimesearch' :
this . set _enddate _visibility ( ) ;
break ;
case 'calendar.list' :
// Wait until _et2_view_init is done
window . setTimeout ( jQuery . proxy ( function ( ) {
this . filter _change ( ) ;
} , this ) , 0 ) ;
break ;
case 'calendar.category_report' :
this . category _report _init ( ) ;
break ;
}
// Record the templates for the views so we can switch between them
this . _et2 _view _init ( _et2 , _name ) ;
} ;
/ * *
* Observer method receives update notifications from all applications
*
* App is responsible for only reacting to "messages" it is interested in !
*
* Calendar binds listeners to the data cache , so if the data is updated , the widget
* will automatically update itself .
*
* @ 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
* /
CalendarApp . prototype . observer = function ( _msg , _app , _id , _type , _msg _type , _links ) {
var do _refresh = false ;
if ( this . state . view === 'listview' ) {
// @ts-ignore
CalendarApp . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) . refresh ( _id , _type ) ;
}
switch ( _app ) {
case 'infolog' :
jQuery ( '.calendar_calDayTodos' )
. find ( 'a' )
. each ( function ( i , a ) {
var match = a . href . split ( /&info_id=/ ) ;
if ( match && typeof match [ 1 ] != "undefined" ) {
if ( match [ 1 ] == _id )
do _refresh = true ;
}
} ) ;
// 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' ) {
if ( jQuery ( 'div [data-app="infolog"][data-app_id="' + _id + '"]' ) . length > 0 )
do _refresh = true ;
switch ( _type ) {
case 'add' :
do _refresh = true ;
break ;
}
}
if ( do _refresh ) {
// Discard cache
this . _clear _cache ( ) ;
// Calendar is the current application, refresh now
if ( framework . activeApp . appName === this . appname ) {
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 ) ) ;
}
}
break ;
case 'calendar' :
// Regular refresh
var event _1 = null ;
if ( _id ) {
event _1 = egw . dataGetUIDdata ( 'calendar::' + _id ) ;
}
if ( event _1 && event _1 . data && event _1 . data . date || _type === 'delete' ) {
// Intelligent refresh without reloading everything
var recurrences = Object . keys ( egw . dataSearchUIDs ( new RegExp ( '^calendar::' + _id + ':' ) ) ) ;
var ids = event _1 && event _1 . data && event _1 . data . recur _type && typeof _id === 'string' && _id . indexOf ( ':' ) < 0 || recurrences . length ?
recurrences :
[ 'calendar::' + _id ] ;
if ( _type === 'delete' ) {
for ( var i in ids ) {
egw . dataStoreUID ( ids [ i ] , null ) ;
}
}
// Updates are handled by events themselves through egw.data
else if ( _type !== 'update' ) {
this . _update _events ( this . state , ids ) ;
}
return false ;
}
else {
this . _clear _cache ( ) ;
// Force redraw to current state
this . setState ( { state : this . state } ) ;
return false ;
}
break ;
default :
return undefined ;
}
} ;
2020-07-14 21:39:45 +02:00
/ * *
* Handle a push notification about entry changes from the websocket
*
* @ param pushData
* @ param { string } pushData . app application name
* @ param { ( string | number ) } pushData . id id of entry to refresh or null
* @ param { string } pushData . 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 : ask server for data , add in intelligently
* @ param { object | null } pushData . acl Extra data for determining relevance . eg : owner or responsible to decide if update is necessary
* @ param { number } pushData . account _id User that caused the notification
* /
CalendarApp . prototype . push = function ( pushData ) {
// Calendar cares about calendar & infolog
if ( pushData . app !== this . appname && pushData . app !== 'infolog' )
return ;
switch ( pushData . app ) {
case "calendar" :
2020-09-22 19:33:20 +02:00
if ( pushData . type === 'delete' ) {
return _super . prototype . push . call ( this , pushData ) ;
}
2020-07-14 21:39:45 +02:00
return this . push _calendar ( pushData ) ;
case "infolog" :
return this . push _infolog ( pushData ) ;
}
} ;
/ * *
* Handle a push about infolog
*
* @ param pushData
* /
CalendarApp . prototype . push _infolog = function ( pushData ) {
2020-09-22 19:33:20 +02:00
var _this = this ;
2020-10-27 15:06:51 +01:00
var _a ;
2020-09-22 19:33:20 +02:00
// check visibility - grants is ID => permission of people we're allowed to see
var owners = [ ] ;
var infolog _grants = egw . grants ( pushData . app ) ;
// Filter what's allowed down to those we care about
var filtered = Object . keys ( infolog _grants ) . filter ( function ( account ) { return _this . state . owner . indexOf ( account ) >= 0 ; } ) ;
// Check if we're interested in displaying by owner / responsible
var owner _check = filtered . filter ( function ( value ) {
return pushData . acl . info _owner == value || pushData . acl . info _responsible . indexOf ( value ) >= 0 ;
} ) ;
if ( ! owner _check || owner _check . length == 0 ) {
// The owner is not in the list of what we're allowed / care about
return ;
}
// Only need to update the list if we're on that view
var update _list = this . state . view == "day" ;
// Delete, just pull it out of the list
if ( update _list && pushData . type == "delete" ) {
jQuery ( '.calendar_calDayTodos' )
. find ( 'a' )
. each ( function ( i , a ) {
var match = a . href . split ( /&info_id=/ ) ;
if ( match && typeof match [ 1 ] != "undefined" && match [ 1 ] == pushData . id ) {
jQuery ( a ) . parentsUntil ( "tbody" ) . remove ( ) ;
}
} ) ;
}
// Refresh todos if we're there - add, update or edit doesn't matter
if ( update _list ) {
this . egw . jsonq ( 'calendar_uiviews::ajax_get_todos' , [ this . state . date , this . state . owner [ 0 ] ] , function ( data ) {
this . getWidgetById ( 'label' ) . set _value ( data . label || '' ) ;
this . getWidgetById ( 'todos' ) . set _value ( { content : data . todos || '' } ) ;
} , CalendarApp . views . day . etemplates [ 1 ] . widgetContainer ) ;
}
else {
// Only care about certain infolog types, or already loaded (type may have changed)
2020-10-27 15:06:51 +01:00
var types = ( ( _a = egw . preference ( 'calendar_integration' , 'infolog' ) ) === null || _a === void 0 ? void 0 : _a . split ( "," ) ) || [ ] ;
2020-09-22 19:33:20 +02:00
var info _uid = this . appname + "::" + pushData . app + pushData . id ;
if ( types . indexOf ( pushData . acl . info _type ) >= 0 || this . egw . dataHasUID ( info _uid ) ) {
if ( pushData . type === 'delete' ) {
return this . egw . dataStoreUID ( info _uid , null ) ;
}
// We could try to be a little smarter, but this will work
// Discard cache
this . _clear _cache ( ) ;
// Calendar is the current application, refresh now
if ( framework . activeApp . appName === this . appname ) {
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' , function ( ) {
this . setState ( { state : this . state } ) ;
} . bind ( this ) ) ;
}
}
}
2020-07-14 21:39:45 +02:00
} ;
/ * *
* Handle a push from calendar
*
* @ param pushData
* /
CalendarApp . prototype . push _calendar = function ( pushData ) {
2020-07-30 21:00:53 +02:00
var _this = this ;
2020-07-16 18:04:13 +02:00
// pushData does not contain everything, just the minimum. See calendar_hooks::search_link().
var cal _event = pushData . acl || { } ;
2020-07-14 21:39:45 +02:00
// check visibility - grants is ID => permission of people we're allowed to see
var owners = [ ] ;
if ( typeof this . _grants === 'undefined' ) {
this . _grants = egw . grants ( this . appname ) ;
}
// Filter what's allowed down to those we care about
2020-07-30 21:00:53 +02:00
var filtered = Object . keys ( this . _grants ) . filter ( function ( account ) { return _this . state . owner . indexOf ( account ) >= 0 ; } ) ;
2020-07-14 21:39:45 +02:00
// Check if we're interested in displaying by owner / participant
2020-07-30 21:00:53 +02:00
var owner _check = et2 _widget _event _1 . et2 _calendar _event . owner _check ( cal _event , jQuery . extend ( { } , { options : { owner : filtered } } , this . et2 ) ) ;
2020-07-14 21:39:45 +02:00
if ( ! owner _check ) {
// The owner is not in the list of what we're allowed / care about
return ;
}
// Check if we're interested by date?
2020-07-16 18:04:13 +02:00
if ( cal _event . end <= new Date ( this . state . first ) . valueOf ( ) / 1000 || cal _event . start > new Date ( this . state . last ) . valueOf ( ) / 1000 ) {
2020-07-14 21:39:45 +02:00
// The event is outside our current view
return ;
}
2020-07-27 18:13:13 +02:00
// Do we already have "fresh" data? Most user actions give fresh data in response
var existing = egw . dataGetUIDdata ( 'calendar::' + pushData . id ) ;
if ( existing && Math . abs ( existing . timestamp - new Date ( ) . valueOf ( ) ) < 1000 ) {
// Update directly
this . _update _events ( this . state , [ 'calendar::' + pushData . id ] ) ;
return ;
}
;
// Ask for the real data, we don't have it
2020-07-14 21:39:45 +02:00
egw . json ( "calendar.calendar_ui.ajax_get" , [ [ pushData . id ] ] , function ( data ) {
2020-07-14 22:13:05 +02:00
if ( data && data . data && data . data . data )
return ;
2020-07-14 21:39:45 +02:00
// Store it, which will call all registered listeners
egw . dataStoreUID ( data . uid , data . data ) ;
// Any existing events were updated. Run this to catch new events or events moved into view
2020-07-27 18:13:13 +02:00
this . _update _events ( this . state , [ data . uid ] ) ;
2020-07-14 21:39:45 +02:00
} . bind ( this ) ) . sendRequest ( true ) ;
} ;
2020-03-05 13:21:02 +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
* /
CalendarApp . prototype . linkHandler = function ( _url ) {
if ( _url == 'about:blank' || _url . match ( 'menuaction=preferences\.preferences_categories_ui\.index' ) ) {
return false ;
}
if ( _url . match ( 'menuaction=calendar\.calendar_uiviews\.' ) ) {
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 ) {
q [ i . split ( '=' ) [ 0 ] ] = unescape ( i . split ( '=' ) [ 1 ] ) ;
} ) ;
delete q . ajax ;
delete q . menuaction ;
if ( ! view && q . view || q . view != view && view == 'index' )
view = q . view ;
// 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 ;
}
if ( this . sidebox _et2 && typeof CalendarApp . views [ view ] == 'undefined' && view != 'index' ) {
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 ) ) ;
jQuery ( this . sidebox _et2 . parentNode ) . show ( ) ;
return true ;
}
// Known AJAX view
else if ( CalendarApp . views [ view ] ) {
// Reload of known view?
if ( view == 'index' ) {
var pref = this . egw . preference ( 'saved_states' , 'calendar' ) ;
view = pref . view || 'day' ;
}
// View etemplate not loaded
if ( typeof CalendarApp . 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 ;
}
}
else if ( this . sidebox _et2 ) {
var iframe = this . sidebox _et2 . getWidgetById ( 'iframe' ) ;
if ( ! iframe )
return false ;
iframe . set _src ( _url ) ;
jQuery ( this . sidebox _et2 . parentNode ) . show ( ) ;
// Hide other views
for ( var _view in CalendarApp . views ) {
for ( var i = 0 ; i < CalendarApp . views [ _view ] . etemplates . length ; i ++ ) {
jQuery ( CalendarApp . views [ _view ] . etemplates [ i ] . DOMContainer ) . hide ( ) ;
}
}
this . state . view = '' ;
return true ;
}
// can not load our own index page, has to be done by framework
return false ;
} ;
/ * *
* Handle actions from the toolbar
*
* @ param { egwAction } action Action from the toolbar
* /
CalendarApp . prototype . toolbar _action = function ( action ) {
// Most can just provide state change data
if ( action . data && action . data . state ) {
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 ) ;
}
// Special handling
switch ( action . id ) {
case 'add' :
// Default date/time to start of next hour
var tempDate = new Date ( ) ;
if ( tempDate . getMinutes ( ) !== 0 ) {
tempDate . setHours ( tempDate . getHours ( ) + 1 ) ;
tempDate . setMinutes ( 0 ) ;
}
var today = new Date ( tempDate . getFullYear ( ) , tempDate . getMonth ( ) , tempDate . getDate ( ) , tempDate . getHours ( ) , - tempDate . getTimezoneOffset ( ) , 0 ) ;
return egw . open ( null , "calendar" , "add" , { start : today } ) ;
case 'weekend' :
this . update _state ( { weekend : action . checked } ) ;
break ;
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 ;
case 'next' :
case 'previous' :
var delta = action . id == 'previous' ? - 1 : 1 ;
2020-07-30 21:00:53 +02:00
var view = CalendarApp . views [ this . state . view ] || false ;
var start = new Date ( this . state . date ) ;
2020-03-05 13:21:02 +01:00
if ( view ) {
start = view . scroll ( delta ) ;
2020-07-30 21:00:53 +02:00
app . calendar . update _state ( { date : this . date . toString ( start ) } ) ;
2020-03-05 13:21:02 +01:00
}
break ;
}
} ;
/ * *
* Set the app header
*
* 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
*
* @ param { string } header Text to display
* /
CalendarApp . prototype . set _app _header = function ( header ) {
var template = etemplate2 _1 . 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' ) ;
}
} ;
/ * *
* 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 }
* /
CalendarApp . prototype . _sortable = function ( ) {
// Calender current state
var state = this . getState ( ) ;
// 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 {
var sortable = weekly ;
if ( daily . sortable ( 'instance' ) )
daily . sortable ( 'disable' ) ;
}
if ( ! sortable . sortable ( 'instance' ) ) {
sortable . sortable ( {
cancel : "#divAppboxHeader, .calendar_calWeekNavHeader, .calendar_plannerHeader" ,
handle : '.calendar_calGridHeader' ,
//placeholder: "srotable_cal_wk_ph",
axis : "y" ,
revert : true ,
helper : "clone" ,
create : function ( ) {
var $sortItem = jQuery ( this ) ;
} ,
start : function ( event , ui ) {
jQuery ( '.calendar_calTimeGrid' , ui . helper ) . css ( 'position' , 'absolute' ) ;
// Put owners into row IDs
CalendarApp . views [ app . calendar . state . view ] . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
if ( widget . options . owner && ! widget . disabled ) {
widget . div . parents ( 'tr' ) . attr ( 'data-owner' , widget . options . owner ) ;
}
else {
widget . div . parents ( 'tr' ) . removeAttr ( 'data-owner' ) ;
}
} , this , et2 _widget _timegrid _1 . et2 _calendar _timegrid ) ;
} ,
stop : function ( ) {
} ,
update : function ( ) {
var state = app . calendar . getState ( ) ;
if ( state && typeof state . owner !== 'undefined' ) {
var sortedArr = sortable . sortable ( 'toArray' , { attribute : "data-owner" } ) ;
// No duplicates, no empties
sortedArr = sortedArr . filter ( function ( value , index , self ) {
return value !== '' && self . indexOf ( value ) === index ;
} ) ;
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
CalendarApp . views . day . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
var idx = sortedArr . indexOf ( widget . options . owner . toString ( ) ) ;
// 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 _widget _daycol _1 . et2 _calendar _daycol ) ;
parent . day _widgets . sort ( function ( a , b ) {
return children . indexOf ( a ) - children . indexOf ( b ) ;
} ) ;
}
else {
// Re-order the children, or it won't stay
CalendarApp . views . day . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( widget ) {
parent = widget . _parent ;
var idx = sortedArr . indexOf ( widget . options . owner ) ;
children . splice ( idx , 0 , widget ) ;
widget . resize ( ) ;
} , this , et2 _widget _timegrid _1 . et2 _calendar _timegrid ) ;
}
parent . _children . sort ( function ( a , b ) {
return children . indexOf ( a ) - children . indexOf ( b ) ;
} ) ;
// Directly update, since there is no other changes needed,
// and we don't want the current sort order applied
app . calendar . state . owner = sortedArr ;
parent . options . owner = sortedArr ;
}
}
} ) ;
}
// Enable or disable
if ( state . owner . length > 1 && ( state . view == 'day' && state . owner . length < parseInt ( '' + egw . preference ( 'day_consolidate' , 'calendar' ) ) ||
state . view == 'week' && state . owner . length < parseInt ( '' + egw . preference ( 'week_consolidate' , 'calendar' ) ) ) ) {
sortable . sortable ( 'enable' )
. sortable ( "refresh" )
. disableSelection ( ) ;
var options = { } ;
switch ( state . view ) {
case "day" :
options = {
placeholder : "srotable_cal_day_ph" ,
axis : "x" ,
handle : '> div:first' ,
helper : function ( event , element ) {
var scroll = element . parentsUntil ( '.calendar_calTimeGrid' ) . last ( ) . next ( ) ;
var helper = jQuery ( document . createElement ( 'div' ) )
. append ( element . clone ( ) )
. css ( 'height' , scroll . parent ( ) . css ( 'height' ) )
. css ( 'background-color' , 'white' )
. css ( 'width' , element . css ( 'width' ) ) ;
return helper ;
}
} ;
sortable . sortable ( 'option' , options ) ;
break ;
case "week" :
options = {
placeholder : "srotable_cal_wk_ph" ,
axis : "y" ,
handle : '.calendar_calGridHeader' ,
helper : 'clone'
} ;
sortable . sortable ( 'option' , options ) ;
break ;
}
}
else {
sortable . sortable ( 'disable' ) ;
}
} ;
2020-06-19 21:27:41 +02:00
/ * *
* Unlock the event before closing the popup
*
* @ private
* /
CalendarApp . prototype . _unlock = function ( ) {
var content = this . et2 . getArrayMgr ( 'content' ) ;
this . egw . json ( 'calendar.calendar_uiforms.ajax_unlock' , [ content . data . id , content . data . lock _token ] , null , this , "keepalive" , null ) . sendRequest ( ) ;
} ;
2020-03-05 13:21:02 +01:00
/ * *
* Bind scroll event
* When the user scrolls , we ' ll move enddate - startdate days
* /
CalendarApp . prototype . _scroll = function ( ) {
/ * *
* 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
var id = jQuery ( this ) . closest ( '.et2_container' ) . attr ( 'id' ) ;
if ( id ) {
var template = etemplate2 _1 . etemplate2 . getById ( id ) ;
}
else {
template = CalendarApp . views [ app . calendar . state . view ] . etemplates [ 0 ] ;
}
if ( ! template )
return ;
// Prevent scrolling too fast
app . calendar . _scroll _disabled = true ;
// Animate the transition, if possible
var widget = null ;
template . widgetContainer . iterateOver ( function ( w ) {
if ( w . getDOMNode ( ) == this )
widget = w ;
2020-09-22 19:33:20 +02:00
} , this , et2 _core _widget _1 . et2 _widget ) ;
2020-03-05 13:21:02 +01:00
if ( widget == null ) {
template . widgetContainer . iterateOver ( function ( w ) {
widget = w ;
} , this , et2 _widget _timegrid _1 . et2 _calendar _timegrid ) ;
if ( widget == null )
return ;
}
/ * D i s a b l e d
*
// We clone the nodes so we can animate the transition
var original = jQuery ( widget . getDOMNode ( ) ) . closest ( '.et2_grid' ) ;
var cloned = original . clone ( true ) . attr ( "id" , "CLONE" ) ;
// Moving this stuff around scrolls things around too
// We need this later
var scrollTop = jQuery ( '.calendar_calTimeGridScroll' , original ) . scrollTop ( ) ;
// This is to hide the scrollbar
var wrapper = original . parent ( ) ;
if ( direction == "right" || direction == "left" )
{
original . css ( { "display" : "inline-block" , "width" : original . width ( ) + "px" } ) ;
cloned . css ( { "display" : "inline-block" , "width" : original . width ( ) + "px" } ) ;
}
else
{
original . css ( "height" , original . height ( ) + "px" ) ;
cloned . css ( "height" , original . height ( ) + "px" ) ;
}
var original _size = { height : wrapper . parent ( ) . css ( 'height' ) , width : wrapper . parent ( ) . css ( 'width' ) } ;
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 ( ) ) ;
// Re-scroll to previous to avoid "jumping"
jQuery ( '.calendar_calTimeGridScroll' , original ) . scrollTop ( scrollTop ) ;
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.
original . parent ( ) . append ( cloned ) ;
// Makes it jump to destination
wrapper . css ( {
"transition-duration" : "0s" ,
"transition-delay" : "0s" ,
"transform" : direction == "up" ? "translateY(-50%)" : "translateX(-50%)"
} ) ;
// Stop browser from caching style by forcing reflow
if ( wrapper [ 0 ] ) wrapper [ 0 ] . offsetHeight ;
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"
jQuery ( '.calendar_calTimeGridScroll' , cloned ) . scrollTop ( scrollTop ) ;
// 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 ( ) {
cloned . remove ( ) ;
// Makes it jump to destination
wrapper . css ( {
"transition-duration" : "0s" ,
"transition-delay" : "0s"
} ) ;
// Clean up from animation
wrapper
. removeClass ( "calendar_slide" )
. css ( { "transform" : '' , height : '' , width : '' , overflow : '' } ) ;
wrapper . parent ( ) . css ( { overflow : '' , width : original _size . width , height : original _size . height } ) ;
original . css ( "display" , "" ) ;
if ( wrapper . length )
{
wrapper [ 0 ] . offsetHeight ;
}
wrapper . css ( {
"transition-duration" : "" ,
"transition-delay" : ""
} ) ;
// Re-scroll to start of day
template . widgetContainer . iterateOver ( function ( w ) {
w . resizeTimes ( ) ;
} , this , et2 _calendar _timegrid ) ;
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 ) ;
* /
window . setTimeout ( function ( ) {
if ( app . calendar ) {
app . calendar . _scroll _disabled = false ;
}
} , 2000 ) ;
// 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 = CalendarApp . 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 ) ;
} ;
// Bind only once, to the whole thing
/ * D i s a b l e d
jQuery ( 'body' ) . off ( '.calendar' )
//.on('wheel','.et2_container:#calendar-list,#calendar-sidebox)',
. on ( 'wheel.calendar' , '.et2_container .calendar_calTimeGrid, .et2_container .calendar_plannerWidget' ,
function ( e )
{
// Consume scroll if in the middle of something
if ( app . calendar . _scroll _disabled ) return false ;
// 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 ;
jQuery ( this ) . children ( ":not(.calendar_calGridHeader)" ) . each ( function ( ) {
// 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 ;
} ) ;
if ( ! at _bottom && ! at _top ) return ;
e . preventDefault ( ) ;
scroll _animate . call ( this , direction > 0 ? "down" : "up" , direction ) ;
return false ;
}
) ;
* /
if ( typeof framework !== 'undefined' && framework . applications . calendar && framework . applications . calendar . tab ) {
jQuery ( framework . applications . calendar . tab . contentDiv )
. swipe ( 'destroy' ) ;
jQuery ( framework . applications . calendar . tab . contentDiv )
. swipe ( {
//Generic swipe handler for all directions
swipe : function ( event , direction , distance , duration , fingerCount ) {
if ( direction == "up" || direction == "down" ) {
if ( fingerCount <= 1 )
return ;
var at _bottom = direction !== - 1 ;
var at _top = direction !== 1 ;
jQuery ( this ) . children ( ":not(.calendar_calGridHeader)" ) . each ( function ( ) {
// 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 ;
} ) ;
}
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 ] ;
scroll _animate . call ( jQuery ( event . target ) . closest ( '.calendar_calTimeGrid, .calendar_plannerWidget' ) [ 0 ] , direction , delta ) ;
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' ) {
return false ;
}
scroll _animate . call ( this , "up" , - 1 ) ;
return true ;
} , this ) ;
egw _registerGlobalShortcut ( jQuery . ui . keyCode . PAGE _DOWN , false , false , false , function ( ) {
if ( app . calendar . state . view == 'listview' ) {
return false ;
}
scroll _animate . call ( this , "down" , 1 ) ;
return true ;
} , this ) ;
}
} ;
/ * *
* Handler for changes generated by internal user interactions , like
* drag & drop inside calendar and resize .
*
* @ 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 }
* /
CalendarApp . prototype . event _change = function ( event , widget , dialog _button ) {
// Add loading spinner - not visible if the body / gradient is there though
widget . div . addClass ( 'loading' ) ;
// Integrated infolog event
//Get infologID if in case if it's an integrated infolog event
if ( widget . options . value . app == 'infolog' ) {
// If it is an integrated infolog event we need to edit infolog entry
egw ( ) . json ( 'stylite_infolog_calendar_integration::ajax_moveInfologEvent' , [ widget . options . value . app _id , widget . options . value . start , widget . options . value . duration ] ,
// Remove loading spinner
function ( ) { if ( widget . div )
widget . div . removeClass ( 'loading' ) ; } ) . sendRequest ( ) ;
}
else {
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 ) ;
} ;
if ( dialog _button == 'series' && widget . options . value . recur _type ) {
widget . series _split _prompt ( function ( _button _id ) {
2020-09-22 19:33:20 +02:00
if ( _button _id == et2 _widget _dialog _1 . et2 _dialog . OK _BUTTON ) {
2020-03-05 13:21:02 +01:00
_send ( ) ;
}
} ) ;
}
else {
_send ( ) ;
}
}
} ;
/ * *
* open the freetime search popup
*
* @ param { string } _link
* /
CalendarApp . prototype . freetime _search _popup = function ( _link ) {
this . egw . open _link ( _link , 'ft_search' , '700x500' ) ;
} ;
/ * *
* send an ajax request to server to set the freetimesearch window content
*
* /
CalendarApp . prototype . freetime _search = function ( ) {
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
*
* /
CalendarApp . prototype . check _recur _type = function ( ) {
var recurType = this . et2 . getWidgetById ( 'recur_type' ) ;
var recurData = this . et2 . getWidgetById ( 'recur_data' ) ;
if ( recurType && recurData ) {
recurData . set _disabled ( recurType . get _value ( ) != 2 && recurType . get _value ( ) != 4 ) ;
}
} ;
/ * *
* Actions for when the user changes the event start date in edit dialog
*
* @ returns { undefined }
* /
CalendarApp . prototype . edit _start _change = function ( input , widget ) {
if ( ! widget ) {
widget = etemplate2 _1 . etemplate2 . getById ( 'calendar-edit' ) . widgetContainer . getWidgetById ( 'start' ) ;
}
// 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 . getValue ( ) ) {
recur _end . set _min ( widget . getValue ( ) ) ;
}
2020-10-06 21:55:06 +02:00
// Update end date, min duration is 1 minute
var end = widget . getRoot ( ) . getDOMWidgetById ( 'end' ) ;
var start _time = new Date ( widget . getValue ( ) ) ;
var end _time = new Date ( end . getValue ( ) ) ;
2020-11-09 17:20:56 +01:00
if ( end . getValue ( ) && end _time <= start _time ) {
2020-10-06 21:55:06 +02:00
start _time . setMinutes ( start _time . getMinutes ( ) + 1 ) ;
end . set _value ( start _time ) ;
}
2020-03-05 13:21:02 +01:00
}
// Update currently selected alarm time
this . alarm _custom _date ( ) ;
} ;
/ * *
* Show / Hide end date , for both edit and freetimesearch popups ,
* based on if "use end date" selected or not .
*
* /
CalendarApp . prototype . set _enddate _visibility = function ( ) {
var duration = this . et2 . getWidgetById ( 'duration' ) ;
var start = this . et2 . getWidgetById ( 'start' ) ;
var end = this . et2 . getWidgetById ( 'end' ) ;
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
if ( typeof duration != 'undefined' && typeof end != 'undefined' ) {
end . set _disabled ( duration . get _value ( ) !== '' ) ;
// Only set end date if not provided, adding seconds fails with DST
if ( ! end . disabled && ! content . end ) {
end . set _value ( start . get _value ( ) ) ;
if ( typeof content . duration != 'undefined' )
end . set _value ( "+" + content . duration ) ;
}
}
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 .
* /
CalendarApp . prototype . 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' ) ;
if ( ! participant )
return ;
participant . set _autocomplete _params ( { exec : {
start : content . start ,
end : content . end ,
duration : content . duration ,
whole _day : content . whole _day ,
} } ) ;
} ;
/ * *
* handles actions selectbox in calendar edit popup
*
* @ param { mixed } _event
* @ param { et2 _base _widget } widget "actions selectBox" in edit popup window
* /
CalendarApp . prototype . actions _change = function ( _event , widget ) {
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' :
this . egw . open _link ( 'infolog.infolog_ui.edit&action=calendar&action_id=' + ( jQuery . isPlainObject ( event ) ? event [ 'id' ] : event ) , '_blank' , '700x600' , 'infolog' ) ;
this . et2 . _inst . submit ( ) ;
break ;
case 'ical' :
this . et2 . _inst . postSubmit ( ) ;
break ;
default :
this . et2 . _inst . submit ( ) ;
}
}
} ;
/ * *
* open mail compose popup window
*
* @ param { Array } vars
* @ todo need to provide right mail compose from server to custom _mail function
* /
CalendarApp . prototype . custom _mail = function ( vars ) {
this . egw . open _link ( this . egw . link ( "/index.php" , vars ) , '_blank' , '700x700' ) ;
} ;
/ * *
* control delete _series popup visibility
*
* @ param { et2 _widget } widget
* @ param { Array } exceptions an array contains number of exception entries
*
* /
CalendarApp . prototype . delete _btn = function ( widget , exceptions ) {
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
if ( exceptions ) {
var buttons = [
{
button _id : 'keep' ,
title : this . egw . lang ( 'All exceptions are converted into single events.' ) ,
text : this . egw . lang ( 'Keep exceptions' ) ,
id : 'button[delete_keep_exceptions]' ,
image : 'keep' , "default" : true
} ,
{
button _id : 'delete' ,
title : this . egw . lang ( 'The exceptions are deleted together with the series.' ) ,
text : this . egw . lang ( 'Delete exceptions' ) ,
id : 'button[delete_exceptions]' ,
image : 'delete'
} ,
{
button _id : 'cancel' ,
text : this . egw . lang ( 'Cancel' ) ,
id : 'dialog[cancel]' ,
image : 'cancel'
}
] ;
var self = this ;
2020-09-22 19:33:20 +02:00
et2 _widget _dialog _1 . et2 _dialog . show _dialog ( function ( _button _id ) {
2020-03-05 13:21:02 +01:00
if ( _button _id != 'dialog[cancel]' ) {
widget . getRoot ( ) . getWidgetById ( 'delete_exceptions' ) . set _value ( _button _id == 'button[delete_exceptions]' ) ;
widget . getInstanceManager ( ) . submit ( 'button[delete]' ) ;
return true ;
}
else {
return false ;
}
2020-09-22 19:33:20 +02:00
} , 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 _widget _dialog _1 . et2 _dialog . WARNING _MESSAGE ) ;
2020-03-05 13:21:02 +01:00
}
else if ( content [ 'recur_type' ] !== 0 ) {
2020-09-22 19:33:20 +02:00
et2 _widget _dialog _1 . et2 _dialog . confirm ( widget , 'Delete this series of recurring events' , 'Delete Series' ) ;
2020-03-05 13:21:02 +01:00
}
else {
2020-09-22 19:33:20 +02:00
et2 _widget _dialog _1 . et2 _dialog . confirm ( widget , 'Delete this event' , 'Delete' ) ;
2020-03-05 13:21:02 +01: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 .
*
* /
CalendarApp . prototype . participantOnChange = function ( ) {
var add = this . et2 . getWidgetById ( 'add' ) ;
var quantity = this . et2 . getWidgetById ( 'quantity' ) ;
var participant = this . et2 . getWidgetById ( 'participant' ) ;
// 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 ++ ;
}
} ;
/ * *
* print _participants _status ( egw , widget )
* Handle to apply changes from status in print popup
*
* @ param { mixed } _event
* @ param { et2 _base _widget } widget widget "status" in print popup window
*
* /
CalendarApp . prototype . print _participants _status = function ( _event , widget ) {
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' ) ;
}
} ;
/ * *
* Handles to select freetime , and replace the selected one on Start ,
* and End date & time in edit calendar entry popup .
*
* @ param { mixed } _event
* @ param { et2 _base _widget } _widget widget "select button" in freetime search popup window
*
* /
CalendarApp . prototype . freetime _select = function ( _event , _widget ) {
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
if ( window . opener && sTime ) {
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 ) {
startTime . set _value ( sTime . get _value ( ) ) ;
endTime . set _value ( sTime . get _value ( ) ) ;
endTime . set _value ( '+' + content [ 'duration' ] ) ;
}
}
}
else {
alert ( this . egw . lang ( 'The original calendar edit popup is closed!' ) ) ;
}
}
egw ( window ) . close ( ) ;
} ;
/ * *
* show / hide the filter of nm list in calendar listview
*
* /
CalendarApp . prototype . filter _change = function ( ) {
var view = CalendarApp . views [ 'listview' ] . etemplates [ 0 ] . widgetContainer || null ;
var nm = view ? view . getWidgetById ( 'nm' ) : null ;
var filter = view && nm ? nm . getWidgetById ( 'filter' ) : null ;
var dates = view ? view . getWidgetById ( 'calendar.list.dates' ) : null ;
// Update state when user changes it
if ( view && filter ) {
app . calendar . state . filter = filter . getValue ( ) ;
// Change sort order for before - this is just the UI, server does the query
if ( app . calendar . state . filter == 'before' ) {
nm . sortBy ( 'cal_start' , false , false ) ;
}
else {
nm . sortBy ( 'cal_start' , true , false ) ;
}
}
else {
delete app . calendar . state . filter ;
}
if ( filter && dates ) {
dates . set _disabled ( filter . getValue ( ) !== "custom" ) ;
if ( filter . getValue ( ) == "custom" && ! this . state _update _in _progress ) {
// 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 ;
jQuery ( view . getWidgetById ( 'startdate' ) . getDOMNode ( ) ) . find ( 'input' ) . focus ( ) ;
}
}
} ;
/ * *
* Application links from non - list events
*
* The ID looks like calendar : : < id > or calendar : : < id > : < recurrence _date >
* For processing the links :
* '$app' gets replaced with 'calendar'
* '$id' gets replaced with < id >
* ' $app _id gets replaced with < id > : < recurrence _date >
*
* Use either $id or $app _id depending on if you want the series [ beginning ]
* or a particular date .
*
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _events
* /
CalendarApp . prototype . action _open = function ( _action , _events ) {
var id = _events [ 0 ] . id . split ( '::' ) ;
var app = id [ 0 ] ;
var app _id = id [ 1 ] ;
if ( app _id && app _id . indexOf ( ':' ) ) {
var split = id [ 1 ] . split ( ':' ) ;
id = split [ 0 ] ;
}
else {
id = app _id ;
}
if ( _action . data . open ) {
var open = JSON . parse ( _action . data . open ) || { } ;
var extra = open . extra || '' ;
extra = extra . replace ( /(\$|%24)app/ , app ) . replace ( /(\$|%24)app_id/ , app _id )
. replace ( /(\$|%24)id/ , id ) ;
// Get a little smarter with the context
if ( ! extra ) {
var context = { } ;
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 ( ) . _get _time _from _position &&
_action . menu _context && _action . menu _context . event ) {
// Non-row space in planner
// Context menu has position information, but target is not what we expact
var target = jQuery ( '.calendar_plannerGrid' , _action . menu _context . event . currentTarget ) ;
var y = _action . menu _context . event . pageY - target . offset ( ) . top ;
var x = _action . menu _context . event . pageX - target . offset ( ) . left ;
var date = _events [ 0 ] . iface . getWidget ( ) . _get _time _from _position ( x , y ) ;
if ( date ) {
context . start = date . toJSON ( ) ;
}
}
else if ( _events [ 0 ] . iface . getWidget ( ) && _events [ 0 ] . iface . getWidget ( ) . instanceOf ( et2 _widget _planner _row _1 . et2 _calendar _planner _row ) ) {
// Empty space on a planner row
var widget = _events [ 0 ] . iface . getWidget ( ) ;
var parent = widget . getParent ( ) ;
if ( parent . options . group _by == 'month' ) {
var date = parent . _get _time _from _position ( _action . menu _context . event . clientX , _action . menu _context . event . clientY ) ;
}
else {
var date = parent . _get _time _from _position ( _action . menu _context . event . offsetX , _action . menu _context . event . offsetY ) ;
}
if ( date ) {
context . start = date . toJSON ( ) ;
}
jQuery . extend ( context , widget . getDOMNode ( ) . dataset ) ;
}
2020-09-22 19:33:20 +02:00
else if ( _events [ 0 ] . iface . getWidget ( ) && _events [ 0 ] . iface . getWidget ( ) . instanceOf ( et2 _core _valueWidget _1 . et2 _valueWidget ) ) {
2020-03-05 13:21:02 +01:00
// Able to extract something from the widget
context = _events [ 0 ] . iface . getWidget ( ) . getValue ?
_events [ 0 ] . iface . getWidget ( ) . getValue ( ) :
_events [ 0 ] . iface . getWidget ( ) . options . value || { } ;
extra = { } ;
}
// 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 ;
}
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 ( ',' ) ;
}
}
if ( context . date )
extra . date = context . date ;
if ( context . app )
extra . app = context . app ;
if ( context . app _id )
extra . app _id = context . app _id ;
}
this . egw . open ( open . id _data || '' , open . app , open . type , extra ? extra : context ) ;
}
else if ( _action . data . url ) {
var url = _action . data . url ;
url = url . replace ( /(\$|%24)app/ , app ) . replace ( /(\$|%24)app_id/ , app _id )
. replace ( /(\$|%24)id/ , id ) ;
this . egw . open _link ( url ) ;
}
} ;
/ * *
* 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
* /
CalendarApp . prototype . ical = function ( _action , _events ) {
// Send it through nextmatch
_action . data . nextmatch = etemplate2 _1 . 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 ) ;
} ;
/ * *
* Change status ( via AJAX )
*
* @ param { egwAction } _action
* @ param { egwActionObject } _events
* /
CalendarApp . prototype . 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' :
egw ( ) . json ( 'calendar.calendar_uiforms.ajax_status' , [ event _data . app _id , egw . user ( 'account_id' ) , _action . data . id ] ) . sendRequest ( true ) ;
break ;
case 'series' :
case 'single' :
egw ( ) . json ( 'calendar.calendar_uiforms.ajax_status' , [ event _data . id , egw . user ( 'account_id' ) , _action . data . id ] ) . sendRequest ( true ) ;
break ;
case 'cancel' :
default :
break ;
}
} , this ) ) ;
}
} ;
/ * *
* this function try to fix ids which are from integrated apps
*
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _senders
* /
CalendarApp . prototype . cal _fix _app _id = function ( _action , _senders ) {
var app = 'calendar' ;
var id = _senders [ 0 ] . id ;
var matches = id . match ( /^(?:calendar::)?([0-9]+)(:([0-9]+))?$/ ) ;
if ( matches ) {
id = matches [ 1 ] ;
}
else {
matches = id . match ( /^([a-z_-]+)([0-9]+)/i ) ;
if ( matches ) {
app = matches [ 1 ] ;
id = matches [ 2 ] ;
}
}
var backup _url = _action . data . url ;
_action . data . url = _action . data . url . replace ( /(\$|%24)id/ , id ) ;
_action . data . url = _action . data . url . replace ( /(\$|%24)app/ , app ) ;
nm _action ( _action , _senders , false , { ids : [ id ] } ) ;
_action . data . url = backup _url ; // restore url
} ;
/ * *
* Open a smaller dialog / popup to add a new entry
*
* This is opened inside a dialog widget , not a popup . This causes issues
* with the submission , handling of the response , and cleanup .
*
* @ param { Object } options Array of values for new
* @ param { et2 _calendar _event } event Placeholder showing where new event goes
* /
CalendarApp . prototype . add = function ( options , event ) {
if ( this . egw . preference ( 'new_event_dialog' , 'calendar' ) === 'edit' ) {
// Set this to open the add template in a popup
//options.template = 'calendar.add';
return this . egw . open ( null , 'calendar' , 'edit' , options , '_blank' , 'calendar' ) ;
}
2020-04-03 18:59:53 +02:00
// Hold on to options, may have to pass them into edit (rather than all, just send what the programmer wanted)
this . quick _add = options ;
2020-03-05 13:21:02 +01:00
// Open dialog to use as target
2020-09-22 19:33:20 +02:00
var add _dialog = et2 _widget _dialog _1 . et2 _dialog . show _dialog ( null , '' , ' ' , null , [ ] , et2 _widget _dialog _1 . et2 _dialog . PLAIN _MESSAGE , this . egw ) ;
2020-03-05 13:21:02 +01:00
// Call the server, get it into the dialog
options = jQuery . extend ( { menuaction : 'calendar.calendar_uiforms.ajax_add' , template : 'calendar.add' } , options ) ;
this . egw . json ( this . egw . link ( '/json.php' , options ) ,
//menuaction + options.join('&'),
[ options ] , function ( data ) {
if ( data . type )
return false ;
var content = {
html : data [ 0 ] ,
js : ''
} ;
egw _seperateJavaScript ( content ) ;
// Check for right template in the response
if ( content . html . indexOf ( 'calendar-add' ) <= 0 )
return false ;
// Insert the content
jQuery ( add _dialog . div ) . append ( content . html ) ;
// Run the javascript code
jQuery ( add _dialog . div ) . append ( content . js ) ;
// Re-position after load
jQuery ( 'form' , add _dialog . div ) . one ( 'load' , function ( ) {
// Hide close button
jQuery ( ".ui-dialog-titlebar-close" , add _dialog . div . parent ( ) ) . hide ( ) ;
// Position by event
add _dialog . div . dialog ( 'widget' ) . position ( {
my : 'center top' , at : event ? 'bottom' : 'center' , of : event ? event . node : window ,
collision : 'flipfit'
} ) ;
} ) ;
} ) . sendRequest ( ) ;
add _dialog . div . dialog ( {
close : function ( ev , ui ) {
// Wait a bit to make sure etemplate button finishes processing, or it will error
window . setTimeout ( function ( ) {
var template = etemplate2 _1 . etemplate2 . getById ( 'calendar-add' ) ;
if ( template && template . name === 'calendar.add' ) {
template . clear ( ) ;
this . dialog . destroy ( ) ;
delete app . calendar . quick _add ;
}
2020-09-15 18:43:08 +02:00
else if ( template || ( template = etemplate2 _1 . etemplate2 . getById ( "calendar-conflicts" ) ) ) {
2020-03-05 13:21:02 +01:00
// Open conflicts
2020-04-08 22:13:07 +02:00
var data = jQuery . extend ( { menuaction : 'calendar.calendar_uiforms.ajax_conflicts' } , template . widgetContainer . getArrayMgr ( 'content' ) . data , app . calendar . quick _add ) ;
egw . openPopup ( egw . link ( '/index.php' , data ) , 850 , 300 , 'conflicts' , 'calendar' ) ;
2020-03-05 13:21:02 +01:00
delete app . calendar . quick _add ;
// Close the JS dialog
this . dialog . destroy ( ) ;
// Do not submit this etemplate
return false ;
}
} . bind ( { dialog : add _dialog , event : ev } ) , 1000 ) ;
}
} ) ;
} ;
/ * *
* Callback for save button in add dialog
*
* @ param { Event } event
* @ param { et2 _button } widget
* @ returns { Boolean }
* /
CalendarApp . prototype . add _dialog _save = function ( event , widget ) {
// Include all sent values so we can pass on things that we don't have UI widgets for
this . quick _add = this . _add _dialog _values ( widget ) ;
// Close the dialog
jQuery ( widget . getInstanceManager ( ) . DOMContainer . parentNode ) . dialog ( 'close' ) ;
// Mess with opener so update opener in response works
window . opener = window ;
window . setTimeout ( function ( ) { window . opener = null ; } , 1000 ) ;
// Proceed with submit
return true ;
} ;
/ * *
* Callback for edit button in add dialog
*
* @ param { Event } event
* @ param { et2 _button } widget
* @ returns { Boolean }
* /
CalendarApp . prototype . add _dialog _edit = function ( event , widget ) {
var title = widget . getRoot ( ) . getWidgetById ( 'title' ) ;
if ( title && ! title . get _value ( ) ) {
title . set _value ( title . egw ( ) . lang ( 'Event' ) ) ;
}
2020-04-03 18:59:53 +02:00
var options = jQuery . extend ( this . _add _dialog _values ( widget ) , this . quick _add ) ;
2020-03-05 13:21:02 +01:00
// Open regular edit
2020-04-03 18:59:53 +02:00
egw . open ( null , 'calendar' , 'edit' , options ) ;
2020-03-05 13:21:02 +01:00
// Close the dialog
jQuery ( widget . getInstanceManager ( ) . DOMContainer . parentNode ) . dialog ( 'close' ) ;
// Do not submit this etemplate
return false ;
} ;
/ * *
* Include some additional values so we can pass on things that we don ' t have
* UI widgets for in the add template
*
* @ param { et2 _widget } widget
* @ returns { Object }
* /
CalendarApp . prototype . _add _dialog _values = function ( widget ) {
// Some select things to pass on, since not everything will fit
var mgr = widget . getRoot ( ) . getArrayMgr ( 'content' ) ;
var values = {
owner : typeof mgr . getEntry ( 'owner' ) == 'object' ? mgr . getEntry ( 'owner' ) : ( mgr . getEntry ( 'owner' ) + '' ) . split ( ',' ) ,
participants : [ ] ,
whole _day : mgr . getEntry ( 'whole_day' )
} ;
if ( mgr . getEntry ( 'link_to' ) && typeof mgr . getEntry ( 'link_to' ) . to _id === 'object' ) {
var links = mgr . getEntry ( 'link_to' ) . to _id ;
values . link _app = [ ] ;
values . link _id = [ ] ;
for ( var id in links ) {
values . link _app . push ( links [ id ] . app ) ;
values . link _id . push ( links [ id ] . id ) ;
}
}
for ( var id in mgr . getEntry ( 'participants' ) ) {
var participant = mgr . getEntry ( 'participants' ) [ id ] ;
if ( participant && participant . uid ) {
values . participants . push ( participant . uid ) ;
}
}
2020-04-03 18:59:53 +02:00
var send = jQuery . extend ( values , widget . getInstanceManager ( ) . getValues ( widget . getRoot ( ) ) ) ;
// Don't need the checkbox
delete send . new _event _dialog ;
return send ;
2020-03-05 13:21:02 +01:00
} ;
/ * *
* 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
*
* /
CalendarApp . prototype . cal _open = function ( _action , _senders ) {
// Try for easy way - find a widget
if ( _senders [ 0 ] . iface . getWidget ) {
var widget = _senders [ 0 ] . iface . getWidget ( ) ;
return widget . recur _prompt ( ) ;
}
// Nextmatch in list view does not have a widget, but we can pull
// the data by ID
// Check for series
var id = _senders [ 0 ] . id ;
var data = egw . dataGetUIDdata ( id ) ;
if ( data && data . data ) {
et2 _widget _event _1 . et2 _calendar _event . recur _prompt ( data . data ) ;
return ;
}
var matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
// 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 ] ] ) {
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 ] ) + "&" ;
if ( js _integration _data [ app ] . edit _popup ) {
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' ) ;
}
}
// Regular, single event
egw . open ( id . replace ( /^calendar::/g , '' ) , 'calendar' , 'edit' ) ;
} ;
/ * *
* Delete ( a single ) calendar entry over ajax .
*
* Used for the non - list views
*
* @ param { egwAction } _action
* @ param { egwActionObject } _events
* /
CalendarApp . prototype . 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 ) ) ;
}
} ;
/ * *
* Delete calendar entry , asking if you want to delete series or exception
*
* Used for nextmatch
*
* @ param _action
* @ param _senders
* /
CalendarApp . prototype . cal _delete = function ( _action , _senders ) {
2020-07-16 15:05:45 +02:00
var _a , _b ;
var all = ( _a = _action . parent . data . nextmatch ) === null || _a === void 0 ? void 0 : _a . getSelection ( ) . all ;
var no _notifications = ( _b = _action . parent . getActionById ( "no_notifications" ) ) === null || _b === void 0 ? void 0 : _b . checked ;
2020-03-05 13:21:02 +01:00
var matches = false ;
2020-07-15 23:56:28 +02:00
var ids = [ ] ;
var cal _event = this . egw . dataGetUIDdata ( _senders [ 0 ] . id ) ;
2020-03-05 13:21:02 +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 ++ ) {
var id = _senders [ i ] . id ;
if ( ! matches ) {
matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
}
2020-07-15 23:56:28 +02:00
ids . push ( id . split ( "::" ) . pop ( ) ) ;
2020-03-05 13:21:02 +01:00
}
if ( matches ) {
2020-07-15 23:56:28 +02:00
// At least one event is a series, use its data to trigger the prompt
var cal _event _1 = this . egw . dataGetUIDdata ( matches [ 0 ] ) ;
}
et2 _widget _event _1 . et2 _calendar _event . recur _prompt ( cal _event . data , function ( button _id , event _data ) {
switch ( button _id ) {
case 'single' :
case 'exception' :
// Just this one, handle in the normal way but over AJAX
egw . json ( "calendar.calendar_uilist.ajax_action" , [ _action . id , ids , all , no _notifications ] ) . sendRequest ( true ) ;
break ;
case 'series' :
// No recurrences, handle in the normal way but over AJAX
egw . json ( "calendar.calendar_uilist.ajax_action" , [ "delete_series" , ids , all , no _notifications ] ) . sendRequest ( true ) ;
break ;
case 'cancel' :
default :
break ;
2020-03-05 13:21:02 +01:00
}
2020-07-15 23:56:28 +02:00
} . bind ( this ) ) ;
2020-03-05 13:21:02 +01:00
} ;
/ * *
* Confirmation dialog for moving a series entry
*
* @ param { object } _DOM
* @ param { et2 _widget } _button button Save | Apply
* /
CalendarApp . prototype . move _edit _series = function ( _DOM , _button ) {
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var start _date = this . et2 . getWidgetById ( 'start' ) . get _value ( ) ;
var end _date = this . et2 . getWidgetById ( 'end' ) . get _value ( ) ;
var whole _day = this . et2 . getWidgetById ( 'whole_day' ) ;
var duration = '' + this . et2 . getWidgetById ( 'duration' ) . get _value ( ) ;
var is _whole _day = whole _day && whole _day . get _value ( ) == whole _day . options . selected _value ;
var button = _button ;
var that = this ;
var instance _date _regex = window . location . search . match ( /date=(\d{4}-\d{2}-\d{2}(?:.+Z)?)/ ) ;
var instance _date ;
if ( instance _date _regex && instance _date _regex . length && instance _date _regex [ 1 ] ) {
instance _date = new Date ( unescape ( instance _date _regex [ 1 ] ) ) ;
instance _date . setUTCMinutes ( instance _date . getUTCMinutes ( ) + instance _date . getTimezoneOffset ( ) ) ;
}
if ( typeof content != 'undefined' && content . id != null &&
typeof content . recur _type != 'undefined' && content . recur _type != null && content . recur _type != 0 ) {
if ( content . start != start _date ||
content . whole _day != is _whole _day ||
( 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 ) ) {
et2 _widget _event _1 . et2 _calendar _event . series _split _prompt ( content , instance _date , function ( _button _id ) {
2020-09-22 19:33:20 +02:00
if ( _button _id == et2 _widget _dialog _1 . et2 _dialog . OK _BUTTON ) {
2020-03-05 13:21:02 +01:00
that . et2 . getInstanceManager ( ) . submit ( button ) ;
}
} ) ;
}
else {
return true ;
}
}
else {
return true ;
}
} ;
/ * *
* Send a mail or meeting request to event participants
*
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _selected
* /
CalendarApp . prototype . action _mail = function ( _action , _selected ) {
var data = egw . dataGetUIDdata ( _selected [ 0 ] . id ) || { data : { } } ;
var event = data . data ;
this . egw . json ( 'calendar.calendar_uiforms.ajax_custom_mail' , [ event , false , _action . id === 'sendrequest' ] , null , null , null , null ) . sendRequest ( ) ;
} ;
/ * *
* Insert selected event ( s ) into a document
*
* Actually , just pass it off to the nextmatch
*
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _selected
* /
CalendarApp . prototype . action _merge = function ( _action , _selected ) {
var ids = { ids : [ ] } ;
for ( var i = 0 ; i < _selected . length ; i ++ ) {
ids . ids . push ( _selected [ i ] . id ) ;
}
nm _action ( egw _getActionManager ( this . appname , false , 1 )
. getActionById ( 'nm' ) . getActionById ( _action . id ) , _selected , null , ids ) ;
} ;
/ * *
* 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 .
*
* @ param { Event } event UI event
* @ param { et2 _widget } widget Should be the merge selectbox
* /
CalendarApp . prototype . 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 _1 . etemplate2 . getById ( 'calendar-list' ) . widgetContainer . getWidgetById ( 'nm' ) || false ;
var selected = nm ? nm . controller . _objectManager . getSelectedLinks ( ) : [ ] ;
var action = nm . controller . _actionManager . getActionById ( 'document_' + widget . getValue ( ) ) ;
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 ) ;
if ( widget . getRoot ( ) . getArrayMgr ( 'content' ) . getEntry ( 'collabora_enabled' ) ) {
widget . getInstanceManager ( ) . submit ( ) ;
}
else {
widget . getInstanceManager ( ) . postSubmit ( ) ;
window . setTimeout ( function ( ) { widget . set _value ( '' ) ; } , 100 ) ;
}
}
return false ;
} ;
/ * *
* Method to set state for JSON requests ( jdots ajax _exec or et2 submits can NOT use egw . js script tag )
*
* @ param { object } _state
* /
CalendarApp . prototype . set _state = function ( _state ) {
if ( typeof _state == 'object' ) {
// 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 .
*
* 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 .
*
* @ param { Object } _set New settings
* /
CalendarApp . prototype . update _state = function ( _set ) {
// Make sure we're running in top window
// @ts-ignore
if ( window !== window . top && window . top . app . calendar ) {
// @ts-ignore
return window . top . app . calendar . update _state ( _set ) ;
}
if ( this . state _update _in _progress )
return ;
var changed = [ ] ;
var new _state = jQuery . extend ( { } , this . state ) ;
if ( typeof _set === 'object' ) {
for ( var s in _set ) {
if ( new _state [ s ] !== _set [ s ] && ( typeof new _state [ s ] == 'string' || typeof new _state [ s ] !== 'string' && new _state [ s ] + '' !== _set [ s ] + '' ) ) {
changed . push ( s + ': ' + new _state [ s ] + ' -> ' + _set [ s ] ) ;
new _state [ s ] = _set [ s ] ;
}
}
}
if ( changed . length && ! this . state _update _in _progress ) {
// 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.
if ( typeof framework !== 'undefined' && framework . applications . calendar && framework . applications . calendar . hasSideboxMenuContent ) {
framework . setActiveApp ( framework . applications . calendar ) ;
}
console . log ( 'Calendar state changed' , changed . join ( "\n" ) ) ;
// Log
this . egw . debug ( 'navigation' , 'Calendar state changed' , changed . join ( "\n" ) ) ;
this . setState ( { state : new _state } ) ;
}
} ;
/ * *
* Return state object defining current view
*
* Called by favorites to query current state .
*
* @ return { object } description
* /
CalendarApp . prototype . getState = function ( ) {
var state = jQuery . extend ( { } , this . state ) ;
if ( ! state ) {
var egw _script _tag = document . getElementById ( 'egw_script_id' ) ;
state = egw _script _tag . getAttribute ( 'data-calendar-state' ) ;
state = state ? JSON . parse ( state ) : { } ;
}
// 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 ;
}
// Keywords are only for list view
if ( state . view == 'listview' ) {
var listview = typeof CalendarApp . views . listview . etemplates [ 0 ] !== 'string' &&
CalendarApp . views . listview . etemplates [ 0 ] . widgetContainer &&
CalendarApp . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
if ( listview && listview . activeFilters && listview . activeFilters . search ) {
state . keywords = listview . activeFilters . search ;
}
}
// Don't store date or first and last
delete state . date ;
delete state . first ;
delete state . last ;
delete state . startdate ;
delete state . enddate ;
delete state . start _date ;
delete state . end _date ;
return state ;
} ;
/ * *
* 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
* /
CalendarApp . prototype . setState = function ( state ) {
// 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 ) ;
}
}
if ( typeof state . state !== 'object' || ! state . state . view ) {
state . state = { view : 'week' } ;
}
// States with no name (favorites other than No filters) default to
// today. Applying a favorite should keep the current date.
if ( ! state . state . date ) {
state . state . date = state . name ? this . state . date : new Date ( ) ;
}
if ( typeof state . state . weekend == 'undefined' ) {
state . state . weekend = true ;
}
// Hide other views
var view = CalendarApp . views [ state . state . view ] ;
for ( var _view in CalendarApp . views ) {
if ( state . state . view != _view && CalendarApp . views [ _view ] ) {
for ( var i = 0 ; i < CalendarApp . views [ _view ] . etemplates . length ; i ++ ) {
if ( typeof CalendarApp . views [ _view ] . etemplates [ i ] !== 'string' &&
view . etemplates . indexOf ( CalendarApp . views [ _view ] . etemplates [ i ] ) == - 1 ) {
jQuery ( CalendarApp . views [ _view ] . etemplates [ i ] . DOMContainer ) . hide ( ) ;
}
}
}
}
if ( this . sidebox _et2 ) {
jQuery ( this . sidebox _et2 . getInstanceManager ( ) . DOMContainer ) . hide ( ) ;
}
// Check for valid cache
var cachable _changes = [ 'date' , 'weekend' , 'view' , 'days' , 'planner_view' , 'sortby' ] ;
// @ts-ignore
var keys = ( Object . keys ( this . state ) . concat ( Object . keys ( state . state ) ) ) . filter ( function ( value , index , self ) {
return self . indexOf ( value ) === index ;
} ) ;
for ( var i = 0 ; i < keys . length ; i ++ ) {
var s = keys [ i ] ;
if ( this . state [ s ] !== state . state [ s ] ) {
if ( cachable _changes . indexOf ( s ) === - 1 ) {
// Expire daywise cache
var daywise = egw . dataKnownUIDs ( CalendarApp . 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 ( CalendarApp . DAYWISE _CACHE _ID + '::' + daywise [ i ] , null ) ;
}
break ;
}
}
}
// Check for a supported client-side view
if ( CalendarApp . views [ state . state . view ] &&
// Check that the view is instanciated
typeof CalendarApp . views [ state . state . view ] . etemplates [ 0 ] !== 'string' && CalendarApp . views [ state . state . view ] . etemplates [ 0 ] . widgetContainer ) {
// 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 ;
// Sanitize owner so it's always an array
if ( state . state . owner === null || ! state . state . owner ||
( typeof state . state . owner . length != 'undefined' && state . state . owner . length == 0 ) ) {
state . state . owner = undefined ;
}
switch ( typeof state . state . owner ) {
case 'undefined' :
state . state . owner = [ this . egw . user ( 'account_id' ) ] ;
break ;
case 'string' :
state . state . owner = state . state . owner . split ( ',' ) ;
break ;
case 'number' :
state . state . owner = [ state . state . owner ] ;
break ;
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 ; } ) ;
}
}
// Remove duplicates
state . state . owner = state . state . owner . filter ( function ( value , index , self ) {
return self . indexOf ( value ) === index ;
} ) ;
// Make sure they're all strings
state . state . owner = state . state . owner . map ( function ( owner ) { return '' + owner ; } ) ;
if ( state . state . owner . indexOf ( '0' ) >= 0 ) {
state . state . owner [ state . state . owner . indexOf ( '0' ) ] = this . egw . user ( 'account_id' ) ;
}
// Show the correct number of grids
var grid _count = 0 ;
switch ( state . state . view ) {
case 'day' :
grid _count = 1 ;
break ;
case 'day4' :
case 'week' :
grid _count = state . state . owner . length >= parseInt ( '' + this . egw . preference ( 'week_consolidate' , 'calendar' ) ) ? 1 : state . state . owner . length ;
break ;
case 'weekN' :
grid _count = parseInt ( '' + this . egw . preference ( 'multiple_weeks' , 'calendar' ) ) || 3 ;
break ;
// Month is calculated individually for the month
}
var grid = view . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'view' ) ;
// 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 ++ ) {
jQuery ( view . etemplates [ i ] . DOMContainer ) . show ( ) ;
}
/ *
If the count is different , we need to have the correct number
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 .
* /
if ( grid ) {
// 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 ( ) ? 'horizontal' : 'spinner' ) ;
var loading = false ;
var value = [ ] ;
state . state . first = view . start _date ( state . state ) . toJSON ( ) ;
// We'll modify this one, so it needs to be a new object
var date = new Date ( state . state . first ) ;
// Hide all but the first day header
jQuery ( grid . getDOMNode ( ) ) . toggleClass ( 'hideDayColHeader' , state . state . view == 'week' || state . state . view == 'day4' ) ;
// Determine the different end date & varying values
switch ( state . state . view ) {
case 'month' :
var end = state . state . last = view . end _date ( state . state ) ;
grid _count = Math . ceil ( ( end - date . valueOf ( ) ) / ( 1000 * 60 * 60 * 24 ) / 7 ) ;
// fall through
case 'weekN' :
for ( var week = 0 ; week < grid _count ; week ++ ) {
var val = {
id : CalendarApp . _daywise _cache _id ( date , state . state . owner ) ,
start _date : date . toJSON ( ) ,
end _date : new Date ( date . toJSON ( ) ) ,
owner : state . state . owner
} ;
val . end _date . setUTCHours ( 24 * 7 - 1 ) ;
val . end _date . setUTCMinutes ( 59 ) ;
val . end _date . setUTCSeconds ( 59 ) ;
val . end _date = val . end _date . toJSON ( ) ;
value . push ( val ) ;
date . setUTCHours ( 24 * 7 ) ;
}
state . state . last = val . end _date ;
break ;
case 'day' :
var end = state . state . last = view . end _date ( state . state ) . toJSON ( ) ;
value . push ( {
id : CalendarApp . _daywise _cache _id ( date , state . state . owner ) ,
start _date : state . state . first ,
end _date : state . state . last ,
owner : view . owner ( state . state )
} ) ;
break ;
default :
var end = state . state . last = view . end _date ( state . state ) . toJSON ( ) ;
2020-06-05 21:22:13 +02:00
for ( var owner = 0 ; owner < grid _count && owner < state . state . owner . length ; owner ++ ) {
var _owner = grid _count > 1 ? state . state . owner [ owner ] || 0 : state . state . owner ;
2020-03-05 13:21:02 +01:00
value . push ( {
id : CalendarApp . _daywise _cache _id ( date , _owner ) ,
start _date : date ,
end _date : end ,
owner : _owner
} ) ;
}
break ;
}
// If we have cached data for the timespan, pass it along
// 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' ) ) ) {
var day _value = [ ] ;
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 ]
} ) ;
}
loading = this . _need _data ( day _value , state . state ) ;
}
else {
loading = this . _need _data ( value , state . state ) ;
}
var row _index = 0 ;
// 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 ) {
// 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 ( ) ) ;
// Swap DOM nodes
var a = grid . _children [ 0 ] . getDOMNode ( ) . parentNode . parentNode ;
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( ) ;
var b = grid . _children [ 1 ] . getDOMNode ( ) . parentNode . parentNode ;
a . parentNode . insertBefore ( a , b ) ;
// Moving nodes changes scrolling, so set it back
jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( a _scroll ) ;
}
}
else if ( row _index > i ) {
// Swap DOM nodes
var a = grid . _children [ row _index ] . getDOMNode ( ) . parentNode . parentNode ;
var a _scroll = jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( ) ;
var b = grid . _children [ i ] . getDOMNode ( ) . parentNode . parentNode ;
// Simple scroll forward, put top on the bottom
// This makes it faster if they scroll back next
if ( i == 0 && row _index == 1 ) {
jQuery ( b ) . appendTo ( b . parentNode ) ;
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
jQuery ( '.calendar_calTimeGridScroll' , a ) . scrollTop ( a _scroll ) ;
}
break ;
}
}
row _index ++ ;
} , this , et2 _widget _view _1 . et2 _calendar _view ) ;
row _index = 0 ;
// Set rows that need it
var was _disabled = [ ] ;
grid . iterateOver ( function ( widget ) {
was _disabled [ row _index ] = false ;
if ( row _index < value . length ) {
was _disabled [ row _index ] = widget . options . disabled ;
widget . set _disabled ( false ) ;
}
else {
widget . set _disabled ( true ) ;
}
row _index ++ ;
} , this , et2 _widget _view _1 . et2 _calendar _view ) ;
row _index = 0 ;
grid . iterateOver ( function ( widget ) {
if ( row _index >= value . length )
return ;
2020-08-04 21:56:54 +02:00
// Clear height to make sure there's correct calculations
widget . div . css ( "height" , "" ) ;
2020-03-05 13:21:02 +01:00
if ( widget . set _show _weekend ) {
widget . set _show _weekend ( view . show _weekend ( state . state ) ) ;
}
if ( widget . set _granularity ) {
if ( widget . loader )
widget . loader . show ( ) ;
widget . set _granularity ( view . granularity ( state . state ) ) ;
}
if ( widget . id == value [ row _index ] . id &&
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 ) ) {
// Do not need to re-set this row, but we do need to re-do
// the times, as they may have changed
widget . resizeTimes ( ) ;
window . setTimeout ( jQuery . proxy ( widget . set _header _classes , widget ) , 0 ) ;
// If disabled while the daycols were loaded, they won't load their events
for ( var day = 0 ; was _disabled [ row _index ] && day < widget . day _widgets . length ; day ++ ) {
egw . dataStoreUID ( widget . day _widgets [ day ] . registeredUID , egw . dataGetUIDdata ( widget . day _widgets [ day ] . registeredUID ) . data ) ;
}
widget . set _owner ( value [ row _index ] . owner ) ;
// Hide loader
widget . loader . hide ( ) ;
row _index ++ ;
return ;
}
if ( widget . set _value ) {
widget . set _value ( value [ row _index ++ ] ) ;
}
} , this , et2 _widget _view _1 . et2 _calendar _view ) ;
}
else if ( state . state . view !== 'listview' ) {
var _loop _1 = function ( ) {
if ( typeof view [ updater ] === 'function' ) {
var value _1 = view [ updater ] . call ( this _1 , state . state ) ;
if ( updater === 'start_date' )
state . state . first = this _1 . date . toString ( value _1 ) ;
if ( updater === 'end_date' )
state . state . last = this _1 . date . toString ( value _1 ) ;
// Set value
for ( var i = 0 ; i < view . etemplates . length ; i ++ ) {
view . etemplates [ i ] . widgetContainer . iterateOver ( function ( widget ) {
if ( typeof widget [ 'set_' + updater ] === 'function' ) {
widget [ 'set_' + updater ] ( value _1 ) ;
}
} , this _1 , et2 _widget _view _1 . et2 _calendar _view ) ;
}
}
} ;
var this _1 = this ;
// Simple, easy case - just one widget for the selected time span. (planner)
// Update existing view's special attribute filters, defined in the view list
for ( var updater in view ) {
_loop _1 ( ) ;
}
var value _2 = [ { start _date : state . state . first , end _date : state . state . last } ] ;
loading = this . _need _data ( value _2 , state . state ) ;
}
// Include first & last dates in state, mostly for server side processing
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 ( ) ;
// Toggle todos
if ( ( state . state . view == 'day' || this . state . view == 'day' ) && jQuery ( view . etemplates [ 0 ] . DOMContainer ) . is ( ':visible' ) ) {
2020-05-07 18:24:22 +02:00
if ( state . state . view == 'day' && state . state . owner . length === 1 && ! isNaN ( state . state . owner ) && state . state . owner [ 0 ] >= 0 && ! egwIsMobile ( )
// Check preferences and permissions
&& egw . user ( 'apps' ) [ 'infolog' ] && egw . preference ( 'cal_show' , 'infolog' ) !== '0' ) {
2020-03-05 13:21:02 +01:00
// Set width to 70%, otherwise if a scrollbar is needed for the view, it will conflict with the todo list
jQuery ( CalendarApp . views . day . etemplates [ 0 ] . DOMContainer ) . css ( "width" , "70%" ) ;
2020-12-01 17:51:04 +01:00
jQuery ( view . etemplates [ 1 ] . DOMContainer ) . css ( { "left" : "70%" } ) ;
2020-03-05 13:21:02 +01: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 ( ) ;
}
else {
jQuery ( CalendarApp . views . day . etemplates [ 1 ] . DOMContainer ) . css ( "left" , "100%" ) ;
jQuery ( CalendarApp . views . day . etemplates [ 1 ] . DOMContainer ) . hide ( ) ;
jQuery ( CalendarApp . views . day . etemplates [ 0 ] . DOMContainer ) . css ( "width" , "100%" ) ;
view . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( w ) {
w . set _width ( '100%' ) ;
} , this , et2 _widget _timegrid _1 . et2 _calendar _timegrid ) ;
}
}
else if ( jQuery ( view . etemplates [ 0 ] . DOMContainer ) . is ( ':visible' ) ) {
jQuery ( view . etemplates [ 0 ] . DOMContainer ) . css ( "width" , "" ) ;
view . etemplates [ 0 ] . widgetContainer . iterateOver ( function ( w ) {
w . set _width ( '100%' ) ;
} , this , et2 _widget _timegrid _1 . et2 _calendar _timegrid ) ;
}
// List view (nextmatch) has slightly different fields
if ( state . state . view === 'listview' ) {
state . state . startdate = state . state . date ;
if ( state . state . startdate . toJSON ) {
state . state . startdate = state . state . startdate . toJSON ( ) ;
}
if ( state . state . end _date ) {
state . state . enddate = state . state . end _date ;
}
if ( state . state . enddate && state . state . enddate . toJSON ) {
state . state . enddate = state . state . enddate . toJSON ( ) ;
}
state . state . col _filter = { participant : state . state . owner } ;
state . state . search = state . state . keywords ? state . state . keywords : state . state . search ;
delete state . state . keywords ;
var nm = view . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
// '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 ;
}
nm . applyFilters ( state . state ) ;
// Try to keep last value up to date with what's in nextmatch
if ( nm . activeFilters . enddate ) {
this . state . last = nm . activeFilters . enddate ;
}
// Updates the display of start & end date
this . filter _change ( ) ;
}
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 = CalendarApp . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
nm . controller . _grid . doInvalidate = false ;
}
catch ( e ) { }
// Other views do not search
delete state . state . keywords ;
}
this . state = jQuery . extend ( { } , state . state ) ;
/* Update re-orderable calendars */
this . _sortable ( ) ;
/* Update sidebox widgets to show current value*/
if ( this . sidebox _hooked _templates . length ) {
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 ( ) ) {
this . sidebox _hooked _templates . splice ( j , 1 , 0 ) ;
continue ;
}
sidebox . iterateOver ( function ( widget ) {
if ( widget . id == 'view' ) {
// View widget has a list of state settings, which require special handling
for ( var i = 0 ; i < widget . options . select _options . length ; i ++ ) {
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 ;
}
}
}
else if ( widget . id == 'keywords' ) {
widget . set _value ( '' ) ;
}
else if ( typeof state . state [ widget . id ] !== 'undefined' && state . state [ widget . id ] != widget . getValue ( ) ) {
// 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 ( '' ) ;
}
}
2020-09-22 19:33:20 +02:00
else if ( widget . instanceOf ( et2 _core _inputWidget _1 . et2 _inputWidget ) && typeof state . state [ widget . id ] == 'undefined' ) {
2020-03-05 13:21:02 +01:00
// No value, clear it
widget . set _value ( '' ) ;
}
2020-09-22 19:33:20 +02:00
} , this , et2 _core _valueWidget _1 . et2 _valueWidget ) ;
2020-03-05 13:21:02 +01:00
}
}
// If current state matches a favorite, hightlight it
this . highlight _favorite ( ) ;
// Update app header
this . set _app _header ( view . header ( state . state ) ) ;
// Reset auto-refresh timer
this . _set _autorefresh ( ) ;
// Sidebox is updated, we can clear the flag
this . state _update _in _progress = false ;
// Update saved state in preferences
var save = { } ;
for ( var i = 0 ; i < CalendarApp . states _to _save . length ; i ++ ) {
save [ CalendarApp . states _to _save [ i ] ] = this . state [ CalendarApp . states _to _save [ i ] ] ;
}
egw . set _preference ( 'calendar' , 'saved_states' , save ) ;
// 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 ( ) ;
}
// 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 ) ;
}
return ;
}
// old calendar state handling on server-side (incl. switching to and from listview)
var menuaction = 'calendar.calendar_uiviews.index' ;
if ( typeof state . state != 'undefined' && ( typeof state . state . view == 'undefined' || state . state . view == 'listview' ) ) {
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 , '_' ) ;
// set date for "No Filter" (blank) favorite to todays date
if ( state . state . favorite == 'blank' )
state . state . date = jQuery . datepicker . formatDate ( 'yymmdd' , new Date ) ;
}
menuaction = 'calendar.calendar_uilist.listview' ;
state . state . ajax = 'true' ;
// check if we already use et2 / are in listview
if ( this . et2 || etemplate2 _1 . etemplate2 && etemplate2 _1 . etemplate2 . getByApplication ( 'calendar' ) ) {
// 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 ;
// 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 ;
}
}
break ;
}
break ;
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 ;
}
}
}
if ( ! need _redirect ) {
return _super . prototype . setState . call ( this , [ state ] ) ;
}
}
}
// setting internal state now, that linkHandler does not intercept switching from listview to any old view
this . state = jQuery . extend ( { } , state . state ) ;
if ( this . sidebox _et2 ) {
jQuery ( this . sidebox _et2 . getInstanceManager ( ) . DOMContainer ) . show ( ) ;
}
var query = jQuery . extend ( { menuaction : menuaction } , state . state || { } ) ;
// prepend an owner 0, to reset all owners and not just set given resource type
if ( typeof query . owner != 'undefined' ) {
query . owner = '0,' + ( typeof query . owner == 'object' ? query . owner . join ( ',' ) : ( '' + query . owner ) . replace ( '0,' , '' ) ) ;
}
this . egw . open _link ( this . egw . link ( '/index.php' , query ) , 'calendar' ) ;
// Stop the normal bubbling if this is called on click
return false ;
} ;
/ * *
* Check to see if any of the selected is an event widget
* Used to separate grid actions from event actions
*
* @ param { egwAction } _action
* @ param { egwActioObject [ ] } _selected
* @ returns { boolean } Is any of the selected an event widget
* /
CalendarApp . prototype . 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 _widget _event _1 . et2 _calendar _event ) ) {
is _widget = true ;
}
// Also check classes, usually indicating permission
if ( _action . data && _action . data . enableClass ) {
is _widget = is _widget && ( jQuery ( _selected [ i ] . iface . getDOMNode ( ) ) . hasClass ( _action . data . enableClass ) ) ;
}
if ( _action . data && _action . data . disableClass ) {
is _widget = is _widget && ! ( jQuery ( _selected [ i ] . iface . getDOMNode ( ) ) . hasClass ( _action . data . disableClass ) ) ;
}
}
return is _widget ;
} ;
/ * *
* Enable / Disable custom Date - time for set Alarm
*
* @ param { widget object } _widget new _alarm [ options ] selectbox
* /
2020-05-25 19:06:33 +02:00
CalendarApp . prototype . alarm _custom _date = function ( selectbox , _widget ) {
var alarm _date = this . et2 . getInputWidgetById ( 'new_alarm[date]' ) ;
var alarm _options = _widget || this . et2 . getInputWidgetById ( 'new_alarm[options]' ) ;
var start = this . et2 . getInputWidgetById ( 'start' ) ;
if ( alarm _date && alarm _options && start ) {
if ( alarm _options . getValue ( ) != '0' ) {
2020-03-05 13:21:02 +01:00
alarm _date . set _class ( 'calendar_alarm_date_display' ) ;
}
else {
alarm _date . set _class ( '' ) ;
}
2020-05-25 19:06:33 +02:00
var startDate = typeof start . getValue != 'undefined' ? start . getValue ( ) : start . value ;
2020-03-05 13:21:02 +01:00
if ( startDate ) {
var date = new Date ( startDate ) ;
2020-05-25 19:06:33 +02:00
date . setTime ( date . getTime ( ) - 1000 * parseInt ( alarm _options . getValue ( ) ) ) ;
2020-03-05 13:21:02 +01:00
alarm _date . set _value ( date ) ;
}
}
} ;
/ * *
* Set alarm options based on WD / Regular event user preferences
* Gets fired by wholeday checkbox . This is mainly for display purposes ,
* the default alarm is calculated on the server as well .
*
* @ param { egw object } _egw
* @ param { widget object } _widget whole _day checkbox
* /
CalendarApp . prototype . set _alarmOptions _WD = function ( _egw , _widget ) {
var alarm = this . et2 . getWidgetById ( 'alarm' ) ;
if ( ! alarm )
return ; // no default alarm
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 ;
// 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 ) ;
}
else {
label = self . egw . lang ( '%1 days' , _secs / ( 3600 * 24 ) ) ;
}
return label ;
} ;
if ( typeof content [ 'alarm' ] [ 1 ] [ 'default' ] == 'undefined' ) {
// user deleted alarm --> nothing to do
}
else {
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 ( ) ;
start . set _hours ( 0 ) ;
start . set _minutes ( 0 ) ;
time . set _value ( start . get _value ( ) ) ;
time . set _value ( new Date ( new Date ( start . get _value ( ) ) . valueOf ( ) - ( 60 * def _alarm * 1000 ) ) . toJSON ( ) ) ;
event . set _value ( _secs _to _label ( 60 * def _alarm ) ) ;
}
}
} ;
/ * *
* Clear all calendar data from egw . data cache
* /
CalendarApp . prototype . _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 ( CalendarApp . DAYWISE _CACHE _ID ) ;
for ( var i = 0 ; i < daywise . length ; i ++ ) {
// Empty to clear existing widgets
egw . dataStoreUID ( CalendarApp . DAYWISE _CACHE _ID + '::' + daywise [ i ] , null ) ;
}
} ;
/ * *
* 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 .
*
* @ param { Object } value
* @ param { Object } state
*
* @ return { boolean } Data was requested
* /
CalendarApp . prototype . _need _data = function ( value , state ) {
var need _data = false ;
// Determine if we're showing multiple owners seperate or consolidated
var seperate _owners = false ;
var last _owner = value . length ? value [ 0 ] . owner || 0 : 0 ;
for ( var i = 0 ; i < value . length && ! seperate _owners ; i ++ ) {
seperate _owners = seperate _owners || ( last _owner !== value [ i ] . owner ) ;
}
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 ( ) ) ;
var cache _id = CalendarApp . _daywise _cache _id ( date , seperate _owners && value [ i ] . owner ? value [ i ] . owner : state . owner || false ) ;
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 ) ;
// Some data is missing for the current owner, go get it
if ( need _data && seperate _owners ) {
this . _fetch _data ( jQuery . extend ( { } , state , { owner : value [ i ] . owner , selected _owners : state . owner } ) , this . sidebox _et2 ? null : this . et2 . getInstanceManager ( ) ) ;
need _data = false ;
}
}
// Some data was missing, go get it
if ( need _data && ! seperate _owners ) {
this . _fetch _data ( state , this . sidebox _et2 ? null : this . et2 . getInstanceManager ( ) ) ;
}
return need _data ;
} ;
/ * *
* 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 .
*
* @ 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
* @ param { number } [ start ] Result offset . Internal use only
* /
CalendarApp . prototype . _fetch _data = function ( state , instance , start ) {
if ( ! this . sidebox _et2 && ! instance ) {
return ;
}
if ( typeof start === 'undefined' ) {
start = 0 ;
}
// 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 ;
}
// Make sure cat_id reaches to server in array format
if ( cat _id && typeof cat _id == 'string' && cat _id != "0" )
cat _id = cat _id . split ( ',' ) ;
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' ,
status _filter : state . status _filter ,
cat _id : cat _id ,
csv _export : false ,
selected _owners : state . selected _owners
} ) ;
// Show ajax loader
if ( typeof framework !== 'undefined' ) {
framework . applications . calendar . sidemenuEntry . showAjaxLoader ( ) ;
}
if ( state . view === 'planner' && state . sortby === 'user' ) {
query . order = 'participants' ;
}
else if ( state . view === 'planner' && state . sortby === 'category' ) {
query . order = 'categories' ;
}
// 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 ) ;
this . egw . dataFetch ( instance ? instance . etemplate _exec _id :
this . sidebox _et2 . getInstanceManager ( ) . etemplate _exec _id , { start : start , num _rows : 400 } , query , this . appname , function calendar _handleResponse ( data ) {
var idx = this . _queries _in _progress . indexOf ( query _string ) ;
if ( idx >= 0 ) {
this . _queries _in _progress . splice ( idx , 1 ) ;
}
//console.log(data);
// 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 ] ) {
var found = false ;
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 ;
found = true ;
break ;
}
}
if ( ! found ) {
if ( ! widget . options . select _options . push ) {
widget . options . select _options = [ ] ;
}
widget . options . select _options . push ( option ) ;
}
}
var in _progress = app . calendar . state _update _in _progress ;
app . calendar . state _update _in _progress = true ;
widget . set _select _options ( widget . options . select _options ) ;
widget . set _value ( widget . getValue ( ) ) ;
app . calendar . state _update _in _progress = in _progress ;
}
}
}
if ( data . order && data . total ) {
this . _update _events ( state , data . order ) ;
}
// 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
else if ( typeof framework !== 'undefined' ) {
framework . applications . calendar . sidemenuEntry . hideAjaxLoader ( ) ;
egw . loading _prompt ( 'calendar' , false ) ;
}
} , this , null ) ;
} ;
/ * *
* 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
* @ param data
* /
CalendarApp . prototype . _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' ) ) ||
[ 'week' , 'day4' ] . indexOf ( state . view ) !== - 1 && 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 ||
// Or it's for a day we already have
typeof this . egw . dataGetUIDdata ( 'calendar_daywise::' + record . data . date ) !== 'undefined' ) {
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 ( ) ,
end : typeof record . data . end === 'string' ? record . data . end : record . data . end . toJSON ( )
} ;
if ( dates . start . substr ( 0 , 10 ) !== dates . end . substr ( 0 , 10 ) ) {
var end = new Date ( Math . min ( new Date ( record . data . end ) . valueOf ( ) , new Date ( state . last ) . valueOf ( ) ) ) ;
end . setUTCHours ( 23 ) ;
end . setUTCMinutes ( 59 ) ;
end . setUTCSeconds ( 59 ) ;
var t = new Date ( Math . max ( new Date ( record . data . start ) . valueOf ( ) , new Date ( state . first ) . valueOf ( ) ) ) ;
do {
var expanded _date = '' + t . getUTCFullYear ( ) + sprintf ( '%02d' , t . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , t . getUTCDate ( ) ) ;
// Avoid events ending at midnight having a 0 length event the next day
if ( t . toJSON ( ) . substr ( 0 , 10 ) === dates . end . substr ( 0 , 10 ) && dates . end . substr ( 11 , 8 ) === '00:00:00' )
break ;
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
for ( var i = 0 ; i < ( typeof state . owner == 'object' ? state . owner . length : 1 ) ; i ++ ) {
var owner = multiple _owner ? state . owner [ i ] : state . owner ;
var cache _id = CalendarApp . _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 ;
}
}
egw . loading _prompt ( this . appname , false ) ;
} ;
/ * *
* The sidebox filters use some non - standard and not - exposed options . They
* are set up here .
*
* /
CalendarApp . prototype . _setup _sidebox _filters = function ( ) {
// Further date customizations
var date _widget = this . sidebox _et2 . getWidgetById ( 'date' ) ;
if ( date _widget ) {
// Dynamic resize of sidebox calendar to fill sidebox
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' ) ) ;
var go _button _widget = date _widget . getRoot ( ) . getWidgetById ( 'header_go' ) ;
var auto _update = this . egw . preference ( 'auto_update_on_sidebox_change' , 'calendar' ) === '1' ;
var calendar _resize = function ( ) {
try {
var percent = 1 + ( ( jQuery ( date _widget . getDOMNode ( ) ) . width ( ) - preferred _width ) / preferred _width ) ;
percent *= font _ratio ;
jQuery ( '#calendar-sidebox_date .ui-datepicker-inline' )
. css ( 'font-size' , ( percent * 100 ) + '%' ) ;
// Position go and today
go _button _widget . set _disabled ( false ) ;
var buttons = jQuery ( '#calendar-sidebox_date .ui-datepicker-header a span' ) ;
if ( today . length && go _button . length ) {
go _button . position ( { my : 'left+8px center' , at : 'right center-1' , of : jQuery ( '#calendar-sidebox_date .ui-datepicker-year' ) } ) ;
buttons . position ( { my : 'center' , at : 'center' , of : go _button } )
. css ( 'left' , '' ) ;
today . position ( { my : 'top' , at : 'top' , of : buttons } ) ;
today . css ( {
'left' : ( buttons . first ( ) . offset ( ) . left + buttons . last ( ) . offset ( ) . left ) / 2 - Math . ceil ( today . outerWidth ( ) / 2 ) ,
} ) ;
}
if ( auto _update ) {
go _button _widget . set _disabled ( true ) ;
}
}
catch ( e ) {
// Resize didn't work
}
} ;
var datepicker = date _widget . input _date . datepicker ( "option" , {
showButtonPanel : false ,
onChangeMonthYear : function ( year , month , inst ) {
// Update month button label
if ( go _button _widget ) {
var temp _date = new Date ( year , month - 1 , 1 , 0 , 0 , 0 ) ;
//temp_date.setUTCMinutes(temp_date.getUTCMinutes() + temp_date.getTimezoneOffset());
go _button _widget . btn . attr ( 'title' , egw . lang ( date ( 'F' , temp _date ) ) ) ;
// Store current _displayed_ date in date button for clicking
temp _date . setUTCMinutes ( temp _date . getUTCMinutes ( ) - temp _date . getTimezoneOffset ( ) ) ;
go _button _widget . btn . attr ( 'data-date' , temp _date . toJSON ( ) ) ;
}
if ( auto _update ) {
go _button _widget . click ( ) ;
}
window . setTimeout ( calendar _resize , 0 ) ;
} ,
// Mark holidays
beforeShowDay : function ( date ) {
var holidays = et2 _widget _view _1 . et2 _calendar _view . get _holidays ( { day _class _holiday : function ( ) { } } , date . getFullYear ( ) ) ;
var day _holidays = holidays [ '' + date . getFullYear ( ) +
sprintf ( "%02d" , date . getMonth ( ) + 1 ) +
sprintf ( "%02d" , date . getDate ( ) ) ] ;
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 ] ;
}
} ) ;
// Clickable week numbers
date _widget . input _date . on ( 'mouseenter' , '.ui-datepicker-week-col' , function ( ) {
jQuery ( this ) . siblings ( ) . find ( 'a' ) . addClass ( 'ui-state-hover' ) ;
} )
. on ( 'mouseleave' , '.ui-datepicker-week-col' , function ( ) {
jQuery ( this ) . siblings ( ) . find ( 'a' ) . removeClass ( 'ui-state-hover' ) ;
} )
. on ( 'click' , '.ui-datepicker-week-col' , function ( ) {
var view = app . calendar . state . view ;
var days = app . calendar . state . days ;
// 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 ) ;
date . setUTCMinutes ( date . getUTCMinutes ( ) - date . getTimezoneOffset ( ) ) ;
date = app . calendar . date . toString ( date ) ;
// Set to week view, if in one of the views where we change view
if ( app . calendar . sidebox _changes _views . indexOf ( view ) >= 0 ) {
app . calendar . update _state ( { view : 'week' , date : date , days : days } ) ;
}
else if ( view == 'planner' ) {
// Clicked a week, show just a week
app . calendar . update _state ( { date : date , planner _view : 'week' } ) ;
}
else if ( view == 'listview' ) {
app . calendar . update _state ( {
date : date ,
end _date : app . calendar . date . toString ( CalendarApp . views . week . end _date ( { date : date } ) ) ,
filter : 'week'
} ) ;
}
else {
app . calendar . update _state ( { date : date } ) ;
}
} ) ;
// Set today button
var today = jQuery ( '#calendar-sidebox_header_today' ) ;
today . attr ( 'title' , egw . lang ( 'today' ) ) ;
// Set go button
var go _button _widget = date _widget . getRoot ( ) . getWidgetById ( 'header_go' ) ;
if ( go _button _widget && go _button _widget . btn ) {
var go _button = go _button _widget . btn ;
var temp _date = new Date ( date _widget . get _value ( ) ) ;
temp _date . setUTCDate ( 1 ) ;
temp _date . setUTCMinutes ( temp _date . getUTCMinutes ( ) + temp _date . getTimezoneOffset ( ) ) ;
go _button . attr ( 'title' , egw . lang ( date ( 'F' , temp _date ) ) ) ;
// 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 ( ) ) ;
}
}
jQuery ( window ) . on ( 'resize.calendar' + date _widget . dom _id , calendar _resize ) . trigger ( 'resize' ) ;
// Avoid wrapping owner icons if user has group + search
var button = jQuery ( '#calendar-sidebox_owner ~ span.et2_clickable' ) ;
if ( button . length == 1 ) {
button . parent ( ) . css ( 'margin-right' , button . outerWidth ( true ) + 2 ) ;
button . parent ( ) . parent ( ) . css ( 'white-space' , 'nowrap' ) ;
}
jQuery ( window ) . on ( 'resize.calendar-owner' , function ( ) {
var preferred _width = jQuery ( '#calendar-et2_target' ) . children ( ) . first ( ) . outerWidth ( ) || 0 ;
if ( app . calendar && app . calendar . sidebox _et2 ) {
var owner = app . calendar . sidebox _et2 . getWidgetById ( 'owner' ) ;
if ( preferred _width && owner . input . hasClass ( "chzn-done" ) ) {
owner . input . next ( ) . css ( 'width' , preferred _width ) ;
}
}
} ) ;
window . setTimeout ( calendar _resize , 50 ) ;
} ;
/ * *
* Record view templates so we can quickly switch between them .
*
* @ param { etemplate2 } _et2 etemplate2 template that was just loaded
* @ param { String } _name Name of the template
* /
CalendarApp . prototype . _et2 _view _init = function ( _et2 , _name ) {
var hidden = typeof this . state . view !== 'undefined' ;
var all _loaded = this . sidebox _et2 !== null ;
// Avoid home portlets using our templates, and get them right
if ( _et2 . uniqueId . indexOf ( 'portlet' ) === 0 )
return ;
if ( _et2 . uniqueId === 'calendar-add' )
return ;
// Flag to make sure we don't hide non-view templates
var view _et2 = false ;
for ( var view in CalendarApp . views ) {
var index = CalendarApp . views [ view ] . etemplates . indexOf ( _name ) ;
if ( index > - 1 ) {
view _et2 = true ;
CalendarApp . views [ view ] . etemplates [ index ] = _et2 ;
// If a template disappears, we want to release it
jQuery ( _et2 . DOMContainer ) . one ( 'clear' , jQuery . proxy ( function ( ) {
this . view . etemplates [ this . index ] = _name ;
} , jQuery . extend ( { } , { view : CalendarApp . views [ view ] , index : "" + index , name : _name } ) ) ) ;
if ( this . state . view === view ) {
hidden = false ;
}
}
CalendarApp . views [ view ] . etemplates . forEach ( function ( et ) { all _loaded = all _loaded && typeof et !== 'string' ; } ) ;
}
// 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 ) {
// Avoid unwanted refresh immediately after load
nm . controller . _grid . doInvalidate = false ;
// Preserve pre-set search
if ( nm . activeFilters . search ) {
this . state . keywords = nm . activeFilters . search ;
}
// Bind to keep search up to date
jQuery ( nm . getWidgetById ( 'search' ) . getDOMNode ( ) ) . on ( 'change' , function ( ) {
app . calendar . state . search = jQuery ( 'input' , this ) . val ( ) ;
} ) ;
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 ) ;
}
}
// Start hidden, except for current view
if ( view _et2 ) {
if ( hidden ) {
jQuery ( _et2 . DOMContainer ) . hide ( ) ;
}
}
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
jQuery ( _et2 . DOMContainer ) . one ( 'clear' , jQuery . proxy ( function ( ) {
if ( app . calendar ) {
app . calendar . sidebox _hooked _templates . splice ( this , 1 , 0 ) ;
}
} , this . sidebox _hooked _templates . length - 1 ) ) ;
}
}
if ( all _loaded ) {
jQuery ( window ) . trigger ( 'resize' ) ;
this . setState ( { state : this . state } ) ;
// 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 ) ;
// 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 .
* /
CalendarApp . prototype . _set _autorefresh = function ( ) {
// Listview not loaded
if ( typeof CalendarApp . views . listview . etemplates [ 0 ] == 'string' )
return ;
var nm = CalendarApp . views . listview . etemplates [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
// nextmatch missing
if ( ! nm )
return ;
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 ) ;
}
var self = this ;
var refresh = function ( ) {
// Deleted events are not coming properly, so clear it all
self . _clear _cache ( ) ;
// Force redraw to current state
self . setState ( { state : self . state } ) ;
// This is a fast update, but misses deleted events
//app.calendar._fetch_data(app.calendar.state);
} ;
// Start / update timer
if ( this . _autorefresh _timer ) {
window . clearInterval ( this . _autorefresh _timer ) ;
this . _autorefresh _timer = null ;
}
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
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'hide.calendar' , jQuery . proxy ( function ( e ) {
// Stop
window . clearInterval ( this . _autorefresh _timer ) ;
jQuery ( e . target ) . off ( e ) ;
if ( ! time )
return ;
// 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 ;
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . one ( 'show.calendar' ,
// Important to use anonymous function instead of just 'this.refresh' because
// of the parameters passed
jQuery . proxy ( function ( ) { refresh ( ) ; } , this ) ) ;
} , this ) , time * 1000 ) ;
} , this ) ) ;
jQuery ( nm . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'show.calendar' , jQuery . proxy ( function ( e ) {
// Start normal autorefresh timer again
this . _set _autorefresh ( this . egw . preference ( refresh _preference , 'calendar' ) ) ;
jQuery ( e . target ) . off ( e ) ;
} , this ) ) ;
} ;
/ * *
* Initialization function in order to set / unset
* categories status .
*
* /
CalendarApp . prototype . category _report _init = function ( ) {
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
for ( var i = 1 ; i < content . grid . length ; i ++ ) {
if ( content . grid [ i ] != null )
this . category _report _enable ( { id : i + '' , checked : content . grid [ i ] [ 'enable' ] } ) ;
}
} ;
/ * *
* Set / unset selected category ' s row
*
* @ param { type } _widget
* @ returns { undefined }
* /
CalendarApp . prototype . category _report _enable = function ( _widget ) {
var widgets = [ '[user]' , '[weekend]' , '[holidays]' , '[min_days]' ] ;
var row _id = _widget . id . match ( /\d+/ ) ;
var w = { } ;
for ( var i = 0 ; i < widgets . length ; i ++ ) {
w = this . et2 . getWidgetById ( row _id + widgets [ i ] ) ;
if ( w )
w . set _readonly ( ! _widget . checked ) ;
}
} ;
/ * *
* submit function for report button
* /
CalendarApp . prototype . category _report _submit = function ( ) {
this . et2 . _inst . postSubmit ( ) ;
} ;
/ * *
* Function to enable / disable categories
*
* @ param { object } _widget select all checkbox
* /
CalendarApp . prototype . category _report _selectAll = function ( _widget ) {
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var checkbox = { } ;
var grid _index = typeof content . grid . length != 'undefined' ? content . grid : Object . keys ( content . grid ) ;
for ( var i = 1 ; i < grid _index . length ; i ++ ) {
if ( content . grid [ i ] != null ) {
checkbox = this . et2 . getWidgetById ( i + '[enable]' ) ;
if ( checkbox ) {
checkbox . set _value ( _widget . checked ) ;
this . category _report _enable ( { id : checkbox . id , checked : checkbox . get _value ( ) } ) ;
}
}
}
} ;
/ * *
* Create a cache ID for the daywise cache
*
* @ param { String | Date } date If a string , date should be in Ymd format
* @ param { String | integer | String [ ] } owner
* @ returns { String } Cache ID
* /
CalendarApp . _daywise _cache _id = function ( date , owner ) {
if ( typeof date === 'object' ) {
date = date . getUTCFullYear ( ) + sprintf ( '%02d' , date . getUTCMonth ( ) + 1 ) + sprintf ( '%02d' , date . getUTCDate ( ) ) ;
}
// If the owner is not set, 0, or the current user, don't bother adding it
var _owner = ( owner && owner . toString ( ) != '0' ) ? owner . toString ( ) : '' ;
if ( _owner == egw . user ( 'account_id' ) ) {
_owner = '' ;
}
return CalendarApp . DAYWISE _CACHE _ID + '::' + date + ( _owner ? '-' + _owner : '' ) ;
} ;
2020-04-07 11:10:49 +02:00
/ * *
* Videoconference checkbox checked
* /
CalendarApp . prototype . videoconferenceOnChange = function ( ) {
var widget = this . et2 . getWidgetById ( 'videoconference' ) ;
if ( widget && widget . get _value ( ) ) {
// notify all participants
this . et2 . getWidgetById ( 'participants[notify_externals]' ) . set _value ( 'yes' ) ;
// add alarm for all participants 5min before videoconference
2020-05-04 23:03:03 +02:00
var start = new Date ( widget . getRoot ( ) . getWidgetById ( 'start' ) . getValue ( ) ) ;
var alarms = this . et2 . getArrayMgr ( 'content' ) . getEntry ( 'alarm' ) || { } ;
for ( var _i = 0 , alarms _1 = alarms ; _i < alarms _1 . length ; _i ++ ) {
var alarm = alarms _1 [ _i ] ;
// Check for already existing alarm
if ( ! alarm || typeof alarm != "object" || ! alarm . all )
continue ;
var alarm _time = new Date ( alarm . time ) ;
if ( start . getTime ( ) - alarm _time . getTime ( ) == 5 * 60 * 1000 ) {
// Alarm exists
return ;
}
}
2020-04-07 11:10:49 +02:00
this . et2 . getWidgetById ( 'new_alarm[options]' ) . set _value ( '300' ) ;
this . et2 . getWidgetById ( 'new_alarm[owner]' ) . set _value ( '0' ) ; // all participants
this . et2 . getWidgetById ( 'button[add_alarm]' ) . click ( ) ;
}
} ;
2020-04-08 19:54:26 +02:00
CalendarApp . prototype . isVideoConference = function ( _action , _selected ) {
2020-04-08 20:42:57 +02:00
var data = egw . dataGetUIDdata ( _selected [ 0 ] . id ) ;
return data && data . data ? data . data [ '##videoconference' ] : false ;
} ;
2020-04-24 18:54:08 +02:00
/ * *
* Action handler for join videoconference context menu
*
* @ param _action
* @ param _sender
* /
CalendarApp . prototype . joinVideoConferenceAction = function ( _action , _sender ) {
2020-04-08 20:42:57 +02:00
var data = egw . dataGetUIDdata ( _sender [ 0 ] . id ) [ 'data' ] ;
2020-11-18 15:10:16 +01:00
return this . joinVideoConference ( data [ '##videoconference' ] , data ) ;
2020-04-24 18:54:08 +02:00
} ;
/ * *
* Join a videoconference
*
* Using the videoconference tag / ID , generate the URL and open it via JSON
*
* @ param { string } videoconference
* /
2020-11-18 15:10:16 +01:00
CalendarApp . prototype . joinVideoConference = function ( videoconference , _data ) {
2020-04-24 18:54:08 +02:00
return egw . json ( "EGroupware\\Status\\Videoconference\\Call::ajax_genMeetingUrl" , [ videoconference ,
2020-04-08 20:42:57 +02:00
{
name : egw . user ( 'account_fullname' ) ,
account _id : egw . user ( 'account_id' ) ,
2020-11-24 13:47:22 +01:00
email : egw . user ( 'account_email' ) ,
2020-12-09 18:39:32 +01:00
cal _id : _data . id ,
title : _data . title
2021-01-11 14:19:22 +01:00
} , _data . start , _data . end , {
participants : Object . keys ( _data . participants ) . filter ( function ( v ) { return v . match ( /^[0-9]/ ) ; } )
} ] , function ( _value ) {
2020-12-02 17:03:00 +01:00
if ( _value ) {
if ( _value . err )
egw . message ( _value . err , 'error' ) ;
if ( _value . url )
app . status . openCall ( _value . url ) ;
}
2020-04-08 20:42:57 +02:00
} ) . sendRequest ( ) ;
2020-04-08 19:54:26 +02:00
} ;
2020-03-05 13:21:02 +01:00
/ * *
* These are the keys we keep to set & remember the status , others are discarded
* /
CalendarApp . states _to _save = [ 'owner' , 'status_filter' , 'filter' , 'cat_id' , 'view' , 'sortby' , 'planner_view' , 'weekend' ] ;
CalendarApp . views = {
day : View _1 . day ,
day4 : View _1 . day4 ,
week : View _1 . week ,
weekN : View _1 . weekN ,
month : View _1 . month ,
planner : View _1 . planner ,
listview : View _1 . listview
} ;
/ * *
* 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 )
* /
CalendarApp . DAYWISE _CACHE _ID = 'calendar_daywise' ;
return CalendarApp ;
} ( egw _app _1 . EgwApp ) ) ;
app . classes . calendar = CalendarApp ;
//# sourceMappingURL=app.js.map