mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 09:09:04 +01:00
408 lines
11 KiB
JavaScript
408 lines
11 KiB
JavaScript
/**
|
|
* 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$
|
|
*/
|
|
|
|
var mail_doTimedRefresh;
|
|
var mail_refreshTimeOut = 1000*60*3; // initial call
|
|
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
|
|
//inital call of refresh folderstatus
|
|
window.setTimeout('mail_refreshFolderStatus()',1000);
|
|
|
|
/**
|
|
* mail_startTimerFolderStatusUpdate, timer functions, if the counter changes for the current folder
|
|
* refresh the message list
|
|
* @param timeout
|
|
*/
|
|
function mail_startTimerFolderStatusUpdate(_refreshTimeOut) {
|
|
if (typeof _refreshTimeOut == 'undefined')
|
|
{
|
|
var minutes = egw.preference('refreshTime','mail');
|
|
mail_refreshTimeOut = _refreshTimeOut= 1000*60*(minutes?minutes:3); // either the prefs or 3 Minutes
|
|
}
|
|
if (mail_refreshTimeOut > _refreshTimeOut) _refreshTimeOut = mail_refreshTimeOut;
|
|
if(mail_doTimedRefresh) {
|
|
window.clearTimeout(mail_doTimedRefresh);
|
|
}
|
|
if(_refreshTimeOut > 9999) {//we do not set _refreshTimeOut's less than 10 seconds
|
|
mail_doTimedRefresh = window.setInterval("mail_refreshFolderStatus()", _refreshTimeOut);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* mail_refreshFolderStatus, function to call to read the counters of a folder and apply them
|
|
*
|
|
* @param _nodeID
|
|
* @param mode
|
|
*/
|
|
function mail_refreshFolderStatus(_nodeID,mode) {
|
|
var nodeToRefresh = 0;
|
|
var mode2use = "none";
|
|
if (_nodeID) nodeToRefresh = _nodeID;
|
|
if (mode) {
|
|
if (mode == "forced") {mode2use = mode;}
|
|
}
|
|
var tree_wdg = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('nm[foldertree]');
|
|
|
|
var activeFolders = tree_wdg.getTreeNodeOpenItems(nodeToRefresh,mode2use);
|
|
//alert(activeFolders.join('#,#'));
|
|
mail_queueRefreshFolderList(activeFolders);
|
|
|
|
mail_refreshMessageGrid();
|
|
}
|
|
|
|
var mail_queuedFolders = [];
|
|
var mail_queuedFoldersIndex = 0;
|
|
|
|
/**
|
|
* Queues a refreshFolderList request for 1ms. Actually this will just execute the
|
|
* code after the calling script has finished.
|
|
*/
|
|
function mail_queueRefreshFolderList(_folders)
|
|
{
|
|
mail_queuedFolders.push(_folders);
|
|
mail_queuedFoldersIndex++;
|
|
|
|
// Copy idx onto the anonymous function scope
|
|
var idx = mail_queuedFoldersIndex;
|
|
window.setTimeout(function() {
|
|
if (idx == mail_queuedFoldersIndex)
|
|
{
|
|
//var folders = mail_queuedFolders.join(",");
|
|
mail_queuedFoldersIndex = 0;
|
|
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
|
|
*/
|
|
function mail_setFolderStatus(_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]);
|
|
}
|
|
|
|
/**
|
|
* mail_refreshMessageGrid, function to call to reread ofthe current folder
|
|
*/
|
|
function mail_refreshMessageGrid() {
|
|
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
|
|
*/
|
|
var doStatus;
|
|
window.register_app_refresh("mail", function(_msg, _app, _id, _type)
|
|
{
|
|
var bufferExists = false;
|
|
window.clearInterval(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;
|
|
//}
|
|
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) doStatus = window.setInterval("egw_appWindow('mail').mail_setMsg(myMessageBuffer);", 10000);
|
|
}
|
|
);
|
|
|
|
/**
|
|
* mail_getMsg - gets the current Message
|
|
* @return string
|
|
*/
|
|
function mail_getMsg()
|
|
{
|
|
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
|
|
*/
|
|
function mail_setMsg(myMsg)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Delete mails
|
|
* takes in all arguments
|
|
* @param _action
|
|
* @param _elems
|
|
*/
|
|
function mail_delete(_action,_elems)
|
|
{
|
|
var msg = mail_getFormData(_elems);
|
|
//alert(_action.id+','+ msg);
|
|
app_refresh(egw.lang('delete messages'), 'mail');
|
|
mail_setRowClass(_elems,'deleted');
|
|
var request = new egw_json_request('mail.mail_ui.ajax_deleteMessages',[msg]);
|
|
request.sendRequest(false);
|
|
mail_refreshMessageGrid()
|
|
}
|
|
|
|
/**
|
|
* UnDelete mailMessages
|
|
*
|
|
* @param _messageList
|
|
*/
|
|
function mail_undeleteMessages(_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
|
|
*/
|
|
function mail_emptyTrash() {
|
|
app_refresh(egw.lang('empty trash'), 'mail');
|
|
var request = new egw_json_request('mail.mail_ui.ajax_emptyTrash');
|
|
request.sendRequest();
|
|
}
|
|
|
|
/**
|
|
* mail_compressFolder
|
|
*/
|
|
function mail_compressFolder() {
|
|
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
|
|
*/
|
|
function mail_changeProfile(folder,_widget) {
|
|
// alert(folder);
|
|
var request = new egw_json_request('mail.mail_ui.ajax_changeProfile',[folder]);
|
|
request.sendRequest(false);
|
|
mail_refreshMessageGrid();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* mail_changeFolder
|
|
* @param folder, the ID of the selected Node
|
|
* @param _widget, handle to the tree widget
|
|
*/
|
|
function mail_changeFolder(folder,_widget) {
|
|
//alert('change Folder called:'+folder);
|
|
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))
|
|
{
|
|
if (!(img.search(eval('/'+'thunderbird'+'/'))<0))
|
|
{
|
|
rv = mail_changeProfile(folder,_widget);
|
|
if (rv)
|
|
{
|
|
return rv;
|
|
}
|
|
}
|
|
if (_widget.event_args.length==2)
|
|
{
|
|
folder = _widget.event_args[1];
|
|
_widget.set_value(folder);
|
|
}
|
|
else
|
|
{
|
|
_widget.set_value('');
|
|
}
|
|
}
|
|
var nm = _widget.getRoot().getWidgetById('nm');
|
|
nm.activeFilters["selectedFolder"] = folder;
|
|
nm.applyFilters();
|
|
var msg = _widget.getRoot().getWidgetById('msg');
|
|
if (msg)
|
|
{
|
|
window.clearInterval(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_refresh(myMsg, 'mail');
|
|
}
|
|
//mail_refreshMessageGrid();
|
|
mail_refreshFolderStatus(folder,'forced');
|
|
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
|
|
}
|
|
|
|
/**
|
|
* Flag mail as 'read', 'unread', 'flagged' or 'unflagged'
|
|
*
|
|
* @param _action _action.id is 'read', 'unread', 'flagged' or 'unflagged'
|
|
* @param _elems
|
|
*/
|
|
function mail_flag(_action, _elems)
|
|
{
|
|
//alert(_action.id+' - '+_elems[0].id);
|
|
var msg = mail_getFormData(_elems);
|
|
//
|
|
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
|
|
*/
|
|
function mail_flagMessages(_flag, _elems)
|
|
{
|
|
app_refresh(egw.lang('flag messages'), 'mail');
|
|
var request = new egw_json_request('mail.mail_ui.ajax_flagMessages',[_flag, _elems]);
|
|
request.sendRequest(false);
|
|
mail_refreshMessageGrid()
|
|
}
|
|
|
|
/**
|
|
* display header lines, or source of mail, depending on the url given
|
|
*
|
|
* @param _url
|
|
*/
|
|
function mail_displayHeaderLines(_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
|
|
*/
|
|
function mail_header(_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;
|
|
mail_displayHeaderLines(url);
|
|
}
|
|
|
|
/**
|
|
* View message source
|
|
*
|
|
* @param _action
|
|
* @param _elems _elems[0].id is the row-id
|
|
*/
|
|
function mail_mailsource(_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';
|
|
mail_displayHeaderLines(url);
|
|
}
|
|
|
|
/**
|
|
* mail_getFormData
|
|
*
|
|
* @param _actionObjects, the senders
|
|
* @return structured array of message ids: array(msg=>message-ids)
|
|
*/
|
|
function mail_getFormData(_actionObjects) {
|
|
var messages = {};
|
|
if (_actionObjects.length>0)
|
|
{
|
|
messages['msg'] = [];
|
|
}
|
|
|
|
for (var i = 0; i < _actionObjects.length; i++)
|
|
{
|
|
if (_actionObjects[i].id.length>0)
|
|
{
|
|
messages['msg'][i] = _actionObjects[i].id;
|
|
}
|
|
}
|
|
|
|
return messages;
|
|
}
|
|
|
|
/**
|
|
* mail_setRowClass
|
|
*
|
|
* @param _actionObjects, the senders
|
|
*/
|
|
function mail_setRowClass(_actionObjects,_class) {
|
|
if (typeof _class == 'undefined') return false;
|
|
|
|
for (var i = 0; i < _actionObjects.length; i++)
|
|
{
|
|
if (_actionObjects[i].id.length>0)
|
|
{
|
|
var _id = _actionObjects[i].id;
|
|
var dataElem = $j(_actionObjects[i].iface.getDOMNode());
|
|
dataElem.addClass(_class);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// Tree widget stubs
|
|
mail_dragStart = function(action,sender) {
|
|
console.log(action,sender);
|
|
}
|
|
mail_move = function(action,sender) {
|
|
console.log(action,sender);
|
|
}
|
|
mail_copy = function(action,sender) {
|
|
console.log(action,sender);
|
|
}
|
|
|