]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/panel/Header.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / panel / Header.js
CommitLineData
6527f429
DM
1/**\r
2 * This container class is used to manage the items (such as title and tools) for `Ext.Panel`.\r
3 *\r
4 * @since 6.0.1\r
5 */\r
6Ext.define('Ext.panel.Header', {\r
7 extend: 'Ext.Container',\r
8 xtype: 'panelheader',\r
9\r
10 /**\r
11 * @property {Boolean} isPanelHeader\r
12 * `true` in this class to identify an object as an instantiated Header, or a subclass\r
13 * thereof.\r
14 * @readonly\r
15 */\r
16 isPanelHeader: true,\r
17\r
18 baseCls: Ext.baseCSSPrefix + 'panel-header',\r
19\r
20 config: {\r
21 /**\r
22 * @cfg {Number/String} glyph\r
23 * @accessor\r
24 * A numeric unicode character code to use as the icon. The default font-family\r
25 * for glyphs can be set globally using\r
26 * {@link Ext.app.Application#glyphFontFamily glyphFontFamily} application\r
27 * config or the {@link Ext#setGlyphFontFamily Ext.setGlyphFontFamily()} method.\r
28 *\r
29 * The following shows how to set the glyph using the font icons provided in the\r
30 * SDK (assuming the font-family has been configured globally):\r
31 *\r
32 * // assumes the glyphFontFamily is "FontAwesome"\r
33 * glyph: 'xf005' // the "home" icon\r
34 *\r
35 * // assumes the glyphFontFamily is "Pictos"\r
36 * glyph: 'H' // the "home" icon\r
37 *\r
38 * Alternatively, this config option accepts a string with the charCode and\r
39 * font-family separated by the `@` symbol.\r
40 *\r
41 * // using Font Awesome\r
42 * glyph: 'xf005@FontAwesome' // the "home" icon\r
43 *\r
44 * // using Pictos\r
45 * glyph: 'H@Pictos' // the "home" icon\r
46 *\r
47 * Depending on the theme you're using, you may need include the font icon\r
48 * packages in your application in order to use the icons included in the\r
49 * SDK. For more information see:\r
50 *\r
51 * - [Font Awesome icons](http://fortawesome.github.io/Font-Awesome/cheatsheet/)\r
52 * - [Pictos icons](http://docs.sencha.com/extjs/6.0/core_concepts/font_ext.html)\r
53 * - [Theming Guide](http://docs.sencha.com/extjs/6.0/core_concepts/theming.html)\r
54 */\r
55 glyph: null,\r
56\r
57 /**\r
58 * @cfg {String} icon\r
59 * Path to an image to use as an icon.\r
60 *\r
61 * For instructions on how you can use icon fonts including those distributed in\r
62 * the SDK see {@link #iconCls}.\r
63 * @accessor\r
64 */\r
65 icon: null,\r
66\r
67 /**\r
68 * @cfg {'top'/'right'/'bottom'/'left'} [iconAlign='left']\r
69 * The side of the title to render the icon.\r
70 * @accessor\r
71 */\r
72 iconAlign: null,\r
73\r
74 /**\r
75 * @cfg {String} iconCls\r
76 * @accessor\r
77 * One or more space separated CSS classes to be applied to the icon element.\r
78 * The CSS rule(s) applied should specify a background image to be used as the\r
79 * icon.\r
80 *\r
81 * An example of specifying a custom icon class would be something like:\r
82 *\r
83 * // specify the property in the config for the class:\r
84 * iconCls: 'my-home-icon'\r
85 *\r
86 * // css rule specifying the background image to be used as the icon image:\r
87 * .my-home-icon {\r
88 * background-image: url(../images/my-home-icon.gif) !important;\r
89 * }\r
90 *\r
91 * In addition to specifying your own classes, you can use the font icons\r
92 * provided in the SDK using the following syntax:\r
93 *\r
94 * // using Font Awesome\r
95 * iconCls: 'x-fa fa-home'\r
96 *\r
97 * // using Pictos\r
98 * iconCls: 'pictos pictos-home'\r
99 *\r
100 * Depending on the theme you're using, you may need include the font icon\r
101 * packages in your application in order to use the icons included in the\r
102 * SDK. For more information see:\r
103 *\r
104 * - [Font Awesome icons](http://fortawesome.github.io/Font-Awesome/cheatsheet/)\r
105 * - [Pictos icons](http://docs.sencha.com/extjs/6.0/core_concepts/font_ext.html)\r
106 * - [Theming Guide](http://docs.sencha.com/extjs/6.0/core_concepts/theming.html)\r
107 */\r
108 iconCls: null,\r
109\r
110 /**\r
111 * @cfg {String/Ext.panel.Title}\r
112 * The title text or config object for the {@link Ext.panel.Title Title} component.\r
113 * @accessor\r
114 */\r
115 title: null,\r
116\r
117 /**\r
118 * @cfg {'left'/'center'/'right'} [titleAlign='left']\r
119 * The alignment of the title text within the available space between the\r
120 * icon and the tools.\r
121 * @accessor\r
122 */\r
123 titleAlign: null,\r
124\r
125 layout: {\r
126 type: 'hbox',\r
127 align: 'center'\r
128 }\r
129 },\r
130\r
131 add: function (item) {\r
132 var me = this,\r
133 isArray = Ext.isArray(item),\r
134 array = isArray ? item.slice(0) : [ item ], // copy array since we sort it\r
135 items = me.getItems(),\r
136 length = items.length,\r
137 n = array.length,\r
138 c, i, n, pos;\r
139\r
140 for (i = 0; i < n; ++i) {\r
141 // We have to ensure all items are actual instances because the "weight"\r
142 // config may come from the class.\r
143 array[i] = me.factoryItem(array[i]);\r
144 }\r
145\r
146 Ext.Array.sort(array, me.sortByWeight);\r
147\r
148 if (length) {\r
149 items = items.items; // get the items array of our ItemCollection\r
150 pos = 0;\r
151\r
152 // Both "items" and "array" are in order by weight. For each new item,\r
153 // we find the pos where items[pos] is greater than the new item. This\r
154 // ensures new items of equal weight are added after existing items of\r
155 // that weight.\r
156\r
157 for (i = 0; i < n; ++i) {\r
158 c = array[i];\r
159\r
160 for ( ; pos < length; ++pos) {\r
161 if (me.sortByWeight(c, items[pos]) < 0) {\r
162 break;\r
163 }\r
164 }\r
165\r
166 me.insert(pos, c);\r
167\r
168 ++pos;\r
169 ++length;\r
170 }\r
171 } else {\r
172 me.callParent([ array ]);\r
173 }\r
174\r
175 return isArray ? array : item;\r
176 },\r
177\r
178 applyTitle: function (newTitle, oldTitle) {\r
179 var title = oldTitle;\r
180\r
181 if (title) {\r
182 if (!newTitle || typeof newTitle === 'string') {\r
183 title.setText(newTitle || '');\r
184 } else if (newTitle) {\r
185 title.setConfig(newTitle);\r
186 }\r
187 } else {\r
188 title = Ext.create(this.createTitle(newTitle));\r
189 }\r
190\r
191 return title;\r
192 },\r
193\r
194 createTitle: function (config) {\r
195 var ret = {\r
196 xtype: 'paneltitle',\r
197 flex: 1\r
198 };\r
199\r
200 if (config) {\r
201 if (typeof config === 'string') {\r
202 config = {\r
203 text: config\r
204 };\r
205 }\r
206\r
207 Ext.merge(ret, config);\r
208 }\r
209\r
210 return ret;\r
211 },\r
212\r
213 createTools: function (tools, toolOwner) {\r
214 var n = tools && tools.length,\r
215 ret = n && [],\r
216 c, i;\r
217\r
218 toolOwner = toolOwner || null;\r
219\r
220 for (i = 0; i < n; ++i) {\r
221 c = tools[i];\r
222\r
223 if (typeof c === 'string') {\r
224 c = {\r
225 xtype: 'paneltool',\r
226 type: c,\r
227 toolOwner: toolOwner\r
228 };\r
229 } else if (c.isInstance) {\r
230 if (toolOwner) {\r
231 c.setToolOwner(toolOwner);\r
232 }\r
233 } else {\r
234 c = Ext.apply({\r
235 xtype: 'paneltool',\r
236 toolOwner: toolOwner\r
237 }, c);\r
238 }\r
239\r
240 ret[i] = c;\r
241 }\r
242\r
243 return ret;\r
244 },\r
245\r
246 updateGlyph: function(glyph) {\r
247 this.ensureTitle().setGlyph(glyph);\r
248 },\r
249\r
250 updateIcon: function(icon) {\r
251 this.ensureTitle().setIcon(icon);\r
252 },\r
253\r
254 updateIconAlign: function(align, oldAlign) {\r
255 this.ensureTitle().setIconAlign(align);\r
256 },\r
257\r
258 updateIconCls: function(cls) {\r
259 this.ensureTitle().setIconCls(cls);\r
260 },\r
261\r
262 updateTitle: function(title, oldTitle) {\r
263 if (oldTitle) {\r
264 oldTitle.setConfig(title);\r
265 } else {\r
266 this.add(title);\r
267 }\r
268 },\r
269\r
270 updateTitleAlign: function(align, oldAlign) {\r
271 this.ensureTitle().setTextAlign(align);\r
272 },\r
273\r
274 updateUi: function(ui, oldValue) {\r
275 this.callParent([ ui, oldValue ]);\r
276\r
277 this.ensureTitle().setUi(ui);\r
278 },\r
279\r
280 privates: {\r
281 clearTools: function () {\r
282 var items = this.getItems().items,\r
283 c, i;\r
284\r
285 for (i = items.length; i-- > 0; ) {\r
286 c = items[i];\r
287\r
288 if (c.isPanelTool) {\r
289 this.remove(c);\r
290 }\r
291 }\r
292 },\r
293\r
294 ensureTitle: function () {\r
295 var me = this,\r
296 title = me.getTitle();\r
297\r
298 if (!title) {\r
299 me.setTitle('');\r
300 title = me.getTitle();\r
301 }\r
302\r
303 return title;\r
304 },\r
305\r
306 sortByWeight: function (item1, item2) {\r
307 return (item1.weight || 0) - (item2.weight || 0);\r
308 }\r
309 }\r
310});\r