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 >
* @ copyright ( c ) 2008 - 13 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2011-04-27 18:53:06 +02:00
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ version $Id$
* /
/ * *
2013-10-31 15:51:19 +01:00
* UI for calendar
*
* @ augments AppJS
2011-04-27 18:53:06 +02:00
* /
2013-11-04 21:54:23 +01:00
app . classes . calendar = AppJS . extend (
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
/ * *
* application name
* /
appname : 'calendar' ,
/ * *
* et2 widget container
* /
et2 : null ,
/ * *
* edit _series vars
* /
calendar _edit _id : null ,
calendar _edit _date : null ,
/ * *
* Constructor
*
* @ memberOf app . calendar
* /
init : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
// call parent
this . _super . apply ( this , arguments ) ;
} ,
/ * *
* Destructor
* /
destroy : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
delete this . et2 ;
// call parent
this . _super . apply ( this , arguments ) ;
2011-04-27 18:53:06 +02:00
2013-10-31 15:51:19 +01:00
} ,
2011-04-27 18:53:06 +02:00
2013-10-31 15:51:19 +01:00
/ * *
* This function is called when the etemplate2 object is loaded
* and ready . If you must store a reference to the et2 object ,
* make sure to clean it up in destroy ( ) .
*
* @ param et2 etemplate2 Newly ready object
* /
et2 _ready : function ( et2 )
{
// call parent
this . _super . apply ( this , arguments ) ;
var content = this . et2 . getArrayMgr ( 'content' ) ;
if ( typeof et2 . templates [ 'calendar.list' ] != 'undefined' )
{
this . filter _change ( ) ;
}
if ( typeof et2 . templates [ 'calendar.edit' ] != 'undefined' && typeof content . data [ 'conflicts' ] == 'undefined' )
{
$j ( document . getElementById ( 'calendar-edit_calendar-delete_series' ) ) . hide ( ) ;
//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 ( ) ;
2013-11-05 14:33:32 +01:00
this . et2 . getWidgetById ( 'recur_exception' ) . set _disabled ( typeof content . data [ 'recur_exception' ] [ 0 ] == 'undefined' ) ;
2013-10-31 15:51:19 +01:00
}
else
{
this . freetime _search ( ) ;
}
//send Syncronus ajax request to the server to unlock the on close entry
//set onbeforeunload with json request to send request when the window gets close by X button
window . onbeforeunload = function ( ) {
this . egw . json ( 'calendar.calendar_uiforms.ajax_unlock'
, [ content . data [ 'id' ] , content . data [ 'lock_token' ] ] , null , true , null , null ) . sendRequest ( true ) ;
} ;
}
//this.replace_eTemplate_onsubmit();
if ( typeof et2 . templates [ 'calendar.freetimesearch' ] != 'undefined' )
{
this . set _enddate _visibility ( ) ;
}
} ,
/ * *
* open the freetime search popup
*
* /
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
*
* /
freetime _search : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
content [ 'start' ] = this . et2 . getWidgetById ( 'start' ) . get _value ( ) ;
content [ 'end' ] = this . et2 . getWidgetById ( 'end' ) . get _value ( ) ;
content [ 'duration' ] = this . et2 . getWidgetById ( 'duration' ) . get _value ( ) ;
var request = this . egw . json ( 'calendar.calendar_uiforms.ajax_freetimesearch' , [ content ] , null , null , null , null ) ;
request . sendRequest ( ) ;
} ,
/ * *
* Function for disabling the recur _data multiselect box
*
* /
check _recur _type : function ( )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
var recurType = this . et2 . getWidgetById ( 'recur_type' ) ;
var recurData = this . et2 . getWidgetById ( 'recur_data' ) ;
2011-04-27 18:53:06 +02:00
2013-10-31 15:51:19 +01:00
if ( recurType && recurData )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
recurData . set _disabled ( recurType . get _value ( ) != 2 ) ;
2011-04-27 18:53:06 +02:00
}
2013-10-31 15:51:19 +01:00
} ,
/ * *
* Show / Hide end date , for both edit and freetimesearch popups ,
* based on if "use end date" selected or not .
*
* /
set _enddate _visibility : function ( )
{
var duration = this . et2 . getWidgetById ( 'duration' ) ;
var end = this . et2 . getWidgetById ( 'end' ) ;
if ( typeof duration != 'undefined' && typeof end != 'undefined' )
2011-04-27 18:53:06 +02:00
{
2013-10-31 15:51:19 +01:00
end . set _disabled ( duration . get _value ( ) !== '' ) ;
2011-04-27 18:53:06 +02:00
}
2013-10-31 15:51:19 +01:00
} ,
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
/ * *
* handles actions selectbox in calendar edit popup
*
* @ param { widget object } widget , widget "actions selectBox" in edit popup window
* /
actions _change : function ( egw , 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' ) ;
this . et2 . _inst . submit ( ) ;
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=' + ( $j . isPlainObject ( event ) ? event [ 'id' ] : event ) , '_self' , '700x600' , 'infolog' ) ;
this . et2 . _inst . submit ( ) ;
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
* /
custom _mail : function ( vars )
{
this . egw . open _link ( 'mail.mail_compose.compose&' , '_blank' , '700x700' ) ;
} ,
/ * *
* control delete _series popup visibility
*
* @ param { Array } exceptions , an array contains number of exception entries
*
* /
delete _btn : function ( exceptions )
{
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
if ( exceptions )
{
$j ( document . getElementById ( 'calendar-edit_calendar-delete_series' ) ) . show ( ) ;
}
else if ( content [ 'recur_type' ] !== 0 )
{
return confirm ( 'Delete this series of recuring events' ) ;
}
else
{
return confirm ( 'Delete this event' ) ;
}
} ,
/ * *
* print _participants _status ( egw , widget )
* Handle to apply changes from status in print popup
*
* @ param { widget object } widget , widget "status" in print popup window
*
* /
print _participants _status : function ( egw , 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 { widget object } _widget , widget "select button" in freetime search popup window
*
* /
freetime _select : function ( _egw , _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' ) ;
var eTime = this . et2 . getWidgetById ( selectedId + '[end]' ) ;
//Catches the start time from freetime content
var str = sTime . get _value ( ) ;
2013-01-09 22:45:55 +01:00
2013-10-31 15:51:19 +01:00
var end = parseInt ( str ) + parseInt ( content [ 'duration' ] ) ;
//check the parent window is still open before to try to access it
if ( window . opener )
{
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 ( str ) ;
endTime . set _value ( end ) ;
}
}
}
else
{
alert ( this . egw . lang ( 'The original calendar edit popup is closed!' ) ) ;
}
}
window . close ( ) ;
} ,
/ * *
* show / hide the filter of nm list in calendar listview
*
* /
filter _change : function ( )
2013-01-09 22:45:55 +01:00
{
2013-10-31 15:51:19 +01:00
var filter = this . et2 . getWidgetById ( 'filter' ) ;
var dates = this . et2 . getWidgetById ( 'calendar.list.dates' ) ;
if ( filter && dates )
2013-01-09 22:45:55 +01:00
{
2013-10-31 15:51:19 +01:00
dates . set _disabled ( filter . value !== "custom" ) ;
2013-01-09 22:45:55 +01:00
}
2013-10-31 15:51:19 +01:00
} ,
/ * *
* this function try to fix ids which are from integrated apps
*
* /
cal _fix _app _id : function ( _action , _senders )
2013-01-09 22:38:18 +01:00
{
2013-10-31 15:51:19 +01:00
var app = 'calendar' ;
var id = _senders [ 0 ] . id ;
2013-11-04 11:23:08 +01:00
var matches = id . match ( /^(?:calendar::)?([0-9]+)(:([0-9]+))?$/ ) ;
2013-10-31 15:51:19 +01:00
if ( matches )
{
id = matches [ 1 ] ;
}
else if ( matches = id . match ( /^([a-z_-]+)([0-9]+)/i ) )
{
app = matches [ 1 ] ;
id = matches [ 2 ] ;
}
var backup _url = _action . data . url ;
2013-11-05 14:30:41 +01:00
_action . data . url = _action . data . url . replace ( /(\$|%24)id/ , id ) ;
_action . data . url = _action . data . url . replace ( /(\$|%24)app/ , app ) ;
2013-10-31 15:51:19 +01:00
nm _action ( _action , _senders ) ;
2013-11-05 14:30:41 +01:00
2013-10-31 15:51:19 +01:00
_action . data . url = backup _url ; // restore url
} ,
/ * *
* Open calendar entry , taking into accout the calendar integration of other apps
*
* calendar _uilist : : get _rows sets var js _calendar _integration object
*
* @ param _action
* @ param _senders
*
* /
cal _open : function ( _action , _senders )
{
var js _integration _data = this . et2 . getArrayMgr ( 'content' ) . data . nm . js _integration _data ;
var id = _senders [ 0 ] . id ;
var matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
var backup = _action . data ;
if ( matches )
{
this . edit _series ( matches [ 1 ] , matches [ 2 ] ) ;
return ;
}
else if ( matches = id . match ( /^([a-z_-]+)([0-9]+)/i ) )
{
var app = matches [ 1 ] ;
_action . data . url = window . egw _webserverUrl + '/index.php?' ;
var get _params = js _integration _data [ app ] . edit ;
get _params [ js _integration _data [ app ] . edit _id ] = matches [ 2 ] ;
for ( var name in get _params )
_action . data . url += name + "=" + encodeURIComponent ( get _params [ name ] ) + "&" ;
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
if ( js _integration _data [ app ] . edit _popup &&
( matches = js _integration _data [ app ] . edit _popup . match ( /^(.*)x(.*)$/ ) ) )
{
_action . data . width = matches [ 1 ] ;
_action . data . height = matches [ 2 ] ;
}
else
{
_action . data . nm _action = 'location' ;
}
}
egw . open ( id . replace ( /^calendar::/g , '' ) , 'calendar' , 'edit' ) ;
_action . data = backup ; // restore url, width, height, nm_action
} ,
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
/ * *
* Delete calendar entry , asking if you want to delete series or exception
*
*
* @ param _action
* @ param _senders
* /
cal _delete : function ( _action , _senders )
{
var backup = _action . data ;
var matches = false ;
2013-01-09 22:38:18 +01:00
2013-10-31 15:51:19 +01:00
// Loop so we ask if any of the selected entries is part of a series
for ( var i = 0 ; i < _senders . length ; i ++ )
2013-01-09 22:38:18 +01:00
{
2013-10-31 15:51:19 +01:00
var id = _senders [ i ] . id ;
if ( ! matches )
{
matches = id . match ( /^(?:calendar::)?([0-9]+):([0-9]+)$/ ) ;
}
}
if ( matches )
{
var id = matches [ 1 ] ;
var date = matches [ 2 ] ;
var popup = jQuery ( document . getElementById ( _action . getManager ( ) . etemplate _var _prefix + '[' + _action . id + '_popup]' ) ) ;
var row = null ;
// Cancel normal confirm
delete _action . data . confirm ;
delete _action . data . confirm _multiple ;
// nm action - show popup
nm _open _popup ( _action , _senders ) ;
if ( ! popup )
{
return ;
}
if ( row = jQuery ( "#" + id + "\\:" + date ) ) {
// Open at row
popup . css ( {
position : "absolute" ,
top : row . position ( ) . top + row . height ( ) - popup . height ( ) / 2 ,
left : $j ( window ) . width ( ) / 2 - popup . width ( ) / 2
} ) ;
} else {
// Open popup in the middle
popup . css ( {
position : "absolute" ,
top : $j ( window ) . height ( ) / 2 - popup . height ( ) / 2 ,
left : $j ( window ) . width ( ) / 2 - popup . width ( ) / 2
} ) ;
}
2013-01-09 22:38:18 +01:00
return ;
}
2013-10-31 15:51:19 +01:00
console . log ( _action ) ;
2013-11-05 17:02:21 +01:00
nm _action ( _action , _senders ) ;
2013-10-31 15:51:19 +01:00
_action . data = backup ; // restore url, width, height, nm_action
} ,
/ * *
* Create edit exception dialog for recurrence entries
*
* @ param { timestamp } date
* @ param { string } id , cal _id
* @ param { type } name description
* /
edit _series : function ( event , id , date )
{
// Coming from list, there is no event
if ( arguments . length == 2 )
{
date = id ;
id = event ;
event = null ;
}
calendar _edit _id = id ;
calendar _edit _date = date ;
var that = this ;
var buttons = [
{ text : this . egw . lang ( "Edit exception" ) , id : "exception" , class : "ui-priority-primary" , "default" : true } ,
{ text : this . egw . lang ( "Edit series" ) , id : "series" } ,
{ text : this . egw . lang ( "Cancel" ) , id : "cancel" } ,
] ;
var callbackExceptionDialog = function ( button _id )
{
switch ( button _id )
{
case 'exception' :
that . open _edit ( false ) ;
break ;
case 'series' :
that . open _edit ( true ) ;
break ;
case 'cancel' :
default :
break ;
}
}
var confirmExcDialog = et2 _dialog . show _dialog ( callbackExceptionDialog , this . egw . lang ( "Do you want to edit this event as an exception or the whole series?" ) , this . egw . lang ( "This event is part of a series" ) , { } , buttons , et2 _dialog . WARNING _MESSAGE ) ;
} ,
/ * *
* open calendar entry with the proper url either as series modifiction or exception modification
*
* /
open _edit : function ( series )
{
this . egw . open ( calendar _edit _id , 'calendar' , 'edit' , '&date=' + calendar _edit _date
+ ( ! series ? '&exception=1' : '' ) ) ;
} ,
} ) ;