Web Interface For Lite Argus Control modules
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.

797 lines
29 KiB

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