1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2008, 2009, 2010, 2011, 2013, 2014, 2015, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2008, 2009, 2010, 2011, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 ZmMailFolderTreeController = function(type, dropTgt) { 25 if (arguments.length == 0) return; 26 ZmFolderTreeController.apply(this, arguments); 27 }; 28 ZmMailFolderTreeController.prototype = new ZmFolderTreeController; 29 ZmMailFolderTreeController.prototype.constructor = ZmMailFolderTreeController; 30 31 ZmMailFolderTreeController.prototype.toString = 32 function() { 33 return "ZmMailFolderTreeController"; 34 }; 35 36 // 37 // ZmFolderTreeController methods 38 // 39 40 ZmMailFolderTreeController.prototype._updateOverview = function(params) { 41 42 ZmTreeController.prototype._updateOverview.call(this, params); 43 44 // for multi-account allow account header to update based on Inbox's unread count 45 var org = params.organizer, fields = params.fields; 46 if (appCtxt.multiAccounts && (fields[ZmOrganizer.F_UNREAD] && org.isSystem()) || 47 (fields[ZmOrganizer.F_TOTAL] && (org.nId == ZmFolder.ID_DRAFTS || org.nId == ZmOrganizer.ID_OUTBOX))) { 48 49 var ovc = appCtxt.getApp(ZmApp.MAIL).getOverviewContainer(true); 50 if (ovc) { 51 ovc.updateLabel(org); 52 } 53 } 54 }; 55 56 ZmMailFolderTreeController.prototype._deleteListener = 57 function(ev) { 58 // check for associated data source 59 if (appCtxt.get(ZmSetting.POP_ACCOUNTS_ENABLED)) { 60 var organizer = this._getActionedOrganizer(ev); 61 if (organizer.isDataSource()) { 62 var accounts = appCtxt.getDataSourceCollection().getPopAccountsFor(organizer.id); 63 var args = [ organizer.getName(), AjxStringUtil.htmlEncode(accounts[0].getName(), true)]; 64 var message = AjxMessageFormat.format(ZmMsg.errorDeletePopFolder, args); 65 66 var dialog = appCtxt.getMsgDialog(); 67 dialog.setMessage(message); 68 dialog.popup(); 69 return; 70 } 71 } 72 73 // perform default action 74 ZmFolderTreeController.prototype._deleteListener.apply(this, arguments); 75 }; 76 77 ZmMailFolderTreeController.prototype._dropListener = 78 function(ev) { 79 // check for associated data source 80 if ((appCtxt.get(ZmSetting.POP_ACCOUNTS_ENABLED) || appCtxt.get(ZmSetting.IMAP_ACCOUNTS_ENABLED)) && ev.action == DwtDropEvent.DRAG_DROP) { 81 var item = ev.srcData.data; 82 var organizer = item instanceof ZmOrganizer ? item : null; 83 if (organizer && organizer.isDataSource()) { 84 var datasources = appCtxt.getDataSourceCollection(); 85 var popAccounts = appCtxt.get(ZmSetting.POP_ACCOUNTS_ENABLED) ? datasources.getPopAccountsFor(organizer.id) : []; 86 var imapAccounts = appCtxt.get(ZmSetting.IMAP_ACCOUNTS_ENABLED) ? datasources.getImapAccountsFor(organizer.id) : []; 87 88 if (popAccounts.length || imapAccounts.length) { 89 var args = [ organizer.getName(), popAccounts.length ? popAccounts[0].getName() : imapAccounts[0].getName() ]; 90 var message = AjxMessageFormat.format(popAccounts.length ? ZmMsg.errorMovePopFolder : ZmMsg.errorMoveImapFolder, args); 91 92 var dialog = appCtxt.getMsgDialog(); 93 dialog.setMessage(message); 94 dialog.popup(); 95 return; 96 } 97 } 98 } 99 100 // perform default action 101 ZmFolderTreeController.prototype._dropListener.apply(this, arguments); 102 }; 103 104 ZmMailFolderTreeController.prototype.resetOperations = 105 function(parent, type, id) { 106 // perform default action 107 ZmFolderTreeController.prototype.resetOperations.apply(this, arguments); 108 109 // disable move for folders with POP accounts 110 if (appCtxt.get(ZmSetting.POP_ACCOUNTS_ENABLED)) { 111 var organizer = appCtxt.getById(id); 112 if (organizer.isDataSource()) { 113 parent.enable(ZmOperation.MOVE, false); 114 parent.enable(ZmOperation.MOVE_MENU, false) 115 } 116 } 117 }; 118 119 ZmMailFolderTreeController.prototype._doMarkAllRead = 120 function(organizer) { 121 // we're not guaranteed mark-all will succeed, so this is a tiny bit risky 122 if (appCtxt.isOffline) { 123 appCtxt.getApp(ZmApp.MAIL).clearNewMailBadge(); 124 } 125 126 ZmTreeController.prototype._doMarkAllRead.apply(this, arguments); 127 }; 128