1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 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, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file defines the overview controller. 27 * 28 */ 29 30 /** 31 * Creates an overview as a set of tree views. When the overview is created, various 32 * characteristics of its tree views can be provided. Each type of tree view 33 * has a corresponding tree controller (also a singleton), which is lazily 34 * created. 35 * @class 36 * This singleton class manages overviews, each of which has a unique ID. 37 * 38 * @author Conrad Damon 39 * 40 * @param {DwtControl} container the top-level container 41 * 42 * @extends ZmController 43 */ 44 ZmOverviewController = function(container) { 45 ZmController.call(this, container); 46 47 this._overviewContainer = {}; 48 this._overview = {}; 49 this._controller = {}; 50 this._appOverviewId = {}; 51 }; 52 53 // Controller for given org type 54 ZmOverviewController.CONTROLLER = {}; 55 56 ZmOverviewController.DEFAULT_FOLDER_ID = ZmFolder.ID_INBOX; 57 58 ZmOverviewController.prototype = new ZmController; 59 ZmOverviewController.prototype.constructor = ZmOverviewController; 60 61 /** 62 * Returns a string representation of the object. 63 * 64 * @return {String} a string representation of the object 65 */ 66 ZmOverviewController.prototype.toString = 67 function() { 68 return "ZmOverviewController"; 69 }; 70 71 /** 72 * Creates a new overview container with the given options. Used when mailbox 73 * has multiple accounts. 74 * 75 * @param {Hash} containerParams a hash of params (see {@link ZmOverviewContainer}) 76 * @param {Hash} overviewParams a hash of params (see {@link ZmOverview}) 77 */ 78 ZmOverviewController.prototype.createOverviewContainer = 79 function(containerParams, overviewParams) { 80 containerParams.parent = containerParams.parent || this._shell; 81 containerParams.controller = this; 82 containerParams.id = ZmId.getOverviewContainerId(containerParams.containerId); 83 84 // the overview container will create overviews for each account 85 var container = this._overviewContainer[containerParams.containerId] = 86 new ZmAccountOverviewContainer(containerParams); 87 88 // we call initialize *after* creating new object since it references 89 // this._overviewContainer hash 90 overviewParams.containerId = containerParams.id; 91 container.initialize(overviewParams); 92 93 return container; 94 }; 95 96 /** 97 * Creates a new overview with the given options. 98 * 99 * @param {Hash} params a hash of params (see {@link ZmOverview}) 100 */ 101 ZmOverviewController.prototype.createOverview = 102 function(params) { 103 params.parent = params.parent || this._shell; 104 105 var ov = this._overview[params.overviewId] = new ZmOverview(params, this); 106 return ov; 107 }; 108 109 /** 110 * Gets the overview container for the given app. 111 * 112 * @param {String} containerId the container ID (defaults to current app name) 113 * @return {ZmOverviewContainer} the container 114 */ 115 ZmOverviewController.prototype.getOverviewContainer = 116 function(containerId) { 117 var containerId = containerId || appCtxt.getCurrentAppName(); 118 return this._overviewContainer[containerId]; 119 }; 120 121 /** 122 * Gets the overview with the given id. 123 * 124 * @param {String} overviewId the overview id 125 * @return {ZmOverview} the overview 126 */ 127 ZmOverviewController.prototype.getOverview = 128 function(overviewId) { 129 return this._overview[overviewId]; 130 }; 131 132 /** 133 * Gets the tree controller. 134 * 135 * @param {String} treeId the tree id 136 * @param {Boolean} noCreate if <code>true</code>, only return an already created controller 137 * 138 * @return {ZmTreeController} the tree controller 139 */ 140 ZmOverviewController.prototype.getTreeController = 141 function(treeId, noCreate) { 142 if (!treeId) { return null; } 143 if (!this._controller[treeId] && !noCreate) { 144 var className = ZmOverviewController.CONTROLLER[treeId]; 145 if (className && window[className]) { // make sure the class has been loaded 146 var treeControllerCtor = eval(ZmOverviewController.CONTROLLER[treeId]); 147 if (treeControllerCtor) { 148 this._controller[treeId] = new treeControllerCtor(treeId); 149 } 150 } 151 } 152 return this._controller[treeId]; 153 }; 154 155 /** 156 * Gets the tree data for the given organizer type. 157 * 158 * @param {String} treeId the tree id 159 * @return {ZmTree} the tree 160 */ 161 ZmOverviewController.prototype.getTreeData = 162 function(treeId) { 163 return treeId ? appCtxt.getTree(treeId) : null; 164 }; 165 166 /** 167 * Gets the tree view in the given overview. 168 * 169 * @param {String} overviewId the overview id 170 * @param {String} treeId the organizer type 171 * @return {ZmTreeView} the tree view or <code>null</code> if not found 172 */ 173 ZmOverviewController.prototype.getTreeView = 174 function(overviewId, treeId) { 175 if (!overviewId || !treeId) { return null; } 176 if (!this.getOverview(overviewId)) { return null; } 177 return this.getOverview(overviewId).getTreeView(treeId); 178 }; 179