1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates the portlet view. 26 * @class 27 * This class represents the portlet view. 28 * 29 * @param {Element} parentEl the parent element 30 * @param {ZmPortlet} portlet the portlet 31 * @param {String} className the class name 32 * 33 * @extends DwtComposite 34 */ 35 ZmPortletView = function(parentEl, portlet, className) { 36 className = className || "ZmPortlet"; 37 DwtComposite.call(this, {parent:DwtShell.getShell(window), className:className, posStyle:DwtControl.STATIC_STYLE}); 38 39 // save data 40 this._portlet = portlet; 41 this._portlet.view = this; 42 43 this._contentsEl = this.getHtmlElement(); 44 if (parentEl) { 45 parentEl.portlet = "loaded"; 46 parentEl.innerHTML = ""; 47 parentEl.appendChild(this._contentsEl); 48 } 49 50 // setup display 51 this.setIcon(portlet.icon); 52 this.setTitle(portlet.title); 53 this.setContentUrl(portlet.actionUrl && portlet.actionUrl.target); 54 } 55 ZmPortletView.prototype = new DwtComposite; 56 ZmPortletView.prototype.constructor = ZmPortletView; 57 58 /** 59 * Returns a string representation of the object. 60 * 61 * @return {String} a string representation of the object 62 */ 63 ZmPortletView.prototype.toString = function() { 64 return "ZmPortletView"; 65 }; 66 67 // 68 // Public methods 69 // 70 71 /** 72 * Sets the icon. 73 * 74 * @param {String} icon the icon 75 * 76 * @see AjxImg.setImage 77 */ 78 ZmPortletView.prototype.setIcon = function(icon) { 79 if (icon == null || !this._iconEl) return; 80 AjxImg.setImage(this._iconEl, icon); 81 }; 82 83 /** 84 * Sets the title. 85 * 86 * @param {String} title the title 87 */ 88 ZmPortletView.prototype.setTitle = function(title) { 89 if (title == null || !this._titleEl) return; 90 this._titleEl.innerHTML = title; 91 }; 92 93 ZmPortletView.prototype.setContent = function(content) { 94 if (AjxUtil.isString(content)) { 95 this._contentsEl.innerHTML = content; 96 } 97 else if (AjxUtil.ELEMENT_NODE) { 98 this._contentsEl.innerHTML = ""; 99 this._contentsEl.appendChild(content); 100 } 101 else { 102 this._contentsEl.innerHTML = AjxStringUtil.htmlEncode(String(content)); 103 } 104 }; 105 106 /** 107 * Sets the content URL as an iframe. 108 * 109 * @param {String} url the url 110 */ 111 ZmPortletView.prototype.setContentUrl = function(url) { 112 if (!url) return; 113 114 var props = this._portlet.properties; 115 var func = AjxCallback.simpleClosure(ZmPortletView.__replaceProp, null, props); 116 url = url.replace(ZmZimletContext.RE_SCAN_PROP, func); 117 url = this._portlet.zimletCtxt ? this._portlet.zimletCtxt.makeURL({ target: url }, null, props) : url; 118 var html = [ 119 "<iframe style='border:none;width:100%;height:100%' ", 120 "src='",url,"'>", 121 "</iframe>" 122 ].join(""); 123 this.setContent(html); 124 }; 125 126 // 127 // Private methods 128 // 129 130 ZmPortletView.__replaceProp = function(props, $0, $1, $2) { 131 return props[$2]; 132 };