2013-08-26 11:45:43 +02:00
/ * *
* EGroupware - Infolog - Javascript UI
*
* @ link http : //www.egroupware.org
* @ package infolog
* @ author Hadi Nategh < hn - AT - stylite . de >
* @ copyright ( c ) 2008 - 13 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
2013-11-04 21:54:23 +01:00
* @ version $Id$
2013-08-26 11:45:43 +02:00
* /
/ * *
* UI for Infolog
*
* @ augments AppJS
* /
2013-11-04 21:54:23 +01:00
app . classes . infolog = AppJS . extend (
2013-08-26 11:45:43 +02:00
{
appname : 'infolog' ,
/ * *
* Constructor
*
* @ memberOf app . infolog
* /
init : function ( )
{
// call parent
this . _super . apply ( this , arguments ) ;
} ,
/ * *
* Destructor
* /
destroy : function ( )
{
// call parent
this . _super . apply ( this , arguments ) ;
} ,
/ * *
* This function is called when the etemplate2 object is loaded
* and ready . If you must store a reference to the et2 object ,
* make sure to clean it up in destroy ( ) .
*
2014-03-03 10:28:56 +01:00
* @ param { etemplate2 } _et2 newly ready object
* @ param { string } _name template name
2013-08-26 11:45:43 +02:00
* /
2014-03-03 10:28:56 +01:00
et2 _ready : function ( _et2 , _name )
2013-08-26 11:45:43 +02:00
{
// call parent
this . _super . apply ( this , arguments ) ;
2014-03-03 10:28:56 +01:00
switch ( _name )
2013-08-26 11:45:43 +02:00
{
2014-03-03 10:28:56 +01:00
case 'infolog.index' :
this . filter _change ( ) ;
break ;
2014-05-20 12:51:37 +02:00
case 'infolog.edit.print' :
// Trigger print command if the infolog oppend for printing porpuse
var that = this ;
jQuery ( '#infolog-edit-print' ) . bind ( 'load' , function ( ) { that . infolog _print _preview ( ) ; } ) ;
2013-08-26 11:45:43 +02:00
}
} ,
/ * *
2014-05-22 17:29:14 +02:00
* Observer method receives update notifications from all applications
*
* InfoLog currently reacts to timesheet updates , as it might show time - sums .
* @ todo only trigger update , if times are shown
2013-08-26 11:45:43 +02:00
*
2014-05-22 17:29:14 +02:00
* @ param { string } _msg message ( already translated ) to show , eg . 'Entry deleted'
* @ param { string } _app application name
* @ param { ( string | number ) } _id id of entry to refresh or null
* @ param { string } _type either 'update' , 'edit' , 'delete' , 'add' or null
* - update : request just modified data from given rows . Sorting is not considered ,
* so if the sort field is changed , the row will not be moved .
* - edit : rows changed , but sorting may be affected . Requires full reload .
* - delete : just delete the given rows clientside ( no server interaction neccessary )
* - add : requires full reload for proper sorting
* @ param { string } _msg _type 'error' , 'warning' or 'success' ( default )
2014-05-26 16:01:18 +02:00
* @ param { object | null } _links app => array of ids of linked entries
* or null , if not triggered on server - side , which adds that info
2013-08-26 11:45:43 +02:00
* /
2014-05-26 16:01:18 +02:00
observer : function ( _msg , _app , _id , _type , _msg _type , _links )
2013-08-26 11:45:43 +02:00
{
2014-05-27 15:36:40 +02:00
if ( typeof _links != 'undefined' )
{
if ( typeof _links . infolog != 'undefined' )
{
switch ( _app )
{
case 'timesheet' :
var nm = this . et2 ? this . et2 . getWidgetById ( 'nm' ) : null ;
if ( nm ) nm . applyFilters ( ) ;
break ;
}
2014-05-26 16:01:18 +02:00
}
}
2014-05-22 17:29:14 +02:00
} ,
2013-08-26 11:45:43 +02:00
2014-05-22 17:29:14 +02:00
/ * *
*
* /
filter _change : function ( )
{
2013-08-26 11:45:43 +02:00
var filter = this . et2 . getWidgetById ( 'filter' ) ;
2014-03-06 23:12:50 +01:00
var nm = this . et2 . getWidgetById ( 'nm' ) ;
if ( nm && filter )
2013-08-26 11:45:43 +02:00
{
2014-03-06 23:12:50 +01:00
switch ( filter . getValue ( ) )
{
case 'bydate' :
case 'duedate' :
nm . set _header _left ( 'infolog.index.dates' ) ;
break ;
default :
2014-03-07 12:55:11 +01:00
nm . set _header _left ( ) ;
2014-03-06 23:12:50 +01:00
break ;
}
2013-08-26 11:45:43 +02:00
}
} ,
/ * *
* show or hide the details of rows by selecting the filter2 option
* either 'all' for details or 'no_description' for no details
*
* /
2013-08-27 12:46:42 +02:00
filter2 _change : function ( )
2013-08-26 11:45:43 +02:00
{
var nm = this . et2 . getWidgetById ( 'nm' ) ;
var filter2 = this . et2 . getWidgetById ( 'filter2' ) ;
if ( nm && filter2 )
{
// Show / hide descriptions
this . show _details ( filter2 . value == 'all' ) ;
// Change preference location - widget is nextmatch
nm . options . settings . columnselection _pref = 'infolog.index.rows' + ( filter2 . value == 'all' ? '-details' : '' ) ;
// Load new preferences
2014-03-03 10:28:56 +01:00
var colData = [ ] ;
2014-06-04 20:43:21 +02:00
for ( var i = 0 ; i < nm . columns . length ; i ++ ) colData [ i ] = { disabled : true , width : '20' } ;
2013-08-26 11:45:43 +02:00
nm . _applyUserPreferences ( nm . columns , colData ) ;
for ( var i = 0 ; i < colData . length ; i ++ )
{
// Wants a string
nm . dataview . getColumnMgr ( ) . columns [ i ] . set _width ( colData [ i ] . width + 'px' ) ;
nm . dataview . getColumnMgr ( ) . columns [ i ] . set _visibility ( ! colData [ i ] . disabled ) ;
}
nm . dataview . getColumnMgr ( ) . updated = true ;
// Update page
nm . dataview . updateColumns ( ) ;
}
} ,
/ * *
* Show or hide details by changing the CSS class
*
* @ param show
* /
show _details : function ( show )
{
// Show / hide descriptions
egw . css ( ".et2_box.infoDes" , "display:" + ( show ? "block;" : "none;" ) ) ;
} ,
2013-09-19 14:52:50 +02:00
confirm _delete _2 : function ( _action , _senders )
{
var children = false ;
var child _button = jQuery ( '#delete_sub' ) . get ( 0 ) || jQuery ( '[id*="delete_sub"]' ) . get ( 0 ) ;
if ( child _button )
{
for ( var i = 0 ; i < _senders . length ; i ++ )
{
if ( $j ( _senders [ i ] . iface . node ) . hasClass ( 'infolog_rowHasSubs' ) )
{
children = true ;
break ;
}
}
child _button . style . display = children ? 'block' : 'none' ;
}
var callbackDeleteDialog = function ( button _id )
2014-03-03 10:28:56 +01:00
{
if ( button _id == et2 _dialog . YES _BUTTON )
{
2013-09-19 15:47:02 +02:00
2014-03-03 10:28:56 +01:00
}
} ;
2013-10-07 18:53:13 +02:00
var confirmDeleteDialog = et2 _dialog . show _dialog ( callbackDeleteDialog , this . egw . lang ( "Do you really want to DELETE this Rule" ) , this . egw . lang ( "Delete" ) , { } , et2 _dialog . BUTTONS _YES _NO _CANCEL , et2 _dialog . WARNING _MESSAGE ) ;
2013-09-19 14:52:50 +02:00
} ,
2013-08-26 11:45:43 +02:00
/ * *
* Confirm delete
* If entry has children , asks if you want to delete children too
*
* @ param _action
* @ param _senders
* /
2013-08-27 12:46:42 +02:00
confirm _delete : function ( _action , _senders )
2013-08-26 11:45:43 +02:00
{
var children = false ;
var child _button = jQuery ( '#delete_sub' ) . get ( 0 ) || jQuery ( '[id*="delete_sub"]' ) . get ( 0 ) ;
if ( child _button )
{
for ( var i = 0 ; i < _senders . length ; i ++ )
{
2014-04-28 22:25:40 +02:00
if ( $j ( _senders [ i ] . iface . getDOMNode ( ) ) . hasClass ( 'infolog_rowHasSubs' ) )
2013-08-26 11:45:43 +02:00
{
children = true ;
break ;
}
}
child _button . style . display = children ? 'block' : 'none' ;
}
nm _open _popup ( _action , _senders ) ;
} ,
/ * *
* Add email from addressbook
*
* @ param ab _id
* @ param info _cc
* /
2013-08-27 12:46:42 +02:00
add _email _from _ab : function ( ab _id , info _cc )
2013-08-26 11:45:43 +02:00
{
var ab = document . getElementById ( ab _id ) ;
if ( ! ab || ! ab . value )
{
jQuery ( "tr.hiddenRow" ) . css ( "display" , "table-row" ) ;
}
else
{
var cc = document . getElementById ( info _cc ) ;
for ( var i = 0 ; i < ab . options . length && ab . options [ i ] . value != ab . value ; ++ i ) ;
if ( i < ab . options . length )
{
cc . value += ( cc . value ? ', ' : '' ) + ab . options [ i ] . text . replace ( /^.* <(.*)>$/ , '$1' ) ;
ab . value = '' ;
ab . onchange ( ) ;
jQuery ( "tr.hiddenRow" ) . css ( "display" , "none" ) ;
}
}
return false ;
} ,
/ * *
* If one of info _status , info _percent or info _datecompleted changed -- > set others to reasonable values
*
2014-03-03 10:28:56 +01:00
* @ param { string } changed _id id of changed element
* @ param { string } status _id
* @ param { string } percent _id
* @ param { string } datecompleted _id
2013-08-26 11:45:43 +02:00
* /
2013-08-27 12:46:42 +02:00
status _changed : function ( changed _id , status _id , percent _id , datecompleted _id )
2013-08-26 11:45:43 +02:00
{
2014-01-10 15:25:41 +01:00
// Make sure this doesn't get executed while template is loading
2014-01-10 16:02:50 +01:00
if ( this . et2 == null || this . et2 . getInstanceManager ( ) == null ) return ;
2014-03-03 10:28:56 +01:00
2013-08-26 11:45:43 +02:00
var status = document . getElementById ( status _id ) ;
var percent = document . getElementById ( percent _id ) ;
var datecompleted = document . getElementById ( datecompleted _id + '[str]' ) ;
if ( ! datecompleted )
{
datecompleted = jQuery ( '#' + datecompleted _id + ' input' ) . get ( 0 ) ;
}
var completed ;
switch ( changed _id )
{
case status _id :
completed = status . value == 'done' || status . value == 'billed' ;
if ( completed || status . value == 'not-started' ||
( status . value == 'ongoing' ) != ( percent . value > 0 && percent . value < 100 ) )
{
percent . value = completed ? 100 : ( status . value == 'not-started' ? 0 : 10 ) ;
}
break ;
case percent _id :
completed = percent . value == 100 ;
if ( completed != ( status . value == 'done' || status . value == 'billed' ) ||
( status . value == 'not-started' ) != ( percent . value == 0 ) )
{
status . value = percent . value == 0 ? 'not-started' : ( percent . value == 100 ? 'done' : 'ongoing' ) ;
}
break ;
case datecompleted _id + '[str]' :
case datecompleted _id :
completed = datecompleted . value != '' ;
if ( completed != ( status . value == 'done' || status . value == 'billed' ) )
{
status . value = completed ? 'done' : 'not-started' ;
}
if ( completed != ( percent . value == 100 ) )
{
percent . value = completed ? 100 : 0 ;
}
break ;
}
if ( ! completed && datecompleted && datecompleted . value != '' )
{
datecompleted . value = '' ;
}
else if ( completed && datecompleted && datecompleted . value == '' )
{
// todo: set current date in correct format
}
} ,
/ * *
* handle "print" action from "Actions" selectbox in edit infolog window .
* check if the template is dirty then submit the template otherwise just open new window as print .
2013-08-27 12:46:42 +02:00
*
2013-08-26 11:45:43 +02:00
* /
2013-08-27 12:46:42 +02:00
edit _actions : function ( )
2013-08-26 11:45:43 +02:00
{
var widget = this . et2 . getWidgetById ( 'action' ) ;
var template = this . et2 . _inst ;
if ( template )
{
var id = template . widgetContainer . getArrayMgr ( 'content' ) . data [ 'info_id' ] ;
}
if ( widget )
{
switch ( widget . get _value ( ) )
{
case 'print' :
if ( template . isDirty ( ) )
{
template . submit ( ) ;
}
egw _open ( id , 'infolog' , 'edit' , { print : 1 } ) ;
break ;
default :
template . submit ( ) ;
}
}
} ,
2014-05-22 17:29:14 +02:00
2014-05-20 12:51:37 +02:00
/ * *
* Open infolog entry for printing
*
* @ param { aciton object } _action
* @ param { object } _selected
* /
infolog _menu _print : function ( _action , _selected )
{
var id = _selected [ 0 ] . id . replace ( /^infolog::/g , '' ) ;
egw _open ( id , 'infolog' , 'edit' , { print : 1 } ) ;
} ,
2014-05-22 17:29:14 +02:00
2014-05-20 12:51:37 +02:00
/ * *
* Trigger print ( ) function to print the current window
* /
infolog _print _preview : function ( )
{
this . egw . message ( 'Printing....' ) ;
this . egw . window . print ( ) ;
} ,
2014-05-22 17:29:14 +02:00
2013-09-13 15:51:33 +02:00
/ * *
*
* /
add _link _sidemenu : function ( )
{
2013-09-25 11:20:32 +02:00
egw . open ( '' , 'infolog' , 'add' ) ;
2013-09-13 15:51:33 +02:00
} ,
2013-11-27 01:17:08 +01:00
/ * *
* Opens a new edit dialog with some extra url parameters pulled from
* standard locations . Done with a function instead of hardcoding so
* the values can be updated if user changes them in UI .
*
2013-11-28 18:34:28 +01:00
* @ param { et2 _widget } widget Originating / calling widget
2013-11-27 01:17:08 +01:00
* @ param _type string Type of infolog entry
* @ param _action string Special action for new infolog entry
* @ param _action _id string ID for special action
* /
2013-11-28 18:34:28 +01:00
add _with _extras : function ( widget , _type , _action , _action _id )
2013-11-27 01:17:08 +01:00
{
2013-11-28 18:34:28 +01:00
// We use widget.getRoot() instead of this.et2 for the case when the
// addressbook tab is viewing a contact + infolog list, there's 2 infolog
// etemplates
var nm = widget . getRoot ( ) . getWidgetById ( 'nm' ) ;
2013-11-27 01:17:08 +01:00
var nm _value = nm . getValue ( ) || { } ;
2013-11-28 18:34:28 +01:00
// It's important that all these keys are here, they override the link
// registry.
2013-11-27 01:17:08 +01:00
var extras = {
2013-11-28 18:34:28 +01:00
type : _type || nm _value . filter || "" ,
cat _id : nm _value . cat _id || "" ,
action : _action || "" ,
action _id : _action _id != '0' ? _action _id : "" || ""
2013-11-27 01:17:08 +01:00
} ;
egw . open ( '' , 'infolog' , 'add' , extras ) ;
}
2013-08-26 11:45:43 +02:00
} ) ;