2013-02-12 18:48:04 +01:00
/ * *
* mail - static javaScript functions
*
* @ link http : //www.egroupware.org
* @ author klaus leithoff < kl at stylite . de >
* @ package mail
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ version $Id$
* /
2013-04-13 12:30:07 +02:00
app . mail = AppJS . extend (
2013-02-19 17:30:59 +01:00
{
2013-04-13 12:30:07 +02:00
appname : 'mail' ,
doStatus : null ,
mail _doTimedRefresh : false ,
mail _refreshTimeOut : 1000 * 60 * 3 , // initial call
mail _queuedFolders : [ ] ,
mail _queuedFoldersIndex : 0 ,
2013-05-21 10:46:54 +02:00
mail _selectedMails : [ ] ,
mail _currentlyFocussed : '' ,
2013-04-13 12:30:07 +02:00
/ * *
* Initialize javascript for this application
*
* @ memberOf app . mail
* /
init : function ( ) {
this . _super . apply ( this , arguments ) ;
window . register _app _refresh ( "mail" , this . app _refresh ) ;
this . mail _startTimerFolderStatusUpdate ( this . mail _refreshTimeOut ) ;
//inital call of refresh folderstatus
var self = this ;
window . setTimeout ( function ( ) { self . mail _refreshFolderStatus . apply ( self ) ; } , 1000 ) ;
} ,
2013-05-21 10:46:54 +02:00
/ * *
* mail _fetchCurrentlyFocussed - implementation to decide wich mail of all the selected ones is the current
*
* @ param _selected array of the selected mails
* @ param _reset bool - tell the function to reset the global vars used
* /
mail _fetchCurrentlyFocussed : function ( _selected , _reset ) {
//console.log("mail_fetchCurrentlyFocussed",_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 )
{
if ( this . mail _currentlyFocussed != '' ) egw . dataDeleteUID ( this . mail _currentlyFocussed ) ;
for ( var k = 0 ; k < this . mail _selectedMails . length ; k ++ ) egw . dataDeleteUID ( this . mail _selectedMails [ k ] ) ;
}
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
*
* @ param _action
* @ param _senders - the representation of the elements ( s ) the action is to be performed on
* /
mail _open : function ( _action , _senders ) {
console . log ( "mail_open" , _action , _senders ) ;
var _id = _senders [ 0 ] . id ;
2013-05-21 10:46:54 +02:00
// reinitialize the buffer-info on selected mails
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 ;
var sw = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewSubject' ) ;
} ,
2013-05-13 16:42:42 +02:00
/ * *
* Open a single message in html mode
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _openAsHtml : function ( _action , _elems )
{
//alert('mail_open('+_elems[0].id+')');
if ( activeFolderB64 == draftFolderB64 || activeFolderB64 == templateFolderB64 )
{
// _action.id='composefromdraft';
// mail_compose(_action,_elems);
}
else
{
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=felamimail.uidisplay.display' ; // todo compose for Draft folder
url += '&uid=' + _elems [ 0 ] . id ;
url += '&tryashtml=1' ;
egw _openWindowCentered ( _url , 'displayMessage_' + _elems [ 0 ] . id , '700' , '600' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
}
} ,
/ * *
* Open a single message in plain text mode
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _openAsText : function ( _action , _elems )
{
//alert('mail_open('+_elems[0].id+')');
if ( activeFolderB64 == draftFolderB64 || activeFolderB64 == templateFolderB64 )
{
// _action.id='composefromdraft';
// mail_compose(_action,_elems);
}
else
{
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=felamimail.uidisplay.display' ; // todo compose for Draft folder
url += '&uid=' + _elems [ 0 ] . id ;
url += '&tryastext=1' ;
egw _openWindowCentered ( _url , 'displayMessage_' + _elems [ 0 ] . id , '700' , '600' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
}
} ,
2013-05-27 15:48:55 +02:00
/ * *
* mail _disablePreviewArea - implementation of the disablePreviewArea action
*
* @ param _value
* /
mail _disablePreviewArea : function ( _value ) {
var splitter = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'mailSplitter' ) ;
//etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('mailPreviewHeadersFrom').set_disabled(_value);
//etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('mailPreviewHeadersTo').set_disabled(_value);
//etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('mailPreviewHeadersDate').set_disabled(_value);
//etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('mailPreviewHeadersSubject').set_disabled(_value);
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'mailPreview' ) . set _disabled ( _value ) ;
if ( _value == true )
{
//splitter.dock();
}
else
{
//splitter.undock();
}
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _preview - implementation of the preview action
*
* @ param nextmatch et2 _nextmatch The widget whose row was selected
* @ param selected Array Selected row IDs . May be empty if user unselected all rows .
* /
mail _preview : function ( nextmatch , selected ) {
2013-05-21 10:46:54 +02:00
console . log ( "mail_preview" , nextmatch , selected ) ;
2013-04-13 12:30:07 +02:00
// Empty values, just in case selected is empty (user cleared selection)
var dataElem = { data : { subject : "" , fromaddress : "" , toaddress : "" , date : "" , subject : "" } } ;
2013-05-21 10:46:54 +02:00
if ( typeof selected != 'undefined' && selected . length > 0 )
2013-02-19 17:30:59 +01:00
{
2013-05-21 10:46:54 +02:00
var _id = this . mail _fetchCurrentlyFocussed ( selected ) ;
2013-04-13 12:30:07 +02:00
dataElem = egw . dataGetUIDdata ( _id ) ;
2013-02-19 17:30:59 +01:00
}
2013-05-21 14:02:58 +02:00
if ( typeof selected == 'undefined' || selected . length == 0 || selected . length > 1 || typeof dataElem == 'undefined' )
2013-04-13 12:30:07 +02:00
{
2013-05-21 10:46:54 +02:00
this . mail _fetchCurrentlyFocussed ( ) ;
2013-04-30 16:16:52 +02:00
var subject = "" ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewFromAddress' ) . set _value ( "" ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewToAddress' ) . set _value ( "" ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewDate' ) . set _value ( "" ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewSubject' ) . set _value ( "" ) ;
var IframeHandle = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'messageIFRAME' ) ;
IframeHandle . set _src ( egw . link ( '/index.php' , { menuaction : 'mail.mail_ui.loadEmailBody' , _messageID : "" } ) ) ;
2013-05-27 15:48:55 +02:00
this . mail _disablePreviewArea ( true ) ;
2013-04-13 12:30:07 +02:00
return ;
}
2013-04-30 16:16:52 +02:00
//console.log("mail_preview",dataElem);
2013-05-21 10:46:54 +02:00
this . mail _selectedMails . push ( _id ) ;
2013-04-13 12:30:07 +02:00
var subject = dataElem . data . subject ;
2013-05-27 15:48:55 +02:00
this . mail _disablePreviewArea ( false ) ;
2013-04-13 12:30:07 +02:00
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewFromAddress' ) . set _value ( dataElem . data . fromaddress ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewToAddress' ) . set _value ( dataElem . data . toaddress ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewDate' ) . set _value ( dataElem . data . date ) ;
etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'previewSubject' ) . set _value ( subject ) ;
var IframeHandle = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'messageIFRAME' ) ;
IframeHandle . set _src ( egw . link ( '/index.php' , { menuaction : 'mail.mail_ui.loadEmailBody' , _messageID : _id } ) ) ;
2013-05-21 10:46:54 +02:00
2013-04-13 12:30:07 +02:00
// var request = new egw_json_request('mail.mail_ui.ajax_loadEmailBody',[_id]);
// request.sendRequest(false);
} ,
2013-05-27 15:48:55 +02:00
2013-04-13 12:30:07 +02:00
mail _setMailBody : function ( content ) {
console . log ( 'mail_setMailBody' , content ) ;
var IframeHandle = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'messageIFRAME' ) ;
IframeHandle . set _value ( '' ) ;
} ,
/ * *
* mail _startTimerFolderStatusUpdate , timer functions , if the counter changes for the current folder
* refresh the message list
* @ param timeout
* /
mail _startTimerFolderStatusUpdate : function ( _refreshTimeOut ) {
if ( typeof _refreshTimeOut == 'undefined' )
{
var minutes = egw . preference ( 'refreshTime' , 'mail' ) ;
this . mail _refreshTimeOut = _refreshTimeOut = 1000 * 60 * ( minutes ? minutes : 3 ) ; // either the prefs or 3 Minutes
}
if ( this . mail _refreshTimeOut > _refreshTimeOut ) _refreshTimeOut = this . mail _refreshTimeOut ;
if ( this . mail _doTimedRefresh ) {
window . clearTimeout ( this . mail _doTimedRefresh ) ;
}
if ( _refreshTimeOut > 9999 ) { //we do not set _refreshTimeOut's less than 10 seconds
var self = this ;
this . mail _doTimedRefresh = window . setInterval ( function ( ) {
self . mail _refreshFolderStatus . apply ( self ) ;
} , _refreshTimeOut ) ;
}
} ,
/ * *
* mail _refreshFolderStatus , function to call to read the counters of a folder and apply them
*
* @ param _nodeID
* @ param mode
* /
mail _refreshFolderStatus : function ( _nodeID , mode ) {
var nodeToRefresh = 0 ;
var mode2use = "none" ;
if ( _nodeID ) nodeToRefresh = _nodeID ;
if ( mode ) {
if ( mode == "forced" ) { mode2use = mode ; }
}
try
{
var tree _wdg = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
var activeFolders = tree _wdg . getTreeNodeOpenItems ( nodeToRefresh , mode2use ) ;
//alert(activeFolders.join('#,#'));
this . mail _queueRefreshFolderList ( activeFolders ) ;
this . mail _refreshMessageGrid ( ) ;
} catch ( e ) { } // ignore the error; maybe the template is not loaded yet
} ,
/ * *
* Queues a refreshFolderList request for 1 ms . Actually this will just execute the
* code after the calling script has finished .
* /
mail _queueRefreshFolderList : function ( _folders )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
this . mail _queuedFolders . push ( _folders ) ;
this . mail _queuedFoldersIndex ++ ;
// Copy idx onto the anonymous function scope
var idx = this . mail _queuedFoldersIndex ;
var self = this ;
window . setTimeout ( function ( ) {
if ( idx == self . mail _queuedFoldersIndex )
{
//var folders = mail_queuedFolders.join(",");
self . mail _queuedFoldersIndex = 0 ;
self . mail _queuedFolders = [ ] ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_setFolderStatus' , [ _folders ] ) ;
request . sendRequest ( ) ;
}
} , 10 ) ;
} ,
/ * *
* mail _setFolderStatus , function to set the status for the visible folders
* /
mail _setFolderStatus : function ( _status ) {
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
for ( var i in _status ) ftree . setLabel ( i , _status [ i ] ) ; //alert(i +'->'+_status[i]);
} ,
2013-04-29 16:56:33 +02:00
/ * *
* mail _setLeaf , function to set the id and description for the folder given by status key
2013-05-07 10:26:17 +02:00
* @ param array _status status array with the required data ( new id , desc , old desc )
* 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 ) {
//console.log('mail_setLeaf',_status);
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[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
if ( typeof _status [ i ] [ 'olddesc' ] !== 'undefined' && _status [ i ] [ 'olddesc' ] !== '#skip-user-interaction-message#' ) app . mail . app _refresh ( egw . lang ( "Renamed Folder %1 to %2" , _status [ i ] [ 'olddesc' ] , _status [ i ] [ 'desc' ] , 'mail' ) ) ;
2013-04-29 16:56:33 +02:00
ftree . renameItem ( i , _status [ i ] [ 'id' ] , _status [ i ] [ 'desc' ] ) ;
//alert(i +'->'+_status[i]['id']+'+'+_status[i]['desc']);
2013-05-07 10:26:17 +02:00
if ( _status [ i ] [ 'id' ] == selectedNode . id )
{
var nm = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
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
* @ param array _status status array with the required data ( KEY id , VALUE desc )
* 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 ) {
console . log ( 'mail_removeLeaf' , _status ) ;
2013-05-13 16:42:42 +02:00
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
var selectedNode = ftree . getSelectedNode ( ) ;
for ( var i in _status )
{
// if olddesc is undefined or #skip# then skip the message, as we process subfolders
if ( typeof _status [ i ] !== 'undefined' && _status [ i ] !== '#skip-user-interaction-message#' ) app . mail . app _refresh ( egw . lang ( "Removed Folder %1 " , _status [ i ] , 'mail' ) ) ;
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 )
{
var nm = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
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
* @ param array _status status array with the required data ( KEY id , VALUE desc )
* key is the id of the leaf to delete
* multiple sets can be passed to mail _deleteLeaf
* /
mail _reloadNode : function ( _status ) {
console . log ( 'mail_reloadNode' , _status ) ;
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
var selectedNode = ftree . getSelectedNode ( ) ;
for ( var i in _status )
{
// if olddesc is undefined or #skip# then skip the message, as we process subfolders
if ( typeof _status [ i ] !== 'undefined' && _status [ i ] !== '#skip-user-interaction-message#' ) app . mail . app _refresh ( egw . lang ( "Reloaded Folder %1 " , _status [ i ] , 'mail' ) ) ;
ftree . refreshItem ( i ) ;
var selectedNodeAfter = ftree . getSelectedNode ( ) ;
//alert(i +'->'+_status[i]['id']+'+'+_status[i]['desc']);
if ( selectedNodeAfter . id != selectedNode . id && selectedNode . id == i )
{
var nm = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
nm . activeFilters [ "selectedFolder" ] = selectedNodeAfter . id ;
nm . applyFilters ( ) ;
}
}
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _refreshMessageGrid , function to call to reread ofthe current folder
* /
mail _refreshMessageGrid : function ( ) {
var nm = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
nm . applyFilters ( ) ; // this should refresh the active folder
} ,
/ * *
* Refresh given application _targetapp display of entry _app _id , incl . outputting _msg
*
* Default implementation here only reloads window with it ' s current url with an added msg = _msg attached
*
* @ param string _msg message ( already translated ) to show , eg . 'Entry deleted'
* @ param string _app application name
* @ param string | int _id = null id of entry to refresh
* @ param string _type = null either 'edit' , 'delete' , 'add' or null
* /
app _refresh : function ( _msg , _app , _id , _type )
2013-04-09 10:53:25 +02:00
{
2013-04-13 12:30:07 +02:00
var bufferExists = false ;
window . clearInterval ( app . mail . doStatus ) ; // whatever message was up to be activated
//alert("app_refresh(\'"+_msg+"\',\'"+_app+"\',\'"+_id+"\',\'"+_type+"\')");
//myCurrentMsg = mail_getMsg();
//if (myCurrentMsg.length) {
// clear message after some time
myMessageBuffer = "" ; //myCurrentMsg;
bufferExists = true ;
//}
app . mail . mail _setMsg ( '<span style="font-weight: bold;">' + _msg + '</span>' ) ;
if ( _app == 'mail' )
{
//we may want to trigger some actions, like modifying the grid, disable preview and stuff
// TODO: more actions
}
if ( bufferExists )
{
this . doStatus = window . setInterval ( "app.mail.mail_setMsg(myMessageBuffer);" , 10000 ) ;
}
} ,
/ * *
* mail _getMsg - gets the current Message
* @ return string
* /
mail _getMsg : function ( )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
var msg _wdg = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'msg' ) ;
if ( msg _wdg )
{
return msg _wdg . valueOf ( ) . htmlNode [ 0 ] . innerHTML ;
}
return "" ;
} ,
/ * *
* mail _setMsg - sets a Message , with the msg container , and controls if the container is enabled / disabled
* @ param string myMsg - the message
* /
mail _setMsg : function ( myMsg )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
var msg _wdg = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'msg' ) ;
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
} ,
/ * *
* Delete mails
* takes in all arguments
* @ param _action
* @ param _elems
* /
mail _delete : function ( _action , _elems )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
var msg = this . mail _getFormData ( _elems ) ;
//alert(_action.id+','+ msg);
app . mail . app _refresh ( egw . lang ( 'delete messages' ) , 'mail' ) ;
this . mail _setRowClass ( _elems , 'deleted' ) ;
2013-05-27 15:48:55 +02:00
this . mail _deleteMessages ( msg ) ;
} ,
/ * *
* Delete mails - actually calls the backend function for deletion
* takes in all arguments
* @ param _msg - message list
* @ param _action - optional action
* /
mail _deleteMessages : function ( _msg , _action )
{
app . mail . app _refresh ( egw . lang ( 'delete messages' ) , 'mail' ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_deleteMessages' , [ _msg , ( typeof _action == 'undefined' ? 'no' : _action ) ] ) ;
2013-04-13 12:30:07 +02:00
request . sendRequest ( false ) ;
2013-05-27 15:48:55 +02:00
for ( var i = 0 ; i < _msg [ 'msg' ] . length ; i ++ ) egw . dataDeleteUID ( _msg [ 'msg' ] [ i ] ) ;
2013-04-13 12:30:07 +02:00
this . mail _refreshMessageGrid ( ) ;
2013-05-21 10:46:54 +02:00
this . mail _preview ( ) ;
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' ] ;
Check = confirm ( reason ) ;
if ( Check == true )
{
this . mail _deleteMessages ( messageList , 'remove_immediately' ) ;
}
else
{
app . mail . app _refresh ( egw . lang ( 'canceled deletion due to userinteraction' ) , 'mail' ) ;
this . mail _removeRowClass ( messageList , 'deleted' ) ;
}
this . mail _refreshMessageGrid ( ) ;
this . mail _preview ( ) ;
} ,
2013-04-13 12:30:07 +02:00
/ * *
* UnDelete mailMessages
*
* @ param _messageList
* /
mail _undeleteMessages : function ( _messageList ) {
// setting class of row, the old style
/ *
for ( var i = 0 ; i < _messageList [ 'msg' ] . length ; i ++ ) {
_id = _messageList [ 'msg' ] [ i ] ;
var dataElem = egw _appWindow ( 'felamimail' ) . mailGrid . dataRoot . getElementById ( _id ) ;
if ( dataElem )
{
//dataElem.clearData();
//dataElem.addClass('deleted');
dataElem . removeClass ( 'deleted' ) ;
}
}
* /
} ,
/ * *
* mail _emptyTrash
* /
mail _emptyTrash : function ( ) {
app . mail . app _refresh ( egw . lang ( 'empty trash' ) , 'mail' ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_emptyTrash' ) ;
request . sendRequest ( ) ;
} ,
/ * *
* mail _compressFolder
* /
mail _compressFolder : function ( ) {
app . mail . app _refresh ( egw . lang ( 'compress folder' ) , 'mail' ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_compressFolder' ) ;
request . sendRequest ( ) ;
} ,
/ * *
* mail _changeProfile
* @ param folder , the ID of the selected Node - > should be an integer
* @ param _widget , handle to the tree widget
* /
mail _changeProfile : function ( folder , _widget ) {
// alert(folder);
var request = new egw _json _request ( 'mail.mail_ui.ajax_changeProfile' , [ folder ] ) ;
request . sendRequest ( false ) ;
this . mail _refreshMessageGrid ( ) ;
return true ;
} ,
/ * *
* mail _changeFolder
* @ param folder , the ID of the selected Node
* @ param _widget , handle to the tree widget
* /
mail _changeFolder : function ( folder , _widget ) {
//alert('change Folder called:'+folder);
app . mail . app _refresh ( egw . lang ( 'change folder' ) + '...' , 'mail' ) ;
var img = _widget . getSelectedNode ( ) . images [ 0 ] ; // fetch first image
if ( ! ( img . search ( eval ( '/' + 'NoSelect' + '/' ) ) < 0 ) || ! ( img . search ( eval ( '/' + 'thunderbird' + '/' ) ) < 0 ) )
2013-02-20 12:31:57 +01:00
{
2013-04-13 12:30:07 +02:00
if ( ! ( img . search ( eval ( '/' + 'thunderbird' + '/' ) ) < 0 ) )
{
rv = this . mail _changeProfile ( folder , _widget ) ;
if ( rv )
{
return rv ;
}
}
if ( _widget . event _args . length == 2 )
2013-02-20 12:31:57 +01:00
{
2013-04-13 12:30:07 +02:00
folder = _widget . event _args [ 1 ] ;
_widget . set _value ( folder ) ;
2013-02-20 12:31:57 +01:00
}
2013-04-13 12:30:07 +02:00
else
{
_widget . set _value ( '' ) ;
}
2013-02-20 12:31:57 +01:00
}
2013-04-13 12:30:07 +02:00
var nm = _widget . getRoot ( ) . getWidgetById ( 'nm' ) ;
nm . activeFilters [ "selectedFolder" ] = folder ;
nm . applyFilters ( ) ;
var msg = _widget . getRoot ( ) . getWidgetById ( 'msg' ) ;
if ( msg )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
window . clearInterval ( this . doStatus ) ;
displayname = _widget . getSelectedLabel ( ) ;
inBraket = displayname . search ( /\(/ ) ;
if ( inBraket != - 1 )
{
outBraket = displayname . search ( /\)/ ) ;
if ( outBraket != - 1 ) displayname = displayname . replace ( /\((.*?)\)/ , "" ) ;
}
myMsg = ( displayname ? displayname : folder ) + ' ' + egw . lang ( 'selected' ) ;
app . mail . app _refresh ( myMsg , 'mail' ) ;
2013-02-13 15:02:02 +01:00
}
2013-04-13 12:30:07 +02:00
//mail_refreshMessageGrid();
this . mail _refreshFolderStatus ( folder , 'forced' ) ;
this . mail _startTimerFolderStatusUpdate ( this . mail _refreshTimeOut ) ;
2013-05-21 14:02:58 +02:00
this . mail _fetchCurrentlyFocussed ( null , true ) ;
2013-05-21 10:46:54 +02:00
this . mail _preview ( ) ;
2013-04-13 12:30:07 +02:00
} ,
/ * *
* Flag mail as 'read' , 'unread' , 'flagged' or 'unflagged'
*
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* /
mail _flag : function ( _action , _elems )
2013-02-13 15:02:02 +01:00
{
2013-04-13 12:30:07 +02:00
//alert(_action.id+' - '+_elems[0].id);
var msg = this . mail _getFormData ( _elems ) ;
//
this . mail _flagMessages ( _action . id , msg ) ;
} ,
/ * *
* Flag mail as 'read' , 'unread' , 'flagged' or 'unflagged'
*
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* /
mail _flagMessages : function ( _flag , _elems )
2013-02-19 17:30:59 +01:00
{
2013-04-13 12:30:07 +02:00
app . mail . app _refresh ( egw . lang ( 'flag messages' ) , 'mail' ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_flagMessages' , [ _flag , _elems ] ) ;
request . sendRequest ( false ) ;
this . mail _refreshMessageGrid ( ) ;
} ,
/ * *
* display header lines , or source of mail , depending on the url given
*
* @ param _url
* /
mail _displayHeaderLines : function ( _url ) {
// only used by right clickaction
egw _openWindowCentered ( _url , 'mail_display_headerLines' , '700' , '600' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
} ,
/ * *
* View header of a message
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _header : function ( _action , _elems )
{
//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 ) ;
} ,
/ * *
* View message source
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _mailsource : function ( _action , _elems )
{
//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 ) ;
} ,
/ * *
* Save a message
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _save : function ( _action , _elems )
{
//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');
document . location = url ;
} ,
/ * *
* Save a message to filemanager
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _save2fm : function ( _action , _elems )
{
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' ;
var filename = dataElem . data . subject . replace ( /[\f\n\t\v/\\:*#?<>\|]/g , "_" ) ;
url += '&name=' + encodeURIComponent ( filename + '.eml' ) ;
url += '&mime=message' + encodeURIComponent ( '/' ) + 'rfc822' ;
url += '&method=mail.mail_ui.vfsSaveMessage'
url += '&id=' + _elems [ 0 ] . id ;
url += '&label=Save' ;
//window.open(url,'_blank','dependent=yes,width=100,height=100,scrollbars=yes,status=yes')
//document.location = url;
egw _openWindowCentered ( url , 'vfs_save_message_' + _elems [ 0 ] . id , '640' , '570' , window . outerWidth / 2 , window . outerHeight / 2 ) ;
} ,
/ * *
* Save message as InfoLog
*
* @ param _action
* @ param _elems _elems [ 0 ] . id is the row - id
* /
mail _infolog : function ( _action , _elems )
2013-02-19 17:30:59 +01:00
{
2013-04-13 12:30:07 +02:00
//alert('mail_infolog('+_elems[0].id+')');return;
var url = window . egw _webserverUrl + '/index.php?' ;
url += 'menuaction=infolog.infolog_ui.import_mail' ; // todo compose for Draft folder
url += '&rowid=' + _elems [ 0 ] . id ;
egw _openWindowCentered ( url , 'import_mail_' + _elems [ 0 ] . id , _action . data . width , _action . data . height ) ;
} ,
/ * *
* Save message as ticket
*
* @ param _action _action . id is 'read' , 'unread' , 'flagged' or 'unflagged'
* @ param _elems
* /
mail _tracker : function ( _action , _elems )
{
//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 ;
egw _openWindowCentered ( url , 'import_tracker_' + _elems [ 0 ] . id , _action . data . width , _action . data . height ) ;
} ,
/ * *
* mail _getFormData
*
* @ param _actionObjects , the senders
* @ return structured array of message ids : array ( msg => message - ids )
* /
mail _getFormData : function ( _actionObjects ) {
var messages = { } ;
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-04-13 12:30:07 +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-04-13 12:30:07 +02:00
return messages ;
} ,
/ * *
* mail _setRowClass
*
* @ param _actionObjects , the senders
* /
mail _setRowClass : function ( _actionObjects , _class ) {
if ( typeof _class == 'undefined' ) return false ;
for ( var i = 0 ; i < _actionObjects . length ; i ++ )
{
if ( _actionObjects [ i ] . id . length > 0 )
{
var dataElem = $j ( _actionObjects [ i ] . iface . getDOMNode ( ) ) ;
dataElem . addClass ( _class ) ;
}
}
} ,
2013-05-27 15:48:55 +02:00
/ * *
* mail _removeRowClass
*
* @ param _actionObjects , the senders , or a messages object
* @ param _class , the class to be removed
* /
mail _removeRowClass : function ( _actionObjects , _class ) {
if ( typeof _class == 'undefined' ) return false ;
if ( typeof _actionObjects [ 'msg' ] == 'undefined' )
{
for ( var i = 0 ; i < _actionObjects . length ; i ++ )
{
if ( _actionObjects [ i ] . id . length > 0 )
{
var dataElem = $j ( _actionObjects [ i ] . iface . getDOMNode ( ) ) ;
dataElem . removeClass ( _class ) ;
}
}
}
else
{
var nm = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm' ) ;
var aO = nm . controller . _objectManager . selectedChildren ;
for ( var i = 0 ; i < _actionObjects [ 'msg' ] . length ; i ++ )
{
for ( var i = 0 ; i < aO . length ; i ++ )
{
if ( aO [ i ] . id == _actionObjects [ 'msg' ] [ i ] )
{
var dataElem = $j ( aO [ i ] . iface . getDOMNode ( ) ) ;
dataElem . removeClass ( _class ) ;
}
}
}
}
} ,
2013-04-13 12:30:07 +02:00
// Tree widget stubs
/ * *
* mail _dragStart - displays information while dragging
*
* @ param action
* @ param _senders - the representation of the elements dragged
* @ return the ddhelper
* /
mail _dragStart : function ( action , _senders ) {
//console.log(action,_senders);
return $j ( "<div class=\"ddhelper\">" + _senders . length + " Mails selected </div>" ) ;
} ,
/ * *
* 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
* /
mail _move : function ( _action , _senders , _target ) {
//console.log(_action,_senders,_target);
var target = _action . id == 'drop_move_mail' ? _target . iface . id : _action . id . substr ( 5 ) ;
var messages = this . mail _getFormData ( _senders ) ;
//alert('mail_move('+messages.msg.join(',')+' --> '+target+')');
// TODO: Write move/copy function which cares about doing the same stuff
// as the "onNodeSelect" function!
var request = new egw _json _request ( 'mail.mail_ui.ajax_moveMessages' , [ target , messages ] ) ;
request . sendRequest ( false ) ;
2013-04-30 16:16:52 +02:00
for ( var i = 0 ; i < messages [ 'msg' ] . length ; i ++ ) egw . dataDeleteUID ( messages [ 'msg' ] [ i ] ) ;
2013-04-13 12:30:07 +02:00
this . mail _refreshMessageGrid ( ) ;
} ,
/ * *
* mail _copy - 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
* /
mail _copy : function ( _action , _senders , _target ) {
//console.log(_action,_senders,_target);
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 ) ;
//alert('mail_copy('+messages.msg.join(',')+' --> '+target+')');
// TODO: Write move/copy function which cares about doing the same stuff
// as the "onNodeSelect" function!
var request = new egw _json _request ( 'mail.mail_ui.ajax_copyMessages' , [ target , messages ] ) ;
2013-04-12 11:22:23 +02:00
request . sendRequest ( false ) ;
2013-04-13 12:30:07 +02:00
this . mail _refreshMessageGrid ( ) ;
} ,
2013-05-21 10:46:54 +02:00
/ * *
* mail _AddFolder - implementation of the AddFolder action of right click options on the tree
*
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
mail _AddFolder : function ( action , _senders ) {
//console.log(action,_senders);
//action.id == 'add'
//_senders.iface.id == target leaf / leaf to edit
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
OldFolderName = ftree . getLabel ( _senders [ 0 ] . iface . id ) ;
if ( jQuery ( OldFolderName ) . text ( ) . length > 0 ) OldFolderName = jQuery ( OldFolderName ) . text ( ) ;
OldFolderName = OldFolderName . trim ( ) ;
OldFolderName = OldFolderName . replace ( /\([0-9]*\)/g , '' ) . trim ( ) ;
//console.log(OldFolderName);
NewFolderName = prompt ( egw . lang ( "Add a new Folder to %1:" , OldFolderName ) ) ;
if ( jQuery ( NewFolderName ) . text ( ) . length > 0 ) NewFolderName = jQuery ( NewFolderName ) . text ( ) ;
//alert(NewFolderName);
if ( NewFolderName && NewFolderName . length > 0 )
{
app . mail . app _refresh ( egw . lang ( "Adding Folder %1 to %2" , NewFolderName , OldFolderName , 'mail' ) ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_addFolder' , [ _senders [ 0 ] . iface . id , NewFolderName ] ) ;
request . sendRequest ( true ) ;
}
} ,
2013-04-13 12:30:07 +02:00
/ * *
* mail _RenameFolder - implementation of the RenameFolder action of right click options on the tree
*
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
mail _RenameFolder : function ( action , _senders ) {
//console.log(action,_senders);
//action.id == 'rename'
//_senders.iface.id == target leaf / leaf to edit
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
OldFolderName = ftree . getLabel ( _senders [ 0 ] . iface . id ) ;
if ( jQuery ( OldFolderName ) . text ( ) . length > 0 ) OldFolderName = jQuery ( OldFolderName ) . text ( ) ;
OldFolderName = OldFolderName . trim ( ) ;
OldFolderName = OldFolderName . replace ( /\([0-9]*\)/g , '' ) . trim ( ) ;
//console.log(OldFolderName);
NewFolderName = prompt ( egw . lang ( "Rename Folder %1 to:" , OldFolderName ) ) ;
if ( jQuery ( NewFolderName ) . text ( ) . length > 0 ) NewFolderName = jQuery ( NewFolderName ) . text ( ) ;
//alert(NewFolderName);
if ( NewFolderName && NewFolderName . length > 0 )
{
2013-05-07 10:26:17 +02:00
app . mail . app _refresh ( egw . lang ( "Renaming Folder %1 to %2" , OldFolderName , NewFolderName , 'mail' ) ) ;
2013-04-13 12:30:07 +02:00
var request = new egw _json _request ( 'mail.mail_ui.ajax_renameFolder' , [ _senders [ 0 ] . iface . id , NewFolderName ] ) ;
2013-05-07 10:26:17 +02:00
request . sendRequest ( true ) ;
2013-04-13 12:30:07 +02:00
}
2013-05-13 16:42:42 +02:00
} ,
/ * *
* mail _DeleteFolder - implementation of the DeleteFolder action of right click options on the tree
*
* @ param _action
* @ param _senders - the representation of the tree leaf to be manipulated
* /
mail _DeleteFolder : function ( action , _senders ) {
//console.log(action,_senders);
//action.id == 'delete'
//_senders.iface.id == target leaf / leaf to edit
var ftree = etemplate2 . getByApplication ( 'mail' ) [ 0 ] . widgetContainer . getWidgetById ( 'nm[foldertree]' ) ;
OldFolderName = ftree . getLabel ( _senders [ 0 ] . iface . id ) ;
if ( jQuery ( OldFolderName ) . text ( ) . length > 0 ) OldFolderName = jQuery ( OldFolderName ) . text ( ) ;
OldFolderName = OldFolderName . trim ( ) ;
OldFolderName = OldFolderName . replace ( /\([0-9]*\)/g , '' ) . trim ( ) ;
//console.log(OldFolderName);
reallyDelete = confirm ( egw . lang ( "Do you really want to DELETE Folder %1 ? \r\nAll messages in the folder will be lost" , OldFolderName ) ) ;
if ( reallyDelete )
{
app . mail . app _refresh ( egw . lang ( "Deleting Folder %1" , OldFolderName , 'mail' ) ) ;
var request = new egw _json _request ( 'mail.mail_ui.ajax_deleteFolder' , [ _senders [ 0 ] . iface . id ] ) ;
request . sendRequest ( true ) ;
}
2013-04-12 11:22:23 +02:00
}
2013-04-09 10:53:25 +02:00
} ) ;