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 * Creates a navigation tool bar. 26 * @class 27 * Navigation toolbar for the client. This toolbar is affected by every 28 * push/pop of a view and must be context sensitive since it can custom apply 29 * to any view. A new class was created since nav toolbar may be expanded in 30 * the future (i.e. to incl. a text input indicating current page, etc) 31 * 32 * @param {Hash} params a hash of parameters 33 * @param {DwtComposite} params.parent the containing widget 34 * @param {constant} params.posStyle the positioning style 35 * @param {String} params.className the CSS class name 36 * @param {Boolean} params.hasText if <code>true</code>, this toolbar includes text in the middle 37 * @param {constant} params.context the view ID (used to generate button IDs) 38 * 39 * @extends ZmButtonToolBar 40 */ 41 ZmNavToolBar = function(params) { 42 43 params.className = params.className || "ZmNavToolBar"; 44 var hasText = (params.hasText !== false); 45 params.buttons = this._getButtons(hasText); 46 params.toolbarType = ZmId.TB_NAV; 47 params.posStyle = params.posStyle || DwtControl.STATIC_STYLE; 48 ZmButtonToolBar.call(this, params); 49 if (hasText) { 50 this._textButton = this.getButton(ZmOperation.TEXT); 51 } 52 }; 53 54 ZmNavToolBar.prototype = new ZmButtonToolBar; 55 ZmNavToolBar.prototype.constructor = ZmNavToolBar; 56 57 ZmNavToolBar.prototype.toString = 58 function() { 59 return "ZmNavToolBar"; 60 }; 61 62 /** 63 * Enables/disables buttons. 64 * 65 * @param {Array} ids a list of button IDs 66 * @param {Boolean} enabled if <code>true</code>, enable the buttons 67 * 68 */ 69 ZmNavToolBar.prototype.enable = 70 function(ids, enabled) { 71 ZmButtonToolBar.prototype.enable.call(this, ids, enabled); 72 73 // also kill the tooltips if buttons are disabled 74 if (!enabled) { 75 if (!(ids instanceof Array)) 76 ids = [ids]; 77 for (var i = 0; i < ids.length; i++) { 78 var button = this.getButton(ids[i]); 79 if (button) 80 button.setToolTipContent(null); 81 } 82 } 83 }; 84 85 /** 86 * Sets the tool tip for the button. 87 * 88 * @param {String} buttonId the button id 89 * @param {String} tooltip the tool tip 90 */ 91 ZmNavToolBar.prototype.setToolTip = 92 function(buttonId, tooltip) { 93 var button = this.getButton(buttonId); 94 if (button) 95 button.setToolTipContent(tooltip); 96 }; 97 98 /** 99 * Sets the text. 100 * 101 * @param {String} text the text 102 */ 103 ZmNavToolBar.prototype.setText = 104 function(text) { 105 if (!this._textButton) return; 106 this._textButton.setText(text); 107 }; 108 109 ZmNavToolBar.prototype._getButtons = 110 function(hasText) { 111 112 var buttons = []; 113 buttons.push(ZmOperation.PAGE_BACK); 114 if (hasText) { 115 buttons.push(ZmOperation.TEXT); 116 } 117 buttons.push(ZmOperation.PAGE_FORWARD); 118 119 return buttons; 120 }; 121 122 ZmNavToolBar.prototype.createOp = 123 function(id, params) { 124 params.textClassName = "ZWidgetTitle ZmNavToolBarTitle"; 125 return ZmButtonToolBar.prototype.createOp.apply(this, arguments); 126 }; 127