1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2008, 2009, 2010, 2011, 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) 2008, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 
 25 /**
 26  * @overview
 27  * This file defines a zimlet app controller.
 28  *
 29  */
 30 
 31 /**
 32  * Creates a zimlet app controller.
 33  * @class
 34  * This class represents a zimlet application controller.
 35  * 
 36  * @param	{String}	name		the application name
 37  * @param	{DwtShell}	container	the container
 38  * @param	{ZmApp}		app			the app
 39  * 
 40  * @extends		ZmController
 41  */
 42 ZmZimletAppController = function(name, container, app) {
 43 	if (arguments.length == 0) { return; }
 44 	ZmController.call(this, container, app);
 45 	this._name = name;
 46 };
 47 
 48 ZmZimletAppController.prototype = new ZmController;
 49 ZmZimletAppController.prototype.constructor = ZmZimletAppController;
 50 
 51 ZmZimletAppController.prototype.isZmZimletAppController = true;
 52 ZmZimletAppController.prototype.toString = function() { return "ZmZimletAppController"; };
 53 
 54 //
 55 // Public methods
 56 //
 57 
 58 // Note: If there's ever a need to make this a session controller (unlikely), we'll have to figure
 59 // out some way to return an appropriate view type in a static context.
 60 ZmZimletAppController.getDefaultViewType =
 61 function() {
 62 	return "zimlet";
 63 };
 64 
 65 ZmZimletAppController.prototype.getDefaultViewType =
 66 function() {
 67 	return this._name;
 68 };
 69 
 70 /**
 71  * Gets the view.
 72  * 
 73  * @return	{ZmZimletAppView}	the view
 74  */
 75 ZmZimletAppController.prototype.getView =
 76 function() {
 77 	if (!this._view) {
 78 		// create components
 79 		this._view = new ZmZimletAppView(this._container, this);
 80 		this._toolbar = new ZmToolBar({parent:DwtShell.getShell(window)});
 81 
 82 		// setup app elements
 83 		var elements = this.getViewElements(null, this._view, this._toolbar);
 84 
 85 
 86 		// create callbacks
 87 		var callbacks = {};
 88 //		callbacks[ZmAppViewMgr.CB_PRE_HIDE] = new AjxCallback(this, this._preHideCallback);
 89 //		callbacks[ZmAppViewMgr.CB_PRE_UNLOAD] = new AjxCallback(this, this._preUnloadCallback);
 90 //		callbacks[ZmAppViewMgr.CB_POST_SHOW] = new AjxCallback(this, this._postShowCallback);
 91 //		callbacks[ZmAppViewMgr.CB_POST_HIDE] = new AjxCallback(this, this._postHideCallback);
 92 
 93 		// create app view
 94 	    this._app.createView({	viewId:			this.getDefaultViewType(),
 95 								elements:		elements,
 96 								controller:		this,
 97 								callbacks:		callbacks,
 98 								isAppView:		true,
 99 								isTransient:	true});
100 	}
101 	return this._view;
102 };
103 
104 /**
105  * Gets the toolbar.
106  * 
107  * @return	{ZmToolBar}	the tool bar
108  */
109 ZmZimletAppController.prototype.getToolbar = function() {
110 	this.getView();
111 	return this._toolbar;
112 };
113 
114 /**
115  * Shows the controller.
116  * 
117  *@return boolean <code>true</code> if previous view was not dirty and hence could swap it with new view; else <code>false</code>
118  */
119 ZmZimletAppController.prototype.show = function() {
120 	this.getView();
121 	return this._app.pushView(this.getDefaultViewType());
122 };
123