From 30ae5f1b8102b2d215dcbc3f5f84287171c64a09 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 27 May 2014 12:05:23 +0000 Subject: [PATCH] * Mail: detect and handle actions on ALL-messages for setting and removing flags and lables for the mailbox we operate on --- mail/inc/class.mail_ui.inc.php | 108 ++++++++++++++++++++++++++++++--- mail/js/app.js | 71 +++++++++++++++++++++- 2 files changed, 168 insertions(+), 11 deletions(-) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 2cb70798cf..09ac8231ed 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -4302,24 +4302,116 @@ $this->partID = $partID; function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse=true) { if(mail_bo::$debug) error_log(__METHOD__."->".$_flag.':'.array2string($_messageList)); + $alreadyFlagged=false; if ($_messageList=='all' || !empty($_messageList['msg'])) { - if ($_messageList=='all') + if (isset($_messageList['all']) && $_messageList['all']) { - // we have no folder information - $folder=null; + // we have both messageIds AND allFlag folder information + $uidA = self::splitRowID($_messageList['msg'][0]); + $folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder + if (isset($_messageList['activeFilters']) && $_messageList['activeFilters']) + { + $query = $_messageList['activeFilters']; + if (!empty($query['search']) || !empty($query['filter'])) + { + //([filterName] => Schnellsuche[type] => quick[string] => ebay[status] => any + if (is_null(emailadmin_imapbase::$supportsORinQuery) || !isset(emailadmin_imapbase::$supportsORinQuery[$this->mail_bo->profileID])) + { + emailadmin_imapbase::$supportsORinQuery = egw_cache::getCache(egw_cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10); + if (!isset(emailadmin_imapbase::$supportsORinQuery[$this->mail_bo->profileID])) emailadmin_imapbase::$supportsORinQuery[$this->mail_bo->profileID]=true; + } + $filter = $filter2toggle = array('filterName' => (emailadmin_imapbase::$supportsORinQuery[$this->mail_bo->profileID]?lang('quicksearch'):lang('subject')),'type' => ($query['filter2']?$query['filter2']:(emailadmin_imapbase::$supportsORinQuery[$this->mail_bo->profileID]?'quick':'subject')),'string' => $query['search'],'status' => 'any'); + } + else + { + $filter = $filter2toggle = array(); + } + // flags read,flagged,label1,label2,label3,label4,label5 can be toggled: handle this when all mails in a folder + // should be affected serverside. here. + $messageList = $messageListForToggle = array(); + if (in_array($_flag,array('read','flagged','label1','label2','label3','label4','label5'))) + { + $filter2toggle['status'] = array('un'.$_flag); + if ($query['filter']) + { + $filter2toggle['status'][] = $query['filter']; + } + $_sR = $this->mail_bo->getSortedList( + $folder, + $sort=0, + $reverse=1, + $filter2toggle, + $rByUid=true, + false + ); + $messageListForToggle = $_sR['match']->ids; + $filter['status'] = array($_flag); + if ($query['filter']) + { + $filter['status'][] = $query['filter']; + } + $_sR = $this->mail_bo->getSortedList( + $folder, + $sort=0, + $reverse=1, + $filter, + $rByUid=true, + false + ); + $messageList = $_sR['match']->ids; + if (count($messageListForToggle)>0) + { + $flag2set = (strtolower($_flag)); + //error_log(__METHOD__.__LINE__." toggle un$_flag -> $flag2set ".array2string($filter2toggle).array2string($messageListForToggle)); + $this->mail_bo->flagMessages($flag2set, $messageListForToggle,$folder); + } + if (count($messageList)>0) + { + $flag2set = 'un'.$_flag; + //error_log(__METHOD__.__LINE__." $_flag -> $flag2set ".array2string($filter).array2string($messageList)); + $this->mail_bo->flagMessages($flag2set, $messageList,$folder); + } + $alreadyFlagged=true; + //unset($_messageList['all']); + } + elseif (!in_array($_flag,array('read','flagged','label1','label2','label3','label4','label5')) && !empty($filter)) + { + $_sR = $this->mail_bo->getSortedList( + $folder, + $sort=0, + $reverse=1, + $filter, + $rByUid=true, + false + ); + $messageList = $_sR['match']->ids; + unset($_messageList['all']); + $_messageList['msg'] = array(); + } + else + { + $alreadyFlagged=true; + $uidA = self::splitRowID($_messageList['msg'][0]); + $folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder + $this->mail_bo->flagMessages($_flag, 'all', $folder); + } + } } else { $uidA = self::splitRowID($_messageList['msg'][0]); $folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder } - foreach($_messageList['msg'] as $rowID) + if (!$alreadyFlagged) { - $hA = self::splitRowID($rowID); - $messageList[] = $hA['msgUID']; + foreach($_messageList['msg'] as $rowID) + { + $hA = self::splitRowID($rowID); + $messageList[] = $hA['msgUID']; + } + $this->mail_bo->flagMessages($_flag, ((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList),$folder); } - $this->mail_bo->flagMessages($_flag, ($_messageList=='all' ? 'all':$messageList),$folder); } else { @@ -4337,7 +4429,7 @@ $this->partID = $partID; if ($_sendJsonResponse) { $response = egw_json_response::get(); - $response->call('egw_message',lang('flagged %1 messages as %2 in %3',count($_messageList['msg']),lang($_flag),$folder)); + $response->call('egw_message',lang('flagged %1 messages as %2 in %3',(isset($_messageList['all']) && $_messageList['all']?lang('all'):count($_messageList['msg'])),lang($_flag),$folder)); } } diff --git a/mail/js/app.js b/mail/js/app.js index 8751eda40b..4072937013 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -214,7 +214,9 @@ app.classes.mail = AppJS.extend( case 'edit': if (node) // we dont care for updated accounts not shown (eg. other users) { - tree.refreshItem(_id); + //tree.refreshItem(_id); + egw.json('mail.mail_ui.ajax_reloadNode',[_id]) + .sendRequest(true); } break; case 'add': @@ -1522,6 +1524,64 @@ app.classes.mail = AppJS.extend( } }, + /** + * mail_checkAllSelected + * + * @param _action + * @return boolean + */ + mail_checkAllSelected: function(_action, _confirm) + { + if (typeof _confirm == 'undefiend') _confirm = false; + var obj_manager = egw_getObjectManager(_action.getManager().id, false); + if (obj_manager && obj_manager.getAllSelected()) + { + if (_confirm) + { +/* var buttons = [ + {text: this.egw.lang("Yes"), id: "all", class: "ui-priority-primary", "default": true}, + {text: this.egw.lang("Cancel"), id:"cancel"} + ]; + et2_dialog.show_dialog(function(_button_id, _value) { + switch (_button_id) + { + case "all": + return true; + case "cancel": + return false; + } + }, + this.egw.lang("Do you really want to apply %1 to ALL messages in the current folder?",this.egw.lang(_action.id))+" ", + this.egw.lang("Confirm"), + _action.id, buttons); +*/ + return confirm(this.egw.lang("Do you really want to apply/toggle %1 to ALL messages in the current folder?\n %2: All (filtered) mesages, will be affected.\n %3: only the selected range will be affected ",this.egw.lang(_action.id),this.egw.lang('ok'),this.egw.lang('cancel'))); + + } + else + { + return true; + } + } + return false; + }, + + /** + * mail_getActiveFilters + * + * @param _action + * @return mixed boolean/activeFilters object + */ + mail_getActiveFilters: function(_action) + { + var obj_manager = egw_getObjectManager(this.nm_index, false); + if (obj_manager && obj_manager.manager && obj_manager.manager.data && obj_manager.manager.data.nextmatch && obj_manager.manager.data.nextmatch.activeFilters) + { + return obj_manager.manager.data.nextmatch.activeFilters; + } + return false; + }, + /** * Flag mail as 'read', 'unread', 'flagged' or 'unflagged' * @@ -1534,6 +1594,7 @@ app.classes.mail = AppJS.extend( var msg; var ftree; var _folder; + if (_action.id=='read') { ftree = this.et2.getWidgetById(this.nm_index+'[foldertree]'); @@ -1573,6 +1634,8 @@ app.classes.mail = AppJS.extend( if (do_nmactions) { msg = this.mail_getFormData(_elems); + msg['all'] = this.mail_checkAllSelected(_action,true); + msg['activeFilters'] = this.mail_getActiveFilters(_action); if (_action.id.substring(0,2)=='un') { //old style, only available for undelete and unlabel (no toggle) if ( _action.id=='unlabel') // this means all labels should be removed @@ -1637,12 +1700,14 @@ app.classes.mail = AppJS.extend( // Notify server of changes if (msg_unset['msg'] && msg_unset['msg'].length) { - this.mail_flagMessages('un'+_action.id,msg_unset); + if (!msg['all']) this.mail_flagMessages('un'+_action.id,msg_unset); } if (msg_set['msg'] && msg_set['msg'].length) { - this.mail_flagMessages(_action.id,msg_set); + if (!msg['all']) this.mail_flagMessages(_action.id,msg_set); } + //server must do the toggle, as we apply to ALL, not only the visible + if (msg['all']) this.mail_flagMessages(_action.id,msg); // No further update needed, only in case of read, the counters should be refreshed if (_action.id=='read') this.mail_refreshFolderStatus(_folder,'thisfolderonly',false,true); return;