1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 // 25 // Constructor 26 // 27 28 /** 29 * Constructs a control that alerts the user to important information. 30 * @class 31 * This class represents an alert. 32 * 33 * @param {DwtComposite} parent the parent container for this control 34 * @param {string} [className="DwtAlert"] the CSS class for this control 35 * @param {Dwt.STATIC_STYLE|Dwt.ABSOLUTE_STYLE|Dwt.RELATIVE_STYLE|Dwt.FIXED_STYLE} [posStyle] the position style of this control 36 * 37 * @extends DwtControl 38 */ 39 DwtAlert = function(parent, className, posStyle) { 40 if (arguments.length == 0) return; 41 className = className || "DwtAlert"; 42 posStyle = posStyle || DwtControl.STATIC_STYLE; 43 DwtControl.call(this, {parent:parent, className:className, posStyle:posStyle}); 44 this._alertStyle = DwtAlert.INFORMATION; 45 this._createHtml(); 46 } 47 48 DwtAlert.prototype = new DwtControl; 49 DwtAlert.prototype.constructor = DwtAlert; 50 51 // 52 // Constants 53 // 54 /** 55 * Defines the "information" style. 56 */ 57 DwtAlert.INFORMATION = 0; 58 /** 59 * Defines the "warning" style. 60 */ 61 DwtAlert.WARNING = 1; 62 /** 63 * Defines the "critical" style. 64 */ 65 DwtAlert.CRITICAL = 2; 66 67 /** 68 * Defines the "success" style 69 */ 70 DwtAlert.SUCCESS = 3; 71 72 DwtAlert._ICONS = [ 73 AjxImg.getClassForImage("Information_32"), 74 AjxImg.getClassForImage("Warning_32"), 75 AjxImg.getClassForImage("Critical_32"), 76 AjxImg.getClassForImage("Success") 77 ]; 78 DwtAlert._CLASSES = [ 79 "DwtAlertInfo", 80 "DwtAlertWarn", 81 "DwtAlertCrit", 82 "DwtAlertWarn" // Reuse for Success 83 ]; 84 85 DwtAlert._RE_ICONS = new RegExp(DwtAlert._ICONS.join("|")); 86 DwtAlert._RE_CLASSES = new RegExp(DwtAlert._CLASSES.join("|")); 87 88 // 89 // Data 90 // 91 92 DwtAlert.prototype.TEMPLATE = "dwt.Widgets#DwtAlert"; 93 94 // 95 // Public methods 96 // 97 98 /** 99 * Sets the style. 100 * 101 * @param {DwtAlert.INFORMATION|DwtAlert.WARNING|DwtAlert.CRITICAL|DwtAlert.SUCCESS} style the style 102 */ 103 DwtAlert.prototype.setStyle = function(style) { 104 this._alertStyle = style || DwtAlert.INFORMATION; 105 if (this._iconDiv) { 106 Dwt.delClass(this._iconDiv, DwtAlert._RE_ICONS, DwtAlert._ICONS[this._alertStyle]); 107 } 108 Dwt.delClass(this.getHtmlElement(), DwtAlert._RE_CLASSES, DwtAlert._CLASSES[this._alertStyle]); 109 }; 110 111 /** 112 * Gets the style. 113 * 114 * @return {DwtAlert.INFORMATION|DwtAlert.WARNING|DwtAlert.CRITICAL|DwtAlert.SUCCESS} the style 115 */ 116 DwtAlert.prototype.getStyle = function() { 117 return this._alertStyle; 118 }; 119 120 /** 121 * Sets the icon visibility. 122 * 123 * @param {boolean} visible if <code>true</code>, the icon is visible 124 */ 125 DwtAlert.prototype.setIconVisible = function(visible) { 126 if (this._iconDiv) { 127 Dwt.setVisible(this._iconDiv, visible); 128 } 129 }; 130 131 /** 132 * Gets the icon visibility. 133 * 134 * @return {boolean} <code>true</code> if the icon is visible 135 */ 136 DwtAlert.prototype.getIconVisible = function() { 137 return this._iconDiv ? Dwt.getVisible(this._iconDiv) : false; 138 }; 139 140 /** 141 * Sets the title. 142 * 143 * @param {string} title the title 144 */ 145 DwtAlert.prototype.setTitle = function(title) { 146 this._alertTitle = title; 147 if (this._titleDiv) { 148 this._titleDiv.innerHTML = title || ""; 149 } 150 }; 151 152 /** 153 * Gets the title. 154 * 155 * @return {string} the title 156 */ 157 DwtAlert.prototype.getTitle = function() { 158 return this._alertTitle; 159 }; 160 161 DwtAlert.prototype.setContent = function(content) { 162 this._alertContent = content; 163 if (this._contentDiv) { 164 this._contentDiv.innerHTML = content || ""; 165 } 166 }; 167 DwtAlert.prototype.getContent = function() { 168 return this._alertContent; 169 }; 170 171 DwtAlert.prototype.setDismissContent = function (dwtElement) { 172 if (this._dismissDiv) { 173 dwtElement.reparentHtmlElement(this._dismissDiv.id) ; 174 } 175 } 176 177 // 178 // DwtControl methods 179 // 180 181 DwtAlert.prototype.getTabGroupMember = function() { 182 // NOTE: This control is not tabbable 183 return null; 184 }; 185 186 // 187 // Protected methods 188 // 189 190 /** 191 * @private 192 */ 193 DwtAlert.prototype._createHtml = function(templateId) { 194 var data = { id: this._htmlElId }; 195 this._createHtmlFromTemplate(templateId || this.TEMPLATE, data); 196 }; 197 198 /** 199 * @private 200 */ 201 DwtAlert.prototype._createHtmlFromTemplate = function(templateId, data) { 202 DwtControl.prototype._createHtmlFromTemplate.apply(this, arguments); 203 this._iconDiv = document.getElementById(data.id+"_icon"); 204 this._titleDiv = document.getElementById(data.id+"_title"); 205 this._contentDiv = document.getElementById(data.id+"_content"); 206 this._dismissDiv = document.getElementById(data.id+"_dismiss") ; 207 }; 208