1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * A generic iframe view that can be associated with an app tab. One use is to display upsell content from an external 26 * URL if the user does not currently have the app enabled. 27 * @class 28 * This class displays an external URL in an iframe. 29 * 30 * @extends DwtControl 31 * 32 * @author Conrad Damon 33 */ 34 ZmAppIframeView = function(params) { 35 36 if (arguments.length === 0) { 37 return; 38 } 39 40 DwtControl.call(this, { 41 parent: appCtxt.getShell(), 42 posStyle: Dwt.ABSOLUTE_STYLE, 43 className: 'ZmAppIframeView' 44 }); 45 46 this._createFrame(params); 47 }; 48 49 ZmAppIframeView.prototype = new DwtControl; 50 ZmAppIframeView.prototype.constructor = ZmAppIframeView; 51 52 ZmAppIframeView.prototype.isZmAppIframeView = true; 53 ZmAppIframeView.prototype.toString = function() { return "ZmAppIframeView"; }; 54 55 ZmAppIframeView.prototype._createFrame = function(params) { 56 57 params = params || {}; 58 59 var app = this._appName = params.appName, 60 iframeUrl = appCtxt.get(ZmApp.UPSELL_URL[app]), 61 htmlArr = [], 62 idx = 0; 63 64 var iframeId = this._iframeId = this._getIframeId(); 65 66 htmlArr[idx++] = "<iframe id='" + iframeId + "' width='100%' height='100%' frameborder='0' src='"; 67 htmlArr[idx++] = iframeUrl; 68 htmlArr[idx++] = "'>"; 69 this.setContent(htmlArr.join("")); 70 }; 71 72 ZmAppIframeView.prototype._getIframeId = function() { 73 return 'iframe_' + this.getHTMLElId(); 74 }; 75 76 ZmAppIframeView.prototype.activate = function(active) {}; 77 78 ZmAppIframeView.prototype.runRefresh = function() {}; 79 80 ZmAppIframeView.prototype.setBounds = 81 function(x, y, width, height, showToolbar) { 82 var deltaHeight = 0; 83 if(!showToolbar) { 84 deltaHeight = this._getToolbarHeight(); 85 } 86 DwtControl.prototype.setBounds.call(this, x, y - deltaHeight, width, height + deltaHeight); 87 var id = "iframe_" + this.getHTMLElId(); 88 var iframe = document.getElementById(id); 89 if(iframe) { 90 iframe.width = width; 91 iframe.height = height + deltaHeight; 92 } 93 }; 94 95 ZmAppIframeView.prototype._getToolbarHeight = 96 function() { 97 var topToolbar = appCtxt.getAppViewMgr().getViewComponent(ZmAppViewMgr.C_TOOLBAR_TOP); 98 if (topToolbar) { 99 var sz = topToolbar.getSize(); 100 var height = sz.y ? sz.y : topToolbar.getHtmlElement().clientHeight; 101 return height; 102 } 103 return 0; 104 }; 105 106 ZmAppIframeView.prototype.getTitle = function() { 107 return [ ZmMsg.zimbraTitle, appCtxt.getApp(this._appName).getDisplayName() ].join(": "); 108 }; 109