From 343a72c3a8fc8b28c60f6e14c4b3dbd7a26a3159 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 6 Dec 2013 10:35:39 +0000 Subject: [PATCH] toggle flags/labels, remove all labels, shortcuts thereoff, codecleanup --- mail/inc/class.mail_bo.inc.php | 117 ++------------------------------- mail/inc/class.mail_ui.inc.php | 12 +++- mail/js/app.js | 88 +++++++++++++++++++++---- 3 files changed, 93 insertions(+), 124 deletions(-) diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 6fa03b3b2d..79ece86a13 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -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': diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 13488900a9..4eaa0fc570 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -952,32 +952,38 @@ class mail_ui 'caption' => "".lang('urgent')."", 'icon' => 'mail_label1', 'onExecute' => 'javaScript:app.mail.mail_flag', + 'shortcut' => egw_keymanager::shortcut(egw_keymanager::_1, true, true), ), 'label2' => array( 'caption' => "".lang('job')."", 'icon' => 'mail_label2', 'onExecute' => 'javaScript:app.mail.mail_flag', + 'shortcut' => egw_keymanager::shortcut(egw_keymanager::_2, true, true), ), 'label3' => array( 'caption' => "".lang('personal')."", 'icon' => 'mail_label3', 'onExecute' => 'javaScript:app.mail.mail_flag', + 'shortcut' => egw_keymanager::shortcut(egw_keymanager::_3, true, true), ), 'label4' => array( 'caption' => "".lang('to do')."", 'icon' => 'mail_label4', 'onExecute' => 'javaScript:app.mail.mail_flag', + 'shortcut' => egw_keymanager::shortcut(egw_keymanager::_4, true, true), ), 'label5' => array( 'caption' => "".lang('later')."", 'icon' => 'mail_label5', 'onExecute' => 'javaScript:app.mail.mail_flag', + 'shortcut' => egw_keymanager::shortcut(egw_keymanager::_5, true, true), ), 'unlabel' => array( 'group' => ++$group, 'caption' => "".lang('remove all')."", '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; } } diff --git a/mail/js/app.js b/mail/js/app.js index 0f426c91e5..1aa971c7d7 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -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; i0) + 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); + + } + } } } },