]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/dataview/component/ListItem.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / dataview / component / ListItem.js
CommitLineData
6527f429
DM
1/**\r
2 * A ListItem is a container for {@link Ext.dataview.List} with \r
3 * useSimpleItems: false. \r
4 * \r
5 * ListItem configures and updates the {@link Ext.data.Model records} for \r
6 * the sub-component items in a list. \r
7 * \r
8 * Overwrite the `updateRecord()` method to set a sub-component's value. \r
9 * the framework calls `updateRecord()` whenever the data in the list updates.\r
10 *\r
11 * The `updatedata` event fires after `updateRecord()` runs.\r
12 *\r
13 * *Note*: Use of ListItem increases overhead since it generates more markup than\r
14 * using the List class with useSimpleItems: true. This overhead is more\r
15 * noticeable in Internet Explorer. If at all possible, use\r
16 * {@link Ext.dataview.component.SimpleListItem} instead.\r
17 * \r
18 * The following example shows how to configure and update sub-component items\r
19 * in a list:\r
20 *\r
21 * Ext.define('Twitter.view.TweetListItem', {\r
22 * extend: 'Ext.dataview.component.ListItem',\r
23 * xtype : 'tweetlistitem',\r
24 * requires: [\r
25 * 'Ext.Img'\r
26 * ],\r
27 * config: {\r
28 * userName: {\r
29 * cls: 'username'\r
30 * },\r
31 * text: {\r
32 * cls: 'text'\r
33 * },\r
34 * avatar: {\r
35 * docked: 'left',\r
36 * xtype : 'image',\r
37 * cls : 'avatar',\r
38 * width: '48px',\r
39 * height: '48px'\r
40 * },\r
41 * layout: {\r
42 * type: 'vbox'\r
43 * }\r
44 * },\r
45 * \r
46 * applyUserName: function(config) {\r
47 * return Ext.factory(config, Ext.Component, this.getUserName());\r
48 * },\r
49 * \r
50 * updateUserName: function(newUserName) {\r
51 * if (newUserName) {\r
52 * this.insert(0, newUserName);\r
53 * }\r
54 * },\r
55 * \r
56 * applyText: function(config) {\r
57 * return Ext.factory(config, Twitter.view.TweetListItemText, this.getText());\r
58 * },\r
59 * \r
60 * updateText: function(newText) {\r
61 * if (newText) {\r
62 * this.add(newText);\r
63 * }\r
64 * },\r
65 * \r
66 * applyAvatar: function(config) {\r
67 * return Ext.factory(config, Ext.Img, this.getAvatar());\r
68 * },\r
69 * \r
70 * updateAvatar: function(newAvatar) {\r
71 * if (newAvatar) {\r
72 * this.add(newAvatar);\r
73 * }\r
74 * },\r
75 * \r
76 * updateRecord: function(record) { \r
77 * if (!record) {\r
78 * return;\r
79 * }\r
80 *\r
81 * this.getUserName().setHtml(record.get('username'));\r
82 * this.getText().setHtml(record.get('text'));\r
83 * this.getAvatar().setSrc(record.get('avatar_url'));\r
84 * this.callParent(arguments);\r
85 *\r
86 * }\r
87 * });\r
88 *\r
89 */\r
90Ext.define('Ext.dataview.component.ListItem', {\r
91 extend: 'Ext.dataview.component.DataItem',\r
92 xtype : 'listitem',\r
93\r
94 config: {\r
95 baseCls: Ext.baseCSSPrefix + 'list-item',\r
96\r
97 dataMap: null,\r
98\r
99 body: {\r
100 xtype: 'component',\r
101 cls: 'x-list-item-body'\r
102 },\r
103\r
104 disclosure: {\r
105 xtype: 'component',\r
106 cls: 'x-list-disclosure',\r
107 hidden: true,\r
108 docked: 'right'\r
109 },\r
110\r
111 header: {\r
112 xtype: 'component',\r
113 cls: 'x-list-header',\r
114 html: ' '\r
115 },\r
116\r
117 tpl: null,\r
118 items: null\r
119 },\r
120\r
121 applyBody: function(body) {\r
122 if (body && !body.isComponent) {\r
123 body = Ext.factory(body, Ext.Component, this.getBody());\r
124 }\r
125 return body;\r
126 },\r
127\r
128 updateBody: function(body, oldBody) {\r
129 if (body) {\r
130 this.add(body);\r
131 } else if (oldBody) {\r
132 oldBody.destroy();\r
133 }\r
134 },\r
135\r
136 applyHeader: function(header) {\r
137 if (header && !header.isComponent) {\r
138 header = Ext.factory(header, Ext.Component, this.getHeader());\r
139 }\r
140 return header;\r
141 },\r
142\r
143 updateHeader: function(header, oldHeader) {\r
144 if (oldHeader) {\r
145 oldHeader.destroy();\r
146 }\r
147 },\r
148\r
149 applyDisclosure: function(disclosure) {\r
150 if (disclosure && !disclosure.isComponent) {\r
151 disclosure = Ext.factory(disclosure, Ext.Component, this.getDisclosure());\r
152 }\r
153 return disclosure;\r
154 },\r
155\r
156 updateDisclosure: function(disclosure, oldDisclosure) {\r
157 if (disclosure) {\r
158 this.add(disclosure);\r
159 } else if (oldDisclosure) {\r
160 oldDisclosure.destroy();\r
161 }\r
162 },\r
163\r
164 updateTpl: function(tpl) {\r
165 this.getBody().setTpl(tpl);\r
166 },\r
167\r
168 updateRecord: function(record) {\r
169 var me = this,\r
170 dataview = me.dataview || this.getDataview(),\r
171 data = record && dataview.prepareData(record.getData(true), dataview.getStore().indexOf(record), record),\r
172 dataMap = me.getDataMap(),\r
173 body = this.getBody(),\r
174 disclosure = this.getDisclosure();\r
175\r
176 me._record = record;\r
177\r
178 if (dataMap) {\r
179 me.doMapData(dataMap, data, body);\r
180 } else if (body) {\r
181 body.updateData(data || null);\r
182 }\r
183\r
184 if (disclosure && record && dataview.getOnItemDisclosure()) {\r
185 var disclosureProperty = dataview.getDisclosureProperty();\r
186 disclosure[(data.hasOwnProperty(disclosureProperty) && data[disclosureProperty] === false) ? 'hide' : 'show']();\r
187 }\r
188\r
189 /**\r
190 * @event updatedata\r
191 * Fires whenever the data of the DataItem is updated.\r
192 * @param {Ext.dataview.component.DataItem} this The DataItem instance.\r
193 * @param {Object} newData The new data.\r
194 */\r
195 me.fireEvent('updatedata', me, data);\r
196 },\r
197\r
198 destroy: function() {\r
199 Ext.destroy(this.getHeader());\r
200 this.callParent();\r
201 }\r
202});\r