1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 */ 27 28 /** 29 * Creates the account alert. 30 * @class 31 * This class represents an alert that highlights and flashes an account accordion item. 32 * 33 * @param {ZmAccount} account the account 34 * 35 * @extends ZmAlert 36 */ 37 ZmAccountAlert = function(account) { 38 ZmAlert.call(this); 39 this.account = account; 40 this._alertApps = {}; 41 appCtxt.accountList.addActiveAcountListener(new AjxListener(this, this._accountListener)); 42 }; 43 44 ZmAccountAlert.prototype = new ZmAlert; 45 ZmAccountAlert.prototype.constructor = ZmAccountAlert; 46 47 /** 48 * Returns a string representation of the object. 49 * 50 * @return {String} a string representation of the object 51 */ 52 ZmAccountAlert.prototype.toString = 53 function() { 54 return "ZmAccountAlert"; 55 }; 56 57 /** 58 * Gets the alert by account. If the alert does not exist for the specified account, a new 59 * alert is created 60 * 61 * @param {ZmAccount} account the account 62 * @return {ZmAccountAlert} the alert 63 */ 64 ZmAccountAlert.get = 65 function(account) { 66 ZmAccountAlert.INSTANCES = ZmAccountAlert.INSTANCES || {}; 67 if (!ZmAccountAlert.INSTANCES[account.id]) { 68 ZmAccountAlert.INSTANCES[account.id] = new ZmAccountAlert(account); 69 } 70 return ZmAccountAlert.INSTANCES[account.id]; 71 }; 72 73 /** 74 * Starts the alert. 75 * 76 * @param {ZmApp} app the application 77 */ 78 ZmAccountAlert.prototype.start = 79 function(app) { 80 if (this.account != appCtxt.getActiveAccount()) { 81 this._started = true; 82 if (app) { 83 this._alertApps[app.getName()] = app; 84 } 85 } 86 }; 87 88 /** 89 * Stops the alert. 90 * 91 */ 92 ZmAccountAlert.prototype.stop = 93 function() { 94 this._started = false; 95 }; 96 97 ZmAccountAlert.prototype._accountListener = 98 function(evt) { 99 if (evt.account == this.account) { 100 this.stop(); 101 for (var appName in this._alertApps) { 102 this._alertApps[appName].startAlert(); 103 } 104 this._alertApps = {}; 105 } 106 }; 107