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-02-13 16:35:12 +01:00
|
|
|
var mail_doTimedRefresh;
|
2013-02-20 17:27:10 +01:00
|
|
|
var mail_refreshTimeOut = 1000*60*3; // initial call
|
2013-02-13 16:35:12 +01:00
|
|
|
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
|
2013-02-20 17:27:10 +01:00
|
|
|
//inital call of refresh folderstatus
|
|
|
|
window.setTimeout('mail_refreshFolderStatus()',1000);
|
2013-02-13 16:35:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2013-02-20 17:27:10 +01:00
|
|
|
if(_refreshTimeOut > 9999) {//we do not set _refreshTimeOut's less than 10 seconds
|
2013-02-13 16:35:12 +01:00
|
|
|
mail_doTimedRefresh = window.setInterval("mail_refreshFolderStatus()", _refreshTimeOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-19 17:30:59 +01:00
|
|
|
/**
|
|
|
|
* mail_refreshFolderStatus, function to call to read the counters of a folder and apply them
|
|
|
|
*
|
|
|
|
* @param _nodeID
|
|
|
|
* @param mode
|
|
|
|
*/
|
2013-02-13 16:35:12 +01:00
|
|
|
function mail_refreshFolderStatus(_nodeID,mode) {
|
|
|
|
var nodeToRefresh = 0;
|
|
|
|
var mode2use = "none";
|
|
|
|
if (_nodeID) nodeToRefresh = _nodeID;
|
|
|
|
if (mode) {
|
|
|
|
if (mode == "forced") {mode2use = mode;}
|
|
|
|
}
|
2013-02-19 17:30:59 +01:00
|
|
|
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() {
|
2013-02-14 18:10:20 +01:00
|
|
|
var nm = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('nm');
|
|
|
|
nm.applyFilters(); // this should refresh the active folder
|
2013-02-13 16:35:12 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:02:02 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2013-02-19 17:30:59 +01:00
|
|
|
window.register_app_refresh("mail", function(_msg, _app, _id, _type)
|
2013-02-13 15:02:02 +01:00
|
|
|
{
|
|
|
|
var bufferExists = false;
|
|
|
|
window.clearInterval(doStatus); // whatever message was up to be activated
|
|
|
|
//alert("app_refresh(\'"+_msg+"\',\'"+_app+"\',\'"+_id+"\',\'"+_type+"\')");
|
2013-02-13 16:35:12 +01:00
|
|
|
//myCurrentMsg = mail_getMsg();
|
2013-02-13 15:02:02 +01:00
|
|
|
//if (myCurrentMsg.length) {
|
|
|
|
// clear message after some time
|
|
|
|
myMessageBuffer = ""; //myCurrentMsg;
|
|
|
|
bufferExists = true;
|
|
|
|
//}
|
2013-02-13 16:35:12 +01:00
|
|
|
mail_setMsg('<span style="font-weight: bold;">' +_msg+ '</span>');
|
2013-02-13 15:02:02 +01:00
|
|
|
if (_app=='mail')
|
|
|
|
{
|
|
|
|
//we may want to trigger some actions, like modifying the grid, disable preview and stuff
|
|
|
|
|
|
|
|
// TODO: more actions
|
|
|
|
}
|
2013-02-19 17:30:59 +01:00
|
|
|
if (bufferExists) doStatus = window.setInterval("egw_appWindow('mail').mail_setMsg(myMessageBuffer);", 10000);
|
2013-02-13 15:02:02 +01:00
|
|
|
}
|
2013-02-19 17:30:59 +01:00
|
|
|
);
|
2013-02-13 15:02:02 +01:00
|
|
|
|
|
|
|
/**
|
2013-02-13 16:35:12 +01:00
|
|
|
* mail_getMsg - gets the current Message
|
2013-02-13 15:02:02 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2013-02-13 16:35:12 +01:00
|
|
|
function mail_getMsg()
|
2013-02-13 15:02:02 +01:00
|
|
|
{
|
|
|
|
var msg_wdg = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('msg');
|
|
|
|
if (msg_wdg)
|
|
|
|
{
|
|
|
|
return msg_wdg.valueOf().htmlNode[0].innerHTML;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-13 16:35:12 +01:00
|
|
|
* mail_setMsg - sets a Message, with the msg container, and controls if the container is enabled/disabled
|
2013-02-13 15:02:02 +01:00
|
|
|
* @param string myMsg - the message
|
|
|
|
*/
|
2013-02-13 16:35:12 +01:00
|
|
|
function mail_setMsg(myMsg)
|
2013-02-13 15:02:02 +01: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-12 18:48:04 +01:00
|
|
|
/**
|
2013-02-13 16:35:12 +01:00
|
|
|
* mail_emptyTrash
|
2013-02-12 18:48:04 +01:00
|
|
|
*/
|
2013-02-13 16:35:12 +01:00
|
|
|
function mail_emptyTrash() {
|
2013-02-13 15:02:02 +01:00
|
|
|
app_refresh(egw.lang('empty trash'), 'mail');
|
2013-02-12 18:48:04 +01:00
|
|
|
var request = new egw_json_request('mail.mail_ui.ajax_emptyTrash');
|
|
|
|
request.sendRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-13 16:35:12 +01:00
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2013-02-20 12:31:57 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 16:35:12 +01:00
|
|
|
/**
|
|
|
|
* mail_changeFolder
|
2013-02-20 12:31:57 +01:00
|
|
|
* @param folder, the ID of the selected Node
|
|
|
|
* @param _widget, handle to the tree widget
|
2013-02-12 18:48:04 +01:00
|
|
|
*/
|
2013-02-13 16:35:12 +01:00
|
|
|
function mail_changeFolder(folder,_widget) {
|
2013-02-12 18:48:04 +01:00
|
|
|
//alert('change Folder called:'+folder);
|
2013-02-19 17:30:59 +01:00
|
|
|
app_refresh(egw.lang('change folder')+'...', 'mail');
|
2013-02-13 15:02:02 +01:00
|
|
|
var img = _widget.getSelectedNode().images[0]; // fetch first image
|
2013-02-19 17:30:59 +01:00
|
|
|
if (!(img.search(eval('/'+'NoSelect'+'/'))<0) || !(img.search(eval('/'+'thunderbird'+'/'))<0))
|
2013-02-13 15:02:02 +01:00
|
|
|
{
|
2013-02-20 12:31:57 +01:00
|
|
|
if (!(img.search(eval('/'+'thunderbird'+'/'))<0))
|
|
|
|
{
|
|
|
|
rv = mail_changeProfile(folder,_widget);
|
|
|
|
if (rv)
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2013-02-13 15:02:02 +01:00
|
|
|
if (_widget.event_args.length==2)
|
|
|
|
{
|
|
|
|
folder = _widget.event_args[1];
|
|
|
|
_widget.set_value(folder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_widget.set_value('');
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 18:48:04 +01:00
|
|
|
var nm = _widget.getRoot().getWidgetById('nm');
|
|
|
|
nm.activeFilters["selectedFolder"] = folder;
|
|
|
|
nm.applyFilters();
|
2013-02-13 15:02:02 +01:00
|
|
|
var msg = _widget.getRoot().getWidgetById('msg');
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
window.clearInterval(doStatus);
|
|
|
|
displayname = _widget.getSelectedLabel();
|
2013-02-19 17:30:59 +01:00
|
|
|
inBraket = displayname.search(/\(/);
|
|
|
|
if (inBraket!=-1)
|
|
|
|
{
|
|
|
|
outBraket = displayname.search(/\)/);
|
|
|
|
if (outBraket!=-1) displayname = displayname.replace(/\((.*?)\)/,"");
|
|
|
|
}
|
2013-02-13 15:02:02 +01:00
|
|
|
myMsg = (displayname?displayname:folder)+' '+egw.lang('selected');
|
|
|
|
app_refresh(myMsg, 'mail');
|
|
|
|
}
|
2013-02-20 17:27:10 +01:00
|
|
|
//mail_refreshMessageGrid();
|
2013-02-19 17:30:59 +01:00
|
|
|
mail_refreshFolderStatus(folder,'forced');
|
2013-02-20 12:31:57 +01:00
|
|
|
mail_startTimerFolderStatusUpdate(mail_refreshTimeOut);
|
2013-02-19 17:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2013-02-12 18:48:04 +01:00
|
|
|
}
|
|
|
|
|
2013-02-15 16:53:18 +01:00
|
|
|
// 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);
|
|
|
|
}
|
2013-02-19 17:30:59 +01:00
|
|
|
|