1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 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) 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 portal controller class.
 27  */
 28 
 29 /**
 30  * Creates the portal controller.
 31  * @class
 32  * This class represents the portal controller.
 33  * 
 34  * @param	{DwtComposite}	container	the containing element
 35  * @param	{ZmPortalApp}	app			the application
 36  * @param	{constant}		type		controller type
 37  * @param	{string}		sessionId	the session id
 38  * 
 39  * @extends		ZmListController
 40  */
 41 ZmPortalController = function(container, app, type, sessionId) {
 42 	if (arguments.length == 0) { return; }
 43 	ZmListController.apply(this, arguments);
 44 
 45     // TODO: Where does this really belong? Answer: in ZmPortalApp
 46     ZmOperation.registerOp(ZmId.OP_PAUSE_TOGGLE, {textKey:"pause", image:"Pause", style: DwtButton.TOGGLE_STYLE});
 47 
 48     this._listeners[ZmOperation.REFRESH] = new AjxListener(this, this._refreshListener);
 49     this._listeners[ZmOperation.PAUSE_TOGGLE] = new AjxListener(this, this._pauseListener);
 50 }
 51 ZmPortalController.prototype = new ZmListController;
 52 ZmPortalController.prototype.constructor = ZmPortalController;
 53 
 54 ZmPortalController.prototype.isZmPortalController = true;
 55 ZmPortalController.prototype.toString = function() { return "ZmPortalController"; };
 56 
 57 //
 58 // Public methods
 59 //
 60 
 61 ZmPortalController.prototype.getDefaultViewType = function() {
 62 	return ZmId.VIEW_PORTAL;
 63 };
 64 
 65 ZmPortalController.prototype.show = function() {
 66 	ZmListController.prototype.show.call(this);
 67 	this._setup(this._currentViewId);
 68 
 69 	var elements = this.getViewElements(this._currentViewId, this._listView[this._currentViewId]);
 70 
 71 	this._setView({ view:		this._currentViewId,
 72 					viewType:	this._currentViewType,
 73 					elements:	elements,
 74 					isAppView:	true});
 75 };
 76 
 77 /**
 78  * Sets the paused flag for the portlets.
 79  * 
 80  * @param	{Boolean}	paused		if <code>true</code>, pause the portlets
 81  */
 82 ZmPortalController.prototype.setPaused = function(paused) {
 83     var view = this._listView[this._currentViewId];
 84     var portletIds = view && view.getPortletIds();
 85     if (portletIds && portletIds.length > 0) {
 86         var portletMgr = appCtxt.getApp(ZmApp.PORTAL).getPortletMgr();
 87         for (var i = 0; i < portletIds.length; i++) {
 88             var portlet = portletMgr.getPortletById(portletIds[i]);
 89             portlet.setPaused(paused);
 90         }
 91     }
 92 };
 93 
 94 //
 95 // Protected methods
 96 //
 97 
 98 ZmPortalController.prototype._getToolBarOps = function() {
 99 	return [ ZmOperation.REFRESH /*, ZmOperation.PAUSE_TOGGLE*/ ];
100 };
101 
102 ZmPortalController.prototype._createNewView = function(view) {
103 	return new ZmPortalView(this._container, this, this._dropTgt);
104 };
105 
106 ZmPortalController.prototype._setViewContents = function(view) {
107 	this._listView[view].set();
108 };
109 
110 // listeners
111 
112 ZmPortalController.prototype._refreshListener = function() {
113     this._app.refreshPortlets();
114 };
115 
116 ZmPortalController.prototype._pauseListener = function(event) {
117     var toolbar = this._toolbar[this._currentViewId];
118 
119     // en/disable refresh button
120     var button = toolbar && toolbar.getButton(ZmOperation.REFRESH);
121     var paused = event.item.isToggled();
122     if (button) {
123         button.setEnabled(!paused);
124     }
125 
126     // pause portlets appearing on portal page
127     this.setPaused(paused);
128 };
129 
130 ZmPortalController.prototype._resetOperations = function(parent, num) {
131 //    ZmListController.prototype._resetOperations.call(parent, num);
132     parent.enable(this._getToolBarOps(), true);
133 };