1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file contains the task controller class. 27 * 28 */ 29 30 /** 31 * Creates a new task controller to manage task creation/editing. 32 * @class 33 * This class manages task creation/editing. 34 * 35 * @author Parag Shah 36 * 37 * @param {DwtShell} container the containing shell 38 * @param {ZmApp} app the containing app 39 * @param {constant} type controller type 40 * @param {string} sessionId the session id 41 * 42 * @extends ZmCalItemComposeController 43 */ 44 ZmTaskController = function(container, app, type, sessionId) { 45 if (arguments.length == 0) { return; } 46 ZmCalItemComposeController.apply(this, arguments); 47 }; 48 49 ZmTaskController.prototype = new ZmCalItemComposeController; 50 ZmTaskController.prototype.constructor = ZmTaskController; 51 52 ZmTaskController.prototype.isZmTaskController = true; 53 ZmTaskController.prototype.toString = function() { return "ZmTaskController"; }; 54 55 ZmTaskController.DEFAULT_TAB_TEXT = ZmMsg.task; 56 57 58 // Public methods 59 60 ZmTaskController.getDefaultViewType = 61 function() { 62 return ZmId.VIEW_TASKEDIT; 63 }; 64 ZmTaskController.prototype.getDefaultViewType = ZmTaskController.getDefaultViewType; 65 66 ZmTaskController.prototype.saveCalItem = 67 function(attId) { 68 var calItem = this._composeView.getCalItem(attId); 69 if (calItem) { 70 this._saveCalItemFoRealz(calItem, attId); 71 return true; 72 } 73 return false; 74 }; 75 76 ZmTaskController.prototype.isCloseAction = 77 function() { 78 return this._action == ZmCalItemComposeController.SAVE; 79 }; 80 81 ZmTaskController.prototype._handleResponseSave = 82 function(calItem, result) { 83 ZmCalItemComposeController.prototype._handleResponseSave.call(this, calItem); 84 if(this._action == ZmCalItemComposeController.SAVE) { 85 this.closeView(); 86 } 87 // XXX: null out message so we re-fetch task next time its opened 88 // To optimize, we should save the modified contents into cache'd task item 89 if (calItem && calItem._orig) 90 calItem._orig.message = null; 91 92 //Cache the item for further processing 93 calItem.cache(); 94 //need to set rev,ms for next soap request 95 calItem.setFromSavedResponse(result); 96 97 appCtxt.setStatusMsg(ZmMsg.taskSaved); 98 if(calItem.alarm == true || calItem.isAlarmModified()) { 99 this._app.getReminderController().refresh(); 100 } 101 }; 102 103 ZmTaskController.prototype._createComposeView = 104 function() { 105 return (new ZmTaskEditView(this._container, this)); 106 }; 107 108 ZmTaskController.prototype._getDefaultFocusItem = 109 function() { 110 return this._composeView._getDefaultFocusItem(); 111 }; 112 113 ZmTaskController.prototype._getButtonOverrides = 114 function(buttons) { 115 116 if (!(buttons && buttons.length)) { return; } 117 118 var overrides = {}; 119 var idParams = { 120 skinComponent: ZmId.SKIN_APP_TOP_TOOLBAR, 121 componentType: ZmId.WIDGET_BUTTON, 122 app: ZmId.APP_TASKS, 123 containingView: ZmId.VIEW_TASKEDIT 124 }; 125 for (var i = 0; i < buttons.length; i++) { 126 var buttonId = buttons[i]; 127 overrides[buttonId] = {}; 128 idParams.componentName = buttonId; 129 var item = (buttonId === ZmOperation.SEP) ? "Separator" : buttonId + " button"; 130 var description = item + " on top toolbar for task edit view"; 131 overrides[buttonId].domId = ZmId.create(idParams, description); 132 } 133 return overrides; 134 }; 135 136 ZmTaskController.prototype._setComposeTabGroup = 137 function(setFocus) { 138 var tg = this._createTabGroup(); 139 var rootTg = appCtxt.getRootTabGroup(); 140 tg.newParent(rootTg); 141 tg.addMember(this._toolbar); 142 this._composeView._addTabGroupMembers(tg); 143 144 var focusItem = this._composeView || this._composeView._getDefaultFocusItem() || tg.getFirstMember(true); 145 var ta = new AjxTimedAction(this, this._setFocus, [focusItem, !setFocus]); 146 AjxTimedAction.scheduleAction(ta, 10); 147 }; 148 149 ZmTaskController.prototype.getKeyMapName = 150 function() { 151 return ZmKeyMap.MAP_EDIT_TASK; 152 }; 153 154 /** 155 * Checks if the tasks is moving from local to remote folder (or vice versa). 156 * 157 * @param {ZmTask} task the task 158 * @param {String} newFolderId the folder id 159 * @return {Boolean} <code>true</code> if moving from local to remote folder 160 */ 161 ZmTaskController.prototype.isMovingBetwAccounts = 162 function(task, newFolderId) { 163 var isMovingBetw = false; 164 if (task._orig) { 165 var origFolder = task._orig.getFolder(); 166 var newFolder = appCtxt.getById(newFolderId); 167 if (origFolder && newFolder) { 168 if ((origFolder.id != newFolderId) && 169 ((origFolder.link && !newFolder.link) || (!origFolder.link && newFolder.link))) 170 { 171 isMovingBetw = true; 172 } 173 } 174 } 175 return isMovingBetw; 176 }; 177 178 // Private / Protected methods 179 180 ZmTaskController.prototype._getTabParams = 181 function() { 182 return {id:this.tabId, image:"CloseGray", hoverImage:"Close", text:ZmTaskController.DEFAULT_TAB_TEXT, textPrecedence:77, 183 tooltip:ZmTaskController.DEFAULT_TAB_TEXT, style: DwtLabel.IMAGE_RIGHT}; 184 }; 185 186 // Callbacks 187 188 ZmTaskController.prototype._printListener = 189 function() { 190 var url = ["/h/printtasks?id=", this._composeView._calItem.invId]; 191 192 if (appCtxt.isOffline) { 193 var acctName = this._composeView._calItem.getAccount().name; 194 url.push("&acct=", acctName); 195 } 196 window.open([appContextPath, url.join(""), "&tz=", AjxTimezone.getServerId(AjxTimezone.DEFAULT)].join(""), "_blank"); 197 }; 198 199 ZmTaskController.prototype.closeView = function() { 200 this._closeView(); 201 }; 202 203