2013-02-12 18:48:04 +01:00
/ * *
* mail - static javaScript functions
*
* @ link http : //www.egroupware.org
2013-10-24 09:15:48 +02:00
* @ author Stylite AG [ info @ stylite . de ]
2014-01-13 14:06:29 +01:00
* @ copyright ( c ) 2013 - 2014 by Stylite AG < info - AT - stylite . de >
2013-02-12 18:48:04 +01:00
* @ package mail
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ version $Id$
* /
2014-02-12 11:56:44 +01:00
/ * e g w : u s e s
phpgwapi . jquery . jquery . base64 ;
* /
2013-10-07 18:53:13 +02:00
/ * *
* UI for mail
2013-10-09 18:44:03 +02:00
*
2013-10-07 18:53:13 +02:00
* @ augments AppJS
* /
2013-11-04 21:54:23 +01:00
app . classes . mail = AppJS . extend (
2013-02-19 17:30:59 +01:00
{
2013-04-13 12:30:07 +02:00
appname : 'mail' ,
2013-08-21 12:47:20 +02:00
2013-06-12 13:50:30 +02:00
/ * *
* et2 widget container
* /
et2 : null ,
2013-04-13 12:30:07 +02:00
doStatus : null ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
mail _queuedFolders : [ ] ,
mail _queuedFoldersIndex : 0 ,
2013-05-21 10:46:54 +02:00
mail _selectedMails : [ ] ,
mail _currentlyFocussed : '' ,
2013-05-29 14:34:33 +02:00
mail _previewAreaActive : true , // we start with the area active
2013-07-25 17:35:44 +02:00
2014-05-23 12:11:17 +02:00
nm _index : 'nm' , // nm name of index
2013-09-23 10:33:30 +02:00
mail _fileSelectorWindow : null ,
2013-10-05 18:36:20 +02:00
mail _isMainWindow : true ,
2014-12-16 11:26:44 +01:00
2014-01-18 18:01:29 +01:00
// Some state variables to track preview pre-loading
preview _preload : {
timeout : null ,
request : null
} ,
2014-01-21 11:21:59 +01:00
2013-12-09 12:17:32 +01:00
/ * *
* abbrevations for common access rights
* @ array
*
* /
2014-02-28 16:39:46 +01:00
aclCommonRights : [ 'lrs' , 'lprs' , 'ilprs' , 'ilprsw' , 'aeiklprstwx' , 'custom' ] ,
2013-12-09 12:17:32 +01:00
/ * *
* Demonstrates ACL rights
* @ array
*
* /
aclRights : [ 'l' , 'r' , 's' , 'w' , 'i' , 'p' , 'c' , 'd' , 'a' ] ,
2014-12-16 11:26:44 +01:00
/ * *
* In order to store Intervals assigned to window
* @ array of setted intervals
* /
W _INTERVALS : [ ] ,
2013-12-09 12:17:32 +01:00
2013-04-13 12:30:07 +02:00
/ * *
* Initialize javascript for this application
2013-07-25 17:35:44 +02:00
*
2013-10-09 16:35:03 +02:00
* @ memberOf mail
2013-04-13 12:30:07 +02:00
* /
init : function ( ) {
this . _super . apply ( this , arguments ) ;
2014-11-20 16:05:25 +01:00
if ( ! this . egw . is _popup ( ) )
2014-11-11 12:46:16 +01:00
// Turn on client side, persistent cache
// egw.data system runs encapsulated below etemplate, so this must be
// done before the nextmatch is created.
this . egw . dataCacheRegister ( 'mail' ,
// Called to determine cache key
this . nm _cache ,
// Called whenever cache is used
// TODO: Change this as needed
function ( server _query )
{
// Unlock tree if using a cache, since the server won't
if ( ! server _query ) this . unlock _tree ( ) ;
} ,
this
) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-06-12 13:50:30 +02:00
/ * *
* Destructor
* /
destroy : function ( )
{
2014-01-11 15:16:36 +01:00
// Unbind from nm refresh
2014-02-03 17:41:10 +01:00
if ( this . et2 != null )
2014-01-11 15:16:36 +01:00
{
2014-05-20 12:02:21 +02:00
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
2014-02-03 17:41:10 +01:00
if ( nm != null )
{
$j ( nm ) . off ( 'refresh' ) ;
}
2014-01-11 15:16:36 +01:00
}
2014-08-13 13:45:55 +02:00
2014-07-28 23:21:23 +02:00
// Unregister client side cache
this . egw . dataCacheUnregister ( 'mail' ) ;
2013-10-09 18:44:03 +02:00
delete this . et2 _obj ;
2013-06-12 13:50:30 +02:00
// call parent
this . _super . apply ( this , arguments ) ;
} ,
2013-07-25 17:35:44 +02:00
2014-07-17 16:39:56 +02:00
/ * *
* check and try to reinitialize et2 of module
* /
checkET2 : function ( )
{
//this.et2 should do the same as etemplate2.getByApplication('mail')[0].widgetContainer
if ( ! this . et2 ) // if not defined try this in order to recover
{
try
{
this . et2 = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer ;
}
catch ( e )
{
return false ;
}
}
return true ;
} ,
2013-06-12 13:50:30 +02: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
2014-05-22 16:46:50 +02:00
* @ param { string } _name template name
2013-06-12 13:50:30 +02:00
* /
2014-05-22 16:46:50 +02:00
et2 _ready : function ( et2 , _name )
2013-06-12 13:50:30 +02:00
{
2013-09-02 17:15:35 +02:00
// call parent; somehow this function is called more often. (twice on a display and compose) why?
2013-06-12 13:50:30 +02:00
this . _super . apply ( this , arguments ) ;
2013-08-09 19:47:53 +02:00
this . et2 _obj = et2 ;
2014-01-11 15:16:36 +01:00
2014-05-22 16:46:50 +02:00
switch ( _name )
2013-09-02 17:15:35 +02:00
{
2014-05-22 16:46:50 +02:00
case 'mail.sieve.vacation' :
this . vacationFilterStatusChange ( ) ;
break ;
case 'mail.index' :
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
this . mail _isMainWindow = true ;
this . mail _disablePreviewArea ( true ) ;
// Bind to nextmatch refresh to update folder status
if ( nm != null && ( typeof jQuery . _data ( nm ) . events == 'undefined' || typeof jQuery . _data ( nm ) . events . refresh == 'undefined' ) )
{
var self = this ;
$j ( nm ) . on ( 'refresh' , function ( ) { self . mail _refreshFolderStatus . call ( self , undefined , undefined , false ) ; } ) ;
}
var tree _wdg = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
if ( tree _wdg )
{
tree _wdg . set _onopenstart ( jQuery . proxy ( this . openstart _tree , this ) ) ;
tree _wdg . set _onopenend ( jQuery . proxy ( this . openend _tree , this ) ) ;
}
2015-01-06 16:59:41 +01:00
// Show vacation notice on load for the current profile
this . mail _callRefreshVacationNotice ( ) ;
2014-05-22 16:46:50 +02:00
break ;
case 'mail.display' :
this . mail _isMainWindow = false ;
this . mail _display ( ) ;
2014-11-20 16:05:25 +01:00
2014-07-14 22:50:08 +02:00
// Register attachments for drag
this . register _for _drag (
this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ,
this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' )
) ;
2014-05-22 16:46:50 +02:00
break ;
case 'mail.compose' :
2014-11-21 14:37:30 +01:00
// use a wrapper on a different url to be able to use a different fpm pool
et2 . menuaction = 'mail_compose::ajax_send' ;
2014-06-02 18:57:30 +02:00
var that = this ;
2014-05-22 16:46:50 +02:00
this . mail _isMainWindow = false ;
2014-10-20 14:25:43 +02:00
this . compose _fieldExpander _init ( ) ;
2014-12-02 20:18:37 +01:00
this . check _sharing _filemode ( ) ;
2014-09-23 10:42:31 +02:00
2014-12-12 16:28:53 +01:00
this . subject2title ( ) ;
2014-09-12 14:10:48 +02:00
// Set autosaving interval to 2 minutes for compose message
2014-12-16 11:26:44 +01:00
this . W _INTERVALS . push ( window . setInterval ( function ( ) {
2014-09-12 14:10:48 +02:00
that . saveAsDraft ( null , that . et2 . getWidgetById ( 'button[saveAsDraft]' ) , 'autosaving' ) ;
2014-12-16 11:26:44 +01:00
} , 120000 ) ) ;
2014-09-23 10:42:31 +02:00
2014-06-02 18:57:30 +02:00
/* Control focus actions on subject to handle expanders properly.*/
jQuery ( "#mail-compose_subject" ) . on ( {
focus : function ( ) {
2014-10-20 14:25:43 +02:00
that . compose _fieldExpander _init ( ) ;
2014-06-02 18:57:30 +02:00
that . compose _fieldExpander ( ) ;
}
} ) ;
2014-06-03 18:37:50 +02:00
/*Trigger compose_resizeHandler after the CKEditor is fully loaded*/
2014-09-05 11:50:30 +02:00
jQuery ( '#mail-compose' ) . on ( 'load' , function ( ) {
2014-11-10 13:03:49 +01:00
window . setTimeout ( function ( ) { that . compose _resizeHandler ( ) ; } , 300 ) ;
2014-09-05 11:50:30 +02:00
} ) ;
2014-11-28 17:18:46 +01:00
//Resize compose after window resize to not getting scrollbar
jQuery ( window ) . on ( 'resize' , function ( ) {
that . compose _resizeHandler ( ) ;
} ) ;
2014-12-02 20:18:37 +01:00
2014-06-02 18:57:30 +02:00
this . compose _fieldExpander ( ) ;
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
//Call drag_n_drop initialization for emails on compose
this . init _dndCompose ( ) ;
2014-05-22 16:46:50 +02:00
break ;
2013-10-16 13:22:53 +02:00
}
2013-06-12 13:50:30 +02:00
} ,
2014-05-23 11:21:59 +02:00
/ * *
* Observer method receives update notifications from all applications
*
* App is responsible for only reacting to "messages" it is interested in !
*
* @ 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
2014-05-23 11:21:59 +02:00
* @ return { false | * } false to stop regular refresh , thought all observers are run
* /
2014-05-26 16:01:18 +02:00
observer : function ( _msg , _app , _id , _type , _msg _type , _links )
2014-05-23 11:21:59 +02:00
{
switch ( _app )
{
case 'mail' :
if ( _id === 'sieve' )
{
var iframe = this . et2 . getWidgetById ( 'extra_iframe' ) ;
if ( iframe && iframe . getDOMNode ( ) )
{
var contentWindow = iframe . getDOMNode ( ) . contentWindow ;
if ( contentWindow && contentWindow . app && contentWindow . app . mail )
{
contentWindow . app . mail . sieve _refresh ( ) ;
}
}
return false ; // mail nextmatch needs NOT to be refreshed
}
break ;
2014-05-23 12:11:17 +02:00
case 'emailadmin' : // update tree with given mail account _id and _type
2014-07-18 19:22:28 +02:00
var tree = this . et2 ? this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) : null ;
2014-05-23 12:11:17 +02:00
if ( ! tree ) break ;
var node = tree . getNode ( _id ) ;
switch ( _type )
{
case 'delete' :
if ( node ) // we dont care for deleted accounts not shown (eg. other users)
{
tree . deleteItem ( _id ) ;
// ToDo: blank list, if _id was active account
}
break
case 'update' :
case 'edit' :
if ( node ) // we dont care for updated accounts not shown (eg. other users)
{
2014-05-27 14:05:23 +02:00
//tree.refreshItem(_id);
egw . json ( 'mail.mail_ui.ajax_reloadNode' , [ _id ] )
. sendRequest ( true ) ;
2014-05-23 12:11:17 +02:00
}
break ;
case 'add' :
tree . refreshItem ( 0 ) ; // refresh root
break ;
}
2014-05-23 11:21:59 +02:00
}
} ,
2014-07-28 23:21:23 +02:00
/ * *
* Callback function for dataFetch caching .
*
* We only cache the first chunk ( 50 rows ) , and only if search filter is not set ,
* but we cache this for every combination of folder , filter & filter2 .
*
2014-08-20 18:12:19 +02:00
* We do not cache , if we dont find selectedFolder in query _context ,
* as looking it up in tree causes mails to be cached for wrong folder
* ( Probably because user already clicked on an other folder ) !
*
2014-07-28 23:21:23 +02:00
* @ param { object } query _context Query information from egw . dataFetch ( )
* @ returns { string | false } Cache key , or false to not cache
* /
nm _cache : function ( query _context )
{
// Only cache first chunk of rows, if no search filter
2014-08-20 18:12:19 +02:00
if ( ( ! query _context || ! query _context . start ) && query _context . count == 0 &&
2014-09-08 17:45:37 +02:00
query _context . filters && query _context . filters . selectedFolder &&
! ( ! query _context . filters || query _context . filters . search )
2014-07-28 23:21:23 +02:00
)
{
// Make sure keys match, even if some filters are not defined
2014-08-21 20:28:05 +02:00
// using JSON.stringfy() directly gave a crash in Safari 7.0.4
return this . egw . jsonEncode ( {
2014-09-08 17:45:37 +02:00
selectedFolder : query _context . filters . selectedFolder || '' ,
filter : query _context . filters . filter || '' ,
filter2 : query _context . filters . filter2 || '' ,
sort : query _context . filters . sort
2014-07-28 23:21:23 +02:00
} ) ;
}
return false ;
} ,
2014-05-20 12:02:21 +02:00
/ * *
* mail rebuild Action menu On nm - list
*
* @ param _actions
* /
mail _rebuildActionsOnList : function ( _actions )
{
this . et2 . getWidgetById ( this . nm _index ) . set _actions ( _actions ) ;
} ,
2013-05-21 10:46:54 +02:00
/ * *
* mail _fetchCurrentlyFocussed - implementation to decide wich mail of all the selected ones is the current
2013-07-25 17:35:44 +02:00
*
2013-05-21 10:46:54 +02:00
* @ param _selected array of the selected mails
* @ param _reset bool - tell the function to reset the global vars used
* /
mail _fetchCurrentlyFocussed : function ( _selected , _reset ) {
// reinitialize the buffer-info on selected mails
if ( _reset == true || typeof _selected == 'undefined' )
{
2013-05-21 14:02:58 +02:00
if ( _reset == true )
{
2014-08-06 23:13:27 +02:00
// Request updated data, if possible
if ( this . mail _currentlyFocussed != '' ) egw . dataRefreshUID ( this . mail _currentlyFocussed ) ;
for ( var k = 0 ; k < this . mail _selectedMails . length ; k ++ ) egw . dataRefreshUID ( this . mail _selectedMails [ k ] ) ;
2013-06-04 17:29:53 +02:00
//nm.refresh(this.mail_selectedMails,'delete');
2013-05-21 14:02:58 +02:00
}
2013-05-21 10:46:54 +02:00
this . mail _selectedMails = [ ] ;
this . mail _currentlyFocussed = '' ;
return '' ;
}
for ( var k = 0 ; k < _selected . length ; k ++ )
{
if ( jQuery . inArray ( _selected [ k ] , this . mail _selectedMails ) == - 1 )
{
this . mail _currentlyFocussed = _selected [ k ] ;
break ;
}
}
this . mail _selectedMails = _selected ;
return this . mail _currentlyFocussed ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _open - implementation of the open action
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _senders - the representation of the elements ( s ) the action is to be performed on
2013-07-20 09:23:55 +02:00
* @ param _mode - you may pass the mode . if not given view is used ( tryastext | tryashtml are supported )
2013-04-13 12:30:07 +02:00
* /
2013-07-20 09:23:55 +02:00
mail _open : function ( _action , _senders , _mode ) {
2014-03-07 11:06:04 +01:00
if ( typeof _senders == 'undefined' || _senders . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _senders = [ ] ;
_senders . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _senders == 'undefined' || _senders . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _senders = [ ] ;
_senders . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
var _id = _senders [ 0 ] . id ;
2013-05-21 10:46:54 +02:00
// reinitialize the buffer-info on selected mails
2014-04-17 11:59:08 +02:00
if ( ! ( _mode == 'tryastext' || _mode == 'tryashtml' || _mode == 'view' || _mode == 'print' ) ) _mode = 'view' ;
2013-05-21 10:46:54 +02:00
this . mail _selectedMails = [ ] ;
this . mail _selectedMails . push ( _id ) ;
this . mail _currentlyFocussed = _id ;
2013-04-13 12:30:07 +02:00
var dataElem = egw . dataGetUIDdata ( _id ) ;
var subject = dataElem . data . subject ;
2013-06-05 16:24:56 +02:00
//alert('Open Message:'+_id+' '+subject);
2014-09-09 14:08:08 +02:00
var h = egw ( ) . open ( _id , 'mail' , 'view' , _mode + '=' + _id . replace ( /=/g , "_" ) + '&mode=' + _mode ) ;
2013-07-17 14:01:01 +02:00
egw ( h ) . ready ( function ( ) {
h . document . title = subject ;
} ) ;
2014-02-07 15:34:04 +01:00
// THE FOLLOWING IS PROBABLY NOT NEEDED, AS THE UNEVITABLE PREVIEW IS HANDLING THE COUNTER ISSUE
var messages = { } ;
messages [ 'msg' ] = [ _id ] ;
// When body is requested, mail is marked as read by the mail server. Update UI to match.
if ( typeof dataElem != 'undefined' && typeof dataElem . data != 'undefined' && typeof dataElem . data . flags != 'undefined' && typeof dataElem . data . flags . read != 'undefined' ) dataElem . data . flags . read = 'read' ;
2014-12-11 13:01:52 +01:00
if ( typeof dataElem != 'undefined' && typeof dataElem . data != 'undefined' && typeof dataElem . data [ 'class' ] != 'undefined' && ( dataElem . data [ 'class' ] . indexOf ( 'unseen' ) >= 0 || dataElem . data [ 'class' ] . indexOf ( 'recent' ) >= 0 ) )
2014-02-07 15:34:04 +01:00
{
this . mail _removeRowClass ( messages , 'recent' ) ;
this . mail _removeRowClass ( messages , 'unseen' ) ;
// reduce counter without server roundtrip
this . mail _reduceCounterWithoutServerRoundtrip ( ) ;
// not needed, as an explizit read flags the message as seen anyhow
//egw.jsonq('mail.mail_ui.ajax_flagMessages',['read', messages, false]);
}
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-05-13 16:42:42 +02:00
/ * *
* Open a single message in html mode
2013-07-25 17:35:44 +02:00
*
2013-05-13 16:42:42 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _openAsHtml : function ( _action , _elems )
{
2013-07-20 09:23:55 +02:00
this . mail _open ( _action , _elems , 'tryashtml' ) ;
2013-05-13 16:42:42 +02:00
} ,
/ * *
* Open a single message in plain text mode
2013-07-25 17:35:44 +02:00
*
2013-05-13 16:42:42 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _openAsText : function ( _action , _elems )
{
2013-07-20 09:23:55 +02:00
this . mail _open ( _action , _elems , 'tryastext' ) ;
} ,
/ * *
* Compose , reply or forward a message
2013-07-25 17:35:44 +02:00
*
2013-10-07 12:12:18 +02:00
* @ function
* @ memberOf mail
2013-07-20 09:23:55 +02:00
* @ param _action _action . id is 'compose' , 'composeasnew' , 'reply' , 'reply_all' or 'forward' ( forward can be multiple messages )
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _compose : function ( _action , _elems )
{
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
2013-10-07 12:12:18 +02:00
if ( this . et2 && this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
2013-10-05 11:03:51 +02:00
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-10-04 19:45:33 +02:00
// Extra info passed to egw.open()
var settings = {
// 'Source' Mail UID
id : '' ,
// How to pull data from the Mail IDs for the compose
from : ''
} ;
2013-10-09 18:44:03 +02:00
2013-10-05 11:03:51 +02:00
// We only handle one for everything but forward
settings . id = ( typeof _elems == 'undefined' ? '' : _elems [ 0 ] . id ) ;
2013-10-09 18:44:03 +02:00
2013-10-04 19:45:33 +02:00
switch ( _action . id )
2013-05-13 16:42:42 +02:00
{
2013-10-04 19:45:33 +02:00
case 'compose' :
if ( _elems . length == 1 )
{
2013-10-05 11:03:51 +02:00
//mail_parentRefreshListRowStyle(settings.id,settings.id);
2013-10-04 19:45:33 +02:00
}
else
{
return this . mail _compose ( 'forward' , _elems ) ;
}
break ;
case 'forward' :
case 'forwardinline' :
case 'forwardasattach' :
2013-10-08 16:23:46 +02:00
if ( _elems . length > 1 || _action . id == 'forwardasattach' )
2013-10-04 19:45:33 +02:00
{
2014-01-30 14:37:36 +01:00
settings . from = 'forward' ;
settings . mode = 'forwardasattach' ;
if ( typeof _elems != 'undefined' && _elems . length > 1 )
{
for ( var j = 1 ; j < _elems . length ; j ++ )
settings . id = settings . id + ',' + _elems [ j ] . id ;
}
2013-10-04 19:45:33 +02:00
}
else
{
settings . from = 'forward' ;
settings . mode = 'forwardinline' ;
}
break ;
default :
// No further client side processing needed for these
settings . from = _action . id ;
2013-07-20 09:23:55 +02:00
}
2013-10-07 17:28:49 +02:00
var compose _list = egw . getOpenWindows ( "mail" , /^compose_/ ) ;
var window _name = 'compose_' + compose _list . length + '_' + ( settings . from || '' ) + '_' + settings . id ;
2013-10-07 12:12:18 +02:00
return egw ( ) . open ( '' , 'mail' , 'add' , settings , window _name , 'mail' ) ;
2013-10-04 19:45:33 +02:00
} ,
2013-10-09 18:44:03 +02:00
2013-10-07 12:12:18 +02:00
/ * *
* Set content into a compose window
2013-10-09 18:44:03 +02:00
*
2013-10-07 12:12:18 +02:00
* @ function
* @ memberOf mail
2013-10-09 18:44:03 +02:00
*
2013-10-07 12:12:18 +02:00
* @ param { String } window _name The name of an open content window .
2014-05-16 17:39:05 +02:00
* @ param { object } content
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ description content Data to set into the window ' s fields
* content . to Addresses to add to the to line
* content . cc Addresses to add to the CC line
* content . bcc Addresses to add to the BCC line
2013-10-09 18:44:03 +02:00
*
2013-10-07 12:12:18 +02:00
* @ return { boolean } Success
* /
setCompose : function ( window _name , content )
{
// Get window
var compose = window . open ( '' , window _name ) ;
if ( ! compose || compose . closed ) return false ;
2013-10-09 18:44:03 +02:00
2013-10-07 12:12:18 +02:00
// Get etemplate of popup
var compose _et2 = compose . etemplate2 . getByApplication ( 'mail' ) ;
if ( ! compose _et2 || compose _et2 . length != 1 || ! compose _et2 [ 0 ] . widgetContainer )
{
return false ;
}
2014-05-20 17:39:20 +02:00
2013-10-07 12:12:18 +02:00
// Set each field provided
var success = true ;
2014-05-16 17:39:05 +02:00
var arrContent = [ ] ;
2013-10-07 12:12:18 +02:00
for ( var field in content )
{
try
{
var widget = compose _et2 [ 0 ] . widgetContainer . getWidgetById ( field ) ;
2014-05-20 17:39:20 +02:00
2013-10-07 12:12:18 +02:00
// Merge array values, replace strings
var value = widget . getValue ( ) || content [ field ] ;
if ( jQuery . isArray ( value ) )
{
if ( jQuery . isArray ( content [ field ] ) )
{
value . concat ( content [ field ] ) ;
}
else
{
2014-05-16 17:39:05 +02:00
arrContent = content [ field ] . split ( ',' ) ;
for ( var k = 0 ; k < arrContent . length ; k ++ )
{
value . push ( arrContent [ k ] ) ;
}
2013-10-07 12:12:18 +02:00
}
}
widget . set _value ( value ) ;
}
catch ( e )
{
egw . log ( "error" , "Unable to set field %s to '%s' in window '%s'" , field , content [ field ] , window _name ) ;
success = false ;
continue ;
}
}
2014-05-23 17:17:42 +02:00
if ( content [ 'cc' ] || content [ 'bcc' ] )
{
2014-06-02 18:57:30 +02:00
this . compose _fieldExpander ( ) ;
2014-10-20 14:25:43 +02:00
this . compose _fieldExpander _init ( ) ;
2014-05-23 17:17:42 +02:00
}
2013-10-07 12:12:18 +02:00
return success ;
} ,
2013-08-21 12:47:20 +02:00
2013-05-27 15:48:55 +02:00
/ * *
* mail _disablePreviewArea - implementation of the disablePreviewArea action
2013-07-25 17:35:44 +02:00
*
2013-05-27 15:48:55 +02:00
* @ param _value
* /
mail _disablePreviewArea : function ( _value ) {
2013-10-18 11:58:25 +02:00
var splitter = this . et2 . getWidgetById ( 'mailSplitter' ) ;
2013-06-12 13:50:30 +02:00
if ( typeof splitter == 'undefined' || splitter == null ) return ;
2013-05-29 14:34:33 +02:00
var splitterDN = splitter . getDOMNode ( ) ;
2013-11-21 00:35:27 +01:00
if ( splitter . isDocked ( ) )
{
this . mail _previewAreaActive = false ;
}
2013-10-18 11:58:25 +02:00
//this.et2.getWidgetById('mailPreviewHeadersFrom').set_disabled(_value);
//this.et2.getWidgetById('mailPreviewHeadersTo').set_disabled(_value);
//this.et2.getWidgetById('mailPreviewHeadersDate').set_disabled(_value);
//this.et2.getWidgetById('mailPreviewHeadersSubject').set_disabled(_value);
this . et2 . getWidgetById ( 'mailPreview' ) . set _disabled ( _value ) ;
2014-12-17 13:02:01 +01:00
//Dock the splitter always if we are browsing with mobile
if ( _value == true || egwIsMobile ( ) )
2013-05-27 15:48:55 +02:00
{
2013-05-29 14:34:33 +02:00
if ( this . mail _previewAreaActive ) splitter . dock ( ) ;
this . mail _previewAreaActive = false ;
2013-07-25 17:35:44 +02:00
}
2013-05-27 15:48:55 +02:00
else
{
2013-05-29 14:34:33 +02:00
if ( ! this . mail _previewAreaActive ) splitter . undock ( ) ;
this . mail _previewAreaActive = true ;
2013-05-27 15:48:55 +02:00
}
} ,
2014-02-04 13:51:15 +01:00
/ * *
* Create an expand on click box
*
* @ param { object } _expContent an object with at least these elements
* { build _children , data _one , data , widget , line }
*
* @ param { object } _dataElem includes data of the widget which need to be expand
*
* @ return _dataElem content of widgets
* /
url _email _expandOnClick : function ( _expContent , _dataElem )
{
for ( var j = 0 ; j < _expContent . length ; j ++ )
{
var field = _expContent [ j ] || [ ] ;
var content = _dataElem . data [ field . data ] || [ ] ;
// Add in single address, if there
2014-09-23 10:42:31 +02:00
if ( typeof field . data _one != 'undefined' && field . data != field . data _one )
2014-02-04 13:51:15 +01:00
{
2014-09-23 10:42:31 +02:00
if ( jQuery . isArray ( _dataElem . data [ field . data _one ] ) )
content = content . concat ( _dataElem . data [ field . data _one ] ) ;
else
content . unshift ( _dataElem . data [ field . data _one ] ) ;
2014-02-04 13:51:15 +01:00
// Unique
content = content . filter ( function ( value , index , self ) {
return self . indexOf ( value ) === index ;
} ) ;
}
// Disable whole box if there are none
var line = this . et2 . getWidgetById ( field . line ) ;
if ( line != null ) line . set _disabled ( content . length == 0 ) ;
var widget = this . et2 . getWidgetById ( field . widget ) ;
if ( widget == null ) continue ;
$j ( widget . getDOMNode ( ) ) . removeClass ( 'visible' ) ;
// Programatically build the child elements
if ( field . build _children )
{
// Remove any existing
var children = widget . getChildren ( ) ;
for ( var i = children . length - 1 ; i >= 0 ; i -- )
{
children [ i ] . destroy ( ) ;
widget . removeChild ( children [ i ] ) ;
}
2014-06-26 10:24:16 +02:00
if ( content . length == 1 && typeof content [ 0 ] != 'undefined' && content [ 0 ] )
2014-06-23 18:22:30 +02:00
{
2014-07-02 09:48:24 +02:00
content = content [ 0 ] . split ( ',' ) ;
2014-06-23 18:22:30 +02:00
}
2014-02-04 13:51:15 +01:00
// Add for current record
2014-09-05 14:20:49 +02:00
var remembervalue = '' ;
2014-02-04 13:51:15 +01:00
for ( var i = 0 ; i < content . length ; i ++ )
{
2014-10-06 11:57:50 +02:00
if ( typeof content [ i ] != 'string' || ! content [ i ] ) continue ;
2014-09-05 14:20:49 +02:00
// if there is no @ in string, its most likely that we have a comma in the personal name part of the emailaddress
2014-10-06 11:57:50 +02:00
if ( content [ i ] . indexOf ( '@' ) < 0 )
2014-09-23 10:42:31 +02:00
{
2014-10-06 11:57:50 +02:00
remembervalue = content [ i ] ;
}
else
{
var value = remembervalue + ( remembervalue ? ',' : '' ) + content [ i ] ;
var email = et2 _createWidget ( 'url-email' , { id : widget . id + '_' + i , value : value , readonly : true , contact _plus : true } , widget ) ;
email . loadingFinished ( ) ;
remembervalue = '' ;
2014-09-05 14:20:49 +02:00
}
2014-02-04 13:51:15 +01:00
}
}
else
{
widget . set _value ( { content : content } ) ;
}
// Show or hide button, as needed
line . iterateOver ( function ( button ) {
// Avoid binding to any child buttons
if ( button . getParent ( ) != line ) return ;
button . set _disabled (
// Disable if only 1 address
content . length <= 1 || (
// Disable if all content is visible
$j ( widget . getDOMNode ( ) ) . innerWidth ( ) >= widget . getDOMNode ( ) . scrollWidth &&
$j ( widget . getDOMNode ( ) ) . innerHeight ( ) >= widget . getDOMNode ( ) . scrollHeight )
) ;
} , this , et2 _button ) ;
}
return _dataElem ;
} ,
/ * *
* Set values for mail dispaly From , Sender , To , Cc , and Bcc
* Additionally , apply expand on click feature on thier widgets
2014-02-05 13:23:04 +01:00
*
2014-02-04 13:51:15 +01:00
* /
mail _display : function ( )
{
var dataElem = { data : { FROM : "" , SENDER : "" , TO : "" , CC : "" , BCC : "" } } ;
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var expand _content = [
{ build _children : true , data _one : 'FROM' , data : 'FROM' , widget : 'FROM' , line : 'mailDisplayHeadersFrom' } ,
{ build _children : true , data : 'SENDER' , widget : 'SENDER' , line : 'mailDisplayHeadersSender' } ,
{ build _children : true , data : 'TO' , widget : 'TO' , line : 'mailDisplayHeadersTo' } ,
{ build _children : true , data : 'CC' , widget : 'CC' , line : 'mailDisplayHeadersCc' } ,
{ build _children : true , data : 'BCC' , widget : 'BCC' , line : 'mailDisplayHeadersBcc' }
] ;
if ( typeof content != 'undefiend' )
{
dataElem . data = jQuery . extend ( dataElem . data , content ) ;
this . url _email _expandOnClick ( expand _content , dataElem ) ;
2014-02-05 17:17:37 +01:00
var toolbaractions = ( ( typeof dataElem != 'undefined' && typeof dataElem . data != 'undefined' && typeof dataElem . data . displayToolbaractions != 'undefined' ) ? JSON . parse ( dataElem . data . displayToolbaractions ) : undefined ) ;
if ( toolbaractions ) this . et2 . getWidgetById ( 'displayToolbar' ) . set _actions ( toolbaractions ) ;
2014-02-04 13:51:15 +01:00
}
2014-05-20 17:39:20 +02:00
2014-04-17 11:59:08 +02:00
// Trigger print command if the mail oppend for printing porpuse
if ( window . location . search . search ( '&print=' ) >= 0 )
{
var that = this ;
2014-05-16 17:39:05 +02:00
jQuery ( '#mail-display_mailDisplayBodySrc' ) . bind ( 'load' , function ( ) { that . mail _print ( ) ; } ) ;
2014-04-17 11:59:08 +02:00
}
2014-02-05 13:23:04 +01:00
2014-02-04 13:51:15 +01:00
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _preview - implementation of the preview action
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param nextmatch et2 _nextmatch The widget whose row was selected
* @ param selected Array Selected row IDs . May be empty if user unselected all rows .
* /
2013-10-09 16:35:03 +02:00
mail _preview : function ( selected , nextmatch ) {
2013-04-13 12:30:07 +02:00
// Empty values, just in case selected is empty (user cleared selection)
2013-12-17 09:47:16 +01:00
//dataElem.data is populated, when available with fromaddress(string),toaddress(string),additionaltoaddress(array),ccaddress (array)
2014-03-03 15:56:12 +01:00
var dataElem = { data : { subject : "" , fromaddress : "" , toaddress : "" , ccaddress : "" , date : "" , attachmentsBlock : "" } } ;
2014-09-22 18:25:36 +02:00
var attachmentArea = this . et2 . getWidgetById ( 'previewAttachmentArea' ) ;
2013-06-04 17:29:53 +02:00
if ( typeof selected != 'undefined' && selected . length == 1 )
2013-02-19 17:30:59 +01:00
{
2013-05-21 10:46:54 +02:00
var _id = this . mail _fetchCurrentlyFocussed ( selected ) ;
2013-12-17 01:26:29 +01:00
dataElem = jQuery . extend ( dataElem , egw . dataGetUIDdata ( _id ) ) ;
2013-02-19 17:30:59 +01:00
}
2014-11-20 16:05:25 +01:00
2014-10-31 11:49:22 +01:00
var $preview _iframe = jQuery ( '#mail-index_mailPreviewContainer' ) ;
2014-11-20 16:05:25 +01:00
2014-10-31 11:49:22 +01:00
// Re calculate the position of preview iframe according to its visible sibilings
var set _prev _iframe _top = function ( )
2013-10-05 18:36:20 +02:00
{
2014-10-31 11:49:22 +01:00
// Need to make sure that the iframe is fullyLoad before calculation
window . setTimeout ( function ( ) {
var lastEl = $preview _iframe . prev ( ) . prev ( ) ;
// Top offset of preview iframe calculated from top level
var iframeTop = $preview _iframe . offset ( ) . top ;
while ( lastEl . css ( 'display' ) === "none" )
2014-09-22 18:25:36 +02:00
{
2014-10-31 11:49:22 +01:00
lastEl = lastEl . prev ( ) ;
2014-09-22 18:25:36 +02:00
}
2014-10-31 11:49:22 +01:00
var offset = iframeTop - ( lastEl . offset ( ) . top + lastEl . height ( ) ) || 130 ; // fallback to 130 px if can not calculate new top
2014-11-20 16:05:25 +01:00
2014-10-31 11:49:22 +01:00
// preview iframe parent has position absolute, therefore need to calculate the top via position
$preview _iframe . css ( 'top' , $preview _iframe . position ( ) . top - offset + 10 ) ;
} , 50 ) ;
2014-11-20 16:05:25 +01:00
} ;
2014-10-31 11:49:22 +01:00
if ( attachmentArea && typeof _id != 'undefined' && _id != '' && typeof dataElem !== 'undefined' )
{
// If there is content to show recalculate the size
set _prev _iframe _top ( ) ;
2013-10-05 18:36:20 +02:00
}
else
{
2014-02-10 20:52:23 +01:00
// Leave if we're here and there is nothing selected, too many, or no data
this . et2 . getWidgetById ( 'previewAttachmentArea' ) . set _value ( { content : [ ] } ) ;
this . et2 . getWidgetById ( 'previewAttachmentArea' ) . set _class ( 'previewAttachmentArea noContent mail_DisplayNone' ) ;
var IframeHandle = this . et2 . getWidgetById ( 'messageIFRAME' ) ;
IframeHandle . set _src ( 'about:blank' ) ;
this . mail _disablePreviewArea ( true ) ;
2013-10-05 18:36:20 +02:00
return ;
}
2014-09-23 10:42:31 +02:00
2013-12-17 01:26:29 +01:00
// Widget ID:data key map of widgets we can directly set from cached data
var data _widgets = {
'previewFromAddress' : 'fromaddress' ,
'previewDate' : 'date' ,
'previewSubject' : 'subject'
} ;
// Set widget values from cached data
for ( var id in data _widgets )
{
var widget = this . et2 . getWidgetById ( id ) ;
if ( widget == null ) continue ;
widget . set _value ( dataElem . data [ data _widgets [ id ] ] || "" ) ;
}
2014-01-18 18:01:29 +01:00
// Blank first, so we don't show previous email while loading
var IframeHandle = this . et2 . getWidgetById ( 'messageIFRAME' ) ;
IframeHandle . set _src ( 'about:blank' ) ;
2013-12-23 23:37:40 +01:00
// Set up additional content that can be expanded.
// We add a new URL widget for each address, so they get all the UI
2013-12-18 19:40:01 +01:00
// TO addresses have the first one split out, not all together
2013-12-17 01:26:29 +01:00
// list of keys:
2013-12-23 23:37:40 +01:00
var expand _content = [
{ build _children : true , data _one : 'toaddress' , data : 'additionaltoaddress' , widget : 'additionalToAddress' , line : 'mailPreviewHeadersTo' } ,
{ build _children : true , data : 'ccaddress' , widget : 'additionalCCAddress' , line : 'mailPreviewHeadersCC' } ,
{ build _children : false , data : 'attachmentsBlock' , widget : 'previewAttachmentArea' , line : 'mailPreviewHeadersAttachments' }
2013-12-17 01:26:29 +01:00
] ;
2014-01-13 15:22:58 +01:00
2014-02-04 13:51:15 +01:00
dataElem = this . url _email _expandOnClick ( expand _content , dataElem ) ;
2014-02-05 13:23:04 +01:00
2014-01-13 15:22:58 +01:00
// Update the internal list of selected mails, if needed
if ( this . mail _selectedMails . indexOf ( _id ) < 0 )
{
this . mail _selectedMails . push ( _id ) ;
}
2013-05-27 15:48:55 +02:00
this . mail _disablePreviewArea ( false ) ;
2014-01-18 18:01:29 +01:00
// Request email body from server
2013-04-13 12:30:07 +02:00
IframeHandle . set _src ( egw . link ( '/index.php' , { menuaction : 'mail.mail_ui.loadEmailBody' , _messageID : _id } ) ) ;
2014-01-18 18:01:29 +01:00
2013-06-05 12:41:38 +02:00
var messages = { } ;
messages [ 'msg' ] = [ _id ] ;
2014-01-13 15:22:58 +01:00
// When body is requested, mail is marked as read by the mail server. Update UI to match.
2014-01-16 13:07:45 +01:00
if ( typeof dataElem != 'undefined' && typeof dataElem . data != 'undefined' && typeof dataElem . data . flags != 'undefined' && typeof dataElem . data . flags . read != 'undefined' ) dataElem . data . flags . read = 'read' ;
2014-12-11 13:01:52 +01:00
if ( typeof dataElem != 'undefined' && typeof dataElem . data != 'undefined' && typeof dataElem . data [ 'class' ] != 'undefined' && ( dataElem . data [ 'class' ] . indexOf ( 'unseen' ) >= 0 || dataElem . data [ 'class' ] . indexOf ( 'recent' ) >= 0 ) )
2014-02-07 15:34:04 +01:00
{
this . mail _removeRowClass ( messages , 'recent' ) ;
this . mail _removeRowClass ( messages , 'unseen' ) ;
// reduce counter without server roundtrip
this . mail _reduceCounterWithoutServerRoundtrip ( ) ;
2014-03-26 10:09:30 +01:00
if ( typeof dataElem . data . dispositionnotificationto != 'undefined' && dataElem . data . dispositionnotificationto &&
typeof dataElem . data . flags . mdnsent == 'undefined' && typeof dataElem . data . flags . mdnnotsent == 'undefined' )
2014-03-25 17:20:28 +01:00
{
var buttons = [
{ text : this . egw . lang ( "Yes" ) , id : "mdnsent" } ,
{ text : this . egw . lang ( "No" ) , id : "mdnnotsent" }
] ;
et2 _dialog . show _dialog ( function ( _button _id , _value ) {
switch ( _button _id )
{
case "mdnsent" :
egw . jsonq ( 'mail.mail_ui.ajax_sendMDN' , [ messages ] ) ;
egw . jsonq ( 'mail.mail_ui.ajax_flagMessages' , [ 'mdnsent' , messages , true ] ) ;
return ;
case "mdnnotsent" :
egw . jsonq ( 'mail.mail_ui.ajax_flagMessages' , [ 'mdnnotsent' , messages , true ] ) ;
}
} ,
this . egw . lang ( "The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?" ) ,
this . egw . lang ( "Confirm" ) ,
messages , buttons ) ;
}
2014-02-07 15:34:04 +01:00
egw . jsonq ( 'mail.mail_ui.ajax_flagMessages' , [ 'read' , messages , false ] ) ;
}
2014-01-18 18:01:29 +01:00
// Pre-load next email already so user gets it faster
// Browser will cache the file for us
2014-01-20 16:25:40 +01:00
/ *
2014-05-20 12:02:21 +02:00
var fO = egw _getObjectManager ( 'mail' , false , 1 ) . getObjectById ( this . nm _index ) . getFocusedObject ( ) ;
2014-01-20 12:53:19 +01:00
var next = false ;
if ( fO ) next = fO . getNext ( 1 ) ;
2014-01-20 09:19:22 +01:00
// Stop until we get all the details worked out - server marks as seen automatically
if ( false && next && next . id )
2014-01-18 18:01:29 +01:00
{
if ( this . preview _preload . timer != null )
{
window . clearTimeout ( this . preview _preload . timer ) ;
}
// Wait 0.5s to avoid flooding server if user is scrolling through their mail
this . preview _preload . timer = window . setTimeout ( jQuery . proxy ( function ( ) {
this . preview _preload . request = jQuery . get (
egw . link ( '/index.php' , { menuaction : 'mail.mail_ui.loadEmailBody' , _messageID : next . id } )
) ;
} , this ) , 500 ) ;
}
2014-01-20 16:25:40 +01:00
* /
2013-04-13 12:30:07 +02:00
} ,
2013-05-27 15:48:55 +02:00
2013-12-03 15:38:50 +01:00
/ * *
2013-12-23 23:37:40 +01:00
* If a preview header is partially hidden , this is the handler for clicking the
* expand button that shows all the content for that header .
* The button must be directly after the widget to be expanded in the template .
* The widget to be expended is set in the event data .
*
2013-12-03 15:38:50 +01:00
* requires : mainWindow , one mail selected for preview
2014-02-12 21:12:59 +01:00
*
2014-02-11 11:45:01 +01:00
* @ param { jQuery event } event
* @ param { Object } widget
2013-12-23 23:37:40 +01:00
* @ param { DOMNode } button
2013-12-03 15:38:50 +01:00
* /
2014-02-11 11:45:01 +01:00
showAllHeader : function ( event , widget , button ) {
2013-12-18 01:37:30 +01:00
// Show list as a list
var list = jQuery ( button ) . prev ( ) ;
2014-02-11 11:45:01 +01:00
/ * i f ( l i s t . l e n g t h < = 0 )
{
list = jQuery ( button . target ) . prev ( ) ;
} * /
2014-02-12 21:12:59 +01:00
2013-12-18 01:37:30 +01:00
list . toggleClass ( 'visible' ) ;
// Revert if user clicks elsewhere
$j ( 'body' ) . one ( 'click' , list , function ( ev ) {
ev . data . removeClass ( 'visible' ) ;
2013-12-03 17:46:32 +01:00
} ) ;
2013-12-03 15:38:50 +01:00
} ,
2013-04-13 12:30:07 +02:00
mail _setMailBody : function ( content ) {
2013-10-18 11:58:25 +02:00
var IframeHandle = this . et2 . getWidgetById ( 'messageIFRAME' ) ;
2013-04-13 12:30:07 +02:00
IframeHandle . set _value ( '' ) ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _refreshFolderStatus , function to call to read the counters of a folder and apply them
2013-07-25 17:35:44 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { stirng } _nodeID
* @ param { string } mode
* @ param { boolean } _refreshGridArea
* @ param { boolean } _refreshQuotaDisplay
2014-05-20 17:39:20 +02:00
*
2013-04-13 12:30:07 +02:00
* /
2014-01-21 12:28:43 +01:00
mail _refreshFolderStatus : function ( _nodeID , mode , _refreshGridArea , _refreshQuotaDisplay ) {
2014-01-09 09:36:22 +01:00
if ( typeof _nodeID != 'undefined' && typeof _nodeID [ _nodeID ] != 'undefined' && _nodeID [ _nodeID ] )
{
_refreshGridArea = _nodeID [ _refreshGridArea ] ;
mode = _nodeID [ mode ] ;
_nodeID = _nodeID [ _nodeID ] ;
}
2013-04-13 12:30:07 +02:00
var nodeToRefresh = 0 ;
var mode2use = "none" ;
2013-11-19 16:14:36 +01:00
if ( typeof _refreshGridArea == 'undefined' ) _refreshGridArea = true ;
2014-01-21 12:28:43 +01:00
if ( typeof _refreshQuotaDisplay == 'undefined' ) _refreshQuotaDisplay = true ;
2013-04-13 12:30:07 +02:00
if ( _nodeID ) nodeToRefresh = _nodeID ;
if ( mode ) {
if ( mode == "forced" ) { mode2use = mode ; }
}
try
{
2013-10-18 11:58:25 +02:00
var tree _wdg = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
var activeFolders = tree _wdg . getTreeNodeOpenItems ( nodeToRefresh , mode2use ) ;
//alert(activeFolders.join('#,#'));
2014-01-27 13:18:16 +01:00
this . mail _queueRefreshFolderList ( ( mode == 'thisfolderonly' && nodeToRefresh ? [ _nodeID ] : activeFolders ) ) ;
2013-11-19 16:14:36 +01:00
if ( _refreshGridArea )
{
// maybe to use the mode forced as trigger for grid reload and using the grids own autorefresh
// would solve the refresh issue more accurately
//if (mode == "forced") this.mail_refreshMessageGrid();
this . mail _refreshMessageGrid ( ) ;
}
2014-01-21 12:28:43 +01:00
if ( _refreshQuotaDisplay )
{
this . mail _refreshQuotaDisplay ( ) ;
}
2013-12-09 10:57:03 +01:00
//the two lines below are not working yet.
//var no =tree_wdg.getSelectedNode();
//tree_wdg.focusItem(no.id);
2013-04-13 12:30:07 +02:00
} catch ( e ) { } // ignore the error; maybe the template is not loaded yet
} ,
2013-07-25 17:35:44 +02:00
2013-10-18 11:58:25 +02:00
/ * *
* mail _refreshQuotaDisplay , function to call to read the quota for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _server
2013-10-18 11:58:25 +02:00
*
* /
mail _refreshQuotaDisplay : function ( _server )
{
egw . json ( 'mail.mail_ui.ajax_refreshQuotaDisplay' , [ _server ] )
. sendRequest ( true ) ;
} ,
/ * *
* mail _setQuotaDisplay , function to call to read the quota for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _data
2013-10-18 11:58:25 +02:00
*
* /
mail _setQuotaDisplay : function ( _data )
{
2014-07-17 16:39:56 +02:00
if ( ! this . et2 && ! this . checkET2 ( ) ) return ;
2014-04-15 13:57:15 +02:00
2013-10-18 11:58:25 +02:00
var quotabox = this . et2 . getWidgetById ( this . nm _index + '[quotainpercent]' ) ;
2014-05-20 17:39:20 +02:00
2014-04-02 22:20:49 +02:00
// Check to make sure it's there
if ( quotabox )
{
//try to set it via set_value and set label
quotabox . set _class ( _data . data . quotaclass ) ;
quotabox . set _value ( _data . data . quotainpercent ) ;
quotabox . set _label ( _data . data . quota ) ;
}
2013-10-18 11:58:25 +02:00
} ,
2013-07-25 17:35:44 +02:00
2014-04-03 14:20:23 +02:00
/ * *
* mail _callRefreshVacationNotice , function to call the serverside function to refresh the vacationnotice for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _server
2014-04-03 14:20:23 +02:00
*
* /
mail _callRefreshVacationNotice : function ( _server )
{
2014-08-11 14:44:33 +02:00
egw . jsonq ( 'mail_ui::ajax_refreshVacationNotice' , [ _server ] ) ;
2014-04-03 14:20:23 +02:00
} ,
2014-07-14 22:50:08 +02:00
/ * *
* Make sure attachments have all needed data , so they can be found for
* HTML5 native dragging
*
* @ param { string } mail _id Mail UID
* @ param { array } attachments Attachment information .
* /
register _for _drag : function ( mail _id , attachments )
{
// Put required info in global store
var data = { } ;
2014-07-16 13:10:25 +02:00
if ( ! attachments ) return ;
2014-07-14 22:50:08 +02:00
for ( var i = 0 ; i < attachments . length ; i ++ )
{
var data = attachments [ i ] || { } ;
if ( ! data . filename || ! data . type ) continue ;
// Add required info
data . mime = data . type ;
data . download _url = egw . link ( '/index.php' , {
menuaction : 'mail.mail_ui.getAttachment' ,
id : mail _id ,
part : data . partID ,
is _winmail : data . winmailFlag
} ) ;
data . name = data . filename ;
}
} ,
/ * *
* Display helper for dragging attachments
*
* @ param { egwAction } _action
* @ param { egwActionElement [ ] } _elems
* @ returns { DOMNode }
* /
drag _attachment : function ( _action , _elems )
{
var div = $j ( document . createElement ( "div" ) )
. css ( {
position : 'absolute' ,
top : '0px' ,
left : '0px' ,
width : '300px'
} ) ;
var data = _elems [ 0 ] . data || { } ;
2014-07-15 11:37:08 +02:00
2014-07-14 22:50:08 +02:00
var text = $j ( document . createElement ( 'div' ) ) . css ( { left : '30px' , position : 'absolute' } ) ;
// add filename or number of files for multiple files
text . text ( _elems . length > 1 ? _elems . length + ' ' + this . egw . lang ( 'files' ) : data . name || '' ) ;
div . append ( text ) ;
// Add notice of Ctrl key, if supported
if ( window . FileReader && 'draggable' in document . createElement ( 'span' ) &&
navigator && navigator . userAgent . indexOf ( 'Chrome' ) >= 0 )
{
var key = [ "Mac68K" , "MacPPC" , "MacIntel" ] . indexOf ( window . navigator . platform ) < 0 ? 'Ctrl' : 'Command' ;
text . append ( '<br />' + this . egw . lang ( 'Hold %1 to drag files to your computer' , key ) ) ;
}
return div ;
} ,
2014-04-03 14:20:23 +02:00
/ * *
* mail _refreshVacationNotice , function to call with appropriate data to refresh the vacationnotice for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _data
2014-04-03 14:20:23 +02:00
*
* /
mail _refreshVacationNotice : function ( _data )
{
2014-07-17 16:39:56 +02:00
if ( ! this . et2 && ! this . checkET2 ( ) ) return ;
2014-04-03 14:20:23 +02:00
if ( _data == null )
{
this . et2 . getWidgetById ( this . nm _index + '[vacationnotice]' ) . set _value ( '' ) ;
this . et2 . getWidgetById ( this . nm _index + '[vacationrange]' ) . set _value ( '' ) ;
}
else
{
this . et2 . getWidgetById ( this . nm _index + '[vacationnotice]' ) . set _value ( _data . vacationnotice ) ;
this . et2 . getWidgetById ( this . nm _index + '[vacationrange]' ) . set _value ( _data . vacationrange ) ;
}
} ,
2014-04-11 15:52:58 +02:00
/ * *
* mail _refreshFilter2Options , function to call with appropriate data to refresh the filter2 options for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _data
2014-04-11 15:52:58 +02:00
*
* /
mail _refreshFilter2Options : function ( _data )
{
//alert('mail_refreshFilter2Options');
if ( _data == null ) return ;
2014-07-17 16:39:56 +02:00
if ( ! this . et2 && ! this . checkET2 ( ) ) return ;
2014-04-11 15:52:58 +02:00
var filter2 = this . et2 . getWidgetById ( 'filter2' ) ;
var current = filter2 . value ;
var currentexists = false ;
for ( var k in _data )
{
if ( k == current ) currentexists = true ;
}
if ( ! currentexists ) filter2 . set _value ( 'subject' ) ;
filter2 . set _select _options ( _data ) ;
} ,
/ * *
* mail _refreshFilterOptions , function to call with appropriate data to refresh the filter options for the active server
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _data
2014-04-11 15:52:58 +02:00
*
* /
mail _refreshFilterOptions : function ( _data )
{
//alert('mail_refreshFilterOptions');
if ( _data == null ) return ;
2014-07-17 16:39:56 +02:00
if ( ! this . et2 && ! this . checkET2 ( ) ) return ;
2014-04-11 15:52:58 +02:00
var filter = this . et2 . getWidgetById ( 'filter' ) ;
var current = filter . value ;
var currentexists = false ;
for ( var k in _data )
{
if ( k == current ) currentexists = true ;
}
if ( ! currentexists ) filter . set _value ( 'any' ) ;
filter . set _select _options ( _data ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
2014-01-27 13:18:16 +01:00
* Queues a refreshFolderList request for 10 ms . Actually this will just execute the
2013-04-13 12:30:07 +02:00
* code after the calling script has finished .
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { array } _folders description
2013-04-13 12:30:07 +02:00
* /
mail _queueRefreshFolderList : function ( _folders )
2013-02-13 15:02:02 +01:00
{
2014-08-07 17:56:25 +02:00
var self = this ;
2014-01-27 13:18:16 +01:00
// as jsonq is too fast wrap it to be delayed a bit, to ensure the folder actions
// are executed last of the queue
2013-04-13 12:30:07 +02:00
window . setTimeout ( function ( ) {
2014-08-15 13:22:43 +02:00
egw . jsonq ( 'mail.mail_ui.ajax_setFolderStatus' , [ _folders ] , function ( ) { self . unlock _tree ( ) ; } ) ;
2014-01-27 13:18:16 +01:00
} , 100 ) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2014-02-11 16:20:44 +01:00
/ * *
* mail _CheckFolderNoSelect - implementation of the mail _CheckFolderNoSelect action to control right click options on the tree
*
2014-05-16 17:39:05 +02:00
* @ param { object } action
* @ param { object } _senders the representation of the tree leaf to be manipulated
* @ param { object } _currentNode
2014-02-11 16:20:44 +01:00
* /
mail _CheckFolderNoSelect : function ( action , _senders , _currentNode ) {
2014-05-20 17:39:20 +02:00
2014-02-11 16:20:44 +01:00
// Abort if user selected an un-selectable node
// Use image over anything else because...?
2014-02-12 14:10:04 +01:00
var ftree , node ;
ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
if ( ftree )
{
node = ftree . getNode ( _senders [ 0 ] . id ) ;
}
2014-02-11 17:01:31 +01:00
2014-02-12 14:10:04 +01:00
if ( node && node . im0 . indexOf ( 'NoSelect' ) !== - 1 )
2014-02-11 16:20:44 +01:00
{
//ftree.reSelectItem(_previous);
return false ;
}
2014-02-11 17:01:31 +01:00
2014-02-11 16:20:44 +01:00
return true ;
} ,
2014-05-22 09:36:02 +02:00
/ * *
* Check if Sieve is enabled on that account
*
* Sieve enabled is stored as data { acl : true / false } on account node .
*
* @ param { object } _action
* @ param { object } _senders the representation of the tree leaf to be manipulated
* @ param { object } _currentNode
* /
sieve _enabled : function ( _action , _senders , _currentNode )
{
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
var acc _id = _senders [ 0 ] . id . split ( '::' ) [ 0 ] ;
var node = ftree ? ftree . getNode ( acc _id ) : null ;
return node && node . data && node . data . sieve ;
} ,
/ * *
* Check if ACL is enabled on that account
*
* ACL enabled is stored as data { acl : true / false } on INBOX node .
* We also need to check if folder is marked as no - select !
*
* @ param { object } _action
* @ param { object } _senders the representation of the tree leaf to be manipulated
* @ param { object } _currentNode
* /
acl _enabled : function ( _action , _senders , _currentNode )
{
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
var inbox = _senders [ 0 ] . id . split ( '::' ) [ 0 ] + '::INBOX' ;
var node = ftree ? ftree . getNode ( inbox ) : null ;
return node && node . data . acl && this . mail _CheckFolderNoSelect ( _action , _senders , _currentNode ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _setFolderStatus , function to set the status for the visible folders
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { array } _status
2013-04-13 12:30:07 +02:00
* /
mail _setFolderStatus : function ( _status ) {
2014-07-17 16:39:56 +02:00
if ( ! this . et2 && ! this . checkET2 ( ) ) return ;
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2013-11-27 14:07:54 +01:00
for ( var i in _status ) {
ftree . setLabel ( i , _status [ i ] ) ;
2014-02-05 13:23:04 +01:00
// display folder-name bold for unseen mails
ftree . setStyle ( i , 'font-weight: ' + ( _status [ i ] . match ( this . _unseen _regexp ) ? 'bold' : 'normal' ) ) ;
2013-11-27 14:07:54 +01:00
//alert(i +'->'+_status[i]);
}
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-29 16:56:33 +02:00
/ * *
* mail _setLeaf , function to set the id and description for the folder given by status key
2014-05-16 17:39:05 +02:00
* @ param { array } _status status array with the required data ( new id , desc , old desc )
2013-05-07 10:26:17 +02:00
* key is the original id of the leaf to change
* multiple sets can be passed to mail _setLeaf
2013-04-29 16:56:33 +02:00
* /
mail _setLeaf : function ( _status ) {
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2013-05-07 10:26:17 +02:00
var selectedNode = ftree . getSelectedNode ( ) ;
2013-04-29 16:56:33 +02:00
for ( var i in _status )
{
2013-05-10 09:24:27 +02:00
// if olddesc is undefined or #skip# then skip the message, as we process subfolders
2014-05-27 15:31:37 +02:00
if ( typeof _status [ i ] [ 'olddesc' ] !== 'undefined' && _status [ i ] [ 'olddesc' ] !== '#skip-user-interaction-message#' ) this . egw . message ( this . egw . lang ( "Renamed Folder %1 to %2" , _status [ i ] [ 'olddesc' ] , _status [ i ] [ 'desc' ] ) ) ;
2013-04-29 16:56:33 +02:00
ftree . renameItem ( i , _status [ i ] [ 'id' ] , _status [ i ] [ 'desc' ] ) ;
2014-02-06 13:48:01 +01:00
ftree . setStyle ( i , 'font-weight: ' + ( _status [ i ] [ 'desc' ] . match ( this . _unseen _regexp ) ? 'bold' : 'normal' ) ) ;
2013-04-29 16:56:33 +02:00
//alert(i +'->'+_status[i]['id']+'+'+_status[i]['desc']);
2013-05-07 10:26:17 +02:00
if ( _status [ i ] [ 'id' ] == selectedNode . id )
{
2013-10-18 11:58:25 +02:00
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
2013-05-07 10:26:17 +02:00
nm . activeFilters [ "selectedFolder" ] = _status [ i ] [ 'id' ] ;
nm . applyFilters ( ) ;
}
2013-04-29 16:56:33 +02:00
}
} ,
2013-05-13 16:42:42 +02:00
/ * *
* mail _removeLeaf , function to remove the leaf represented by the given ID
2014-05-16 17:39:05 +02:00
* @ param { array } _status status array with the required data ( KEY id , VALUE desc )
2013-05-13 16:42:42 +02:00
* key is the id of the leaf to delete
* multiple sets can be passed to mail _deleteLeaf
* /
2013-05-21 10:46:54 +02:00
mail _removeLeaf : function ( _status ) {
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2013-05-13 16:42:42 +02:00
var selectedNode = ftree . getSelectedNode ( ) ;
for ( var i in _status )
{
// if olddesc is undefined or #skip# then skip the message, as we process subfolders
2014-05-27 15:31:37 +02:00
if ( typeof _status [ i ] !== 'undefined' && _status [ i ] !== '#skip-user-interaction-message#' ) this . egw . message ( this . egw . lang ( "Removed Folder %1 " , _status [ i ] ) ) ;
2013-05-13 16:42:42 +02:00
ftree . deleteItem ( i , ( selectedNode . id == i ) ) ;
var selectedNodeAfter = ftree . getSelectedNode ( ) ;
//alert(i +'->'+_status[i]['id']+'+'+_status[i]['desc']);
if ( selectedNodeAfter . id != selectedNode . id && selectedNode . id == i )
{
2013-10-18 11:58:25 +02:00
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
2013-05-13 16:42:42 +02:00
nm . activeFilters [ "selectedFolder" ] = selectedNodeAfter . id ;
nm . applyFilters ( ) ;
}
}
} ,
2013-05-21 10:46:54 +02:00
/ * *
* mail _reloadNode , function to reload the leaf represented by the given ID
2014-01-11 12:58:31 +01:00
* @ param { Object . < string , string > | Object . < string , Object } } _status
* Object with the required data ( KEY id , VALUE desc ) , or ID => { new data }
2013-05-21 10:46:54 +02:00
* /
mail _reloadNode : function ( _status ) {
2014-07-18 19:22:28 +02:00
var ftree = this . et2 ? this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) : null ;
if ( ! ftree ) return ;
2013-05-21 10:46:54 +02:00
var selectedNode = ftree . getSelectedNode ( ) ;
for ( var i in _status )
{
// if olddesc is undefined or #skip# then skip the message, as we process subfolders
2014-01-11 12:58:31 +01:00
if ( typeof _status [ i ] !== 'undefined' && _status [ i ] !== '#skip-user-interaction-message#' )
2013-05-21 10:46:54 +02:00
{
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( "Reloaded Folder %1 " , typeof _status [ i ] == "string" ? _status [ i ] . replace ( this . _unseen _regexp , '' ) : _status [ i ] . text . replace ( this . _unseen _regexp , '' ) ) ) ;
2013-05-21 10:46:54 +02:00
}
2014-01-11 12:58:31 +01:00
ftree . refreshItem ( i , typeof _status [ i ] == "object" ? _status [ i ] : null ) ;
2014-02-06 13:48:01 +01:00
if ( typeof _status [ i ] == "string" ) ftree . setStyle ( i , 'font-weight: ' + ( _status [ i ] . match ( this . _unseen _regexp ) ? 'bold' : 'normal' ) ) ;
2014-01-11 12:58:31 +01:00
}
var selectedNodeAfter = ftree . getSelectedNode ( ) ;
// If selected folder changed, refresh nextmatch
if ( selectedNodeAfter != null && selectedNodeAfter . id != selectedNode . id )
{
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
nm . activeFilters [ "selectedFolder" ] = selectedNodeAfter . id ;
nm . applyFilters ( ) ;
2013-05-21 10:46:54 +02:00
}
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _refreshMessageGrid , function to call to reread ofthe current folder
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { boolean } _isPopup
2013-04-13 12:30:07 +02:00
* /
2013-10-05 11:03:51 +02:00
mail _refreshMessageGrid : function ( _isPopup ) {
if ( typeof _isPopup == 'undefined' ) _isPopup = false ;
var nm ;
2013-10-14 15:30:04 +02:00
if ( _isPopup && ! this . mail _isMainWindow )
2013-10-05 11:03:51 +02:00
{
nm = window . opener . etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( this . nm _index ) ;
}
else
{
2013-10-18 11:58:25 +02:00
nm = this . et2 . getWidgetById ( this . nm _index ) ;
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
nm . applyFilters ( ) ; // this should refresh the active folder
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _getMsg - gets the current Message
* @ return string
* /
mail _getMsg : function ( )
2013-02-13 15:02:02 +01:00
{
2013-10-18 11:58:25 +02:00
var msg _wdg = this . et2 . getWidgetById ( 'msg' ) ;
2013-04-13 12:30:07 +02:00
if ( msg _wdg )
{
return msg _wdg . valueOf ( ) . htmlNode [ 0 ] . innerHTML ;
}
return "" ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _setMsg - sets a Message , with the msg container , and controls if the container is enabled / disabled
2014-05-16 17:39:05 +02:00
* @ param { string } myMsg - the message
2013-04-13 12:30:07 +02:00
* /
mail _setMsg : function ( myMsg )
2013-02-13 15:02:02 +01:00
{
2013-10-18 11:58:25 +02:00
var msg _wdg = this . et2 . getWidgetById ( 'msg' ) ;
2013-04-13 12:30:07 +02:00
if ( msg _wdg )
{
msg _wdg . set _value ( myMsg ) ;
msg _wdg . set _disabled ( myMsg . trim ( ) . length == 0 ) ;
2013-02-28 10:28:08 +01:00
}
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* Delete mails
* takes in all arguments
* @ param _action
* @ param _elems
* /
mail _delete : function ( _action , _elems )
2014-06-26 17:05:04 +02:00
{
this . mail _checkAllSelected ( _action , _elems , null , true ) ;
} ,
/ * *
* call Delete mails
* takes in all arguments
2014-07-03 16:03:59 +02:00
* @ param { object } _action
* @ param { array } _elems
* @ param { boolean } _allMessagesChecked
2014-06-26 17:05:04 +02:00
* /
mail _callDelete : function ( _action , _elems , _allMessagesChecked )
2013-02-13 15:02:02 +01:00
{
2013-10-05 18:36:20 +02:00
var calledFromPopup = false ;
2014-06-26 17:05:04 +02:00
if ( typeof _allMessagesChecked == 'undefined' ) _allMessagesChecked = false ;
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 18:36:20 +02:00
{
calledFromPopup = true ;
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 18:36:20 +02:00
}
2013-04-13 12:30:07 +02:00
var msg = this . mail _getFormData ( _elems ) ;
2014-07-01 17:22:18 +02:00
msg [ 'all' ] = _allMessagesChecked ;
2014-06-26 17:05:04 +02:00
if ( msg [ 'all' ] == 'cancel' ) return false ;
2014-06-20 14:05:03 +02:00
if ( msg [ 'all' ] ) msg [ 'activeFilters' ] = this . mail _getActiveFilters ( _action ) ;
2013-04-13 12:30:07 +02:00
//alert(_action.id+','+ msg);
2013-10-05 18:36:20 +02:00
if ( ! calledFromPopup ) this . mail _setRowClass ( _elems , 'deleted' ) ;
this . mail _deleteMessages ( msg , 'no' , calledFromPopup ) ;
2014-12-12 15:21:04 +01:00
if ( calledFromPopup && this . mail _isMainWindow == false ) egw ( window ) . close ( ) ;
2013-05-27 15:48:55 +02:00
} ,
2014-02-07 15:34:04 +01:00
/ * *
* function to find ( and reduce ) unseen count from folder - name
* /
mail _reduceCounterWithoutServerRoundtrip : function ( )
{
2014-03-03 14:10:27 +01:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-02-07 15:34:04 +01:00
var _foldernode = ftree . getSelectedNode ( ) ;
var counter = _foldernode . label . match ( this . _unseen _regexp ) ;
2014-02-11 13:18:03 +01:00
var icounter = 0 ;
if ( counter ) icounter = parseInt ( counter [ 0 ] . replace ( ' (' , '' ) . replace ( ')' , '' ) ) ;
2014-02-07 15:34:04 +01:00
if ( icounter > 0 )
{
var newcounter = icounter - 1 ;
if ( newcounter > 0 ) _foldernode . label = _foldernode . label . replace ( ' (' + String ( icounter ) + ')' , ' (' + String ( newcounter ) + ')' ) ;
if ( newcounter == 0 ) _foldernode . label = _foldernode . label . replace ( ' (' + String ( icounter ) + ')' , '' ) ;
ftree . setLabel ( _foldernode . id , _foldernode . label ) ;
}
} ,
2014-02-05 13:23:04 +01:00
/ * *
* Regular expression to find ( and remove ) unseen count from folder - name
* /
2014-02-06 13:48:01 +01:00
_unseen _regexp : / \([0-9]+\)$/ ,
2014-02-05 13:23:04 +01:00
2014-02-12 11:56:44 +01:00
/ * *
* mail _splitRowId
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { string } _rowID
2014-05-20 17:39:20 +02:00
*
2014-02-12 11:56:44 +01:00
* /
mail _splitRowId : function ( _rowID )
{
2014-03-03 14:10:27 +01:00
var res = _rowID . split ( '::' ) ;
2014-02-12 11:56:44 +01:00
// as a rowID is perceeded by app::, should be mail!
if ( res . length == 4 && parseInt ( res [ 0 ] ) != NaN )
{
// we have an own created rowID; prepend app=mail
res . unshift ( 'mail' ) ;
}
return res ;
} ,
2013-05-27 15:48:55 +02:00
/ * *
* Delete mails - actually calls the backend function for deletion
* takes in all arguments
2014-05-16 17:39:05 +02:00
* @ param { string } _msg - message list
* @ param { object } _action - optional action
* @ param { object } _calledFromPopup
2013-05-27 15:48:55 +02:00
* /
2013-10-05 18:36:20 +02:00
mail _deleteMessages : function ( _msg , _action , _calledFromPopup )
2013-05-27 15:48:55 +02:00
{
2014-02-12 11:56:44 +01:00
var message , ftree , _foldernode , displayname ;
2014-02-04 12:31:13 +01:00
ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-02-12 11:56:44 +01:00
if ( ftree )
{
_foldernode = ftree . getSelectedNode ( ) ;
2014-02-04 12:31:13 +01:00
2014-02-12 11:56:44 +01:00
displayname = _foldernode . label . replace ( this . _unseen _regexp , '' ) ;
}
else
{
message = this . mail _splitRowId ( _msg [ 'msg' ] [ 0 ] ) ;
if ( message [ 3 ] ) _foldernode = displayname = jQuery . base64Decode ( message [ 3 ] ) ;
}
2014-07-02 09:48:24 +02:00
2014-01-17 19:00:36 +01:00
// Tell server
2013-09-10 22:41:18 +02:00
egw . json ( 'mail.mail_ui.ajax_deleteMessages' , [ _msg , ( typeof _action == 'undefined' ? 'no' : _action ) ] )
2014-01-17 19:00:36 +01:00
. sendRequest ( true ) ;
2014-11-20 16:05:25 +01:00
2014-06-26 17:05:04 +02:00
if ( _msg [ 'all' ] ) this . egw . refresh ( this . egw . lang ( "deleted %1 messages in %2" , ( _msg [ 'all' ] ? egw . lang ( 'all' ) : _msg [ 'msg' ] . length ) , ( displayname ? displayname : egw . lang ( 'current folder' ) ) ) , 'mail' ) ; //,ids,'delete');
2014-06-20 14:05:03 +02:00
this . egw . message ( this . egw . lang ( "deleted %1 messages in %2" , ( _msg [ 'all' ] ? egw . lang ( 'all' ) : _msg [ 'msg' ] . length ) , ( displayname ? displayname : egw . lang ( 'current Folder' ) ) ) ) ;
2014-01-13 14:06:29 +01:00
} ,
/ * *
* Delete mails show result - called from the backend function for display of deletionmessages
* takes in all arguments
* @ param _msg - message list
* /
mail _deleteMessagesShowResult : function ( _msg )
{
2014-02-12 11:56:44 +01:00
// Update list
var ids = [ ] ;
for ( var i = 0 ; i < _msg [ 'msg' ] . length ; i ++ )
{
ids . push ( _msg [ 'msg' ] [ i ] . replace ( /mail::/ , '' ) ) ;
}
2014-05-27 15:31:37 +02:00
//this.egw.message(_msg['egw_message']);
2014-06-20 14:05:03 +02:00
if ( _msg [ 'all' ] )
{
this . egw . refresh ( _msg [ 'egw_message' ] , 'mail' ) ;
}
else
{
this . egw . refresh ( _msg [ 'egw_message' ] , 'mail' , ids , 'delete' ) ;
2014-11-17 18:19:51 +01:00
// Nextmatch automatically selects the next row and calls preview.
// Unselect it and thanks to the timeout selectionMgr uses, preview
// will close when the selection callback fires.
this . et2 . getWidgetById ( this . nm _index ) . controller . _selectionMgr . resetSelection ( ) ;
2014-06-20 14:05:03 +02:00
}
2013-04-13 12:30:07 +02:00
} ,
2013-05-27 15:48:55 +02:00
/ * *
* retry to Delete mails
* @ param responseObject - >
* reason - reason to report
* messageList
* /
mail _retryForcedDelete : function ( responseObject )
{
var reason = responseObject [ 'response' ] ;
var messageList = responseObject [ 'messageList' ] ;
2014-03-03 14:10:27 +01:00
if ( confirm ( reason ) )
2013-05-27 15:48:55 +02:00
{
this . mail _deleteMessages ( messageList , 'remove_immediately' ) ;
}
else
{
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'canceled deletion due to userinteraction' ) ) ;
2013-05-27 15:48:55 +02:00
this . mail _removeRowClass ( messageList , 'deleted' ) ;
}
this . mail _refreshMessageGrid ( ) ;
this . mail _preview ( ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* UnDelete mailMessages
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _messageList
* /
mail _undeleteMessages : function ( _messageList ) {
// setting class of row, the old style
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _emptyTrash
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } action
2014-05-20 17:39:20 +02:00
* @ param { object } _senders
2013-04-13 12:30:07 +02:00
* /
2014-01-17 10:59:25 +01:00
mail _emptyTrash : function ( action , _senders ) {
var server = _senders [ 0 ] . iface . id . split ( '::' ) ;
2014-08-08 12:04:49 +02:00
var activeFilters = this . mail _getActiveFilters ( ) ;
2014-07-09 17:21:42 +02:00
var self = this ;
2014-08-13 13:45:55 +02:00
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'empty trash' ) ) ;
2014-08-15 13:22:43 +02:00
egw . json ( 'mail.mail_ui.ajax_emptyTrash' , [ server [ 0 ] , activeFilters [ 'selectedFolder' ] ? activeFilters [ 'selectedFolder' ] : null ] , function ( ) { self . unlock _tree ( ) ; } )
2014-07-15 11:37:08 +02:00
. sendRequest ( true ) ;
2014-08-12 21:06:58 +02:00
// Directly delete any trash cache for selected server
if ( window . localStorage )
{
for ( var i = 0 ; i < window . localStorage . length ; i ++ )
{
var key = window . localStorage . key ( i ) ;
// Find directly by what the key would look like
if ( key . indexOf ( 'cached_fetch_mail::{"selectedFolder":"' + server [ 0 ] + '::' ) == 0 &&
key . toLowerCase ( ) . indexOf ( egw . lang ( 'trash' ) . toLowerCase ( ) ) > 0 )
{
window . localStorage . removeItem ( key ) ;
}
}
}
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _compressFolder
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } action
* @ param { object } _senders
2014-05-20 17:39:20 +02:00
*
2013-04-13 12:30:07 +02:00
* /
2014-01-17 10:59:25 +01:00
mail _compressFolder : function ( action , _senders ) {
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'compress folder' ) ) ;
2014-01-21 15:46:00 +01:00
egw . jsonq ( 'mail.mail_ui.ajax_compressFolder' , [ _senders [ 0 ] . iface . id ] ) ;
// .sendRequest(true);
2014-05-27 15:31:37 +02:00
// since the json reply is using this.egw.refresh, we should not need to call refreshFolderStatus
2014-01-17 10:59:25 +01:00
// as the actions thereof are now bound to run after grid refresh
2014-02-11 16:20:44 +01:00
//this.mail_refreshFolderStatus();
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _changeProfile
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { string } folder the ID of the selected Node - > should be an integer
* @ param { object } _widget handle to the tree widget
2014-01-22 10:32:18 +01:00
* @ param { boolean } getFolders Flag to indicate that the profile needs the mail
2014-05-16 17:39:05 +02:00
* folders . False means they 're already loaded in the tree, and we don' t need
* them again
2013-04-13 12:30:07 +02:00
* /
2014-01-22 10:32:18 +01:00
mail _changeProfile : function ( folder , _widget , getFolders ) {
if ( typeof getFolders == 'undefined' )
{
getFolders = true ;
}
2013-04-13 12:30:07 +02:00
// alert(folder);
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'Connect to Profile %1' , _widget . getSelectedLabel ( ) . replace ( this . _unseen _regexp , '' ) ) ) ;
2014-01-22 10:32:18 +01:00
this . lock _tree ( ) ;
2014-08-20 16:58:12 +02:00
egw . json ( 'mail_ui::ajax_changeProfile' , [ folder , getFolders , this . et2 . _inst . etemplate _exec _id ] , jQuery . proxy ( function ( ) {
2014-01-22 10:32:18 +01:00
// Profile changed, select inbox
var inbox = folder + '::INBOX' ;
2014-05-16 17:39:05 +02:00
_widget . reSelectItem ( inbox ) ;
2014-01-22 10:32:18 +01:00
this . mail _changeFolder ( inbox , _widget , '' ) ;
this . unlock _tree ( ) ;
} , this ) )
. sendRequest ( true ) ;
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
return true ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _changeFolder
2014-05-16 17:39:05 +02:00
* @ param { string } _folder the ID of the selected Node
* @ param { widget object } _widget handle to the tree widget
2014-01-21 19:56:03 +01:00
* @ param { string } _previous - Previously selected node ID
2013-04-13 12:30:07 +02:00
* /
2014-01-21 19:56:03 +01:00
mail _changeFolder : function ( _folder , _widget , _previous ) {
2014-05-23 11:21:59 +02:00
2014-05-22 16:46:50 +02:00
// to reset iframes to the normal status
this . loadIframe ( ) ;
2014-05-23 11:21:59 +02:00
2014-01-21 19:56:03 +01:00
// Abort if user selected an un-selectable node
// Use image over anything else because...?
var img = _widget . getSelectedNode ( ) . images [ 0 ] ;
if ( img . indexOf ( 'NoSelect' ) !== - 1 )
2013-02-20 12:31:57 +01:00
{
2014-01-21 19:56:03 +01:00
_widget . reSelectItem ( _previous ) ;
return ;
2013-02-20 12:31:57 +01:00
}
2014-01-21 19:56:03 +01:00
// Check if this is a top level node and
// change profile if server has changed
var server = _folder . split ( '::' ) ;
var previousServer = _previous . split ( '::' ) ;
var profile _selected = ( _folder . indexOf ( '::' ) === - 1 ) ;
if ( server [ 0 ] != previousServer [ 0 ] && profile _selected )
{
// mail_changeProfile triggers a refresh, no need to do any more
2014-01-22 10:32:18 +01:00
return this . mail _changeProfile ( _folder , _widget , _widget . getSelectedNode ( ) . childsCount == 0 ) ;
2014-01-21 19:56:03 +01:00
}
// Apply new selected folder to list, which updates data
2013-08-21 12:47:20 +02:00
var nm = _widget . getRoot ( ) . getWidgetById ( this . nm _index ) ;
2013-12-10 19:13:28 +01:00
if ( nm )
2013-02-13 15:02:02 +01:00
{
2014-01-21 12:28:43 +01:00
this . lock _tree ( ) ;
2014-01-21 19:56:03 +01:00
nm . applyFilters ( { 'selectedFolder' : _folder } ) ;
2013-12-10 19:13:28 +01:00
}
2014-01-21 19:56:03 +01:00
// Get nice folder name for message, if selected is not a profile
if ( ! profile _selected )
2014-02-05 13:23:04 +01:00
{
2014-02-06 13:48:01 +01:00
var displayname = _widget . getSelectedLabel ( ) ;
var myMsg = ( displayname ? displayname : _folder ) . replace ( this . _unseen _regexp , '' ) + ' ' + this . egw . lang ( 'selected' ) ;
2014-05-27 15:31:37 +02:00
this . egw . message ( myMsg ) ;
2013-02-13 15:02:02 +01:00
}
2013-12-17 16:21:36 +01:00
2014-01-21 19:56:03 +01:00
// Update non-grid
this . mail _refreshFolderStatus ( _folder , 'forced' , false , false ) ;
2013-10-18 11:58:25 +02:00
this . mail _refreshQuotaDisplay ( server [ 0 ] ) ;
2013-05-21 10:46:54 +02:00
this . mail _preview ( ) ;
2014-04-11 15:52:58 +02:00
if ( server [ 0 ] != previousServer [ 0 ] )
{
this . mail _callRefreshVacationNotice ( server [ 0 ] ) ;
egw . jsonq ( 'mail.mail_ui.ajax_refreshFilters' , [ server [ 0 ] ] ) ;
}
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2014-05-27 14:05:23 +02:00
/ * *
* mail _checkAllSelected
*
* @ param _action
2014-06-26 17:05:04 +02:00
* @ param _elems
* @ param _target
* @ param _confirm
2014-05-27 14:05:23 +02:00
* /
2014-06-26 17:05:04 +02:00
mail _checkAllSelected : function ( _action , _elems , _target , _confirm )
2014-05-27 14:05:23 +02:00
{
2014-06-26 17:05:04 +02:00
if ( typeof _confirm == 'undefined' ) _confirm = false ;
2014-07-02 09:48:24 +02:00
// we can NOT query global object manager for this.nm_index="nm", as we might not get the one from mail,
// if other tabs are open, we have to query for obj_manager for "mail" and then it's child with id "nm"
2014-07-08 11:30:24 +02:00
var obj _manager = egw _getObjectManager ( this . appname ) . getObjectById ( this . nm _index ) ;
2014-06-26 17:05:04 +02:00
var that = this ;
var rvMain = false ;
2014-11-19 21:13:46 +01:00
if ( ( obj _manager && _elems . length > 1 && obj _manager . getAllSelected ( ) && ! _action . paste ) || _action . id == 'readall' )
2014-05-27 14:05:23 +02:00
{
if ( _confirm )
{
2014-06-26 17:05:04 +02:00
var buttons = [
2014-12-11 13:01:52 +01:00
{ text : this . egw . lang ( "Yes" ) , id : "all" , "class" : "ui-priority-primary" , "default" : true } ,
2014-05-27 14:05:23 +02:00
{ text : this . egw . lang ( "Cancel" ) , id : "cancel" }
] ;
2014-07-15 13:17:03 +02:00
var messageToDisplay = '' ;
2014-06-26 17:05:04 +02:00
switch ( _action . id )
{
2014-08-14 17:38:32 +02:00
case "readall" :
messageToDisplay = this . egw . lang ( "Do you really want to mark ALL messages as read in the current folder?" ) + " " ;
break ;
2014-06-26 17:05:04 +02:00
case "unlabel" :
case "label1" :
case "label2" :
case "label3" :
case "label4" :
case "label5" :
case "flagged" :
case "read" :
case "undelete" :
2014-07-15 13:35:47 +02:00
messageToDisplay = this . egw . lang ( "Do you really want to toggle flag %1 for ALL messages in the current view?" , this . egw . lang ( _action . id ) ) + " " ;
2014-06-26 17:05:04 +02:00
break ;
2014-07-15 13:17:03 +02:00
default :
var type = null ;
if ( _action . id . substr ( 0 , 4 ) == 'move' || _action . id === "drop_move_mail" )
{
type = 'Move' ;
}
if ( _action . id . substr ( 0 , 4 ) == 'copy' || _action . id === "drop_copy_mail" )
{
type = 'Copy' ;
}
2014-07-15 13:35:47 +02:00
messageToDisplay = this . egw . lang ( "Do you really want to apply %1 to ALL messages in the current view?" , this . egw . lang ( type ? type : _action . id ) ) + " " ;
2014-06-26 17:05:04 +02:00
}
2014-07-15 13:17:03 +02:00
return et2 _dialog . show _dialog ( function ( _button _id ) {
2014-06-26 17:05:04 +02:00
var rv = false ;
2014-05-27 14:05:23 +02:00
switch ( _button _id )
{
case "all" :
2014-06-26 17:05:04 +02:00
rv = true ;
break ;
2014-05-27 14:05:23 +02:00
case "cancel" :
2014-06-26 17:05:04 +02:00
rv = 'cancel' ;
}
2014-07-14 17:56:34 +02:00
if ( rv != "cancel" ) that . lock _tree ( ) ;
2014-06-26 17:05:04 +02:00
switch ( _action . id )
{
case "delete" :
that . mail _callDelete ( _action , _elems , rv ) ;
break ;
2014-08-14 17:38:32 +02:00
case "readall" :
2014-06-26 17:05:04 +02:00
case "unlabel" :
case "label1" :
case "label2" :
case "label3" :
case "label4" :
case "label5" :
case "flagged" :
case "read" :
case "undelete" :
that . mail _callFlagMessages ( _action , _elems , rv ) ;
break ;
case "drop_move_mail" :
that . mail _callMove ( _action , _elems , _target , rv ) ;
break ;
case "drop_copy_mail" :
that . mail _callCopy ( _action , _elems , _target , rv ) ;
break ;
default :
2014-07-01 11:23:29 +02:00
if ( _action . id . substr ( 0 , 4 ) == 'move' ) that . mail _callMove ( _action , _elems , _target , rv ) ;
if ( _action . id . substr ( 0 , 4 ) == 'copy' ) that . mail _callCopy ( _action , _elems , _target , rv ) ;
2014-05-27 14:05:23 +02:00
}
} ,
2014-06-26 17:05:04 +02:00
messageToDisplay ,
2014-05-27 14:05:23 +02:00
this . egw . lang ( "Confirm" ) ,
_action . id , buttons ) ;
}
else
{
2014-06-26 17:05:04 +02:00
rvMain = true ;
2014-05-27 14:05:23 +02:00
}
}
2014-06-26 17:05:04 +02:00
switch ( _action . id )
{
case "delete" :
this . mail _callDelete ( _action , _elems , rvMain ) ;
break ;
case "unlabel" :
case "label1" :
case "label2" :
case "label3" :
case "label4" :
case "label5" :
case "flagged" :
case "read" :
case "undelete" :
this . mail _callFlagMessages ( _action , _elems , rvMain ) ;
break ;
case "drop_move_mail" :
this . mail _callMove ( _action , _elems , _target , rvMain ) ;
break ;
case "drop_copy_mail" :
this . mail _callCopy ( _action , _elems , _target , rvMain ) ;
break ;
default :
2014-07-01 14:09:10 +02:00
if ( _action . id . substr ( 0 , 4 ) == 'move' ) this . mail _callMove ( _action , _elems , _target , rvMain ) ;
if ( _action . id . substr ( 0 , 4 ) == 'copy' ) this . mail _callCopy ( _action , _elems , _target , rvMain ) ;
2014-06-26 17:05:04 +02:00
}
2014-05-27 14:05:23 +02:00
} ,
2014-06-26 17:05:04 +02:00
/ * *
* mail _doActionCall
*
* @ param _action
* @ param _elems
* /
mail _doActionCall : function ( _action , _elems )
{
} ,
2014-07-08 11:22:21 +02:00
2014-05-27 14:05:23 +02:00
/ * *
* mail _getActiveFilters
*
* @ param _action
* @ return mixed boolean / activeFilters object
* /
mail _getActiveFilters : function ( _action )
{
2014-07-08 11:22:21 +02:00
// we can NOT query global object manager for this.nm_index="nm", as we might not get the one from mail,
// if other tabs are open, we have to query for obj_manager for "mail" and then it's child with id "nm"
2014-07-08 11:30:24 +02:00
var obj _manager = egw _getObjectManager ( this . appname ) . getObjectById ( this . nm _index ) ;
2014-05-27 14:05:23 +02:00
if ( obj _manager && obj _manager . manager && obj _manager . manager . data && obj _manager . manager . data . nextmatch && obj _manager . manager . data . nextmatch . activeFilters )
{
return obj _manager . manager . data . nextmatch . activeFilters ;
}
return false ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* Flag mail as 'read' , 'unread' , 'flagged' or 'unflagged'
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* /
mail _flag : function ( _action , _elems )
2014-06-26 17:05:04 +02:00
{
this . mail _checkAllSelected ( _action , _elems , null , true ) ;
} ,
/ * *
* Flag mail as 'read' , 'unread' , 'flagged' or 'unflagged'
*
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* @ param _allMessagesChecked
* /
mail _callFlagMessages : function ( _action , _elems , _allMessagesChecked )
2013-02-13 15:02:02 +01:00
{
2013-10-05 11:03:51 +02:00
var do _nmactions = true ;
var msg ;
2014-01-27 13:18:16 +01:00
var ftree ;
var _folder ;
2014-06-26 17:05:04 +02:00
if ( typeof _allMessagesChecked == 'undefined' ) _allMessagesChecked = false ;
2014-01-27 13:18:16 +01:00
if ( _action . id == 'read' )
{
ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
var _foldernode = ftree . getSelectedNode ( ) ;
_folder = _foldernode . id ;
}
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
do _nmactions = false ; //indicates that this action is probably a popup?
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
msg = { } ;
msg [ 'msg' ] = [ this . et2 . getArrayMgr ( 'content' ) . getEntry ( 'mail_id' ) || '' ] ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
msg = { } ;
msg [ 'msg' ] = [ this . mail _currentlyFocussed ] ;
2014-01-27 13:18:16 +01:00
_elems = msg ;
do _nmactions = true ; // is triggered from preview
2013-10-14 15:30:04 +02:00
}
}
2013-10-05 11:03:51 +02:00
}
2013-12-06 11:35:39 +01:00
var classToProcess = _action . id ;
if ( _action . id == 'read' ) classToProcess = 'seen' ;
2014-08-14 17:38:32 +02:00
else if ( _action . id == 'readall' ) classToProcess = 'seen' ;
2013-12-06 11:35:39 +01:00
else if ( _action . id == 'label1' ) classToProcess = 'labelone' ;
else if ( _action . id == 'label2' ) classToProcess = 'labeltwo' ;
else if ( _action . id == 'label3' ) classToProcess = 'labelthree' ;
else if ( _action . id == 'label4' ) classToProcess = 'labelfour' ;
else if ( _action . id == 'label5' ) classToProcess = 'labelfive' ;
2013-10-05 11:03:51 +02:00
if ( do _nmactions )
{
msg = this . mail _getFormData ( _elems ) ;
2014-07-01 17:22:18 +02:00
msg [ 'all' ] = _allMessagesChecked ;
2014-06-26 17:05:04 +02:00
if ( msg [ 'all' ] == 'cancel' ) return false ;
2014-08-14 17:38:32 +02:00
msg [ 'activeFilters' ] = ( _action . id == 'readall' ? false : this . mail _getActiveFilters ( _action ) ) ;
2013-10-05 11:03:51 +02:00
if ( _action . id . substring ( 0 , 2 ) == 'un' ) {
2013-12-06 11:35:39 +01:00
//old style, only available for undelete and unlabel (no toggle)
if ( _action . id == 'unlabel' ) // this means all labels should be removed
{
var labels = [ 'labelone' , 'labeltwo' , 'labelthree' , 'labelfour' , 'labelfive' ] ;
2014-03-03 14:10:27 +01:00
for ( var i = 0 ; i < labels . length ; i ++ ) this . mail _removeRowClass ( _elems , labels [ i ] ) ;
2013-12-06 11:35:39 +01:00
this . mail _flagMessages ( _action . id , msg , ( do _nmactions ? false : true ) ) ;
}
else
{
this . mail _removeRowClass ( _elems , _action . id . substring ( 2 ) ) ;
this . mail _setRowClass ( _elems , _action . id ) ;
this . mail _flagMessages ( _action . id , msg , ( do _nmactions ? false : true ) ) ;
}
2013-10-05 11:03:51 +02:00
}
2014-08-14 17:38:32 +02:00
else if ( _action . id == 'readall' )
{
this . mail _flagMessages ( 'read' , msg , ( do _nmactions ? false : true ) ) ;
}
2013-10-05 11:03:51 +02:00
else
{
2013-12-06 11:35:39 +01:00
var msg _set = { msg : [ ] } ;
var msg _unset = { msg : [ ] } ;
var dataElem ;
var flags ;
2014-01-13 15:22:58 +01:00
var classes = '' ;
2014-03-03 14:10:27 +01:00
for ( var i = 0 ; i < msg . msg . length ; i ++ )
2013-12-06 11:35:39 +01:00
{
dataElem = egw . dataGetUIDdata ( msg . msg [ i ] ) ;
2014-01-13 15:22:58 +01:00
if ( typeof dataElem . data . flags == 'undefined' )
{
dataElem . data . flags = { } ;
}
2013-12-06 11:35:39 +01:00
flags = dataElem . data . flags ;
2014-12-11 13:01:52 +01:00
classes = dataElem . data [ 'class' ] || "" ;
2014-01-13 15:22:58 +01:00
classes = classes . split ( ' ' ) ;
2013-12-06 11:35:39 +01:00
// since we toggle we need to unset the ones already set, and set the ones not set
2014-01-13 15:22:58 +01:00
// flags is data, UI is done by class, so update both
// Flags are there or not, class names are flag or 'un'+flag
if ( classes . indexOf ( classToProcess ) >= 0 )
{
classes . splice ( classes . indexOf ( classToProcess ) , 1 ) ;
}
if ( classes . indexOf ( 'un' + classToProcess ) >= 0 )
{
classes . splice ( classes . indexOf ( 'un' + classToProcess ) , 1 ) ;
}
2013-12-06 11:35:39 +01:00
if ( flags [ _action . id ] )
{
msg _unset [ 'msg' ] . push ( msg . msg [ i ] ) ;
2014-01-13 15:22:58 +01:00
classes . push ( 'un' + classToProcess ) ;
delete flags [ _action . id ] ;
2013-12-06 11:35:39 +01:00
}
else
{
msg _set [ 'msg' ] . push ( msg . msg [ i ] ) ;
2014-01-13 15:22:58 +01:00
flags [ _action . id ] = _action . id ;
classes . push ( classToProcess ) ;
2013-12-06 11:35:39 +01:00
}
2014-01-13 15:22:58 +01:00
// Update cache & call callbacks - updates list
2014-12-11 13:01:52 +01:00
dataElem . data [ 'class' ] = classes . join ( ' ' ) ;
2014-09-03 12:34:14 +02:00
egw . dataStoreUID ( msg . msg [ i ] , dataElem . data ) ;
2014-09-03 11:58:21 +02:00
//Refresh the nm rows after we told dataComponent about all changes, since the dataComponent doesn't talk to nm, we need to do it manually
this . updateFilter _data ( msg . msg [ i ] , _action . id , msg . activeFilters ) ;
2013-12-06 11:35:39 +01:00
}
2014-01-13 15:22:58 +01:00
// Notify server of changes
2013-12-06 11:35:39 +01:00
if ( msg _unset [ 'msg' ] && msg _unset [ 'msg' ] . length )
{
2014-05-27 14:05:23 +02:00
if ( ! msg [ 'all' ] ) this . mail _flagMessages ( 'un' + _action . id , msg _unset ) ;
2013-12-06 11:35:39 +01:00
}
if ( msg _set [ 'msg' ] && msg _set [ 'msg' ] . length )
{
2014-05-27 14:05:23 +02:00
if ( ! msg [ 'all' ] ) this . mail _flagMessages ( _action . id , msg _set ) ;
2013-12-06 11:35:39 +01:00
}
2014-05-27 14:05:23 +02:00
//server must do the toggle, as we apply to ALL, not only the visible
if ( msg [ 'all' ] ) this . mail _flagMessages ( _action . id , msg ) ;
2014-01-27 13:18:16 +01:00
// No further update needed, only in case of read, the counters should be refreshed
if ( _action . id == 'read' ) this . mail _refreshFolderStatus ( _folder , 'thisfolderonly' , false , true ) ;
2014-01-13 15:22:58 +01:00
return ;
2013-10-05 11:03:51 +02:00
}
2013-10-04 11:33:44 +02:00
}
else
{
2013-12-05 16:09:35 +01:00
this . mail _flagMessages ( _action . id , msg , ( do _nmactions ? false : true ) ) ;
2013-10-04 11:33:44 +02:00
}
2014-01-27 13:18:16 +01:00
// only refresh counter. not grid as the ajaxmethod is called asyncronously
// on flagging, only seen/unseen has effect on counterdisplay
2014-08-14 17:38:32 +02:00
if ( _action . id == 'read' || _action . id == 'readall' ) this . mail _refreshFolderStatus ( _folder , 'thisfolderonly' , false , true ) ;
2014-01-27 13:18:16 +01:00
//this.mail_refreshFolderStatus();
2013-04-13 12:30:07 +02:00
} ,
2014-09-03 12:34:14 +02:00
2014-09-03 11:58:21 +02:00
/ * *
* Update changes on filtered mail rows in nm , triggers manual refresh
2014-09-03 12:34:14 +02:00
*
* @ param { type } _uid mail uid
2014-09-03 11:58:21 +02:00
* @ param { type } _actionId action id sended by nm action
* @ param { type } _filters activefilters
* /
updateFilter _data : function ( _uid , _actionId , _filters )
{
var uid = _uid . replace ( 'mail::' , '' ) ;
var action = '' ;
switch ( _actionId )
{
case 'flagged' :
action = 'flagged' ;
break ;
case 'read' :
if ( _filters . filter == 'seen' )
{
action = 'seen' ;
}
else if ( _filters . filter == 'unseen' )
{
action = 'unseen' ;
}
break ;
case 'label1' :
action = 'keyword1' ;
break ;
2014-09-03 12:34:14 +02:00
case 'label2' :
2014-09-03 11:58:21 +02:00
action = 'keyword2' ;
break ;
2014-09-03 12:34:14 +02:00
case 'label3' :
2014-09-03 11:58:21 +02:00
action = 'keyword3' ;
break ;
2014-09-03 12:34:14 +02:00
case 'label4' :
2014-09-03 11:58:21 +02:00
action = 'keyword4' ;
break ;
2014-09-03 12:34:14 +02:00
case 'label4' :
2014-09-03 11:58:21 +02:00
action = 'keyword4' ;
break ;
}
if ( action == _filters . filter )
{
egw . refresh ( '' , 'mail' , uid , 'delete' ) ;
}
} ,
2014-09-03 12:34:14 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* Flag mail as 'read' , 'unread' , 'flagged' or 'unflagged'
2013-07-25 17:35:44 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _flag
* @ param { object } _elems
* @ param { boolean } _isPopup
2013-04-13 12:30:07 +02:00
* /
2014-01-13 15:22:58 +01:00
mail _flagMessages : function ( _flag , _elems , _isPopup )
2013-02-19 17:30:59 +01:00
{
2014-01-21 15:46:00 +01:00
egw . jsonq ( 'mail.mail_ui.ajax_flagMessages' , [ _flag , _elems ] ) ;
// .sendRequest(true);
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* display header lines , or source of mail , depending on the url given
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _url
* /
mail _displayHeaderLines : function ( _url ) {
// only used by right clickaction
2013-10-01 13:29:54 +02:00
egw _openWindowCentered ( _url , 'mail_display_headerLines' , '870' , '600' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* View header of a message
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _header : function ( _action , _elems )
{
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
//alert('mail_header('+_elems[0].id+')');
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=mail.mail_ui.displayHeader' ; // todo compose for Draft folder
url += '&id=' + _elems [ 0 ] . id ;
this . mail _displayHeaderLines ( url ) ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* View message source
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _mailsource : function ( _action , _elems )
{
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
//alert('mail_mailsource('+_elems[0].id+')');
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=mail.mail_ui.saveMessage' ; // todo compose for Draft folder
url += '&id=' + _elems [ 0 ] . id ;
url += '&location=display' ;
this . mail _displayHeaderLines ( url ) ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* Save a message
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _save : function ( _action , _elems )
{
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
//alert('mail_save('+_elems[0].id+')');
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=mail.mail_ui.saveMessage' ; // todo compose for Draft folder
url += '&id=' + _elems [ 0 ] . id ;
//window.open(url,'_blank','dependent=yes,width=100,height=100,scrollbars=yes,status=yes');
2014-10-08 22:02:59 +02:00
this . et2 . _inst . download ( url ) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-07-19 17:13:01 +02:00
/ * *
* User clicked an address ( FROM , TO , etc )
2013-10-16 13:22:53 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } tag _info with values for attributes id , label , title , ...
* @ param { widget object } widget
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ todo seems this function is not implemented , need to be checked if it is neccessary at all
2013-07-19 17:13:01 +02:00
* /
2013-10-09 19:29:36 +02:00
address _click : function ( tag _info , widget )
2013-07-19 17:13:01 +02:00
{
2014-05-20 17:39:20 +02:00
2013-07-19 17:13:01 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-10-16 13:25:46 +02:00
/ * *
2014-01-30 10:35:56 +01:00
* displayAttachment
2014-05-20 17:39:20 +02:00
*
* @ param { object } tag _info
2014-05-16 17:39:05 +02:00
* @ param { widget object } widget
* @ param { object } calledForCompose
2013-10-16 13:25:46 +02:00
* /
2014-01-30 10:35:56 +01:00
displayAttachment : function ( tag _info , widget , calledForCompose )
2013-10-16 13:25:46 +02:00
{
2013-10-21 15:07:32 +02:00
var mailid ;
var attgrid ;
2014-02-11 11:01:48 +01:00
if ( typeof calledForCompose == 'undefined' || typeof calledForCompose == 'object' ) calledForCompose = false ;
if ( calledForCompose === false )
2013-10-21 15:07:32 +02:00
{
2014-01-30 10:35:56 +01:00
if ( this . mail _isMainWindow )
{
mailid = this . mail _currentlyFocussed ; //this.et2.getArrayMgr("content").getEntry('mail_id');
var p = widget . getParent ( ) ;
var cont = p . getArrayMgr ( "content" ) . data ;
attgrid = cont [ widget . id . replace ( /\[filename\]/ , '' ) ] ;
}
else
{
mailid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' ) [ widget . id . replace ( /\[filename\]/ , '' ) ] ;
}
2013-10-21 15:07:32 +02:00
}
2014-02-11 11:01:48 +01:00
if ( calledForCompose === true )
2013-10-21 15:07:32 +02:00
{
2014-01-31 11:21:58 +01:00
// CALLED FOR COMPOSE; processedmail_id could hold several IDs seperated by comma
2014-01-30 10:35:56 +01:00
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'attachments' ) [ widget . id . replace ( /\[name\]/ , '' ) ] ;
2014-01-31 11:21:58 +01:00
var mailids = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'processedmail_id' ) ;
var mailida = mailids . split ( ',' ) ;
mailid = mailida [ widget . id . replace ( /\[name\]/ , '' ) ] ;
if ( typeof attgrid . uid != 'undefined' && attgrid . uid && mailid . indexOf ( attgrid . uid ) == - 1 )
{
2014-03-03 14:10:27 +01:00
for ( var i = 0 ; i < mailida . length ; i ++ )
2014-01-31 11:21:58 +01:00
{
if ( mailida [ i ] . indexOf ( '::' + attgrid . uid ) > - 1 ) mailid = mailida [ i ] ;
}
}
2013-10-21 15:07:32 +02:00
}
2013-10-16 13:25:46 +02:00
var url = window . egw _webserverUrl + '/index.php?' ;
var width ;
var height ;
var windowName = 'mail' ;
switch ( attgrid . type . toUpperCase ( ) )
{
case 'MESSAGE/RFC822' :
url += 'menuaction=mail.mail_ui.displayMessage' ; // todo compose for Draft folder
2014-07-11 15:49:27 +02:00
url += '&mode=display' ; //message/rfc822 attachments should be opened in display mode
2013-10-16 13:25:46 +02:00
url += '&id=' + mailid ;
url += '&part=' + attgrid . partID ;
url += '&is_winmail=' + attgrid . winmailFlag ;
windowName = windowName + 'displayMessage_' + mailid + '_' + attgrid . partID ;
width = 870 ;
height = egw _getWindowOuterHeight ( ) ;
break ;
case 'IMAGE/JPEG' :
case 'IMAGE/PNG' :
case 'IMAGE/GIF' :
case 'IMAGE/BMP' :
case 'APPLICATION/PDF' :
case 'TEXT/PLAIN' :
case 'TEXT/HTML' :
case 'TEXT/DIRECTORY' :
/ *
$sfxMimeType = $value [ 'mimeType' ] ;
$buff = explode ( '.' , $value [ 'name' ] ) ;
$suffix = '' ;
if ( is _array ( $buff ) ) $suffix = array _pop ( $buff ) ; // take the last extension to check with ext2mime
if ( ! empty ( $suffix ) ) $sfxMimeType = mime _magic : : ext2mime ( $suffix ) ;
if ( strtoupper ( $sfxMimeType ) == 'TEXT/VCARD' || strtoupper ( $sfxMimeType ) == 'TEXT/X-VCARD' )
{
$attachments [ $key ] [ 'mimeType' ] = $sfxMimeType ;
$value [ 'mimeType' ] = strtoupper ( $sfxMimeType ) ;
}
* /
case 'TEXT/X-VCARD' :
case 'TEXT/VCARD' :
case 'TEXT/CALENDAR' :
case 'TEXT/X-VCALENDAR' :
url += 'menuaction=mail.mail_ui.getAttachment' ; // todo compose for Draft folder
url += '&id=' + mailid ;
url += '&part=' + attgrid . partID ;
url += '&is_winmail=' + attgrid . winmailFlag ;
windowName = windowName + 'displayAttachment_' + mailid + '_' + attgrid . partID ;
var reg = '800x600' ;
var reg2 ;
// handle calendar/vcard
if ( attgrid . type . toUpperCase ( ) == 'TEXT/CALENDAR' )
{
windowName = 'maildisplayEvent_' + mailid + '_' + attgrid . partID ;
reg2 = egw . link _get _registry ( 'calendar' ) ;
2014-02-10 11:25:09 +01:00
if ( typeof reg2 [ 'view' ] != 'undefined' && typeof reg2 [ 'view_popup' ] != 'undefined' )
2013-10-16 13:25:46 +02:00
{
2014-02-10 11:25:09 +01:00
reg = reg2 [ 'view_popup' ] ;
2013-10-16 13:25:46 +02:00
}
}
if ( attgrid . type . toUpperCase ( ) == 'TEXT/X-VCARD' || attgrid . type . toUpperCase ( ) == 'TEXT/VCARD' )
{
windowName = 'maildisplayContact_' + mailid + '_' + attgrid . partID ;
reg2 = egw . link _get _registry ( 'addressbook' ) ;
2014-02-10 11:25:09 +01:00
if ( typeof reg2 [ 'add' ] != 'undefined' && typeof reg2 [ 'add_popup' ] != 'undefined' )
2013-10-16 13:25:46 +02:00
{
2014-02-10 11:25:09 +01:00
reg = reg2 [ 'add_popup' ] ;
2013-10-16 13:25:46 +02:00
}
}
var w _h = reg . split ( 'x' ) ;
width = w _h [ 0 ] ;
height = w _h [ 1 ] ;
break ;
default :
url += 'menuaction=mail.mail_ui.getAttachment' ; // todo compose for Draft folder
url += '&id=' + mailid ;
url += '&part=' + attgrid . partID ;
url += '&is_winmail=' + attgrid . winmailFlag ;
windowName = windowName + 'displayAttachment_' + mailid + '_' + attgrid . partID ;
width = 870 ;
height = 600 ;
2014-10-08 22:02:59 +02:00
break ;
2013-10-16 13:25:46 +02:00
}
egw _openWindowCentered ( url , windowName , width , height ) ;
} ,
2014-01-30 10:35:56 +01:00
/ * *
* displayUploadedFile
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } tag _info
* @ param { widget object } widget
2014-01-30 10:35:56 +01:00
* /
displayUploadedFile : function ( tag _info , widget )
{
var attgrid ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'attachments' ) [ widget . id . replace ( /\[name\]/ , '' ) ] ;
2014-06-23 18:31:43 +02:00
2014-01-31 11:21:58 +01:00
if ( attgrid . uid && ( attgrid . partID || attgrid . folder ) )
2014-01-30 10:35:56 +01:00
{
this . displayAttachment ( tag _info , widget , true ) ;
return ;
}
var url = window . egw _webserverUrl + '/index.php?' ;
var width ;
var height ;
var windowName = 'mail' ;
switch ( attgrid . type . toUpperCase ( ) )
{
case 'IMAGE/JPEG' :
case 'IMAGE/PNG' :
case 'IMAGE/GIF' :
case 'IMAGE/BMP' :
case 'APPLICATION/PDF' :
case 'TEXT/PLAIN' :
case 'TEXT/HTML' :
case 'TEXT/DIRECTORY' :
/ *
$sfxMimeType = $value [ 'mimeType' ] ;
$buff = explode ( '.' , $value [ 'name' ] ) ;
$suffix = '' ;
if ( is _array ( $buff ) ) $suffix = array _pop ( $buff ) ; // take the last extension to check with ext2mime
if ( ! empty ( $suffix ) ) $sfxMimeType = mime _magic : : ext2mime ( $suffix ) ;
if ( strtoupper ( $sfxMimeType ) == 'TEXT/VCARD' || strtoupper ( $sfxMimeType ) == 'TEXT/X-VCARD' )
{
$attachments [ $key ] [ 'mimeType' ] = $sfxMimeType ;
$value [ 'mimeType' ] = strtoupper ( $sfxMimeType ) ;
}
* /
case 'TEXT/X-VCARD' :
case 'TEXT/VCARD' :
case 'TEXT/CALENDAR' :
case 'TEXT/X-VCALENDAR' :
url += 'menuaction=mail.mail_compose.getAttachment' ; // todo compose for Draft folder
url += '&tmpname=' + attgrid . tmp _name ;
url += '&name=' + attgrid . name ;
//url += '&size='+attgrid.size;
url += '&type=' + attgrid . type ;
windowName = windowName + 'displayAttachment_' + attgrid . file . replace ( /\//g , "_" ) ;
var reg = '800x600' ;
var reg2 ;
// handle calendar/vcard
if ( attgrid . type . toUpperCase ( ) == 'TEXT/CALENDAR' )
{
windowName = 'maildisplayEvent_' + attgrid . file . replace ( /\//g , "_" ) ;
reg2 = egw . link _get _registry ( 'calendar' ) ;
2014-02-10 11:25:09 +01:00
if ( typeof reg2 [ 'view' ] != 'undefined' && typeof reg2 [ 'view_popup' ] != 'undefined' )
2014-01-30 10:35:56 +01:00
{
2014-02-10 11:25:09 +01:00
reg = reg2 [ 'view_popup' ] ;
2014-01-30 10:35:56 +01:00
}
}
if ( attgrid . type . toUpperCase ( ) == 'TEXT/X-VCARD' || attgrid . type . toUpperCase ( ) == 'TEXT/VCARD' )
{
windowName = 'maildisplayContact_' + attgrid . file . replace ( /\//g , "_" ) ;
reg2 = egw . link _get _registry ( 'addressbook' ) ;
2014-02-10 11:25:09 +01:00
if ( typeof reg2 [ 'add' ] != 'undefined' && typeof reg2 [ 'add_popup' ] != 'undefined' )
2014-01-30 10:35:56 +01:00
{
2014-02-10 11:25:09 +01:00
reg = reg2 [ 'add_popup' ] ;
2014-01-30 10:35:56 +01:00
}
}
var w _h = reg . split ( 'x' ) ;
width = w _h [ 0 ] ;
height = w _h [ 1 ] ;
break ;
case 'MESSAGE/RFC822' :
/ *
url += 'menuaction=mail.mail_ui.displayMessage' ; // todo compose for Draft folder
url += '&id=' + mailid ;
url += '&part=' + attgrid . partID ;
url += '&is_winmail=' + attgrid . winmailFlag ;
windowName = windowName + 'displayMessage_' + mailid + '_' + attgrid . partID ;
width = 870 ;
height = egw _getWindowOuterHeight ( ) ;
break ;
* /
default :
url += 'menuaction=mail.mail_compose.getAttachment' ; // todo compose for Draft folder
url += '&tmpname=' + attgrid . tmp _name ;
url += '&name=' + attgrid . name ;
//url += '&size='+attgrid.size;
url += '&type=' + attgrid . type ;
url += '&mode=' + 'save' ;
windowName = windowName + 'displayAttachment_' + attgrid . file . replace ( /\//g , "_" ) ;
width = 870 ;
height = 600 ;
2014-10-08 22:02:59 +02:00
break ;
2014-01-30 10:35:56 +01:00
}
egw _openWindowCentered ( url , windowName , width , height ) ;
} ,
2013-10-16 13:25:46 +02:00
saveAttachment : function ( tag _info , widget )
{
2013-10-21 15:07:32 +02:00
var mailid ;
var attgrid ;
if ( this . mail _isMainWindow )
{
mailid = this . mail _currentlyFocussed ; //this.et2.getArrayMgr("content").getEntry('mail_id');
var p = widget . getParent ( ) ;
var cont = p . getArrayMgr ( "content" ) . data ;
attgrid = cont [ widget . id . replace ( /\[save\]/ , '' ) ] ;
}
else
{
mailid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' ) [ widget . id . replace ( /\[save\]/ , '' ) ] ;
}
2013-10-16 13:25:46 +02:00
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=mail.mail_ui.getAttachment' ; // todo compose for Draft folder
url += '&mode=save' ;
url += '&id=' + mailid ;
url += '&part=' + attgrid . partID ;
url += '&is_winmail=' + attgrid . winmailFlag ;
2014-10-08 22:02:59 +02:00
this . et2 . _inst . download ( url ) ;
2013-10-16 13:25:46 +02:00
} ,
2014-07-08 14:01:29 +02:00
saveAllAttachmentsToZip : function ( tag _info , widget )
{
var mailid ;
var attgrid ;
if ( this . mail _isMainWindow )
{
mailid = this . mail _currentlyFocussed ; //this.et2.getArrayMgr("content").getEntry('mail_id');
var p = widget . getParent ( ) ;
var cont = p . getArrayMgr ( "content" ) . data ;
attgrid = cont [ widget . id . replace ( /\[save\]/ , '' ) ] ;
}
else
{
mailid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' ) [ widget . id . replace ( /\[save\]/ , '' ) ] ;
}
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=mail.mail_ui.download_zip' ; // todo compose for Draft folder
url += '&mode=save' ;
url += '&id=' + mailid ;
2014-10-08 22:02:59 +02:00
this . et2 . _inst . download ( url ) ;
2014-07-08 14:01:29 +02:00
} ,
2013-10-16 13:25:46 +02:00
saveAttachmentToVFS : function ( tag _info , widget )
{
2013-10-21 15:07:32 +02:00
var mailid ;
var attgrid ;
if ( this . mail _isMainWindow )
{
mailid = this . mail _currentlyFocussed ; //this.et2.getArrayMgr("content").getEntry('mail_id');
var p = widget . getParent ( ) ;
var cont = p . getArrayMgr ( "content" ) . data ;
attgrid = cont [ widget . id . replace ( /\[saveAsVFS\]/ , '' ) ] ;
}
else
{
mailid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' ) [ widget . id . replace ( /\[saveAsVFS\]/ , '' ) ] ;
}
2013-10-16 13:25:46 +02:00
var url = window . egw _webserverUrl + '/index.php?' ;
var width = 640 ;
var height = 570 ;
var windowName = 'mail' ;
url += 'menuaction=filemanager.filemanager_select.select' ; // todo compose for Draft folder
url += '&mode=saveas' ;
url += '&id=' + mailid + '::' + attgrid . partID + '::' + attgrid . winmailFlag ;
url += '&name=' + attgrid . filename ;
url += '&type=' + attgrid . type . toLowerCase ( ) ;
url += '&method=mail.mail_ui.vfsSaveAttachment' ;
url += '&label=' + egw . lang ( 'Save' ) ;
egw _openWindowCentered ( url , windowName , width , height ) ;
} ,
saveAllAttachmentsToVFS : function ( tag _info , widget )
{
2013-10-21 15:07:32 +02:00
var mailid ;
var attgrid ;
if ( this . mail _isMainWindow )
{
mailid = this . mail _currentlyFocussed ; //this.et2.getArrayMgr("content").getEntry('mail_id');
var p = widget . getParent ( ) ;
attgrid = p . getArrayMgr ( "content" ) . data ;
}
else
{
mailid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) ;
attgrid = this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_displayattachments' ) ;
}
2013-10-16 13:25:46 +02:00
var url = window . egw _webserverUrl + '/index.php?' ;
var width = 640 ;
var height = 570 ;
var windowName = 'mail' ;
url += 'menuaction=filemanager.filemanager_select.select' ; // todo compose for Draft folder
url += '&mode=select-dir' ;
url += '&method=mail.mail_ui.vfsSaveAttachment' ;
url += '&label=' + egw . lang ( 'Save all' ) ;
2014-03-03 14:10:27 +01:00
for ( var i = 0 ; i < attgrid . length ; i ++ )
2013-10-16 13:25:46 +02:00
{
if ( attgrid [ i ] != null ) url += '&id[' + i + ']=' + mailid + '::' + attgrid [ i ] . partID + '::' + attgrid [ i ] . winmailFlag + '::' + attgrid [ i ] . filename ;
}
egw _openWindowCentered ( url , windowName , width , height ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* Save a message to filemanager
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _save2fm : function ( _action , _elems )
{
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
var _id = _elems [ 0 ] . id ;
var dataElem = egw . dataGetUIDdata ( _id ) ;
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=filemanager.filemanager_select.select' ; // todo compose for Draft folder
url += '&mode=saveas' ;
2015-01-08 18:06:56 +01:00
var subject = dataElem ? dataElem . data . subject : _elems [ 0 ] . subject ;
var filename = subject . replace ( /[\f\n\t\v/\\:*#?<>\|]/g , "_" ) || 'unknown' ;
2013-04-13 12:30:07 +02:00
url += '&name=' + encodeURIComponent ( filename + '.eml' ) ;
url += '&mime=message' + encodeURIComponent ( '/' ) + 'rfc822' ;
2014-05-16 17:39:05 +02:00
url += '&method=mail.mail_ui.vfsSaveMessage' ;
2013-04-13 12:30:07 +02:00
url += '&id=' + _elems [ 0 ] . id ;
url += '&label=Save' ;
2015-01-09 10:08:17 +01:00
egw _openWindowCentered ( url , 'vfs_save_message_' + _elems [ 0 ] . id , '680' , '400' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* Save message as InfoLog
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _infolog : function ( _action , _elems )
2013-02-19 17:30:59 +01:00
{
2014-10-16 11:50:16 +02:00
//define/preset w_h in case something fails
var reg = '750x580' ;
var w _h = reg . split ( 'x' ) ;
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
if ( typeof _action . data . width == 'undefined' && typeof _action . data . height == 'undefined' && ! ( typeof _action . data . event == 'undefined' && typeof _action . data . event . popup == 'undefined' ) )
{
if ( _action . data . event . popup )
{
var app _registry = _action . data . event . popup ;
}
else
{
var app _registry = egw . link _get _registry ( 'infolog' ) ; //this.appname);
}
if ( typeof app _registry [ 'edit' ] != 'undefined' && typeof app _registry [ 'edit_popup' ] != 'undefined' )
{
2014-10-16 11:50:16 +02:00
w _h = app _registry [ 'edit_popup' ] . split ( 'x' ) ;
2013-10-14 15:30:04 +02:00
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=infolog.infolog_ui.import_mail' ; // todo compose for Draft folder
url += '&rowid=' + _elems [ 0 ] . id ;
2013-10-14 15:30:04 +02:00
egw _openWindowCentered ( url , 'import_mail_' + _elems [ 0 ] . id , ( _action . data . width ? _action . data . width : w _h [ 0 ] ) , ( _action . data . height ? _action . data . height : w _h [ 1 ] ) ) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* Save message as ticket
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* /
mail _tracker : function ( _action , _elems )
{
2014-10-16 11:50:16 +02:00
//define/preset w_h in case something fails
var reg = '780x535' ;
var w _h = reg . split ( 'x' ) ;
2014-03-07 11:06:04 +01:00
if ( typeof _elems == 'undefined' || _elems . length == 0 )
2013-10-05 11:03:51 +02:00
{
if ( this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) )
{
var _elems = [ ] ;
_elems . push ( { id : this . et2 . getArrayMgr ( "content" ) . getEntry ( 'mail_id' ) || '' } ) ;
}
2014-03-07 11:06:04 +01:00
if ( ( typeof _elems == 'undefined' || _elems . length == 0 ) && this . mail _isMainWindow )
2013-10-14 15:30:04 +02:00
{
if ( this . mail _currentlyFocussed )
{
var _elems = [ ] ;
_elems . push ( { id : this . mail _currentlyFocussed } ) ;
}
}
if ( typeof _action . data . width == 'undefined' && typeof _action . data . height == 'undefined' && ! ( typeof _action . data . event == 'undefined' && typeof _action . data . event . popup == 'undefined' ) )
{
if ( _action . data . event . popup )
{
var app _registry = _action . data . event . popup ;
}
else
{
2014-05-19 14:29:26 +02:00
var app _registry = egw . link _get _registry ( 'tracker' ) ; //this.appname);
2013-10-14 15:30:04 +02:00
}
2014-05-19 14:29:26 +02:00
if ( typeof app _registry [ 'add' ] != 'undefined' && typeof app _registry [ 'add_popup' ] != 'undefined' )
2013-10-14 15:30:04 +02:00
{
2014-10-16 11:50:16 +02:00
w _h = app _registry [ 'add_popup' ] . split ( 'x' ) ;
2013-10-14 15:30:04 +02:00
}
}
2013-10-05 11:03:51 +02:00
}
2013-04-13 12:30:07 +02:00
//alert('mail_tracker('+_elems[0].id+')');
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=tracker.tracker_ui.import_mail' ; // todo compose for Draft folder
url += '&rowid=' + _elems [ 0 ] . id ;
2013-10-14 15:30:04 +02:00
egw _openWindowCentered ( url , 'import_tracker_' + _elems [ 0 ] . id , ( _action . data . width ? _action . data . width : w _h [ 0 ] ) , ( _action . data . height ? _action . data . height : w _h [ 1 ] ) ) ;
2013-04-13 12:30:07 +02:00
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _getFormData
2013-07-25 17:35:44 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _actionObjects the senders
2014-05-20 17:39:20 +02:00
*
2013-04-13 12:30:07 +02:00
* @ return structured array of message ids : array ( msg => message - ids )
* /
mail _getFormData : function ( _actionObjects ) {
var messages = { } ;
2014-02-05 13:23:04 +01:00
// if
2014-01-27 13:18:16 +01:00
if ( typeof _actionObjects [ 'msg' ] != 'undefined' && _actionObjects [ 'msg' ] . length > 0 ) return _actionObjects ;
2013-04-13 12:30:07 +02:00
if ( _actionObjects . length > 0 )
2013-02-19 17:30:59 +01:00
{
2013-04-13 12:30:07 +02:00
messages [ 'msg' ] = [ ] ;
2013-02-19 17:30:59 +01:00
}
2013-07-25 17:35:44 +02:00
2013-04-30 16:16:52 +02:00
for ( var i = 0 ; i < _actionObjects . length ; i ++ )
2013-02-28 10:28:08 +01:00
{
2013-04-13 12:30:07 +02:00
if ( _actionObjects [ i ] . id . length > 0 )
{
messages [ 'msg' ] [ i ] = _actionObjects [ i ] . id ;
}
2013-02-28 10:28:08 +01:00
}
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
return messages ;
} ,
2013-07-25 17:35:44 +02:00
2013-04-13 12:30:07 +02:00
/ * *
* mail _setRowClass
2013-07-25 17:35:44 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { object } _actionObjects the senders
* @ param { string } _class
2013-04-13 12:30:07 +02:00
* /
mail _setRowClass : function ( _actionObjects , _class ) {
if ( typeof _class == 'undefined' ) return false ;
2013-07-25 17:35:44 +02:00
2013-12-06 11:35:39 +01:00
if ( typeof _actionObjects [ 'msg' ] == 'undefined' )
2013-04-13 12:30:07 +02:00
{
2013-12-06 11:35:39 +01:00
for ( var i = 0 ; i < _actionObjects . length ; i ++ )
{
2014-11-17 21:37:17 +01:00
// Check that the ID & interface is there. Paste is missing iface.
if ( _actionObjects [ i ] . id . length > 0 && _actionObjects [ i ] . iface )
2013-12-06 11:35:39 +01:00
{
var dataElem = $j ( _actionObjects [ i ] . iface . getDOMNode ( ) ) ;
dataElem . addClass ( _class ) ;
}
}
}
else
{
for ( var i = 0 ; i < _actionObjects [ 'msg' ] . length ; i ++ )
2013-04-13 12:30:07 +02:00
{
2014-01-13 15:22:58 +01:00
var mail _uid = _actionObjects [ 'msg' ] [ i ] ;
2013-07-25 17:35:44 +02:00
2014-01-13 15:22:58 +01:00
// Get the record from data cache
var dataElem = egw . dataGetUIDdata ( mail _uid ) ;
if ( dataElem == null || typeof dataElem == undefined )
{
// Unknown ID, nothing to update
return ;
2013-12-06 11:35:39 +01:00
}
2014-01-13 15:22:58 +01:00
// Update class
2014-12-11 13:01:52 +01:00
dataElem . data [ 'class' ] += ' ' + _class ;
2014-01-13 15:22:58 +01:00
2014-09-03 12:34:14 +02:00
// need to update flags too
switch ( _class )
{
case 'unseen' :
delete dataElem . data . flags . read ;
break ;
}
2014-01-13 15:22:58 +01:00
// Update record, which updates all listeners (including nextmatch)
egw . dataStoreUID ( mail _uid , dataElem . data ) ;
2013-04-13 12:30:07 +02:00
}
}
} ,
2013-07-25 17:35:44 +02:00
2013-05-27 15:48:55 +02:00
/ * *
2014-01-13 15:22:58 +01:00
* mail _removeRowFlag
* Removes a flag and updates the CSS class . Updates the UI , but not the server .
2013-07-25 17:35:44 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { action object } _actionObjects the senders , or a messages object
* @ param { string } _class the class to be removed
2013-05-27 15:48:55 +02:00
* /
mail _removeRowClass : function ( _actionObjects , _class ) {
if ( typeof _class == 'undefined' ) return false ;
if ( typeof _actionObjects [ 'msg' ] == 'undefined' )
{
2013-07-25 17:35:44 +02:00
for ( var i = 0 ; i < _actionObjects . length ; i ++ )
2013-05-27 15:48:55 +02:00
{
if ( _actionObjects [ i ] . id . length > 0 )
{
var dataElem = $j ( _actionObjects [ i ] . iface . getDOMNode ( ) ) ;
dataElem . removeClass ( _class ) ;
2013-07-25 17:35:44 +02:00
2013-05-27 15:48:55 +02:00
}
}
}
else
{
2013-07-25 17:35:44 +02:00
for ( var i = 0 ; i < _actionObjects [ 'msg' ] . length ; i ++ )
2013-05-27 15:48:55 +02:00
{
2014-01-13 15:22:58 +01:00
var mail _uid = _actionObjects [ 'msg' ] [ i ] ;
// Get the record from data cache
var dataElem = egw . dataGetUIDdata ( mail _uid ) ;
if ( dataElem == null || typeof dataElem == undefined )
2013-05-27 15:48:55 +02:00
{
2014-01-13 15:22:58 +01:00
// Unknown ID, nothing to update
return ;
}
2013-07-25 17:35:44 +02:00
2014-01-13 15:22:58 +01:00
// Update class
2014-12-11 13:01:52 +01:00
var classes = dataElem . data [ 'class' ] || "" ;
2014-01-13 15:22:58 +01:00
classes = classes . split ( ' ' ) ;
if ( classes . indexOf ( _class ) >= 0 )
{
classes . splice ( classes . indexOf ( _class ) , 1 ) ;
2014-12-11 13:01:52 +01:00
dataElem . data [ 'class' ] = classes . join ( ' ' ) ;
2014-01-13 15:22:58 +01:00
2014-09-03 12:34:14 +02:00
// need to update flags too
switch ( _class )
{
case 'unseen' :
dataElem . data . flags . read = true ;
break ;
}
2014-01-13 15:22:58 +01:00
// Update record, which updates all listeners (including nextmatch)
egw . dataStoreUID ( mail _uid , dataElem . data ) ;
2013-07-25 17:35:44 +02:00
}
2013-05-27 15:48:55 +02:00
}
}
} ,
2014-05-20 12:02:21 +02:00
/ * *
* mail _move2folder - implementation of the move action from action menu
*
2014-07-14 17:56:34 +02:00
* @ param _action _action . id holds folder target information
2014-05-20 12:02:21 +02:00
* @ param _elems - the representation of the elements to be affected
* /
mail _move2folder : function ( _action , _elems ) {
this . mail _move ( _action , _elems , null ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _move - implementation of the move action from drag n drop
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _senders - the representation of the elements dragged
* @ param _target - the representation of the target
* /
mail _move : function ( _action , _senders , _target ) {
2014-06-26 17:05:04 +02:00
this . mail _checkAllSelected ( _action , _senders , _target , true ) ;
} ,
/ * *
* mail _move - implementation of the move action from drag n drop
*
* @ param _action
* @ param _senders - the representation of the elements dragged
* @ param _target - the representation of the target
* @ param _allMessagesChecked
* /
mail _callMove : function ( _action , _senders , _target , _allMessagesChecked ) {
2013-04-13 12:30:07 +02:00
var target = _action . id == 'drop_move_mail' ? _target . iface . id : _action . id . substr ( 5 ) ;
var messages = this . mail _getFormData ( _senders ) ;
2014-06-26 17:05:04 +02:00
if ( typeof _allMessagesChecked == 'undefined' ) _allMessagesChecked = false ;
2014-08-18 22:53:23 +02:00
// Directly delete any cache for target
if ( window . localStorage )
{
for ( var i = 0 ; i < window . localStorage . length ; i ++ )
{
var key = window . localStorage . key ( i ) ;
// Find directly by what the key would look like
2014-08-19 15:54:04 +02:00
if ( key . indexOf ( 'cached_fetch_mail::{"selectedFolder":"' + target + '"' ) == 0 )
2014-08-18 22:53:23 +02:00
{
window . localStorage . removeItem ( key ) ;
}
}
}
2013-04-13 12:30:07 +02:00
// TODO: Write move/copy function which cares about doing the same stuff
// as the "onNodeSelect" function!
2014-07-01 17:22:18 +02:00
messages [ 'all' ] = _allMessagesChecked ;
2014-06-26 17:05:04 +02:00
if ( messages [ 'all' ] == 'cancel' ) return false ;
2014-06-20 14:05:03 +02:00
if ( messages [ 'all' ] ) messages [ 'activeFilters' ] = this . mail _getActiveFilters ( _action ) ;
2014-10-20 20:08:03 +02:00
// Make sure a default target folder is set in case of drop target is parent 0 (mail account name)
2014-10-14 10:01:52 +02:00
if ( ! target . match ( /::/g ) ) target += '::INBOX' ;
2014-10-20 20:08:03 +02:00
2014-07-14 17:56:34 +02:00
var self = this ;
2013-10-18 11:58:25 +02:00
var nm = this . et2 . getWidgetById ( this . nm _index ) ;
2014-11-17 18:19:51 +01:00
egw . json ( 'mail.mail_ui.ajax_copyMessages' , [ target , messages , 'move' ] , function ( ) {
self . unlock _tree ( ) ;
// Nextmatch automatically selects the next row and calls preview.
// Unselect it and thanks to the timeout selectionMgr uses, preview
// will close when the selection callback fires instead of load the
// next message
nm . controller . _selectionMgr . resetSelection ( ) ;
2014-12-15 18:26:04 +01:00
// Server response may contain refresh, but it's always delete
// Refresh list if current view is the target (happens when pasting)
var tree = self . et2 . getWidgetById ( 'nm[foldertree]' ) ;
if ( nm && tree && target == tree . getValue ( ) )
{
// Can't trust the sorting, needs to be full refresh
nm . refresh ( ) ;
}
2014-11-17 18:19:51 +01:00
} )
. sendRequest ( ) ;
2013-06-04 17:29:53 +02:00
this . mail _setRowClass ( _senders , 'deleted' ) ;
2014-12-15 18:26:04 +01:00
// Server response may contain refresh, not needed here
2013-04-13 12:30:07 +02:00
} ,
2014-03-10 12:13:51 +01:00
2013-04-13 12:30:07 +02:00
/ * *
2014-06-26 17:05:04 +02:00
* mail _copy - implementation of the move action from drag n drop
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _senders - the representation of the elements dragged
* @ param _target - the representation of the target
* /
mail _copy : function ( _action , _senders , _target ) {
2014-06-26 17:05:04 +02:00
this . mail _checkAllSelected ( _action , _senders , _target , true ) ;
} ,
/ * *
* mail _callCopy - implementation of the copy action from drag n drop
*
* @ param _action
* @ param _senders - the representation of the elements dragged
* @ param _target - the representation of the target
* @ param _allMessagesChecked
* /
mail _callCopy : function ( _action , _senders , _target , _allMessagesChecked ) {
2013-04-29 16:56:33 +02:00
var target = _action . id == 'drop_copy_mail' ? _target . iface . id : _action . id . substr ( 5 ) ;
2013-04-13 12:30:07 +02:00
var messages = this . mail _getFormData ( _senders ) ;
2014-06-26 17:05:04 +02:00
if ( typeof _allMessagesChecked == 'undefined' ) _allMessagesChecked = false ;
2013-04-13 12:30:07 +02:00
// TODO: Write move/copy function which cares about doing the same stuff
// as the "onNodeSelect" function!
2014-07-01 17:22:18 +02:00
messages [ 'all' ] = _allMessagesChecked ;
2014-06-26 17:05:04 +02:00
if ( messages [ 'all' ] == 'cancel' ) return false ;
2014-06-20 14:05:03 +02:00
if ( messages [ 'all' ] ) messages [ 'activeFilters' ] = this . mail _getActiveFilters ( _action ) ;
2014-07-14 17:56:34 +02:00
var self = this ;
egw . json ( 'mail.mail_ui.ajax_copyMessages' , [ target , messages ] , function ( ) { self . unlock _tree ( ) ; } )
2014-07-15 11:37:08 +02:00
. sendRequest ( ) ;
2014-02-27 01:22:25 +01:00
// Server response contains refresh
2013-04-13 12:30:07 +02:00
} ,
2013-05-21 10:46:54 +02:00
/ * *
* mail _AddFolder - implementation of the AddFolder action of right click options on the tree
2013-07-25 17:35:44 +02:00
*
2013-05-21 10:46:54 +02:00
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
2014-02-12 21:12:59 +01:00
mail _AddFolder : function ( _action , _senders ) {
2013-05-21 10:46:54 +02:00
//action.id == 'add'
//_senders.iface.id == target leaf / leaf to edit
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-03-03 14:10:27 +01:00
var OldFolderName = ftree . getLabel ( _senders [ 0 ] . id ) . replace ( this . _unseen _regexp , '' ) ;
2013-12-12 16:44:47 +01:00
var buttons = [
2014-12-11 13:01:52 +01:00
{ text : this . egw . lang ( "Add" ) , id : "add" , "class" : "ui-priority-primary" , "default" : true } ,
2014-02-12 21:12:59 +01:00
{ text : this . egw . lang ( "Cancel" ) , id : "cancel" }
2013-12-12 16:44:47 +01:00
] ;
2014-02-12 21:12:59 +01:00
et2 _dialog . show _prompt ( function ( _button _id , _value ) {
2013-12-12 16:44:47 +01:00
var NewFolderName = null ;
if ( _value . length > 0 ) NewFolderName = _value ;
//alert(NewFolderName);
if ( NewFolderName && NewFolderName . length > 0 )
{
switch ( _button _id )
{
case "add" :
2014-02-12 21:12:59 +01:00
egw . json ( 'mail.mail_ui.ajax_addFolder' , [ _senders [ 0 ] . id , NewFolderName ] )
2013-12-12 16:44:47 +01:00
. sendRequest ( true ) ;
return ;
case "cancel" :
}
}
} ,
this . egw . lang ( "Enter the name for the new Folder:" ) ,
this . egw . lang ( "Add a new Folder to %1:" , OldFolderName ) ,
'' , buttons ) ;
2013-05-21 10:46:54 +02:00
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _RenameFolder - implementation of the RenameFolder action of right click options on the tree
2013-07-25 17:35:44 +02:00
*
2013-04-13 12:30:07 +02:00
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
2014-02-12 21:12:59 +01:00
mail _RenameFolder : function ( _action , _senders ) {
2013-04-13 12:30:07 +02:00
//action.id == 'rename'
//_senders.iface.id == target leaf / leaf to edit
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-03-03 14:10:27 +01:00
var OldFolderName = ftree . getLabel ( _senders [ 0 ] . id ) . replace ( this . _unseen _regexp , '' ) ;
2013-12-12 16:10:25 +01:00
var buttons = [
2014-12-11 13:01:52 +01:00
{ text : this . egw . lang ( "Rename" ) , id : "rename" , "class" : "ui-priority-primary" , image : 'edit' , "default" : true } ,
2014-02-12 21:12:59 +01:00
{ text : this . egw . lang ( "Cancel" ) , id : "cancel" }
2013-12-12 16:10:25 +01:00
] ;
2014-02-12 21:12:59 +01:00
et2 _dialog . show _prompt ( function ( _button _id , _value ) {
2013-12-12 16:10:25 +01:00
var NewFolderName = null ;
if ( _value . length > 0 ) NewFolderName = _value ;
//alert(NewFolderName);
if ( NewFolderName && NewFolderName . length > 0 )
{
switch ( _button _id )
{
case "rename" :
2014-02-12 21:12:59 +01:00
egw . json ( 'mail.mail_ui.ajax_renameFolder' , [ _senders [ 0 ] . id , NewFolderName ] )
2013-12-12 16:10:25 +01:00
. sendRequest ( true ) ;
return ;
case "cancel" :
}
}
} ,
this . egw . lang ( "Rename Folder %1 to:" , OldFolderName ) ,
this . egw . lang ( "Rename Folder %1 ?" , OldFolderName ) ,
OldFolderName , buttons ) ;
2013-05-13 16:42:42 +02:00
} ,
2014-01-06 10:51:24 +01:00
/ * *
2014-01-11 12:58:31 +01:00
* mail _MoveFolder - implementation of the MoveFolder action on the tree
2014-01-06 10:51:24 +01:00
*
2014-01-11 12:58:31 +01:00
* @ param { egwAction } _action
* @ param { egwActionObject [ ] } _senders - the representation of the tree leaf to be manipulated
* @ param { egwActionObject } destination Drop target egwActionObject representing the destination
2014-01-06 10:51:24 +01:00
* /
2014-01-11 12:58:31 +01:00
mail _MoveFolder : function ( _action , _senders , destination ) {
if ( ! destination || ! destination . id )
{
egw . debug ( 'warn' , "Move folder, but no target" ) ;
return ;
}
2014-01-11 13:51:45 +01:00
// Some UI feedback while the folder is moved - using just the iface DOMNode would
// put the load image in every row
var load _node = $j ( destination . iface . getDOMNode ( ) ) . closest ( 'td' ) . prev ( )
. addClass ( 'loading' ) ;
2014-01-06 10:51:24 +01:00
2014-01-11 12:58:31 +01:00
for ( var i = 0 ; i < _senders . length ; i ++ )
{
2014-02-12 21:12:59 +01:00
egw . jsonq ( 'mail.mail_ui.ajax_MoveFolder' , [ _senders [ i ] . id , destination . id ] ,
2014-01-11 12:58:31 +01:00
// Move is done (successfully or not), remove loading
2014-01-11 13:51:45 +01:00
function ( ) { load _node . removeClass ( 'loading' ) ; }
2014-01-11 12:58:31 +01:00
) ;
}
2014-01-06 10:51:24 +01:00
} ,
2013-05-13 16:42:42 +02:00
/ * *
* mail _DeleteFolder - implementation of the DeleteFolder action of right click options on the tree
2013-07-25 17:35:44 +02:00
*
2013-05-13 16:42:42 +02:00
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
2014-02-12 21:12:59 +01:00
mail _DeleteFolder : function ( _action , _senders ) {
2013-05-13 16:42:42 +02:00
//action.id == 'delete'
//_senders.iface.id == target leaf / leaf to edit
2013-10-18 11:58:25 +02:00
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-03-03 14:10:27 +01:00
var OldFolderName = ftree . getLabel ( _senders [ 0 ] . id ) . replace ( this . _unseen _regexp , '' ) ;
2013-12-12 14:34:35 +01:00
var buttons = [
2014-12-11 13:01:52 +01:00
{ text : this . egw . lang ( "Yes" ) , id : "delete" , "class" : "ui-priority-primary" , "default" : true } ,
2014-02-12 21:12:59 +01:00
{ text : this . egw . lang ( "Cancel" ) , id : "cancel" }
2013-12-12 14:34:35 +01:00
] ;
2014-02-12 21:12:59 +01:00
et2 _dialog . show _dialog ( function ( _button _id , _value ) {
2013-12-12 14:34:35 +01:00
switch ( _button _id )
{
case "delete" :
2014-02-12 21:12:59 +01:00
egw . json ( 'mail.mail_ui.ajax_deleteFolder' , [ _senders [ 0 ] . id ] )
2013-12-12 14:34:35 +01:00
. sendRequest ( true ) ;
return ;
case "cancel" :
}
} ,
2014-02-12 21:12:59 +01:00
this . egw . lang ( "Do you really want to DELETE Folder %1 ?" , OldFolderName ) + " " + ( ftree . hasChildren ( _senders [ 0 ] . id ) ? this . egw . lang ( "All subfolders will be deleted too, and all messages in all affected folders will be lost" ) : this . egw . lang ( "All messages in the folder will be lost" ) ) ,
2013-12-12 14:34:35 +01:00
this . egw . lang ( "DELETE Folder %1 ?" , OldFolderName ) ,
OldFolderName , buttons ) ;
2013-07-25 17:35:44 +02:00
} ,
2013-09-02 17:15:35 +02:00
/ * *
* Send names of uploaded files ( again ) to server , to process them : either copy to vfs or ask overwrite / rename
2013-10-09 18:44:03 +02:00
*
2013-09-02 17:15:35 +02:00
* @ param _event
* @ param _file _count
2014-02-12 21:12:59 +01:00
* @ param { string ? } _path where the file is uploaded to , default current directory
2013-09-02 17:15:35 +02:00
* /
uploadForImport : function ( _event , _file _count , _path )
{
2013-09-05 16:52:11 +02:00
// path is probably not needed when uploading for file; maybe it is when from vfs
2013-09-02 17:15:35 +02:00
if ( typeof _path == 'undefined' )
{
//_path = this.get_path();
}
if ( _file _count && ! jQuery . isEmptyObject ( _event . data . getValue ( ) ) )
{
2013-09-05 16:52:11 +02:00
var widget = _event . data ;
// var request = new egw_json_request('mail_ui::ajax_importMessage', ['upload', widget.getValue(), _path], this);
2013-09-02 17:15:35 +02:00
// widget.set_value('');
2013-09-05 16:52:11 +02:00
// request.sendRequest();//false, this._upload_callback, this);
2013-09-10 15:39:44 +02:00
this . et2 _obj . submit ( ) ;
}
} ,
/ * *
* Send names of uploaded files ( again ) to server , to process them : either copy to vfs or ask overwrite / rename
2013-10-09 18:44:03 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { event object } _event
* @ param { string } _file _count
* @ param { string } _path [ _path = current directory ] Where the file is uploaded to .
2013-09-10 15:39:44 +02:00
* /
uploadForCompose : function ( _event , _file _count , _path )
{
// path is probably not needed when uploading for file; maybe it is when from vfs
if ( typeof _path == 'undefined' )
{
//_path = this.get_path();
}
if ( _file _count && ! jQuery . isEmptyObject ( _event . data . getValue ( ) ) )
{
var widget = _event . data ;
2013-09-11 15:46:00 +02:00
this . et2 _obj . submit ( ) ;
2013-09-02 17:15:35 +02:00
}
} ,
2014-09-03 14:42:34 +02:00
/ * *
* Visible attachment box in compose dialog as soon as the file starts to upload
* /
composeUploadStart : function ( )
{
2014-09-04 11:01:43 +02:00
var boxAttachment = this . et2 . getWidgetById ( 'attachments' ) ;
2014-09-03 14:42:34 +02:00
if ( boxAttachment )
{
var groupbox = boxAttachment . getParent ( ) ;
if ( groupbox ) groupbox . set _disabled ( false ) ;
}
2014-09-03 17:48:57 +02:00
//Resize the compose dialog
2014-12-09 09:56:45 +01:00
var self = this ;
setTimeout ( function ( ) { self . compose _resizeHandler ( ) ; } , 100 ) ;
2014-09-03 14:42:34 +02:00
return true ;
} ,
2014-09-08 17:45:37 +02:00
2014-05-16 17:39:05 +02:00
/ * *
* Upload for import ( VFS )
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { egw object } _egw
* @ param { widget object } _widget
* @ param { window object } _window
* /
2013-10-03 18:09:25 +02:00
vfsUploadForImport : function ( _egw , _widget , _window ) {
2013-11-22 14:55:09 +01:00
if ( jQuery . isEmptyObject ( _widget ) ) return ;
2013-10-03 18:09:25 +02:00
if ( ! jQuery . isEmptyObject ( _widget . getValue ( ) ) )
{
this . et2 _obj . submit ( ) ;
}
} ,
2014-05-16 17:39:05 +02:00
/ * *
* Upload for compose ( VFS )
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { egw object } _egw
* @ param { widget object } _widget
* @ param { window object } _window
* /
2013-10-02 16:50:24 +02:00
vfsUploadForCompose : function ( _egw , _widget , _window )
{
2013-11-22 14:55:09 +01:00
if ( jQuery . isEmptyObject ( _widget ) ) return ;
2013-10-04 13:17:45 +02:00
if ( ! jQuery . isEmptyObject ( _widget . getValue ( ) ) )
{
this . et2 _obj . submit ( ) ;
}
} ,
2014-05-16 17:39:05 +02:00
/ * *
* Submit on change ( VFS )
2014-05-20 17:39:20 +02:00
*
2014-05-16 17:39:05 +02:00
* @ param { egw object } _egw
* @ param { widget object } _widget
* /
2014-08-13 14:55:28 +02:00
submitOnChange : function ( _egw , _widget )
{
2013-11-22 14:55:09 +01:00
if ( ! jQuery . isEmptyObject ( _widget ) )
2013-10-02 16:50:24 +02:00
{
2014-08-13 14:55:28 +02:00
if ( typeof _widget . id !== 'undefined' ) var widgetId = _widget . id ;
switch ( widgetId )
2013-11-22 14:55:09 +01:00
{
2014-08-13 14:55:28 +02:00
case 'mimeType' :
this . et2 _obj . submit ( ) ;
break ;
default :
if ( ! jQuery . isEmptyObject ( _widget . getValue ( ) ) )
{
this . et2 _obj . submit ( ) ;
}
2013-11-22 14:55:09 +01:00
}
2013-10-02 16:50:24 +02:00
}
} ,
2014-09-23 10:42:31 +02:00
2014-05-16 17:39:05 +02:00
/ * *
2014-09-12 13:52:38 +02:00
* Save as Draft ( VFS )
* - handel both actions save as draft and save as draft and print
2014-09-23 10:42:31 +02:00
*
2014-09-12 13:52:38 +02:00
* @ param { egw object } _egw
* @ param { widget object } _widget
* @ param { string } _action autosaving trigger action
* /
2015-01-07 12:57:34 +01:00
saveAsDraft : function ( _egw _action , _action )
2013-10-02 16:50:24 +02:00
{
2014-09-12 13:52:38 +02:00
//this.et2_obj.submit();
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
2015-01-07 12:57:34 +01:00
if ( _egw _action )
2014-09-12 13:52:38 +02:00
{
2015-01-07 12:57:34 +01:00
var action = _action == 'autosaving' ? _action : _egw _action . id ;
2014-09-12 13:52:38 +02:00
}
2014-09-23 10:42:31 +02:00
2014-09-12 13:52:38 +02:00
var widgets = [ 'from' , 'to' , 'cc' , 'bcc' , 'subject' , 'folder' , 'replyto' , 'mailaccount' , 'mail_htmltext' , 'mail_plaintext' , 'lastDrafted' ] ;
var widget = { } ;
for ( var index in widgets )
{
widget = this . et2 . getWidgetById ( widgets [ index ] ) ;
if ( widget )
{
content [ widgets [ index ] ] = widget . get _value ( ) ;
}
}
var self = this ;
2014-09-23 10:42:31 +02:00
if ( content )
{
2014-09-12 13:52:38 +02:00
this . egw . json ( 'mail.mail_compose.ajax_saveAsDraft' , [ content ] , function ( _data ) {
self . savingDraft _response ( _data , action ) ;
} ) . sendRequest ( true ) ;
}
} ,
/ * *
* Set content of drafted message with new information sent back from server
* This function would be used as callback of send request to ajax _saveAsDraft .
2014-09-23 10:42:31 +02:00
*
2014-09-12 13:52:38 +02:00
* @ param { object } _responseData response data sent back from server by ajax _saveAsDraft function .
* the object conatins below items :
* - draftedId : new drafted id created by server
* - message : resault message
* - success : true if saving was successful otherwise false
2014-09-22 11:07:48 +02:00
* - draftfolder : Name of draft folder including its delimiter
2014-09-23 10:42:31 +02:00
*
2014-09-12 13:52:38 +02:00
* @ param { string } _action action is the element which caused saving draft , it could be as such :
* - button [ saveAsDraft ]
* - button [ saveAsDraftAndPrint ]
* - autosaving
* /
savingDraft _response : function ( _responseData , _action )
2013-10-07 17:02:35 +02:00
{
2014-09-12 13:52:38 +02:00
//Make sure there's a response from server otherwise shoot an error message
if ( jQuery . isEmptyObject ( _responseData ) )
{
2014-09-22 11:07:48 +02:00
this . egw . message ( 'Could not saved the message. Because, the response from server failed.' , 'error' ) ;
2014-09-12 13:52:38 +02:00
return false ;
}
2014-09-23 10:42:31 +02:00
2014-09-12 13:52:38 +02:00
if ( _responseData . success )
{
var content = this . et2 . getArrayMgr ( 'content' ) ;
var lastDrafted = this . et2 . getWidgetById ( 'lastDrafted' ) ;
2014-10-06 11:57:50 +02:00
var folderTree = typeof opener . etemplate2 . getByApplication ( 'mail' ) [ 0 ] != 'undefined' ?
2014-09-23 14:19:28 +02:00
opener . etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) : null ;
2014-09-22 11:07:48 +02:00
var activeFolder = folderTree ? folderTree . getSelectedNode ( ) : null ;
2014-09-12 13:52:38 +02:00
if ( content )
{
var prevDraftedId = content . data . lastDrafted ;
content . data . lastDrafted = _responseData . draftedId ;
this . et2 . setArrayMgr ( 'content' , content ) ;
lastDrafted . set _value ( _responseData . draftedId ) ;
2014-09-23 14:19:28 +02:00
if ( folderTree && activeFolder )
2014-09-12 13:52:38 +02:00
{
2014-09-23 14:19:28 +02:00
if ( typeof activeFolder . id != 'undefined' && _responseData . draftfolder == activeFolder . id )
2014-09-22 11:07:48 +02:00
{
2014-09-23 14:19:28 +02:00
if ( prevDraftedId )
{
opener . egw _refresh ( _responseData . message , 'mail' , prevDraftedId , 'delete' ) ;
}
this . egw . refresh ( _responseData . message , 'mail' , _responseData . draftedId ) ;
2014-09-22 11:07:48 +02:00
}
2014-10-06 11:57:50 +02:00
}
2014-09-12 13:52:38 +02:00
switch ( _action )
{
case 'button[saveAsDraftAndPrint]' :
this . mail _compose _print ( 'mail::' + _responseData . draftedId ) ;
2014-09-22 10:12:54 +02:00
this . egw . message ( _responseData . message ) ;
2014-09-12 13:52:38 +02:00
break ;
case 'autosaving' :
//Any sort of thing if it's an autosaving action
default :
2014-09-22 10:12:54 +02:00
this . egw . message ( _responseData . message ) ;
2014-09-12 13:52:38 +02:00
}
}
}
else
{
this . egw . message ( _responseData . message , 'error' ) ;
}
2013-10-07 17:02:35 +02:00
} ,
2014-09-23 10:42:31 +02:00
2013-10-09 19:29:36 +02:00
/ * *
* Focus handler for folder , address , reject textbox / taglist to automatic check associated radio button
2014-02-27 18:47:06 +01:00
*
* @ param { event } _ev
2014-02-13 18:06:16 +01:00
* @ param { object } _widget taglist
2014-02-27 18:47:06 +01:00
*
2013-10-09 19:29:36 +02:00
* /
sieve _focus _radioBtn : function ( _ev , _widget )
2013-08-09 19:47:53 +02:00
{
2013-10-09 19:29:36 +02:00
_widget . getRoot ( ) . getWidgetById ( 'action' ) . set _value ( _widget . id . replace ( /^action_([^_]+)_text$/ , '$1' ) ) ;
2013-08-09 19:47:53 +02:00
} ,
2013-10-09 19:29:36 +02:00
2013-08-09 19:47:53 +02:00
/ * *
2014-02-13 18:06:16 +01:00
* Select all aliases
2014-02-27 18:47:06 +01:00
*
2013-08-09 19:47:53 +02:00
* /
sieve _vac _all _aliases : function ( )
{
2014-04-25 12:38:31 +02:00
var aliases = [ ] ;
2014-08-01 15:40:45 +02:00
var tmp = [ ] ;
2013-08-09 19:47:53 +02:00
var addr = this . et2 . getWidgetById ( 'addresses' ) ;
2014-04-25 12:38:31 +02:00
var addresses = this . et2 . getArrayMgr ( 'sel_options' ) . data . addresses ;
2014-05-20 17:39:20 +02:00
2014-04-25 12:38:31 +02:00
for ( var id in addresses ) aliases . push ( id ) ;
2014-08-01 15:40:45 +02:00
if ( addr )
{
tmp = aliases . concat ( addr . get _value ( ) ) ;
2014-08-13 13:45:55 +02:00
2014-08-01 15:40:45 +02:00
// returns de-duplicate items of an array
2014-08-15 13:22:43 +02:00
var deDuplicator = function ( item , pos )
{
return tmp . indexOf ( item ) == pos ;
2014-08-01 15:40:45 +02:00
} ;
2014-08-13 13:45:55 +02:00
2014-08-01 15:40:45 +02:00
aliases = tmp . filter ( deDuplicator ) ;
addr . set _value ( aliases ) ;
}
2013-08-09 19:47:53 +02:00
} ,
2013-10-16 13:22:53 +02:00
/ * *
* Disable / Enable date widgets on vacation seive rules form when status is "by_date"
*
* /
vacationFilterStatusChange : function ( )
{
var status = this . et2 . getWidgetById ( 'status' ) ;
var s _date = this . et2 . getWidgetById ( 'start_date' ) ;
var e _date = this . et2 . getWidgetById ( 'end_date' ) ;
var by _date _label = this . et2 . getWidgetById ( 'by_date_label' ) ;
if ( status && s _date && e _date && by _date _label )
{
s _date . set _disabled ( status . get _value ( ) != "by_date" ) ;
e _date . set _disabled ( status . get _value ( ) != "by_date" ) ;
by _date _label . set _disabled ( status . get _value ( ) != "by_date" ) ;
}
} ,
2013-07-25 17:35:44 +02:00
/ * *
* action - handling actions on sieve rules
*
* @ param _type - action name
* @ param _selected - selected row from the sieve rule list
* /
action : function ( _type , _selected )
{
var actionData ;
var that = this ;
var typeId = _type . id ;
2014-02-14 10:37:59 +01:00
var linkData = '' ;
2013-07-25 17:35:44 +02:00
var ruleID = ( ( _selected [ 0 ] . id . split ( "_" ) . pop ( ) ) - 1 ) ; // subtract the row id from 1 because the first row id is reserved by grid header
if ( _type )
{
switch ( _type . id )
{
case 'delete' :
var callbackDeleteDialog = function ( button _id )
{
if ( button _id == et2 _dialog . YES _BUTTON )
{
actionData = _type . parent . data . widget . getArrayMgr ( 'content' ) ;
that . _do _action ( typeId , actionData [ 'data' ] , ruleID ) ;
}
2014-05-16 17:39:05 +02:00
} ;
2014-05-23 09:57:16 +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 _CANCEL , et2 _dialog . WARNING _MESSAGE ) ;
2013-07-25 17:35:44 +02:00
break ;
case 'add' :
2014-02-14 10:37:59 +01:00
linkData = "mail.mail_sieve.edit" ;
this . egw . open _link ( linkData , '_blank' , "600x480" ) ;
2013-07-25 17:35:44 +02:00
break ;
case 'edit' :
2014-02-14 10:37:59 +01:00
linkData = "mail.mail_sieve.edit&ruleID=" + ruleID ;
this . egw . open _link ( linkData , '_blank' , "600x480" ) ;
2013-07-25 17:35:44 +02:00
break ;
case 'enable' :
actionData = _type . parent . data . widget . getArrayMgr ( 'content' ) ;
this . _do _action ( typeId , actionData [ 'data' ] , ruleID ) ;
break ;
case 'disable' :
actionData = _type . parent . data . widget . getArrayMgr ( 'content' ) ;
this . _do _action ( typeId , actionData [ 'data' ] , ruleID ) ;
break ;
}
}
} ,
2014-02-13 18:06:16 +01:00
/ * *
2014-06-26 17:05:04 +02:00
* Send back sieve action result to server
2014-02-27 18:47:06 +01:00
*
2014-05-16 17:39:05 +02:00
* @ param { string } _typeID action name
2014-02-13 18:06:16 +01:00
* @ param { object } _data content
* @ param { string } _selectedID selected row id
* @ param { string } _msg message
2014-02-27 18:47:06 +01:00
*
2014-02-13 18:06:16 +01:00
* /
2013-08-09 19:47:53 +02:00
_do _action : function ( _typeID , _data , _selectedID , _msg )
2013-07-25 17:35:44 +02:00
{
if ( _typeID && _data )
{
2014-05-22 17:22:19 +02:00
var request = this . egw . json ( 'mail.mail_sieve.ajax_action' , [ _typeID , _selectedID , _msg ] , null , null , true ) ;
2013-08-09 19:47:53 +02:00
request . sendRequest ( ) ;
2013-07-25 17:35:44 +02:00
}
} ,
2014-02-13 18:06:16 +01:00
/ * *
2014-05-16 17:39:05 +02:00
* Send ajax request to server to refresh the sieve grid
2014-02-13 18:06:16 +01:00
* /
2014-02-13 20:00:11 +01:00
sieve _refresh : function ( )
2013-07-25 17:35:44 +02:00
{
2014-05-22 16:46:50 +02:00
this . et2 . _inst . submit ( ) ;
2013-07-25 17:35:44 +02:00
} ,
2013-08-09 19:47:53 +02:00
2013-11-29 15:59:34 +01:00
/ * *
2014-02-06 13:48:01 +01:00
* Select the right combination of the rights for radio buttons from the selected common right
*
2014-02-13 18:06:16 +01:00
* @ @ param { jQuery event } event
2014-02-06 13:48:01 +01:00
* @ param { widget } widget common right selectBox
*
* /
2014-02-13 18:06:16 +01:00
acl _common _rights _selector : function ( event , widget )
2013-11-29 15:59:34 +01:00
{
2013-12-09 12:17:32 +01:00
var rowId = widget . id . replace ( /[^0-9.]+/g , '' ) ;
2014-05-22 16:46:50 +02:00
var rights = ( widget . get _value ( ) == "custom" ? [ ] : widget . get _value ( ) == "aeiklprstwx" ) ?
widget . get _value ( ) . replace ( /[k,x,t,e]/g , "cd" ) . split ( "" ) : widget . get _value ( ) . split ( "" ) ;
2014-05-23 11:21:59 +02:00
2013-12-09 12:17:32 +01:00
for ( var i = 0 ; i < this . aclRights . length ; i ++ )
2013-11-29 15:59:34 +01:00
{
2014-02-14 10:24:52 +01:00
var rightsWidget = this . et2 . getWidgetById ( rowId + '[acl_' + this . aclRights [ i ] + ']' ) ;
2013-12-09 12:17:32 +01:00
rightsWidget . set _value ( ( jQuery . inArray ( this . aclRights [ i ] , rights ) != - 1 ) ? true : false ) ;
2013-11-29 15:59:34 +01:00
}
} ,
2013-12-09 12:17:32 +01:00
/ * *
2014-02-06 13:48:01 +01:00
*
* Choose the right common right option for common ACL selecBox
*
2014-02-13 18:06:16 +01:00
* @ param { jQuery event } event
2014-02-06 13:48:01 +01:00
* @ param { widget } widget radioButton rights
*
* /
2014-02-13 18:06:16 +01:00
acl _common _rights : function ( event , widget )
2014-02-06 13:48:01 +01:00
{
2013-12-09 12:17:32 +01:00
var rowId = widget . id . replace ( /[^0-9.]+/g , '' ) ;
var aclCommonWidget = this . et2 . getWidgetById ( rowId + '[acl]' ) ;
var rights = '' ;
2013-12-17 16:21:36 +01:00
2013-12-09 12:17:32 +01:00
for ( var i = 0 ; i < this . aclRights . length ; i ++ )
{
2014-02-14 10:24:52 +01:00
var rightsWidget = this . et2 . getWidgetById ( rowId + '[acl_' + this . aclRights [ i ] + ']' ) ;
2013-12-09 12:17:32 +01:00
if ( rightsWidget . get _value ( ) == "true" )
rights += this . aclRights [ i ] ;
}
for ( var i = 0 ; i < this . aclCommonRights . length ; i ++ )
{
if ( rights . split ( "" ) . sort ( ) . toString ( ) == this . aclCommonRights [ i ] . split ( "" ) . sort ( ) . toString ( ) )
rights = this . aclCommonRights [ i ] ;
}
2014-02-28 14:49:10 +01:00
if ( jQuery . inArray ( rights , this . aclCommonRights ) == - 1 && rights != 'lrswipcda' )
2013-12-09 12:17:32 +01:00
{
aclCommonWidget . set _value ( 'custom' ) ;
}
2014-02-28 14:49:10 +01:00
else if ( rights == 'lrswipcda' )
{
2014-02-28 16:39:46 +01:00
aclCommonWidget . set _value ( 'aeiklprstwx' ) ;
2014-02-28 14:49:10 +01:00
}
2013-12-09 12:17:32 +01:00
else
{
aclCommonWidget . set _value ( rights ) ;
}
2014-02-06 13:48:01 +01:00
} ,
/ * *
2014-02-13 20:00:11 +01:00
* Open seive filter list
2014-02-27 18:47:06 +01:00
*
2014-05-21 19:44:10 +02:00
* @ param { action } _action
* @ param { sender } _senders
2014-02-06 13:48:01 +01:00
*
* /
2014-05-21 19:44:10 +02:00
edit _sieve : function ( _action , _senders )
2014-02-06 13:48:01 +01:00
{
2014-05-21 19:44:10 +02:00
var acc _id = parseInt ( _senders [ 0 ] . id ) ;
2014-05-23 11:21:59 +02:00
2014-05-22 16:46:50 +02:00
var url = this . egw . link ( '/index.php' , {
'menuaction' : 'mail.mail_sieve.index' ,
'acc_id' : acc _id ,
'ajax' : 'true'
} ) ;
2014-05-23 11:21:59 +02:00
2014-05-22 16:46:50 +02:00
if ( ! this . loadIframe ( url ) )
{
this . egw . open _link ( url ) ;
}
} ,
2014-05-23 11:21:59 +02:00
2014-05-22 16:46:50 +02:00
/ * *
* Load an url on an iframe
*
2014-05-23 11:21:59 +02:00
* @ param { string } _url string egw url
2014-05-22 16:46:50 +02:00
* @ param { iframe widget } _iFrame an iframe to be set if non , extra _iframe is default
*
2014-05-23 11:21:59 +02:00
* @ return { boolean } return TRUE if success , and FALSE if iframe not given
2014-05-22 16:46:50 +02:00
* /
loadIframe : function ( _url , _iFrame )
{
var mailSplitter = this . et2 . getWidgetById ( 'mailSplitter' ) ;
var quotaipercent = this . et2 . getWidgetById ( 'nm[quotainpercent]' ) ;
var iframe = _iFrame || this . et2 . getWidgetById ( 'extra_iframe' ) ;
if ( typeof iframe != 'undefined' )
{
if ( _url )
2014-05-21 19:44:10 +02:00
{
2014-05-22 16:46:50 +02:00
iframe . set _src ( _url ) ;
}
if ( typeof mailSplitter != 'undefined' && typeof quotaipercent != 'undefined' )
{
mailSplitter . set _disabled ( ! ! _url ) ;
quotaipercent . set _disabled ( ! ! _url ) ;
iframe . set _disabled ( ! _url ) ;
}
return true ;
}
return false ;
2014-02-06 13:48:01 +01:00
} ,
2013-12-17 18:06:44 +01:00
2014-02-06 13:48:01 +01:00
/ * *
2014-05-20 17:39:20 +02:00
* Edit vacation message
2014-02-06 13:48:01 +01:00
*
2014-05-20 17:39:20 +02:00
* @ param { action } _action
* @ param { sender } _senders
2014-02-06 13:48:01 +01:00
* /
2014-05-20 17:39:20 +02:00
edit _vacation : function ( _action , _senders )
2014-02-06 13:48:01 +01:00
{
2014-05-20 17:39:20 +02:00
var acc _id = parseInt ( _senders [ 0 ] . id ) ;
this . egw . open _link ( 'mail.mail_sieve.editVacation&acc_id=' + acc _id , '_blank' , '700x480' ) ;
2014-02-06 13:48:01 +01:00
} ,
2014-05-20 17:39:20 +02:00
2014-02-06 18:18:12 +01:00
/ * *
* Popup the subscription dialog
*
* @ param { action } _action
* @ param { sender } _senders
* /
edit _subscribe : function ( _action , _senders )
{
var acc _id = parseInt ( _senders [ 0 ] . id ) ;
this . egw . open _link ( 'mail.mail_ui.subscription&acc_id=' + acc _id , '_blank' , '720x500' ) ;
} ,
2013-12-20 17:17:12 +01:00
2014-02-06 13:48:01 +01:00
/ * *
* Subscribe selected unsubscribed folder
*
* @ param { action } _action
* @ param { sender } _senders
* /
subscribe _folder : function ( _action , _senders )
{
var mailbox = _senders [ 0 ] . id . split ( '::' ) ;
var folder = mailbox [ 1 ] , acc _id = mailbox [ 0 ] ;
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'Subscribe to Folder %1' , ftree . getLabel ( _senders [ 0 ] . id ) . replace ( this . _unseen _regexp , '' ) ) ) ;
2014-02-06 13:48:01 +01:00
egw . json ( 'mail.mail_ui.ajax_foldersubscription' , [ acc _id , folder , true ] )
2013-12-20 17:17:12 +01:00
. sendRequest ( ) ;
2014-02-06 13:48:01 +01:00
} ,
2013-12-20 17:17:12 +01:00
2014-02-06 13:48:01 +01:00
/ * *
* Unsubscribe selected subscribed folder
*
* @ param { action } _action
* @ param { sender } _senders
* /
unsubscribe _folder : function ( _action , _senders )
{
2014-02-07 09:33:23 +01:00
var mailbox = _senders [ 0 ] . id . split ( '::' ) ;
var folder = mailbox [ 1 ] , acc _id = mailbox [ 0 ] ;
var ftree = this . et2 . getWidgetById ( this . nm _index + '[foldertree]' ) ;
2014-05-27 15:31:37 +02:00
this . egw . message ( this . egw . lang ( 'Unsubscribe from Folder %1' , ftree . getLabel ( _senders [ 0 ] . id ) . replace ( this . _unseen _regexp , '' ) ) ) ;
2014-02-07 09:33:23 +01:00
egw . json ( 'mail.mail_ui.ajax_foldersubscription' , [ acc _id , folder , false ] )
2013-12-20 11:48:04 +01:00
. sendRequest ( ) ;
2014-02-06 13:48:01 +01:00
} ,
2013-12-20 11:48:04 +01:00
2014-08-15 13:22:43 +02:00
/ * *
* Onclick for node / foldername in subscription popup
*
* Used to ( un ) check node including all children
*
* @ param { string } _id id of clicked node
* @ param { et2 _tree } _widget reference to tree widget
* /
subscribe _onclick : function ( _id , _widget )
{
_widget . setSubChecked ( _id , "toggle" ) ;
} ,
2013-11-15 18:22:46 +01:00
/ * *
* Edit a folder acl for account ( s )
*
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
edit _acl : function ( _action , _senders )
{
2013-12-20 17:17:12 +01:00
var mailbox = _senders [ 0 ] . id . split ( '::' ) ;
2014-08-28 14:30:16 +02:00
var folder = mailbox [ 1 ] || 'INBOX' , acc _id = mailbox [ 0 ] ;
2013-12-20 17:17:12 +01:00
this . egw . open _link ( 'mail.mail_acl.edit&mailbox=' + jQuery . base64Encode ( folder ) + '&acc_id=' + acc _id , '_blank' , '640x480' ) ;
2013-11-15 18:22:46 +01:00
} ,
2014-10-06 11:57:50 +02:00
2014-09-24 14:02:35 +02:00
/ * *
2014-09-24 14:08:10 +02:00
* Submit new selected folder back to server in order to read its acl ' s rights
2014-09-24 14:02:35 +02:00
* /
acl _folderChange : function ( )
{
var mailbox = this . et2 . getWidgetById ( 'mailbox' ) ;
2014-10-06 11:57:50 +02:00
2014-09-24 14:02:35 +02:00
if ( mailbox )
{
if ( mailbox . taglist . getValue ( ) . length > 0 )
{
this . et2 . _inst . submit ( ) ;
2014-10-06 11:57:50 +02:00
}
2014-09-24 14:02:35 +02:00
}
} ,
2014-10-06 11:57:50 +02:00
2013-11-03 11:24:09 +01:00
/ * *
* Edit a mail account
*
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
edit _account : function ( _action , _senders )
{
var acc _id = parseInt ( _senders [ 0 ] . id ) ;
2013-11-17 14:31:19 +01:00
this . egw . open _link ( 'mail.mail_wizard.edit&acc_id=' + acc _id , '_blank' , '720x500' ) ;
2014-01-18 15:01:07 +01:00
} ,
/ * *
2014-10-20 14:25:43 +02:00
* Set expandable fields ( Folder , Cc and Bcc ) based on their content
* - Only fields which have no content should get hidden
2014-01-18 15:01:07 +01:00
* /
2014-10-20 14:25:43 +02:00
compose _fieldExpander _init : function ( )
2014-01-18 15:01:07 +01:00
{
2014-10-16 10:29:10 +02:00
var widgets = {
cc : {
widget : { } ,
jQClass : '.mailComposeJQueryCc'
} ,
bcc : {
widget : { } ,
jQClass : '.mailComposeJQueryBcc'
} ,
folder : {
widget : { } ,
jQClass : '.mailComposeJQueryFolder'
2014-11-20 16:05:25 +01:00
} ,
replyto : {
widget : { } ,
jQClass : '.mailComposeJQueryReplyto'
2014-10-16 10:29:10 +02:00
} } ;
2014-10-20 20:08:03 +02:00
2014-06-02 18:57:30 +02:00
for ( var widget in widgets )
{
2014-10-16 10:29:10 +02:00
var expanderBtn = widget + '_expander' ;
widgets [ widget ] . widget = this . et2 . getWidgetById ( widget ) ;
// Add expander button widget to the widgets object
widgets [ expanderBtn ] = { widget : this . et2 . getWidgetById ( expanderBtn ) } ;
2014-10-20 20:08:03 +02:00
if ( typeof widgets [ widget ] . widget != 'undefined'
2014-10-16 10:29:10 +02:00
&& typeof widgets [ expanderBtn ] . widget != 'undefined'
&& widgets [ widget ] . widget . get _value ( ) . length == 0 )
2014-07-02 09:48:24 +02:00
{
2014-10-16 10:29:10 +02:00
widgets [ expanderBtn ] . widget . set _disabled ( false ) ;
jQuery ( widgets [ widget ] . jQClass ) . hide ( ) ;
2014-07-02 09:48:24 +02:00
}
2014-06-02 18:57:30 +02:00
}
2014-01-18 15:01:07 +01:00
} ,
2014-07-02 09:48:24 +02:00
2014-06-03 18:37:50 +02:00
/ * *
* Control textArea size based on available free space at the bottom
*
* /
compose _resizeHandler : function ( )
{
2014-11-10 13:03:49 +01:00
var bodyH = egw _getWindowInnerHeight ( ) ;
2014-06-03 18:37:50 +02:00
var textArea = this . et2 . getWidgetById ( 'mail_plaintext' ) ;
2014-12-09 09:56:45 +01:00
var $headerSec = jQuery ( '.mailComposeHeaderSection' ) ;
var attachments = this . et2 . getWidgetById ( 'attachments' ) ;
2014-11-10 13:03:49 +01:00
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
2014-12-12 16:28:53 +01:00
2014-12-09 09:56:45 +01:00
// @var arrbitary int represents px
// Visible height of attachment progress
var prgV _H = 150 ;
2014-12-12 16:28:53 +01:00
2014-12-09 09:56:45 +01:00
// @var arrbitary int represents px
// Visible height of attchements list
var attchV _H = 68 ;
2014-12-12 16:28:53 +01:00
2014-09-09 14:08:08 +02:00
if ( typeof textArea != 'undefined' && textArea != null )
2014-06-03 18:37:50 +02:00
{
if ( textArea . getParent ( ) . disabled )
{
textArea = this . et2 . getWidgetById ( 'mail_htmltext' ) ;
2014-07-02 09:48:24 +02:00
}
2014-11-10 13:03:49 +01:00
// Tolerate values base on plain text or html, in order to calculate freespaces
var textAreaDelta = textArea . id == "mail_htmltext" ? 20 : 40 ;
2014-12-12 16:28:53 +01:00
2014-12-09 09:56:45 +01:00
// while attachments are in progress take progress visiblity into account
// otherwise the attachment progress is finished and consider attachments list
var delta = ( attachments . table . find ( 'li' ) . length > 0 && attachments . table . height ( ) > 0 ) ? prgV _H : ( content . attachments ? attchV _H : textAreaDelta ) ;
2014-12-12 16:28:53 +01:00
2014-12-09 09:56:45 +01:00
var bodySize = ( bodyH - Math . round ( $headerSec . height ( ) + $headerSec . offset ( ) . top ) - delta ) ;
2014-07-02 09:48:24 +02:00
2014-06-03 18:37:50 +02:00
if ( textArea . id != "mail_htmltext" )
{
2014-11-20 16:54:09 +01:00
textArea . set _height ( bodySize ) ;
2014-06-03 18:37:50 +02:00
}
else if ( typeof textArea != 'undefined' && textArea . id == 'mail_htmltext' && typeof textArea . getParent ( ) . node . children [ 1 ] != 'undefined' )
{
2014-11-20 16:54:09 +01:00
jQuery ( textArea . getParent ( ) . node . children [ 1 ] . children [ 1 ] . children [ 1 ] ) . css ( 'height' , bodySize - 90 ) ;
2014-06-03 18:37:50 +02:00
}
else
{
2014-11-20 16:54:09 +01:00
textArea . set _height ( bodySize - 90 ) ;
2014-06-03 18:37:50 +02:00
}
}
} ,
2014-07-02 09:48:24 +02:00
2014-01-18 15:01:07 +01:00
/ * *
2014-06-02 18:57:30 +02:00
* Display Folder , Cc or Bcc fields in compose popup
2014-01-18 15:01:07 +01:00
*
2014-02-13 09:16:14 +01:00
* @ param { jQuery event } event
2014-06-02 18:57:30 +02:00
* @ param { widget object } widget clicked label ( Folder , Cc or Bcc ) from compose popup
2014-01-18 15:01:07 +01:00
*
* /
2014-06-02 18:57:30 +02:00
compose _fieldExpander : function ( event , widget )
2014-01-18 15:01:07 +01:00
{
2014-11-20 16:05:25 +01:00
var expWidgets = { cc : { } , bcc : { } , folder : { } , replyto : { } } ;
2014-06-02 18:57:30 +02:00
for ( var name in expWidgets )
2014-01-18 15:01:07 +01:00
{
2014-06-02 18:57:30 +02:00
expWidgets [ name ] = this . et2 . getWidgetById ( name + '_expander' ) ;
2014-01-18 15:01:07 +01:00
}
2014-07-02 09:48:24 +02:00
2014-06-02 18:57:30 +02:00
if ( typeof widget != 'undefined' )
2014-01-18 15:01:07 +01:00
{
2014-06-02 18:57:30 +02:00
switch ( widget . id )
2014-01-18 15:01:07 +01:00
{
2014-06-02 18:57:30 +02:00
case 'cc_expander' :
jQuery ( ".mailComposeJQueryCc" ) . show ( ) ;
if ( typeof expWidgets . cc != 'undefined' )
{
expWidgets . cc . set _disabled ( true ) ;
}
break ;
case 'bcc_expander' :
jQuery ( ".mailComposeJQueryBcc" ) . show ( ) ;
if ( typeof expWidgets . bcc != 'undefined' )
{
expWidgets . bcc . set _disabled ( true ) ;
}
break ;
case 'folder_expander' :
jQuery ( ".mailComposeJQueryFolder" ) . show ( ) ;
if ( typeof expWidgets . folder != 'undefined' )
{
expWidgets . folder . set _disabled ( true ) ;
}
2014-11-20 16:05:25 +01:00
break ;
case 'replyto_expander' :
jQuery ( ".mailComposeJQueryReplyto" ) . show ( ) ;
if ( typeof expWidgets . replyto != 'undefined' )
{
expWidgets . replyto . set _disabled ( true ) ;
}
break ;
2014-01-18 15:01:07 +01:00
}
}
2014-01-23 14:59:10 +01:00
else if ( typeof widget == "undefined" )
{
2014-11-20 16:05:25 +01:00
var widgets = { cc : { } , bcc : { } , folder : { } , replyto : { } } ;
2014-07-02 09:48:24 +02:00
2014-06-02 18:57:30 +02:00
for ( var widget in widgets )
2014-01-23 14:59:10 +01:00
{
2014-06-02 18:57:30 +02:00
widgets [ widget ] = this . et2 . getWidgetById ( widget ) ;
2014-07-02 09:48:24 +02:00
2014-06-02 18:57:30 +02:00
if ( widgets [ widget ] . get _value ( ) . length )
2014-01-23 14:59:10 +01:00
{
2014-06-02 18:57:30 +02:00
switch ( widget )
{
case 'cc' :
jQuery ( ".mailComposeJQueryCc" ) . show ( ) ;
if ( typeof expWidgets . cc != 'undefiend' )
{
2014-06-23 18:22:30 +02:00
expWidgets . cc . set _disabled ( true ) ;
2014-06-02 18:57:30 +02:00
}
break ;
case 'bcc' :
jQuery ( ".mailComposeJQueryBcc" ) . show ( ) ;
if ( typeof expWidgets . bcc != 'undefiend' )
{
2014-06-23 18:22:30 +02:00
expWidgets . bcc . set _disabled ( true ) ;
2014-06-02 18:57:30 +02:00
}
break ;
case 'folder' :
jQuery ( ".mailComposeJQueryFolder" ) . show ( ) ;
if ( typeof expWidgets . folder != 'undefiend' )
{
2014-06-23 18:22:30 +02:00
expWidgets . folder . set _disabled ( true ) ;
2014-06-02 18:57:30 +02:00
}
2014-11-20 16:05:25 +01:00
break ;
case 'replyto' :
jQuery ( ".mailComposeJQueryReplyto" ) . show ( ) ;
if ( typeof expWidgets . replyto != 'undefiend' )
{
expWidgets . replyto . set _disabled ( true ) ;
}
break ;
2014-06-02 18:57:30 +02:00
}
2014-01-23 14:59:10 +01:00
}
}
}
2014-06-03 18:37:50 +02:00
this . compose _resizeHandler ( ) ;
2014-01-18 15:01:07 +01:00
} ,
2014-01-21 11:21:59 +01:00
/ * *
* Lock tree so it does NOT receive any more mouse - clicks
* /
lock _tree : function ( )
{
if ( ! document . getElementById ( 'mail_folder_lock_div' ) )
{
var parent = jQuery ( '#mail-index_nm\\[foldertree\\]' ) ;
var lock _div = jQuery ( document . createElement ( 'div' ) ) ;
lock _div . attr ( 'id' , 'mail_folder_lock_div' )
. addClass ( 'mail_folder_lock' ) ;
parent . prepend ( lock _div ) ;
}
} ,
/ * *
* Unlock tree so it receives again mouse - clicks after calling lock _tree ( )
* /
unlock _tree : function ( )
{
jQuery ( '#mail_folder_lock_div' ) . remove ( ) ;
2014-01-21 14:34:02 +01:00
} ,
/ * *
* Called when tree opens up an account or folder
*
* @ param { String } _id account - id [ : : folder - name ]
* @ param { et2 _widget _tree } _widget
* @ param { Number } _hasChildren 0 - item has no child nodes , - 1 - item is closed , 1 - item is opened
* /
openstart _tree : function ( _id , _widget , _hasChildren )
{
if ( _id . indexOf ( '::' ) == - 1 && // it's an account, not a folder in an account
! _hasChildren )
{
this . lock _tree ( ) ;
}
return true ; // allow opening of node
} ,
/ * *
* Called when tree opens up an account or folder
*
* @ param { String } _id account - id [ : : folder - name ]
* @ param { et2 _widget _tree } _widget
* @ param { Number } _hasChildren 0 - item has no child nodes , - 1 - item is closed , 1 - item is opened
* /
openend _tree : function ( _id , _widget , _hasChildren )
{
if ( _id . indexOf ( '::' ) == - 1 && // it's an account, not a folder in an account
_hasChildren == 1 )
{
this . unlock _tree ( ) ;
}
2014-02-12 21:12:59 +01:00
} ,
/ * *
* Print a mail from list
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
mail _print : function ( _action , _senders )
{
2014-04-17 11:59:08 +02:00
var currentTemp = this . et2 . _inst . name ;
2014-05-20 17:39:20 +02:00
2014-04-17 11:59:08 +02:00
switch ( currentTemp )
{
case 'mail.index' :
2014-09-09 14:08:08 +02:00
this . mail _prev _print ( _action , _senders ) ;
2014-04-17 11:59:08 +02:00
break ;
case 'mail.display' :
this . mail _display _print ( ) ;
}
2014-05-20 17:39:20 +02:00
2014-04-17 11:59:08 +02:00
} ,
2014-09-23 10:42:31 +02:00
2014-09-09 14:08:08 +02:00
/ * *
* Print a mail from compose
* @ param { stirng } _id id of new draft
* /
mail _compose _print : function ( _id )
{
this . egw . open ( _id , 'mail' , 'view' , '&print=' + _id + '&mode=print' ) ;
} ,
2014-09-23 10:42:31 +02:00
2014-09-09 14:08:08 +02:00
/ * *
2014-09-23 10:42:31 +02:00
* Bind special handler on print media .
* - FF and IE have onafterprint event , and as Chrome does not have that event we bind afterprint function to onFocus
2014-09-09 14:08:08 +02:00
* /
print _for _compose : function ( )
{
var afterprint = function ( ) {
2014-12-12 15:21:04 +01:00
egw ( window ) . close ( ) ;
2014-09-09 14:08:08 +02:00
} ;
2014-09-23 10:42:31 +02:00
2014-09-09 14:08:08 +02:00
if ( ! window . onafterprint )
{
2014-09-09 15:55:43 +02:00
// For browsers which does not support onafterprint event, eg. Chrome
setTimeout ( function ( ) {
2014-12-12 15:21:04 +01:00
egw ( window ) . close ( ) ;
2014-09-09 15:55:43 +02:00
} , 2000 ) ;
2014-09-09 14:08:08 +02:00
}
else
{
window . onafterprint = afterprint ;
}
2014-09-23 10:42:31 +02:00
} ,
2014-04-17 11:59:08 +02:00
/ * *
* Print a mail from Display
2014-05-20 17:39:20 +02:00
*
2014-04-17 11:59:08 +02:00
* /
mail _display _print : function ( )
{
2014-04-16 19:16:42 +02:00
var mainIframe = jQuery ( '#mail-display_mailDisplayBodySrc' ) ;
2014-11-28 14:51:00 +01:00
var tmpPrintDiv = jQuery ( '#tempPrintDiv' ) ;
2014-12-02 20:18:37 +01:00
2014-11-28 14:51:00 +01:00
if ( tmpPrintDiv . length == 0 && tmpPrintDiv . children ( ) )
2014-04-16 19:16:42 +02:00
{
2014-11-28 14:51:00 +01:00
tmpPrintDiv = jQuery ( document . createElement ( 'div' ) )
2014-04-16 19:16:42 +02:00
. attr ( 'id' , 'tempPrintDiv' )
. addClass ( 'tmpPrintDiv' ) ;
2014-11-28 14:51:00 +01:00
var notAttached = true ;
}
2014-12-02 20:18:37 +01:00
2014-11-28 14:51:00 +01:00
if ( mainIframe )
{
tmpPrintDiv [ 0 ] . innerHTML = mainIframe . contents ( ) . find ( 'body' ) . html ( ) ;
2014-04-16 19:16:42 +02:00
}
2014-11-28 14:51:00 +01:00
// Attach the element to the DOM after maniupulation
if ( notAttached ) jQuery ( '#mail-display_mailDisplayBodySrc' ) . after ( tmpPrintDiv ) ;
tmpPrintDiv . find ( '#divAppboxHeader' ) . remove ( ) ;
2014-04-16 19:16:42 +02:00
this . egw . message ( 'Printing....' ) ;
2014-12-02 20:18:37 +01:00
2014-11-28 14:51:00 +01:00
// Make sure the print happens after the content is loaded. Seems Firefox and IE can't handle timing for print command correctly
setTimeout ( function ( ) {
egw ( window ) . window . print ( ) ;
} , 100 ) ;
2014-04-17 11:59:08 +02:00
} ,
2014-05-20 17:39:20 +02:00
2014-04-17 11:59:08 +02:00
/ * *
* Print a mail from list
2014-05-20 17:39:20 +02:00
*
* @ param { Object } _action
* @ param { Object } _elems
*
2014-04-17 11:59:08 +02:00
* /
mail _prev _print : function ( _action , _elems )
{
this . mail _open ( _action , _elems , 'print' ) ;
2014-05-20 10:48:50 +02:00
} ,
2014-05-20 17:39:20 +02:00
2014-05-20 10:48:50 +02:00
/ * *
* Print a mail from list
2014-05-20 17:39:20 +02:00
*
* @ param { egw object } _egw
2014-05-20 10:48:50 +02:00
* @ param { widget object } _widget mail account selectbox
2014-05-20 17:39:20 +02:00
*
2014-05-20 10:48:50 +02:00
* /
vacation _change _account : function ( _egw , _widget )
{
_widget . getInstanceManager ( ) . submit ( ) ;
2014-08-15 13:22:43 +02:00
} ,
2014-08-14 16:44:16 +02:00
/ * *
2014-08-15 13:22:43 +02:00
* Set email items draggable
2014-08-14 16:44:16 +02:00
* * /
set _dragging _dndCompose : function ( )
{
var zIndex = 100 ;
2014-10-29 18:15:14 +01:00
var dragItem = jQuery ( 'div.ms-sel-item:not(div.ui-draggable)' ) ;
2014-10-30 12:55:22 +01:00
if ( dragItem . length > 0 )
{
dragItem . draggable ( {
appendTo : 'body' ,
//Performance wise better to not add ui-draggable class to items since we are not using that class
containment : 'document' ,
distance : 0 ,
cursor : 'move' ,
cursorAt : { left : 2 } ,
//cancel dragging on close button to avoid conflict with close action
cancel : '.ms-close-btn' ,
/ * *
* function to act on draggable item on revert ' s event
* @ returns { Boolean } return true
* /
revert : function ( ) {
this . parent ( ) . find ( '.ms-sel-item' ) . css ( 'position' , 'relative' ) ;
return true ;
} ,
/ * *
* function to act as draggable starts dragging
*
* @ param { type } event
* @ param { type } ui
* /
start : function ( event , ui )
{
var dragItem = jQuery ( this ) ;
if ( event . ctrlKey || event . metaKey )
{
dragItem . addClass ( 'mailCompose_copyEmail' )
. css ( 'cursor' , 'copy' ) ;
}
dragItem . css ( 'z-index' , zIndex ++ ) ;
dragItem . css ( 'position' , 'absolute' ) ;
} ,
/ * *
*
* @ param { type } event
* @ param { type } ui
* /
create : function ( event , ui )
2014-08-14 16:44:16 +02:00
{
2014-10-30 12:55:22 +01:00
jQuery ( this ) . css ( 'css' , 'move' ) ;
2014-08-14 16:44:16 +02:00
}
2014-10-30 12:55:22 +01:00
} ) . draggable ( 'disable' ) ;
window . setTimeout ( function ( ) {
2014-11-20 16:05:25 +01:00
2014-10-30 12:55:22 +01:00
if ( dragItem && dragItem . data ( ) && typeof dragItem . data ( ) [ 'uiDraggable' ] !== 'undefined' ) dragItem . draggable ( 'enable' ) ;
} , 100 ) ;
}
2014-11-20 16:05:25 +01:00
2014-08-14 16:44:16 +02:00
} ,
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
/ * *
* Initialize dropping targets for draggable emails
* -
2014-08-15 13:22:43 +02:00
* /
2014-08-14 16:44:16 +02:00
init _dndCompose : function ( )
{
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
var self = this ;
2014-10-29 18:15:14 +01:00
var emailTags = jQuery ( '#mail-compose_to,#mail-compose_cc,#mail-compose_bcc' ) ;
2014-08-14 16:44:16 +02:00
//Call to make new items draggable
2014-10-29 18:15:14 +01:00
emailTags . hover ( function ( ) {
2014-08-14 16:44:16 +02:00
self . set _dragging _dndCompose ( ) ;
} ) ;
2014-08-15 13:22:43 +02:00
//Make used email-tag list widgets in mail compose droppable
2014-10-29 18:15:14 +01:00
emailTags . droppable ( {
2015-01-07 12:57:34 +01:00
accept : '.ms-sel-item' ,
2014-08-14 16:44:16 +02:00
/ * *
* Run after a draggable email item dropped over one of the email - taglists
* - Set the dropped item to the dropped current target widget
2014-08-15 13:22:43 +02:00
*
2014-08-14 16:44:16 +02:00
* @ param { type } event
* @ param { type } ui
* /
drop : function ( event , ui )
{
var widget = self . et2 . getWidgetById ( this . getAttribute ( 'name' ) ) ;
var emails = [ ] ;
var fromWidget = { } ;
var draggedValue = ui . draggable . text ( ) ;
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
if ( typeof widget != 'undefined' )
{
emails = widget . get _value ( ) ;
2014-08-15 13:22:43 +02:00
if ( emails ) emails = emails . concat ( [ draggedValue ] ) ;
2014-08-14 16:44:16 +02:00
widget . set _value ( emails ) ;
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
var parentWidgetDOM = ui . draggable . parentsUntil ( 'div[id^="mail-compoe_"]' , '.ui-droppable' ) ;
if ( parentWidgetDOM != 'undefined' && parentWidgetDOM . length > 0 )
{
fromWidget = self . et2 . getWidgetById ( parentWidgetDOM . attr ( 'name' ) ) ;
}
2014-08-15 13:22:43 +02:00
if ( ! jQuery . isEmptyObject ( fromWidget )
2014-08-14 16:44:16 +02:00
&& ! ( ui . draggable . attr ( 'class' ) . search ( 'mailCompose_copyEmail' ) > - 1 ) )
{
if ( ! _removeDragged ( fromWidget , draggedValue ) )
{
//Not successful remove, returns the item to its origin
jQuery ( ui . draggable ) . draggable ( 'option' , 'revert' , true ) ;
}
}
else
{
ui . draggable
. removeClass ( 'mailCompose_copyEmail' )
. css ( 'cursor' , 'move' ) ;
}
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
//Destroy draggables after dropping, we need to enable them again
jQuery ( 'div.ms-sel-item' ) . draggable ( 'destroy' ) ;
}
2014-08-15 13:22:43 +02:00
}
2014-08-14 16:44:16 +02:00
} ) ;
2014-08-15 13:22:43 +02:00
2014-08-14 16:44:16 +02:00
/ * *
* Remove dragged item from the widget which the item was dragged
2014-08-15 13:22:43 +02:00
*
2014-08-14 16:44:16 +02:00
* @ param { type } _widget
* @ param { type } _value
* @ return { boolean } true if successul | false unsuccessul
* /
var _removeDragged = function ( _widget , _value )
{
if ( _widget && _value )
{
var emails = _widget . get _value ( ) ;
var itemIndex = emails . indexOf ( _value ) ;
if ( itemIndex > - 1 )
{
emails . splice ( itemIndex , 1 ) ;
_widget . set _value ( emails ) ;
}
else
{
return false ;
}
}
return true ;
2014-08-15 13:22:43 +02:00
} ;
2014-12-02 20:18:37 +01:00
} ,
/ * *
* Check sharing mode and disable not available options
*
* @ param { DOMNode } _node
* @ param { et2 _widget } _widget
* /
check _sharing _filemode : function ( _node , _widget )
{
if ( ! _widget ) _widget = this . et2 . getWidgetById ( 'filemode' ) ;
var extended _settings = _widget . get _value ( ) != 'attach' && this . egw . app ( 'stylite' ) ;
2014-12-03 17:25:10 +01:00
this . et2 . getWidgetById ( 'expiration' ) . set _readonly ( ! extended _settings ) ;
this . et2 . getWidgetById ( 'password' ) . set _readonly ( ! extended _settings ) ;
2014-12-02 20:18:37 +01:00
if ( _widget . get _value ( ) == 'share_rw' && ! this . egw . app ( 'stylite' ) )
{
this . egw . message ( this . egw . lang ( 'Writable sharing required EPL version!' ) , 'info' ) ;
_widget . setValue ( 'share_ro' ) ;
}
2014-12-12 16:28:53 +01:00
} ,
/ * *
* Write / update compose window title with subject
*
* @ param { DOMNode } _node
* @ param { et2 _widget } _widget
* /
subject2title : function ( _node , _widget )
{
if ( ! _widget ) _widget = this . et2 . getWidgetById ( 'subject' ) ;
if ( _widget && _widget . get _value ( ) )
{
document . title = _widget . get _value ( ) ;
}
2014-12-16 11:26:44 +01:00
} ,
/ * *
* Clear intervals stored in W _INTERVALS which assigned to window
* /
clearIntevals : function ( )
{
for ( var i = 0 ; i < this . W _INTERVALS . length ; i ++ )
{
clearInterval ( this . W _INTERVALS [ i ] ) ;
delete this . W _INTERVALS [ i ] ;
}
2015-01-05 15:28:35 +01:00
} ,
/ * *
* Window title getter function in order to set the window title
*
* @ returns { string } window title
* /
getWindowTitle : function ( )
{
var widget = { } ;
switch ( this . et2 . _inst . name )
{
case 'mail.display' :
widget = this . et2 . getWidgetById ( 'mail_displaysubject' ) ;
if ( widget ) return widget . options . value ;
break ;
case 'mail.compose' :
widget = this . et2 . getWidgetById ( 'subject' ) ;
if ( widget ) return widget . get _value ( ) ;
break ;
}
2015-01-07 12:57:34 +01:00
} ,
/ * *
* Set the relevant widget to toolbar actions and submit
* @ param { type } _action toolbar action
* /
compose _submitAction : function ( _action )
{
2015-01-13 16:52:00 +01:00
this . et2 . _inst . submit ( null , null , true ) ;
} ,
/ * *
* Set the selected checkbox action
*
* @ param { type } _action selected toolbar action with checkbox
* @ returns { undefined }
* /
compose _setToggle : function ( _action )
{
var widget = this . et2 . getWidgetById ( _action . id ) ;
if ( widget && typeof _action . checkbox != 'undefined' && _action . checkbox )
2015-01-07 12:57:34 +01:00
{
2015-01-13 16:52:00 +01:00
widget . set _value ( _action . checked ? "on" : "off" ) ;
2015-01-07 12:57:34 +01:00
}
} ,
2015-01-13 13:14:41 +01:00
/ * *
* Set the selected priority value
* @ param { type } _action selected action
* @ returns { undefined }
* /
compose _priorityChange : function ( _action )
{
var widget = this . et2 . getWidgetById ( 'priority' ) ;
if ( widget )
{
widget . set _value ( _action . id ) ;
}
} ,
2015-01-13 16:52:00 +01:00
2015-01-07 12:57:34 +01:00
/ * *
* Triger relative widget via its toolbar identical action
* @ param { type } _action toolbar action
* /
compose _triggerWidget : function ( _action )
{
var widget = this . et2 . getWidgetById ( _action . id ) ;
if ( widget )
{
switch ( widget . id )
{
case 'uploadForCompose' :
document . getElementById ( 'mail-compose_uploadForCompose' ) . click ( ) ;
break ;
default :
widget . click ( ) ;
}
}
} ,
2015-01-08 18:06:56 +01:00
/ * *
* Save drafted compose as eml file into VFS
* @ param { type } _action action
* /
compose _saveDraft2fm : function ( _action )
{
var content = this . et2 . getArrayMgr ( 'content' ) . data ;
var subject = this . et2 . getWidgetById ( 'subject' ) ;
var elem = { 0 : { id : "" , subject : "" } } ;
if ( typeof content != 'undefined' && content . lastDrafted && subject )
{
elem [ 0 ] . id = content . lastDrafted ;
elem [ 0 ] . subject = subject . get _value ( ) ;
this . mail _save2fm ( _action , elem ) ;
}
else
{
et2 _dialog . alert ( 'You need to save the message as draft first before to be able to save it into VFS' , 'Save into VFS' , 'info' ) ;
}
}
2013-04-09 10:53:25 +02:00
} ) ;