1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 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) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates a new controller to show mail send confirmation. 26 * @constructor 27 * @class 28 * This class represents the mail confirmation controller. 29 * 30 * @param {DwtShell} container the containing shell 31 * @param {ZmApp} mailApp the containing app 32 * @param {constant} type controller type 33 * @param {string} sessionId the session id 34 * 35 * @extends ZmController 36 */ 37 ZmMailConfirmController = function(container, mailApp, type, sessionId) { 38 39 ZmController.apply(this, arguments); 40 this._elementsToHide = ZmAppViewMgr.LEFT_NAV; 41 }; 42 43 ZmMailConfirmController.prototype = new ZmController(); 44 ZmMailConfirmController.prototype.constructor = ZmMailConfirmController; 45 46 ZmMailConfirmController.prototype.isZmMailConfirmController = true; 47 ZmMailConfirmController.prototype.toString = function() { return "ZmMailConfirmController"; }; 48 49 ZmMailConfirmController.getDefaultViewType = 50 function() { 51 return ZmId.VIEW_MAIL_CONFIRM; 52 }; 53 ZmMailConfirmController.prototype.getDefaultViewType = ZmMailConfirmController.getDefaultViewType; 54 55 /** 56 * Shows the confirmation that the message was sent. 57 * 58 * @param {ZmMailMsg} msg the message that was sent 59 * @param {constant} composeViewId the compose view id 60 * @param {constant} composeTabId the compose tab id 61 * @param {ZmComposeController} controller compose controller 62 */ 63 ZmMailConfirmController.prototype.showConfirmation = 64 function(msg, composeViewId, composeTabId, controller) { 65 66 this._composeViewId = composeViewId; 67 this._composeTabId = composeTabId; 68 this._composeController = controller; 69 70 if (!this._view) { 71 this._initView(); 72 } 73 74 this._initializeToolBar(); 75 this.resetToolbarOperations(this._toolbar); 76 this._view.showConfirmation(msg); 77 78 if (appCtxt.isChildWindow) { 79 appCtxt.getAppViewMgr()._setViewVisible(ZmId.VIEW_LOADING, false); 80 } 81 82 var avm = appCtxt.getAppViewMgr(); 83 avm.pushView(this._currentViewId); 84 }; 85 86 ZmMailConfirmController.prototype.resetToolbarOperations = 87 function() { 88 this._toolbar.enableAll(true); 89 }; 90 91 ZmMailConfirmController.prototype.getKeyMapName = 92 function() { 93 return ZmKeyMap.MAP_GLOBAL; 94 }; 95 96 ZmMailConfirmController.prototype.handleKeyAction = 97 function(actionCode) { 98 switch (actionCode) { 99 case ZmKeyMap.CANCEL: 100 this._closeListener(); 101 break; 102 103 default: 104 return ZmController.prototype.handleKeyAction.call(this, actionCode); 105 break; 106 } 107 return true; 108 }; 109 110 ZmMailConfirmController.prototype._initView = 111 function() { 112 this._view = new ZmMailConfirmView(this._container, this); 113 this._view.addNewContactsListener(new AjxListener(this, this._addNewContactsListener)); 114 115 var tg = this._createTabGroup(); 116 var rootTg = appCtxt.getRootTabGroup(); 117 tg.newParent(rootTg); 118 tg.addMember(this._view.getTabGroupMember()); 119 120 this._initializeToolBar(); 121 var elements = this.getViewElements(null, this._view, this._toolbar); 122 123 var callbacks = {}; 124 callbacks[ZmAppViewMgr.CB_PRE_HIDE] = this._preHideCallback.bind(this); 125 callbacks[ZmAppViewMgr.CB_POST_SHOW] = this._postShowCallback.bind(this); 126 this._app.createView({ viewId: this._currentViewId, 127 viewType: this._currentViewType, 128 elements: elements, 129 hide: this._elementsToHide, 130 controller: this, 131 callbacks: callbacks, 132 tabParams: { id:this._composeTabId }}); 133 }; 134 135 ZmMailConfirmController.prototype._initializeToolBar = 136 function() { 137 if (this._toolbar) return; 138 139 var buttons = [ZmOperation.CLOSE]; 140 141 var className = appCtxt.isChildWindow ? "ZmAppToolBar_cw" : "ZmAppToolBar"; 142 this._toolbar = new ZmButtonToolBar({parent:this._container, buttons:buttons, className:className+" ImgSkin_Toolbar", 143 context:ZmId.VIEW_MAIL_CONFIRM}); 144 this._toolbar.addSelectionListener(ZmOperation.CLOSE, new AjxListener(this, this._closeListener)); 145 }; 146 147 ZmMailConfirmController.prototype._getDefaultFocusItem = 148 function() { 149 return this._view.getDefaultFocusItem(); 150 }; 151 152 ZmMailConfirmController.prototype._closeListener = 153 function() { 154 this._doClose(); 155 }; 156 157 ZmMailConfirmController.prototype._addNewContactsListener = 158 function(attrs) { 159 if (!attrs.length) { 160 this._doClose(); 161 return; 162 } 163 164 var batchCommand = new ZmBatchCommand(false, null, true); 165 for (var i = 0, count = attrs.length; i < count; i++) { 166 var contact = new ZmContact(); 167 batchCommand.add(new AjxCallback(contact, contact.create, [attrs[i]])); 168 } 169 batchCommand.run(new AjxCallback(this, this._handleResponseCreateContacts)); 170 }; 171 172 ZmMailConfirmController.prototype._handleResponseCreateContacts = 173 function() { 174 this._doClose(); 175 }; 176 177 ZmMailConfirmController.prototype._doClose = 178 function() { 179 appCtxt.getAppViewMgr().popView(true); 180 }; 181