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 * @class 26 * This class is responsible for providing unique, predictable IDs for HTML elements. 27 * That way, code outside the client can locate particular elements. 28 * <p> 29 * Not every element that has an associated JS object will have a known ID. Those are 30 * allocated only for elements it would be useful to locate: major components of the UI, 31 * toolbars, buttons, views, menus, some menu items, and some selects. 32 * <p> 33 * There is a simple naming scheme for the IDs themselves. Each ID starts with a "z" followed 34 * by one to a few letters that indicate the type of object (widget) represented by the element. 35 * 36 * @author Conrad Damon 37 */ 38 39 DwtId = function() {} 40 41 // separator for parts used in constructing IDs - need to pick one that 42 // doesn't show up in any of the parts 43 DwtId.SEP = "__"; 44 45 // widget types (used to prefix IDs) 46 /** 47 * Defines the widget "list view". 48 */ 49 DwtId.WIDGET_LIST_VIEW = "zl"; // list view 50 /** 51 * Defines the widget "list view header". 52 */ 53 DwtId.WIDGET_HDR = "zlh"; // list view header 54 /** 55 * Defines the widget "list view header table". 56 */ 57 DwtId.WIDGET_HDR_TABLE = "zlht"; // list view header table 58 /** 59 * Defines the widget "list view header icon image". 60 */ 61 DwtId.WIDGET_HDR_ICON = "zlhi"; // list view header image 62 /** 63 * Defines the widget "list view header text". 64 */ 65 DwtId.WIDGET_HDR_LABEL = "zlhl"; // list view header text 66 /** 67 * Defines the widget "list view header dropdown arrow". 68 */ 69 DwtId.WIDGET_HDR_ARROW = "zlha"; // list view header dropdown arrow 70 /** 71 * Defines the widget "sash between list view headers". 72 */ 73 DwtId.WIDGET_HDR_SASH = "zlhs"; // sash between list view headers 74 /** 75 * Defines the widget "list view item". 76 */ 77 DwtId.WIDGET_ITEM = "zli"; // list view item 78 /** 79 * Defines the widget "list view item row". 80 */ 81 DwtId.WIDGET_ITEM_ROW = "zlir"; // list view item row 82 /** 83 * Defines the widget "list view item cell". 84 */ 85 DwtId.WIDGET_ITEM_CELL = "zlic"; // list view item cell 86 /** 87 * Defines the widget "list view item field". 88 */ 89 DwtId.WIDGET_ITEM_FIELD = "zlif"; // list view item field 90 91 // list view modifiers 92 /** 93 * Defines the list view "headers" modifier. 94 */ 95 DwtId.LIST_VIEW_HEADERS = "headers"; 96 /** 97 * Defines the list view "rows" modifier. 98 */ 99 DwtId.LIST_VIEW_ROWS = "rows"; 100 101 DwtId.IFRAME = "iframe"; 102 103 DwtId.DND_PLUS_ID = "z__roundPlus"; 104 105 /** 106 * Joins the given arguments into an ID, excluding empty ones. 107 * 108 * @private 109 */ 110 DwtId.makeId = 111 function() { 112 var list = []; 113 for (var i = 0; i < arguments.length; i++) { 114 var arg = arguments[i]; 115 if (arg != null && arg != "") { 116 list.push(arg); 117 } 118 } 119 return list.join(DwtId.SEP); 120 }; 121 DwtId._makeId = DwtId.makeId; // back-compatibility 122 123 /** 124 * Gets an ID for a list view. 125 * 126 * @param {constant} context the owning view identifier 127 * @param {DwtId.LIST_VIEW_HEADERS|DwtId.LIST_VIEW_ROWS} modifier indicates element within list view (see <code>DwtId.LIST_VIEW*</code> constants) 128 * @return {string} the ID 129 */ 130 DwtId.getListViewId = 131 function(context, modifier) { 132 return DwtId.makeId(DwtId.WIDGET_LIST_VIEW, context, modifier); 133 }; 134 135 /** 136 * Gets an ID for an element within a list view header. 137 * 138 * @param {constant} type the type of hdr element (see <code>DwtId.WIDGET_HDR*</code> constants) 139 * @param {constant} context the the ID of owning view 140 * @param {constant} hdr the header ID 141 * @return {string} the ID 142 */ 143 DwtId.getListViewHdrId = 144 function(type, context, hdr) { 145 return DwtId.makeId(type, context, hdr); 146 }; 147 148 /** 149 * Gets an ID for an element associated with the display of an item in a list view. 150 * 151 * @param {constant} type the type of item element (see <code>DwtId.WIDGET_ITEM*</code> constants) 152 * @param {constant} context the ID of owning view 153 * @param {string} itemId the item ID (typically numeric) 154 * @param {constant} field the field identifier (for example, "su" for subject) 155 * @return {string} the ID 156 */ 157 DwtId.getListViewItemId = 158 function(type, context, itemId, field) { 159 return DwtId.makeId(type, context, itemId, field); 160 }; 161 162 /** 163 * Gets an ID for an IFRAME. 164 * 165 * @param {constant} context the ID of owning {@link DwtIframe} 166 * @return {string} the ID 167 */ 168 DwtId.getIframeId = 169 function(context) { 170 return DwtId.makeId(context, DwtId.IFRAME); 171 }; 172