1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014, 2015, 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, 2011, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file defines the tab application button. 27 * 28 */ 29 30 /** 31 * @class 32 * This class represents a button that behaves like a "tab" button, designed specifically for the row of 33 * applications buttons at the top of the Zimbra Web Client interface. 34 * <p> 35 * Limitations: 36 * <ul> 37 * <li>cannot have a menu</li> 38 * <li>does not support enabled/disabled</li> 39 * </ul> 40 * </p> 41 * 42 * @author Conrad Damon 43 * 44 * @param {Hash} params a hash of parameters 45 * 46 * @extends DwtButton 47 */ 48 ZmAppButton = function(params) { 49 50 if (arguments.length == 0) { 51 return; 52 } 53 54 params.style = params.style ? params.style : DwtLabel.IMAGE_LEFT; 55 params.posStyle = DwtControl.RELATIVE_STYLE; 56 DwtButton.call(this, params); 57 58 if (params.image) { 59 this.setImage(params.image); 60 } 61 else { 62 if (params.leftImage) { 63 this.setImage( params.leftImage, DwtLabel.LEFT); 64 } 65 if (params.rightImage) { 66 this.setImage(params.rightImage, DwtLabel.RIGHT); 67 } 68 } 69 70 if (params.hoverImage) { 71 this.setHoverImage(params.hoverImage); 72 } 73 else { 74 if (params.leftHoverImage) { 75 this.setHoverImage(params.leftHoverImage, DwtLabel.LEFT); 76 } 77 if (params.rightHoverImage) { 78 this.setHoverImage(params.rightHoverImage, DwtLabel.RIGHT); 79 } 80 } 81 this.setText(params.text); 82 }; 83 84 ZmAppButton.prototype = new DwtButton; 85 ZmAppButton.prototype.constructor = ZmAppButton; 86 ZmAppButton.prototype.role = "tab"; 87 88 /** 89 * Returns a string representation of the object. 90 * 91 * @return {String} a string representation of the object 92 */ 93 ZmAppButton.prototype.toString = 94 function() { 95 return "ZmAppButton"; 96 }; 97 98 // 99 // Data 100 // 101 102 ZmAppButton.prototype.TEMPLATE = "share.Widgets#ZmAppChooserButton"; 103 104 // 105 // Public methods 106 // 107 ZmAppButton.prototype.setSelected = 108 function(selected) { 109 this.isSelected = selected; 110 this.setDisplayState(selected ? DwtControl.SELECTED : DwtControl.NORMAL); 111 }; 112 113 /** 114 * Sets the display state. 115 * 116 * @param {String} state the display state 117 * @see DwtControl 118 */ 119 ZmAppButton.prototype.setDisplayState = 120 function(state) { 121 if (this.isSelected && state != DwtControl.SELECTED) { 122 state = [DwtControl.SELECTED, state].join(" "); 123 } 124 DwtButton.prototype.setDisplayState.call(this, state); 125 }; 126 127 ZmAppButton.prototype.handleKeyAction = 128 function(actionCode, ev) { 129 130 switch (actionCode) { 131 132 case DwtKeyMap.SELECT: 133 if (this.isListenerRegistered(DwtEvent.SELECTION)) { 134 var selEv = DwtShell.selectionEvent; 135 selEv.item = this; 136 this.notifyListeners(DwtEvent.SELECTION, selEv); 137 } 138 break; 139 140 default: 141 return false; 142 } 143 return true; 144 }; 145