]> git.proxmox.com Git - extjs.git/blame - extjs/packages/ux/classic/src/DataTip.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / ux / classic / src / DataTip.js
CommitLineData
6527f429
DM
1/**\r
2 * @class Ext.ux.DataTip\r
3 * @extends Ext.ToolTip.\r
4 * This plugin implements automatic tooltip generation for an arbitrary number of child nodes *within* a Component.\r
5 *\r
6 * This plugin is applied to a high level Component, which contains repeating elements, and depending on the host Component type,\r
7 * it automatically selects a {@link Ext.ToolTip#delegate delegate} so that it appears when the mouse enters a sub-element.\r
8 *\r
9 * When applied to a GridPanel, this ToolTip appears when over a row, and the Record's data is applied\r
10 * using this object's {@link #tpl} template.\r
11 *\r
12 * When applied to a DataView, this ToolTip appears when over a view node, and the Record's data is applied\r
13 * using this object's {@link #tpl} template.\r
14 *\r
15 * When applied to a TreePanel, this ToolTip appears when over a tree node, and the Node's {@link Ext.data.Model} record data is applied\r
16 * using this object's {@link #tpl} template.\r
17 *\r
18 * When applied to a FormPanel, this ToolTip appears when over a Field, and the Field's `tooltip` property is used is applied\r
19 * using this object's {@link #tpl} template, or if it is a string, used as HTML content. If there is no `tooltip` property,\r
20 * the field itself is used as the template's data object.\r
21 *\r
22 * If more complex logic is needed to determine content, then the {@link #beforeshow} event may be used.\r
23 * This class also publishes a **`beforeshowtip`** event through its host Component. The *host Component* fires the\r
24 * **`beforeshowtip`** event.\r
25 */\r
26Ext.define('Ext.ux.DataTip', function(DataTip) {\r
27\r
28// Target the body (if the host is a Panel), or, if there is no body, the main Element.\r
29 function onHostRender() {\r
30 var e = this.isXType('panel') ? this.body : this.el;\r
31 if (this.dataTip.renderToTarget) {\r
32 this.dataTip.render(e);\r
33 }\r
34 this.dataTip.setTarget(e);\r
35 }\r
36\r
37 function updateTip(tip, data) {\r
38 if (tip.rendered) {\r
39 if (tip.host.fireEvent('beforeshowtip', tip.eventHost, tip, data) === false) {\r
40 return false;\r
41 }\r
42 tip.update(data);\r
43 } else {\r
44 if (Ext.isString(data)) {\r
45 tip.html = data;\r
46 } else {\r
47 tip.data = data;\r
48 }\r
49 }\r
50 }\r
51\r
52 function beforeViewTipShow(tip) {\r
53 var rec = this.view.getRecord(tip.triggerElement),\r
54 data;\r
55\r
56 if (rec) {\r
57 data = tip.initialConfig.data ? Ext.apply(tip.initialConfig.data, rec.data) : rec.data;\r
58 return updateTip(tip, data);\r
59 } else {\r
60 return false;\r
61 }\r
62 }\r
63\r
64 function beforeFormTipShow(tip) {\r
65 var field = Ext.getCmp(tip.triggerElement.id);\r
66 if (field && (field.tooltip || tip.tpl)) {\r
67 return updateTip(tip, field.tooltip || field);\r
68 } else {\r
69 return false;\r
70 }\r
71 }\r
72\r
73 return {\r
74 extend: 'Ext.tip.ToolTip',\r
75\r
76 mixins: {\r
77 plugin: 'Ext.plugin.Abstract'\r
78 },\r
79\r
80 alias: 'plugin.datatip',\r
81\r
82 lockableScope: 'both',\r
83\r
84 constructor: function(config) {\r
85 var me = this;\r
86 me.callParent([config]);\r
87 me.mixins.plugin.constructor.call(me, config);\r
88 },\r
89\r
90 init: function(host) {\r
91 var me = this;\r
92\r
93 me.mixins.plugin.init.call(me, host);\r
94 host.dataTip = me;\r
95 me.host = host;\r
96\r
97 if (host.isXType('tablepanel')) {\r
98 me.view = host.getView();\r
99 if (host.ownerLockable) {\r
100 me.host = host.ownerLockable;\r
101 }\r
102 me.delegate = me.delegate || me.view.rowSelector;\r
103 me.on('beforeshow', beforeViewTipShow);\r
104 } else if (host.isXType('dataview')) {\r
105 me.view = me.host;\r
106 me.delegate = me.delegate || host.itemSelector;\r
107 me.on('beforeshow', beforeViewTipShow);\r
108 } else if (host.isXType('form')) {\r
109 me.delegate = '.' + Ext.form.Labelable.prototype.formItemCls;\r
110 me.on('beforeshow', beforeFormTipShow);\r
111 } else if (host.isXType('combobox')) {\r
112 me.view = host.getPicker();\r
113 me.delegate = me.delegate || me.view.getItemSelector();\r
114 me.on('beforeshow', beforeViewTipShow);\r
115 }\r
116 if (host.rendered) {\r
117 onHostRender.call(host);\r
118 } else {\r
119 host.onRender = Ext.Function.createSequence(host.onRender, onHostRender);\r
120 }\r
121 }\r
122 };\r
123});\r