You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

801 lines
32 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-DataView-method-constructor'><span id='Ext-DataView'>/**
  19. </span></span> * @class Ext.DataView
  20. * @extends Ext.BoxComponent
  21. * A mechanism for displaying data using custom layout templates and formatting. DataView uses an {@link Ext.XTemplate}
  22. * as its internal templating mechanism, and is bound to an {@link Ext.data.Store}
  23. * so that as the data in the store changes the view is automatically updated to reflect the changes. The view also
  24. * provides built-in behavior for many common events that can occur for its contained items including click, doubleclick,
  25. * mouseover, mouseout, etc. as well as a built-in selection model. &lt;b&gt;In order to use these features, an {@link #itemSelector}
  26. * config must be provided for the DataView to determine what nodes it will be working with.&lt;/b&gt;
  27. *
  28. * &lt;p&gt;The example below binds a DataView to a {@link Ext.data.Store} and renders it into an {@link Ext.Panel}.&lt;/p&gt;
  29. * &lt;pre&gt;&lt;code&gt;
  30. var store = new Ext.data.JsonStore({
  31. url: 'get-images.php',
  32. root: 'images',
  33. fields: [
  34. 'name', 'url',
  35. {name:'size', type: 'float'},
  36. {name:'lastmod', type:'date', dateFormat:'timestamp'}
  37. ]
  38. });
  39. store.load();
  40. var tpl = new Ext.XTemplate(
  41. '&amp;lt;tpl for=&quot;.&quot;&amp;gt;',
  42. '&amp;lt;div class=&quot;thumb-wrap&quot; id=&quot;{name}&quot;&amp;gt;',
  43. '&amp;lt;div class=&quot;thumb&quot;&amp;gt;&amp;lt;img src=&quot;{url}&quot; title=&quot;{name}&quot;&amp;gt;&amp;lt;/div&amp;gt;',
  44. '&amp;lt;span class=&quot;x-editable&quot;&amp;gt;{shortName}&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;',
  45. '&amp;lt;/tpl&amp;gt;',
  46. '&amp;lt;div class=&quot;x-clear&quot;&amp;gt;&amp;lt;/div&amp;gt;'
  47. );
  48. var panel = new Ext.Panel({
  49. id:'images-view',
  50. frame:true,
  51. width:535,
  52. autoHeight:true,
  53. collapsible:true,
  54. layout:'fit',
  55. title:'Simple DataView',
  56. items: new Ext.DataView({
  57. store: store,
  58. tpl: tpl,
  59. autoHeight:true,
  60. multiSelect: true,
  61. overClass:'x-view-over',
  62. itemSelector:'div.thumb-wrap',
  63. emptyText: 'No images to display'
  64. })
  65. });
  66. panel.render(document.body);
  67. &lt;/code&gt;&lt;/pre&gt;
  68. * @constructor
  69. * Create a new DataView
  70. * @param {Object} config The config object
  71. * @xtype dataview
  72. */
  73. Ext.DataView = Ext.extend(Ext.BoxComponent, {
  74. <span id='Ext-DataView-cfg-tpl'> /**
  75. </span> * @cfg {String/Array} tpl
  76. * The HTML fragment or an array of fragments that will make up the template used by this DataView. This should
  77. * be specified in the same format expected by the constructor of {@link Ext.XTemplate}.
  78. */
  79. <span id='Ext-DataView-cfg-store'> /**
  80. </span> * @cfg {Ext.data.Store} store
  81. * The {@link Ext.data.Store} to bind this DataView to.
  82. */
  83. <span id='Ext-DataView-cfg-itemSelector'> /**
  84. </span> * @cfg {String} itemSelector
  85. * &lt;b&gt;This is a required setting&lt;/b&gt;. A simple CSS selector (e.g. &lt;tt&gt;div.some-class&lt;/tt&gt; or
  86. * &lt;tt&gt;span:first-child&lt;/tt&gt;) that will be used to determine what nodes this DataView will be
  87. * working with.
  88. */
  89. <span id='Ext-DataView-cfg-multiSelect'> /**
  90. </span> * @cfg {Boolean} multiSelect
  91. * True to allow selection of more than one item at a time, false to allow selection of only a single item
  92. * at a time or no selection at all, depending on the value of {@link #singleSelect} (defaults to false).
  93. */
  94. <span id='Ext-DataView-cfg-singleSelect'> /**
  95. </span> * @cfg {Boolean} singleSelect
  96. * True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false).
  97. * Note that if {@link #multiSelect} = true, this value will be ignored.
  98. */
  99. <span id='Ext-DataView-cfg-simpleSelect'> /**
  100. </span> * @cfg {Boolean} simpleSelect
  101. * True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl,
  102. * false to force the user to hold Ctrl or Shift to select more than on item (defaults to false).
  103. */
  104. <span id='Ext-DataView-cfg-overClass'> /**
  105. </span> * @cfg {String} overClass
  106. * A CSS class to apply to each item in the view on mouseover (defaults to undefined).
  107. */
  108. <span id='Ext-DataView-cfg-loadingText'> /**
  109. </span> * @cfg {String} loadingText
  110. * A string to display during data load operations (defaults to undefined). If specified, this text will be
  111. * displayed in a loading div and the view's contents will be cleared while loading, otherwise the view's
  112. * contents will continue to display normally until the new data is loaded and the contents are replaced.
  113. */
  114. <span id='Ext-DataView-cfg-selectedClass'> /**
  115. </span> * @cfg {String} selectedClass
  116. * A CSS class to apply to each selected item in the view (defaults to 'x-view-selected').
  117. */
  118. selectedClass : &quot;x-view-selected&quot;,
  119. <span id='Ext-DataView-cfg-emptyText'> /**
  120. </span> * @cfg {String} emptyText
  121. * The text to display in the view when there is no data to display (defaults to '').
  122. */
  123. emptyText : &quot;&quot;,
  124. <span id='Ext-DataView-cfg-deferEmptyText'> /**
  125. </span> * @cfg {Boolean} deferEmptyText True to defer emptyText being applied until the store's first load
  126. */
  127. deferEmptyText: true,
  128. <span id='Ext-DataView-cfg-trackOver'> /**
  129. </span> * @cfg {Boolean} trackOver True to enable mouseenter and mouseleave events
  130. */
  131. trackOver: false,
  132. <span id='Ext-DataView-cfg-blockRefresh'> /**
  133. </span> * @cfg {Boolean} blockRefresh Set this to true to ignore datachanged events on the bound store. This is useful if
  134. * you wish to provide custom transition animations via a plugin (defaults to false)
  135. */
  136. blockRefresh: false,
  137. <span id='Ext-DataView-property-last'> //private
  138. </span> last: false,
  139. <span id='Ext-DataView-method-initComponent'> // private
  140. </span> initComponent : function(){
  141. Ext.DataView.superclass.initComponent.call(this);
  142. if(Ext.isString(this.tpl) || Ext.isArray(this.tpl)){
  143. this.tpl = new Ext.XTemplate(this.tpl);
  144. }
  145. this.addEvents(
  146. <span id='Ext-DataView-event-beforeclick'> /**
  147. </span> * @event beforeclick
  148. * Fires before a click is processed. Returns false to cancel the default action.
  149. * @param {Ext.DataView} this
  150. * @param {Number} index The index of the target node
  151. * @param {HTMLElement} node The target node
  152. * @param {Ext.EventObject} e The raw event object
  153. */
  154. &quot;beforeclick&quot;,
  155. <span id='Ext-DataView-event-click'> /**
  156. </span> * @event click
  157. * Fires when a template node is clicked.
  158. * @param {Ext.DataView} this
  159. * @param {Number} index The index of the target node
  160. * @param {HTMLElement} node The target node
  161. * @param {Ext.EventObject} e The raw event object
  162. */
  163. &quot;click&quot;,
  164. <span id='Ext-DataView-event-mouseenter'> /**
  165. </span> * @event mouseenter
  166. * Fires when the mouse enters a template node. trackOver:true or an overClass must be set to enable this event.
  167. * @param {Ext.DataView} this
  168. * @param {Number} index The index of the target node
  169. * @param {HTMLElement} node The target node
  170. * @param {Ext.EventObject} e The raw event object
  171. */
  172. &quot;mouseenter&quot;,
  173. <span id='Ext-DataView-event-mouseleave'> /**
  174. </span> * @event mouseleave
  175. * Fires when the mouse leaves a template node. trackOver:true or an overClass must be set to enable this event.
  176. * @param {Ext.DataView} this
  177. * @param {Number} index The index of the target node
  178. * @param {HTMLElement} node The target node
  179. * @param {Ext.EventObject} e The raw event object
  180. */
  181. &quot;mouseleave&quot;,
  182. <span id='Ext-DataView-event-containerclick'> /**
  183. </span> * @event containerclick
  184. * Fires when a click occurs and it is not on a template node.
  185. * @param {Ext.DataView} this
  186. * @param {Ext.EventObject} e The raw event object
  187. */
  188. &quot;containerclick&quot;,
  189. <span id='Ext-DataView-event-dblclick'> /**
  190. </span> * @event dblclick
  191. * Fires when a template node is double clicked.
  192. * @param {Ext.DataView} this
  193. * @param {Number} index The index of the target node
  194. * @param {HTMLElement} node The target node
  195. * @param {Ext.EventObject} e The raw event object
  196. */
  197. &quot;dblclick&quot;,
  198. <span id='Ext-DataView-event-contextmenu'> /**
  199. </span> * @event contextmenu
  200. * Fires when a template node is right clicked.
  201. * @param {Ext.DataView} this
  202. * @param {Number} index The index of the target node
  203. * @param {HTMLElement} node The target node
  204. * @param {Ext.EventObject} e The raw event object
  205. */
  206. &quot;contextmenu&quot;,
  207. <span id='Ext-DataView-event-containercontextmenu'> /**
  208. </span> * @event containercontextmenu
  209. * Fires when a right click occurs that is not on a template node.
  210. * @param {Ext.DataView} this
  211. * @param {Ext.EventObject} e The raw event object
  212. */
  213. &quot;containercontextmenu&quot;,
  214. <span id='Ext-DataView-event-selectionchange'> /**
  215. </span> * @event selectionchange
  216. * Fires when the selected nodes change.
  217. * @param {Ext.DataView} this
  218. * @param {Array} selections Array of the selected nodes
  219. */
  220. &quot;selectionchange&quot;,
  221. <span id='Ext-DataView-event-beforeselect'> /**
  222. </span> * @event beforeselect
  223. * Fires before a selection is made. If any handlers return false, the selection is cancelled.
  224. * @param {Ext.DataView} this
  225. * @param {HTMLElement} node The node to be selected
  226. * @param {Array} selections Array of currently selected nodes
  227. */
  228. &quot;beforeselect&quot;
  229. );
  230. this.store = Ext.StoreMgr.lookup(this.store);
  231. this.all = new Ext.CompositeElementLite();
  232. this.selected = new Ext.CompositeElementLite();
  233. },
  234. <span id='Ext-DataView-method-afterRender'> // private
  235. </span> afterRender : function(){
  236. Ext.DataView.superclass.afterRender.call(this);
  237. this.mon(this.getTemplateTarget(), {
  238. &quot;click&quot;: this.onClick,
  239. &quot;dblclick&quot;: this.onDblClick,
  240. &quot;contextmenu&quot;: this.onContextMenu,
  241. scope:this
  242. });
  243. if(this.overClass || this.trackOver){
  244. this.mon(this.getTemplateTarget(), {
  245. &quot;mouseover&quot;: this.onMouseOver,
  246. &quot;mouseout&quot;: this.onMouseOut,
  247. scope:this
  248. });
  249. }
  250. if(this.store){
  251. this.bindStore(this.store, true);
  252. }
  253. },
  254. <span id='Ext-DataView-method-refresh'> /**
  255. </span> * Refreshes the view by reloading the data from the store and re-rendering the template.
  256. */
  257. refresh : function() {
  258. this.clearSelections(false, true);
  259. var el = this.getTemplateTarget(),
  260. records = this.store.getRange();
  261. el.update('');
  262. if(records.length &lt; 1){
  263. if(!this.deferEmptyText || this.hasSkippedEmptyText){
  264. el.update(this.emptyText);
  265. }
  266. this.all.clear();
  267. }else{
  268. this.tpl.overwrite(el, this.collectData(records, 0));
  269. this.all.fill(Ext.query(this.itemSelector, el.dom));
  270. this.updateIndexes(0);
  271. }
  272. this.hasSkippedEmptyText = true;
  273. },
  274. <span id='Ext-DataView-method-getTemplateTarget'> getTemplateTarget: function(){
  275. </span> return this.el;
  276. },
  277. <span id='Ext-DataView-method-prepareData'> /**
  278. </span> * Function which can be overridden to provide custom formatting for each Record that is used by this
  279. * DataView's {@link #tpl template} to render each node.
  280. * @param {Array/Object} data The raw data object that was used to create the Record.
  281. * @param {Number} recordIndex the index number of the Record being prepared for rendering.
  282. * @param {Record} record The Record being prepared for rendering.
  283. * @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
  284. * (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
  285. */
  286. prepareData : function(data){
  287. return data;
  288. },
  289. <span id='Ext-DataView-method-collectData'> /**
  290. </span> * &lt;p&gt;Function which can be overridden which returns the data object passed to this
  291. * DataView's {@link #tpl template} to render the whole DataView.&lt;/p&gt;
  292. * &lt;p&gt;This is usually an Array of data objects, each element of which is processed by an
  293. * {@link Ext.XTemplate XTemplate} which uses &lt;tt&gt;'&amp;lt;tpl for=&quot;.&quot;&amp;gt;'&lt;/tt&gt; to iterate over its supplied
  294. * data object as an Array. However, &lt;i&gt;named&lt;/i&gt; properties may be placed into the data object to
  295. * provide non-repeating data such as headings, totals etc.&lt;/p&gt;
  296. * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
  297. * @param {Number} startIndex the index number of the Record being prepared for rendering.
  298. * @return {Array} An Array of data objects to be processed by a repeating XTemplate. May also
  299. * contain &lt;i&gt;named&lt;/i&gt; properties.
  300. */
  301. collectData : function(records, startIndex){
  302. var r = [],
  303. i = 0,
  304. len = records.length;
  305. for(; i &lt; len; i++){
  306. r[r.length] = this.prepareData(records[i].data, startIndex + i, records[i]);
  307. }
  308. return r;
  309. },
  310. <span id='Ext-DataView-method-bufferRender'> // private
  311. </span> bufferRender : function(records, index){
  312. var div = document.createElement('div');
  313. this.tpl.overwrite(div, this.collectData(records, index));
  314. return Ext.query(this.itemSelector, div);
  315. },
  316. <span id='Ext-DataView-method-onUpdate'> // private
  317. </span> onUpdate : function(ds, record){
  318. var index = this.store.indexOf(record);
  319. if(index &gt; -1){
  320. var sel = this.isSelected(index),
  321. original = this.all.elements[index],
  322. node = this.bufferRender([record], index)[0];
  323. this.all.replaceElement(index, node, true);
  324. if(sel){
  325. this.selected.replaceElement(original, node);
  326. this.all.item(index).addClass(this.selectedClass);
  327. }
  328. this.updateIndexes(index, index);
  329. }
  330. },
  331. <span id='Ext-DataView-method-onAdd'> // private
  332. </span> onAdd : function(ds, records, index){
  333. if(this.all.getCount() === 0){
  334. this.refresh();
  335. return;
  336. }
  337. var nodes = this.bufferRender(records, index), n, a = this.all.elements;
  338. if(index &lt; this.all.getCount()){
  339. n = this.all.item(index).insertSibling(nodes, 'before', true);
  340. a.splice.apply(a, [index, 0].concat(nodes));
  341. }else{
  342. n = this.all.last().insertSibling(nodes, 'after', true);
  343. a.push.apply(a, nodes);
  344. }
  345. this.updateIndexes(index);
  346. },
  347. <span id='Ext-DataView-method-onRemove'> // private
  348. </span> onRemove : function(ds, record, index){
  349. this.deselect(index);
  350. this.all.removeElement(index, true);
  351. this.updateIndexes(index);
  352. if (this.store.getCount() === 0){
  353. this.refresh();
  354. }
  355. },
  356. <span id='Ext-DataView-method-refreshNode'> /**
  357. </span> * Refreshes an individual node's data from the store.
  358. * @param {Number} index The item's data index in the store
  359. */
  360. refreshNode : function(index){
  361. this.onUpdate(this.store, this.store.getAt(index));
  362. },
  363. <span id='Ext-DataView-method-updateIndexes'> // private
  364. </span> updateIndexes : function(startIndex, endIndex){
  365. var ns = this.all.elements;
  366. startIndex = startIndex || 0;
  367. endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
  368. for(var i = startIndex; i &lt;= endIndex; i++){
  369. ns[i].viewIndex = i;
  370. }
  371. },
  372. <span id='Ext-DataView-method-getStore'> /**
  373. </span> * Returns the store associated with this DataView.
  374. * @return {Ext.data.Store} The store
  375. */
  376. getStore : function(){
  377. return this.store;
  378. },
  379. <span id='Ext-DataView-method-bindStore'> /**
  380. </span> * Changes the data store bound to this view and refreshes it.
  381. * @param {Store} store The store to bind to this view
  382. */
  383. bindStore : function(store, initial){
  384. if(!initial &amp;&amp; this.store){
  385. if(store !== this.store &amp;&amp; this.store.autoDestroy){
  386. this.store.destroy();
  387. }else{
  388. this.store.un(&quot;beforeload&quot;, this.onBeforeLoad, this);
  389. this.store.un(&quot;datachanged&quot;, this.onDataChanged, this);
  390. this.store.un(&quot;add&quot;, this.onAdd, this);
  391. this.store.un(&quot;remove&quot;, this.onRemove, this);
  392. this.store.un(&quot;update&quot;, this.onUpdate, this);
  393. this.store.un(&quot;clear&quot;, this.refresh, this);
  394. }
  395. if(!store){
  396. this.store = null;
  397. }
  398. }
  399. if(store){
  400. store = Ext.StoreMgr.lookup(store);
  401. store.on({
  402. scope: this,
  403. beforeload: this.onBeforeLoad,
  404. datachanged: this.onDataChanged,
  405. add: this.onAdd,
  406. remove: this.onRemove,
  407. update: this.onUpdate,
  408. clear: this.refresh
  409. });
  410. }
  411. this.store = store;
  412. if(store){
  413. this.refresh();
  414. }
  415. },
  416. <span id='Ext-DataView-method-onDataChanged'> /**
  417. </span> * @private
  418. * Calls this.refresh if this.blockRefresh is not true
  419. */
  420. onDataChanged: function() {
  421. if (this.blockRefresh !== true) {
  422. this.refresh.apply(this, arguments);
  423. }
  424. },
  425. <span id='Ext-DataView-method-findItemFromChild'> /**
  426. </span> * Returns the template node the passed child belongs to, or null if it doesn't belong to one.
  427. * @param {HTMLElement} node
  428. * @return {HTMLElement} The template node
  429. */
  430. findItemFromChild : function(node){
  431. return Ext.fly(node).findParent(this.itemSelector, this.getTemplateTarget());
  432. },
  433. <span id='Ext-DataView-method-onClick'> // private
  434. </span> onClick : function(e){
  435. var item = e.getTarget(this.itemSelector, this.getTemplateTarget()),
  436. index;
  437. if(item){
  438. index = this.indexOf(item);
  439. if(this.onItemClick(item, index, e) !== false){
  440. this.fireEvent(&quot;click&quot;, this, index, item, e);
  441. }
  442. }else{
  443. if(this.fireEvent(&quot;containerclick&quot;, this, e) !== false){
  444. this.onContainerClick(e);
  445. }
  446. }
  447. },
  448. <span id='Ext-DataView-method-onContainerClick'> onContainerClick : function(e){
  449. </span> this.clearSelections();
  450. },
  451. <span id='Ext-DataView-method-onContextMenu'> // private
  452. </span> onContextMenu : function(e){
  453. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  454. if(item){
  455. this.fireEvent(&quot;contextmenu&quot;, this, this.indexOf(item), item, e);
  456. }else{
  457. this.fireEvent(&quot;containercontextmenu&quot;, this, e);
  458. }
  459. },
  460. <span id='Ext-DataView-method-onDblClick'> // private
  461. </span> onDblClick : function(e){
  462. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  463. if(item){
  464. this.fireEvent(&quot;dblclick&quot;, this, this.indexOf(item), item, e);
  465. }
  466. },
  467. <span id='Ext-DataView-method-onMouseOver'> // private
  468. </span> onMouseOver : function(e){
  469. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  470. if(item &amp;&amp; item !== this.lastItem){
  471. this.lastItem = item;
  472. Ext.fly(item).addClass(this.overClass);
  473. this.fireEvent(&quot;mouseenter&quot;, this, this.indexOf(item), item, e);
  474. }
  475. },
  476. <span id='Ext-DataView-method-onMouseOut'> // private
  477. </span> onMouseOut : function(e){
  478. if(this.lastItem){
  479. if(!e.within(this.lastItem, true, true)){
  480. Ext.fly(this.lastItem).removeClass(this.overClass);
  481. this.fireEvent(&quot;mouseleave&quot;, this, this.indexOf(this.lastItem), this.lastItem, e);
  482. delete this.lastItem;
  483. }
  484. }
  485. },
  486. <span id='Ext-DataView-method-onItemClick'> // private
  487. </span> onItemClick : function(item, index, e){
  488. if(this.fireEvent(&quot;beforeclick&quot;, this, index, item, e) === false){
  489. return false;
  490. }
  491. if(this.multiSelect){
  492. this.doMultiSelection(item, index, e);
  493. e.preventDefault();
  494. }else if(this.singleSelect){
  495. this.doSingleSelection(item, index, e);
  496. e.preventDefault();
  497. }
  498. return true;
  499. },
  500. <span id='Ext-DataView-method-doSingleSelection'> // private
  501. </span> doSingleSelection : function(item, index, e){
  502. if(e.ctrlKey &amp;&amp; this.isSelected(index)){
  503. this.deselect(index);
  504. }else{
  505. this.select(index, false);
  506. }
  507. },
  508. <span id='Ext-DataView-method-doMultiSelection'> // private
  509. </span> doMultiSelection : function(item, index, e){
  510. if(e.shiftKey &amp;&amp; this.last !== false){
  511. var last = this.last;
  512. this.selectRange(last, index, e.ctrlKey);
  513. this.last = last; // reset the last
  514. }else{
  515. if((e.ctrlKey||this.simpleSelect) &amp;&amp; this.isSelected(index)){
  516. this.deselect(index);
  517. }else{
  518. this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
  519. }
  520. }
  521. },
  522. <span id='Ext-DataView-method-getSelectionCount'> /**
  523. </span> * Gets the number of selected nodes.
  524. * @return {Number} The node count
  525. */
  526. getSelectionCount : function(){
  527. return this.selected.getCount();
  528. },
  529. <span id='Ext-DataView-method-getSelectedNodes'> /**
  530. </span> * Gets the currently selected nodes.
  531. * @return {Array} An array of HTMLElements
  532. */
  533. getSelectedNodes : function(){
  534. return this.selected.elements;
  535. },
  536. <span id='Ext-DataView-method-getSelectedIndexes'> /**
  537. </span> * Gets the indexes of the selected nodes.
  538. * @return {Array} An array of numeric indexes
  539. */
  540. getSelectedIndexes : function(){
  541. var indexes = [],
  542. selected = this.selected.elements,
  543. i = 0,
  544. len = selected.length;
  545. for(; i &lt; len; i++){
  546. indexes.push(selected[i].viewIndex);
  547. }
  548. return indexes;
  549. },
  550. <span id='Ext-DataView-method-getSelectedRecords'> /**
  551. </span> * Gets an array of the selected records
  552. * @return {Array} An array of {@link Ext.data.Record} objects
  553. */
  554. getSelectedRecords : function(){
  555. return this.getRecords(this.selected.elements);
  556. },
  557. <span id='Ext-DataView-method-getRecords'> /**
  558. </span> * Gets an array of the records from an array of nodes
  559. * @param {Array} nodes The nodes to evaluate
  560. * @return {Array} records The {@link Ext.data.Record} objects
  561. */
  562. getRecords : function(nodes){
  563. var records = [],
  564. i = 0,
  565. len = nodes.length;
  566. for(; i &lt; len; i++){
  567. records[records.length] = this.store.getAt(nodes[i].viewIndex);
  568. }
  569. return records;
  570. },
  571. <span id='Ext-DataView-method-getRecord'> /**
  572. </span> * Gets a record from a node
  573. * @param {HTMLElement} node The node to evaluate
  574. * @return {Record} record The {@link Ext.data.Record} object
  575. */
  576. getRecord : function(node){
  577. return this.store.getAt(node.viewIndex);
  578. },
  579. <span id='Ext-DataView-method-clearSelections'> /**
  580. </span> * Clears all selections.
  581. * @param {Boolean} suppressEvent (optional) True to skip firing of the selectionchange event
  582. */
  583. clearSelections : function(suppressEvent, skipUpdate){
  584. if((this.multiSelect || this.singleSelect) &amp;&amp; this.selected.getCount() &gt; 0){
  585. if(!skipUpdate){
  586. this.selected.removeClass(this.selectedClass);
  587. }
  588. this.selected.clear();
  589. this.last = false;
  590. if(!suppressEvent){
  591. this.fireEvent(&quot;selectionchange&quot;, this, this.selected.elements);
  592. }
  593. }
  594. },
  595. <span id='Ext-DataView-method-isSelected'> /**
  596. </span> * Returns true if the passed node is selected, else false.
  597. * @param {HTMLElement/Number/Ext.data.Record} node The node, node index or record to check
  598. * @return {Boolean} True if selected, else false
  599. */
  600. isSelected : function(node){
  601. return this.selected.contains(this.getNode(node));
  602. },
  603. <span id='Ext-DataView-method-deselect'> /**
  604. </span> * Deselects a node.
  605. * @param {HTMLElement/Number/Record} node The node, node index or record to deselect
  606. */
  607. deselect : function(node){
  608. if(this.isSelected(node)){
  609. node = this.getNode(node);
  610. this.selected.removeElement(node);
  611. if(this.last == node.viewIndex){
  612. this.last = false;
  613. }
  614. Ext.fly(node).removeClass(this.selectedClass);
  615. this.fireEvent(&quot;selectionchange&quot;, this, this.selected.elements);
  616. }
  617. },
  618. <span id='Ext-DataView-method-select'> /**
  619. </span> * Selects a set of nodes.
  620. * @param {Array/HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node,
  621. * id of a template node, record associated with a node or an array of any of those to select
  622. * @param {Boolean} keepExisting (optional) true to keep existing selections
  623. * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
  624. */
  625. select : function(nodeInfo, keepExisting, suppressEvent){
  626. if(Ext.isArray(nodeInfo)){
  627. if(!keepExisting){
  628. this.clearSelections(true);
  629. }
  630. for(var i = 0, len = nodeInfo.length; i &lt; len; i++){
  631. this.select(nodeInfo[i], true, true);
  632. }
  633. if(!suppressEvent){
  634. this.fireEvent(&quot;selectionchange&quot;, this, this.selected.elements);
  635. }
  636. } else{
  637. var node = this.getNode(nodeInfo);
  638. if(!keepExisting){
  639. this.clearSelections(true);
  640. }
  641. if(node &amp;&amp; !this.isSelected(node)){
  642. if(this.fireEvent(&quot;beforeselect&quot;, this, node, this.selected.elements) !== false){
  643. Ext.fly(node).addClass(this.selectedClass);
  644. this.selected.add(node);
  645. this.last = node.viewIndex;
  646. if(!suppressEvent){
  647. this.fireEvent(&quot;selectionchange&quot;, this, this.selected.elements);
  648. }
  649. }
  650. }
  651. }
  652. },
  653. <span id='Ext-DataView-method-selectRange'> /**
  654. </span> * Selects a range of nodes. All nodes between start and end are selected.
  655. * @param {Number} start The index of the first node in the range
  656. * @param {Number} end The index of the last node in the range
  657. * @param {Boolean} keepExisting (optional) True to retain existing selections
  658. */
  659. selectRange : function(start, end, keepExisting){
  660. if(!keepExisting){
  661. this.clearSelections(true);
  662. }
  663. this.select(this.getNodes(start, end), true);
  664. },
  665. <span id='Ext-DataView-method-getNode'> /**
  666. </span> * Gets a template node.
  667. * @param {HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node,
  668. * the id of a template node or the record associated with the node.
  669. * @return {HTMLElement} The node or null if it wasn't found
  670. */
  671. getNode : function(nodeInfo){
  672. if(Ext.isString(nodeInfo)){
  673. return document.getElementById(nodeInfo);
  674. }else if(Ext.isNumber(nodeInfo)){
  675. return this.all.elements[nodeInfo];
  676. }else if(nodeInfo instanceof Ext.data.Record){
  677. var idx = this.store.indexOf(nodeInfo);
  678. return this.all.elements[idx];
  679. }
  680. return nodeInfo;
  681. },
  682. <span id='Ext-DataView-method-getNodes'> /**
  683. </span> * Gets a range nodes.
  684. * @param {Number} start (optional) The index of the first node in the range
  685. * @param {Number} end (optional) The index of the last node in the range
  686. * @return {Array} An array of nodes
  687. */
  688. getNodes : function(start, end){
  689. var ns = this.all.elements,
  690. nodes = [],
  691. i;
  692. start = start || 0;
  693. end = !Ext.isDefined(end) ? Math.max(ns.length - 1, 0) : end;
  694. if(start &lt;= end){
  695. for(i = start; i &lt;= end &amp;&amp; ns[i]; i++){
  696. nodes.push(ns[i]);
  697. }
  698. } else{
  699. for(i = start; i &gt;= end &amp;&amp; ns[i]; i--){
  700. nodes.push(ns[i]);
  701. }
  702. }
  703. return nodes;
  704. },
  705. <span id='Ext-DataView-method-indexOf'> /**
  706. </span> * Finds the index of the passed node.
  707. * @param {HTMLElement/String/Number/Record} nodeInfo An HTMLElement template node, index of a template node, the id of a template node
  708. * or a record associated with a node.
  709. * @return {Number} The index of the node or -1
  710. */
  711. indexOf : function(node){
  712. node = this.getNode(node);
  713. if(Ext.isNumber(node.viewIndex)){
  714. return node.viewIndex;
  715. }
  716. return this.all.indexOf(node);
  717. },
  718. <span id='Ext-DataView-method-onBeforeLoad'> // private
  719. </span> onBeforeLoad : function(){
  720. if(this.loadingText){
  721. this.clearSelections(false, true);
  722. this.getTemplateTarget().update('&lt;div class=&quot;loading-indicator&quot;&gt;'+this.loadingText+'&lt;/div&gt;');
  723. this.all.clear();
  724. }
  725. },
  726. <span id='Ext-DataView-method-onDestroy'> onDestroy : function(){
  727. </span> this.all.clear();
  728. this.selected.clear();
  729. Ext.DataView.superclass.onDestroy.call(this);
  730. this.bindStore(null);
  731. }
  732. });
  733. <span id='Ext-DataView-method-setStore'>/**
  734. </span> * Changes the data store bound to this view and refreshes it. (deprecated in favor of bindStore)
  735. * @param {Store} store The store to bind to this view
  736. */
  737. Ext.DataView.prototype.setStore = Ext.DataView.prototype.bindStore;
  738. Ext.reg('dataview', Ext.DataView);
  739. </pre>
  740. </body>
  741. </html>