From c7cc902e1a4bb377c6f5f548c1293a97fbc668da Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 11 Aug 2015 16:28:59 +0000 Subject: [PATCH] WIP mail folder management dialog: - Use long task dialog - Fix multiple selection and highlighting - Update index tree after delete operation --- mail/inc/class.mail_ui.inc.php | 47 ++++++++------ mail/js/app.js | 68 +++++++++++++++----- mail/templates/default/folder_management.xet | 2 +- 3 files changed, 81 insertions(+), 36 deletions(-) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 6d99747eaa..35e6546ed3 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -704,6 +704,7 @@ class mail_ui unset($tree_actions['add']); unset($tree_actions['move']); unset($tree_actions['delete']); + unset($tree_actions['foldermanagement']); // manage folders should not affect the ability to subscribe or unsubscribe // to existing folders, it should only affect add/rename/move/delete } @@ -3723,9 +3724,10 @@ class mail_ui /** * ajax_deleteFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) * @param string $_folderName folder to delete + * @param boolean $_return = false wheter return the success value (true) or send response to client (false) * @return nothing */ - function ajax_deleteFolder($_folderName) + function ajax_deleteFolder($_folderName, $_return = false) { //error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName)); $success = false; @@ -3803,22 +3805,10 @@ class mail_ui $msg = lang("refused to delete folder INBOX"); } } + if ($_return) return $success; $response = egw_json_response::get(); if ($success) { - $folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1); - if (isset($folders2return[$this->mail_bo->profileID])) - { - //error_log(__METHOD__.__LINE__.array2string($folders2return[$this->mail_bo->profileID])); - if (empty($subFolders)) $subFolders = array($folderName); - //error_log(__METHOD__.__LINE__.array2string($subFolders)); - foreach($subFolders as $i => $f) - { - //error_log(__METHOD__.__LINE__.$f.'->'.array2string($folders2return[$this->mail_bo->profileID][$f])); - if (isset($folders2return[$this->mail_bo->profileID][$f])) unset($folders2return[$this->mail_bo->profileID][$f]); - } - } - egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return, $expiration=60*60*1); //error_log(__METHOD__.__LINE__.array2string($oA)); $response->call('app.mail.mail_removeLeaf',$oA); } @@ -4620,10 +4610,6 @@ class mail_ui { $content = array ('acc_id' => $profileID); } - else - { - - } $readonlys = array(); // Preserv @@ -4632,4 +4618,29 @@ class mail_ui ); $dtmpl->exec('mail.mail_ui.folderManagement', $content,$sel_options,$readonlys,$preserv,2); } + + /** + * Function to delete folder for management longTask dialog + * it sends successfully deleted folder as response to be + * used in long task response handler. + * + * @param type $_folderName + */ + function ajax_folderMgmt_delete ($_folderName) + { + if ($_folderName) + { + $success = $this->ajax_deleteFolder($_folderName,true); + $response = egw_json_response::get(); + if ($success) + { + $res = $_folderName; + } + else + { + $res = lang("Failed to delete %1",$_folderName); + } + $response->data($res); + } + } } diff --git a/mail/js/app.js b/mail/js/app.js index 173e84de44..806615e619 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -4882,9 +4882,6 @@ app.classes.mail = AppJS.extend( */ folderMgmt_onSelect: function(_ids, _widget) { - // et2 content - var content = this.et2.getArrayMgr('content').data; - // Flag to reset selected items var resetSelection = false; @@ -4914,20 +4911,18 @@ app.classes.mail = AppJS.extend( } }; - if (content) + // extract items ids + var itemIds = _ids.split(_widget.input.dlmtr); + + if(itemIds.length == 2) // there's a range selected { - var itemIds = _ids.split(_widget.input.dlmtr); - - if(itemIds.length == 2) // there's a range selected - { - var branch = _widget.input.getSubItems(_widget.input.getParentId(itemIds[0])); - // Set range of selected/unselected - rangeSelector(itemIds[0], itemIds[1], branch); - } - else if(itemIds.length != 1) - { - resetSelection = true; - } + var branch = _widget.input.getSubItems(_widget.input.getParentId(itemIds[0])); + // Set range of selected/unselected + rangeSelector(itemIds[0], itemIds[1], branch); + } + else if(itemIds.length != 1) + { + resetSelection = true; } if (resetSelection) @@ -4950,7 +4945,6 @@ app.classes.mail = AppJS.extend( _widget.input.setCheck(_itemId, _stat); _widget.input.setSubChecked(_itemId,_stat); } - }, /** @@ -4963,6 +4957,46 @@ app.classes.mail = AppJS.extend( folderMgmt_onCheck: function (_id, _widget) { console.log(); + }, + + /** + * Detele button handler + * triggers longTask dialog and send delete operation url + * + * @param {egw object} _egw egw object + * @param {widget object} _widget button widget + */ + folderMgmt_deleteBtn: function (_egw, _widget) + { + var tree = this.et2.getWidgetById('tree'); + var menuaction= 'mail.mail_ui.ajax_folderMgmt_delete'; + + if (tree) + { + var selFolders = tree.input.getAllChecked(); + if (selFolders) + { + var selFldArr = selFolders.split(tree.input.dlmtr); + var msg = egw.lang('Folders deleting in progress ...'); + et2_dialog.long_task(function(_val, _resp){ + console.log(_val, _resp); + if (_val && _resp.type !== 'error') + { + var stat = []; + var tree = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('tree'); + + // delete the item in folderMgmt dialog + if (tree) tree.deleteItem(_resp, false); + + stat[_resp] = _resp; + // delete the item from index folderTree + egw.window.app.mail.mail_removeLeaf(stat); + } + }, msg, 'Deleting folders', menuaction, selFldArr, 'mail'); + return true; + } + } } + }); diff --git a/mail/templates/default/folder_management.xet b/mail/templates/default/folder_management.xet index fefded2b22..87ce3d928c 100644 --- a/mail/templates/default/folder_management.xet +++ b/mail/templates/default/folder_management.xet @@ -19,7 +19,7 @@ -