1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2008, 2009, 2010, 2011, 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, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 
 25 /**
 26  * Creates a Header Tree Item.
 27  * @constructor
 28  * @class
 29  * This class implements a tree item widget.
 30  *
 31  * @author Dave Comfort
 32  *
 33  * @param {hash}	params				a hash of parameters
 34  * @param {DwtComposite}      params.parent				the parent widget
 35  * @param {number}      params.index 				the index at which to add this control among parent's children
 36  * @param {string}      params.text 					the label text for the tree item
 37  * @param {string}      params.imageInfo				the icon for the tree item
 38  * @param {boolean}      params.deferred				if <code>true</code>, postpone initialization until needed.
 39  * @param {string}      params.className				the CSS class
 40  * @param  {constant}	params.posStyle				the positioning style
 41  * @param {boolean}      params.forceNotifySelection	force notify selection even if checked style
 42  * @param {boolean}      params.forceNotifyAction		force notify action even if checked style
 43  * @param {hash}		  params.optButton				a hash of data for showing a options button in the item: image, tooltip, callback
 44  * @param {boolean}      params.selectable			if <code>true</code>, this item is selectable
 45  *        
 46  * @extend		DwtTreeItem
 47  */
 48 DwtHeaderTreeItem = function(params) {
 49 	this.overview = params.overview;
 50 	this._optButton = params.optButton;
 51 	this._noNodeCell = params.noNodeCell;
 52 	DwtTreeItem.call(this, params);
 53 	this._arrowDisabled = true; //override what DwTreeItem constructor sets.
 54 };
 55 
 56 DwtHeaderTreeItem.prototype = new DwtTreeItem;
 57 DwtHeaderTreeItem.prototype.constructor = DwtHeaderTreeItem;
 58 
 59 DwtHeaderTreeItem.prototype.TEMPLATE = "dwt.Widgets#ZHeaderTreeItem";
 60 
 61 DwtHeaderTreeItem.prototype.toString =
 62 function() {
 63 	return "DwtHeaderTreeItem";
 64 };
 65 
 66 DwtHeaderTreeItem.prototype._createHtmlFromTemplate =
 67 function(template, data) {
 68 	data.noNodeCell = this._noNodeCell;
 69 	DwtTreeItem.prototype._createHtmlFromTemplate.apply(this, arguments);
 70 };
 71 
 72 DwtHeaderTreeItem.prototype._initialize =
 73 function() {
 74 	DwtTreeItem.prototype._initialize.apply(this, arguments);
 75 
 76 	// We must label the tree root, otherwise IE will let screen readers read
 77 	// THE ENTIRE TREE when it gets focus
 78 	var treeEl = this._tree.getHtmlElement();
 79 	treeEl.setAttribute("aria-labelledby", this._textCell.id);
 80 
 81 	if (this._optButton) {
 82 		this._optButtonId = this._htmlElId + "_optButton";
 83 		var optButtonEl = document.getElementById(this._optButtonId);
 84 		if (optButtonEl) {
 85 			this._optButtonItem = new DwtBorderlessButton({parent:this, style:DwtLabel.IMAGE_LEFT});
 86 			this._optButtonItem.setToolTipContent(this._optButton.tooltip);
 87 			this._optButtonItem.callback = this._optButton.callback;
 88 			this._optButtonItem.addSelectionListener(new AjxListener(this, this._onclickHandler));
 89 			this._optButtonItem.replaceElement(this._optButtonId);
 90 			this._optButtonItem.setImage("ContextMenu");
 91 			this._optButtonItem.setIconEl(this._optButtonItem.getHtmlElement()); // image container is button
 92 		}
 93 	}
 94 };
 95 
 96 DwtHeaderTreeItem.prototype._onclickHandler =
 97 function(ev) {
 98     this._tree._itemActioned(this, ev);
 99 };
100 
101 
102 DwtHeaderTreeItem.prototype._focusByMouseUpEvent =
103 function(ev)  {
104 	var targetId = ev.target && ev.target.id;
105 	if (targetId && (targetId == this._headerButtonId)) { return; }
106 	DwtTreeItem.prototype._focusByMouseUpEvent.apply(this, arguments);
107 };
108