toggle flags/labels, remove all labels, shortcuts thereoff, codecleanup

This commit is contained in:
Klaus Leithoff 2013-12-06 10:35:39 +00:00
parent 3219eccec4
commit 343a72c3a8
3 changed files with 93 additions and 124 deletions

View File

@ -1063,8 +1063,6 @@ class mail_bo
//$queryString = implode(',', $sortResult);
// fetch the data for the selected messages
if (self::$debug) $starttime = microtime(true);
//$headersNew = $this->icServer->getSummary($queryString, $rByUid);
//$headersNew = $this->_getSummary($queryString, $rByUid,false,$_folderName);
$uidsToFetch = new Horde_Imap_Client_Ids();
$uidsToFetch->add($sortResult);
@ -2791,22 +2789,13 @@ class mail_bo
case "unlabelfive":
$ret = $this->icServer->store($folder, array('remove'=>array('$label5'), 'ids'=> $uidsToModify));
break;
}
$summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
$cachemodified = false;
foreach ((array)$_messageUID as $k => $_uid)
{
//error_log(__METHOD__.__LINE__.' try to unset summarycache for:'.$_uid.' in '.(!empty($_folder)?$_folder: $this->sessionData['mailbox']));
if (isset($summary[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])][$_uid]))
{
//error_log(__METHOD__.__LINE__.' unset summarycache for:'.$_uid.' in '.(!empty($_folder)?$_folder: $this->sessionData['mailbox']));
$cachemodified = true;
unset($summary[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])][$_uid]);
}
}
if ($cachemodified)
{
egw_cache::setCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$summary,$expiration=60*60*1);
case "unlabel":
$ret = $this->icServer->store($folder, array('remove'=>array('$label1'), 'ids'=> $uidsToModify));
$ret = $this->icServer->store($folder, array('remove'=>array('$label2'), 'ids'=> $uidsToModify));
$ret = $this->icServer->store($folder, array('remove'=>array('$label3'), 'ids'=> $uidsToModify));
$ret = $this->icServer->store($folder, array('remove'=>array('$label4'), 'ids'=> $uidsToModify));
$ret = $this->icServer->store($folder, array('remove'=>array('$label5'), 'ids'=> $uidsToModify));
break;
}
self::$folderStatusCache[$this->profileID][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
@ -2877,20 +2866,6 @@ class mail_bo
if ($cachemodified) egw_cache::setCache(egw_cache::INSTANCE,'email','structureCache'.trim($GLOBALS['egw_info']['user']['account_id']),$structure,$expiration=60*60*1);
}
}
$summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
$cachemodified = false;
foreach ((array)$_messageUID as $k => $_uid)
{
if (isset($summary[$this->icServer->ImapServerId][(!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox'])][$_uid]))
{
$cachemodified = true;
unset($summary[$this->icServer->ImapServerId][(!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox'])][$_uid]);
}
}
if ($cachemodified)
{
egw_cache::setCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$summary,$expiration=60*60*1);
}
//error_log(__METHOD__.__LINE__.array2string($retUid));
return ($returnUIDs ? $retUid : true);
@ -3081,68 +3056,6 @@ class mail_bo
return $structure[$this->icServer->ImapServerId][$_folder][$_uid];
}
/**
* _getSummary
* fetch the summary for the mails, requested by queryString
* @param string/int $queryString the messageuid(s),
* @param boolean $byUid=true, is the messageuid given by UID or ID
* @param boolean $_ignoreCache=false, use or disregard cache, when fetching
* @param string $_folder='', if given search within that folder for the given $queryString, else use sessionData['mailbox'], or servers getCurrentMailbox()
* @return array an array with the mail headers requested
*/
function _getSummary($queryString, $byUid=true, $_ignoreCache=false, $_folder = '')
{
static $summary;
if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
//error_log(__METHOD__.__LINE__.'User:'.trim($GLOBALS['egw_info']['user']['account_id'])." UID: $_uid, ".$this->icServer->ImapServerId.','.$_folder);
if (is_null($summary)) $summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
$_uids = explode(',', $queryString);
$uidsCached = (is_array($summary[$this->icServer->ImapServerId][$_folder])?array_keys($summary[$this->icServer->ImapServerId][$_folder]):array());
$toFetch = array_diff($_uids,(array)$uidsCached);
$saveNeeded = false;
if (!empty($toFetch))
{
//error_log(__METHOD__.__LINE__.':'.$GLOBALS['egw_info']['user']['account_id'].'::'.$this->icServer->ImapServerId.'::'. $_folder.':QS:'.$queryString.'->'.array2string(array_keys((array)$summary[$this->icServer->ImapServerId][$_folder])));
error_log(__METHOD__.__LINE__.':UserID:'.$GLOBALS['egw_info']['user']['account_id'].':ServerID:'.$this->icServer->ImapServerId.'::'.' fetch Summary for Headers in Folder:'.$_folder.' with:'.implode(',',$toFetch));
if (!isset($summary[$this->icServer->ImapServerId])) $summary[$this->icServer->ImapServerId]=array();
if (!isset($summary[$this->icServer->ImapServerId][$_folder])) $summary[$this->icServer->ImapServerId][$_folder]=array();
$result = $this->icServer->getSummary(implode(',',$toFetch), $byUid);
foreach ($result as $sum)
{
//error_log(__METHOD__.__LINE__.'::'.$sum['UID'].':'.$sum['SUBJECT']);
$summary[$this->icServer->ImapServerId][$_folder][$sum['UID']]=$sum;
}
$saveNeeded = true;
}
foreach ($_uids as $_uid)
{
$fetched=false;
//error_log(__METHOD__.__LINE__." UID: $_uid, ".$this->icServer->ImapServerId.','.$_folder.'->'.array2string($summary[$this->icServer->ImapServerId][$_folder][$_uid]));
if (isset($summary[$this->icServer->ImapServerId]) && !empty($summary[$this->icServer->ImapServerId]) &&
isset($summary[$this->icServer->ImapServerId][$_folder]) && !empty($summary[$this->icServer->ImapServerId][$_folder]) &&
isset($summary[$this->icServer->ImapServerId][$_folder][$_uid]) && !empty($summary[$this->icServer->ImapServerId][$_folder][$_uid]))
{
if ($_ignoreCache===false)
{
//error_log(__METHOD__.__LINE__.' Using cache for structure on Server:'.$this->icServer->ImapServerId.' for uid:'.$_uid." in Folder:".$_folder.'->'.array2string($structure[$this->icServer->ImapServerId][$_folder][$_uid]));
$rv[] = $summary[$this->icServer->ImapServerId][$_folder][$_uid];
$fetched=true;
}
}
if ($fetched==false)
{
error_log(__METHOD__.__LINE__.':UserID:'.$GLOBALS['egw_info']['user']['account_id'].':ServerID:'.$this->icServer->ImapServerId.'::'.' fetch Summary for Header in Folder:'.$_folder.' with:'.$_uid);
$result = $this->icServer->getSummary($_uid, $byUid);
$summary[$this->icServer->ImapServerId][$_folder][$_uid] = $result[0];
$rv[] = $summary[$this->icServer->ImapServerId][$_folder][$_uid];
$saveNeeded = true;
}
}
if ( $saveNeeded ) egw_cache::setCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$summary,$expiration=60*60*1);
//error_log(__METHOD__.__LINE__.' Using query for summary on Server:'.$this->icServer->ImapServerId.' for uid:'.$_uid." in Folder:".$_folder.'->'.array2string($structure[$this->icServer->ImapServerId][$_folder][$_uid]));
return $rv;
}
/**
* _getSubStructure
* fetch the substructure of a mail, by given structure and partid
@ -3679,22 +3592,6 @@ class mail_bo
$_structure = $this->getStructure($_uid, $_partID, $_folder, $_preserveSeen);
}
/*
if ($_preserveSeen==false)
{
$summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
$cachemodified = false;
if (isset($summary[$this->icServer->ImapServerId][$_folder][$_uid]))
{
$cachemodified = true;
unset($summary[$this->icServer->ImapServerId][$_folder][$_uid]);
}
if ($cachemodified)
{
egw_cache::setCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$summary,$expiration=60*60*1);
}
}
*/
switch($_structure->getPrimaryType())
{
case 'application':

View File

@ -952,32 +952,38 @@ class mail_ui
'caption' => "<font color='#ff0000'>".lang('urgent')."</font>",
'icon' => 'mail_label1',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_1, true, true),
),
'label2' => array(
'caption' => "<font color='#ff8000'>".lang('job')."</font>",
'icon' => 'mail_label2',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_2, true, true),
),
'label3' => array(
'caption' => "<font color='#008000'>".lang('personal')."</font>",
'icon' => 'mail_label3',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_3, true, true),
),
'label4' => array(
'caption' => "<font color='#0000ff'>".lang('to do')."</font>",
'icon' => 'mail_label4',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_4, true, true),
),
'label5' => array(
'caption' => "<font color='#8000ff'>".lang('later')."</font>",
'icon' => 'mail_label5',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_5, true, true),
),
'unlabel' => array(
'group' => ++$group,
'caption' => "<font color='#ff0000'>".lang('remove all')."</font>",
'icon' => 'mail_label',
'onExecute' => 'javaScript:app.mail.mail_flag',
'shortcut' => egw_keymanager::shortcut(egw_keymanager::_0, true, true),
),
),
),
@ -1043,6 +1049,8 @@ class mail_ui
'onExecute' => 'javaScript:app.mail.mail_flag',
//'enableClass' => 'unseen',
//'enabled' => "javaScript:mail_enabledByClass",
'shortcut' => egw_keymanager::shortcut(egw_keymanager::U, true, true),
),
/*
'unread' => array(
@ -1535,7 +1543,8 @@ unset($query['actions']);
$data["size"] = $header['size']; /// size
$data["class"] = implode(' ', $css_styles);
if ($header['seen']) $data["flags"]['seen'] = 'seen';
//translate style-classes back to flags
if ($header['seen']) $data["flags"]['read'] = 'read';
foreach ($css_styles as $k => $flag) {
if ($flag!='mail')
{
@ -1544,6 +1553,7 @@ unset($query['actions']);
elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';}
elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';}
elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';}
elseif ($flag=='unseen') {$data["flags"]['unread'] = 'unread';}
else $data["flags"][$flag] = $flag;
}
}

View File

@ -1078,22 +1078,64 @@ app.classes.mail = AppJS.extend(
//alert(_action.id+' - '+_elems[0].id);
//console.log(_action, _elems);
var classToProcess = _action.id;
if (_action.id=='read') classToProcess='seen';
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';
if (do_nmactions)
{
msg = this.mail_getFormData(_elems);
if (_action.id.substring(0,2)=='un') {
//old style, probably only available for undelete (no toggle)
this.mail_removeRowClass(_elems,_action.id.substring(2));
this.mail_setRowClass(_elems,_action.id);
this.mail_flagMessages(_action.id,msg,(do_nmactions?false:true));
//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'];
for (i=0; i<labels.length; i++) this.mail_removeRowClass(_elems,labels[i]);
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));
}
}
else
{
var dataElem = egw.dataGetUIDdata(msg.msg[0]);
var flags = dataElem.data.flags;
this.mail_removeRowClass(_elems,(flags[_action.id]?'un':'')+_action.id);
this.mail_setRowClass(_elems,(flags[_action.id]?'':'un')+_action.id);
this.mail_flagMessages((flags[_action.id]?'un':'')+_action.id,msg,(do_nmactions?false:true),false);
var msg_set = {msg:[]};
var msg_unset = {msg:[]};
var dataElem;
var flags;
for (i=0; i<msg.msg.length; i++)
{
dataElem = egw.dataGetUIDdata(msg.msg[i]);
flags = dataElem.data.flags;
// since we toggle we need to unset the ones already set, and set the ones not set
if (flags[_action.id])
{
msg_unset['msg'].push(msg.msg[i]);
}
else
{
msg_set['msg'].push(msg.msg[i]);
}
}
if (msg_unset['msg'] && msg_unset['msg'].length)
{
this.mail_removeRowClass(msg_unset,classToProcess);
this.mail_setRowClass(msg_unset,'un'+classToProcess);
this.mail_flagMessages('un'+_action.id,msg_unset,(do_nmactions?false:true),false);
}
if (msg_set['msg'] && msg_set['msg'].length)
{
this.mail_removeRowClass(msg_set,'un'+classToProcess);
this.mail_setRowClass(msg_set,classToProcess);
this.mail_flagMessages(_action.id,msg_set,(do_nmactions?false:true),false);
}
this.mail_refreshMessageGrid((do_nmactions?false:true));
}
}
@ -1602,13 +1644,33 @@ app.classes.mail = AppJS.extend(
mail_setRowClass: function(_actionObjects,_class) {
if (typeof _class == 'undefined') return false;
for (var i = 0; i < _actionObjects.length; i++)
if (typeof _actionObjects['msg'] == 'undefined')
{
if (_actionObjects[i].id.length>0)
for (var i = 0; i < _actionObjects.length; i++)
{
var dataElem = $j(_actionObjects[i].iface.getDOMNode());
dataElem.addClass(_class);
if (_actionObjects[i].id.length>0)
{
var dataElem = $j(_actionObjects[i].iface.getDOMNode());
dataElem.addClass(_class);
}
}
}
else
{
var nm = this.et2.getWidgetById(this.nm_index);
var aO = nm.controller._objectManager.selectedChildren;
for (var i = 0; i < _actionObjects['msg'].length; i++)
{
for (var k = 0; k < aO.length; k++)
{
if (aO[k].id==_actionObjects['msg'][i])
{
var dataElem = $j(aO[k].iface.getDOMNode());
dataElem.addClass(_class);
}
}
}
}
},