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.

1538 lines
52 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.DataView
  9. * @extends Ext.BoxComponent
  10. * A mechanism for displaying data using custom layout templates and formatting. DataView uses an {@link Ext.XTemplate}
  11. * as its internal templating mechanism, and is bound to an {@link Ext.data.Store}
  12. * so that as the data in the store changes the view is automatically updated to reflect the changes. The view also
  13. * provides built-in behavior for many common events that can occur for its contained items including click, doubleclick,
  14. * mouseover, mouseout, etc. as well as a built-in selection model. <b>In order to use these features, an {@link #itemSelector}
  15. * config must be provided for the DataView to determine what nodes it will be working with.</b>
  16. *
  17. * <p>The example below binds a DataView to a {@link Ext.data.Store} and renders it into an {@link Ext.Panel}.</p>
  18. * <pre><code>
  19. var store = new Ext.data.JsonStore({
  20. url: 'get-images.php',
  21. root: 'images',
  22. fields: [
  23. 'name', 'url',
  24. {name:'size', type: 'float'},
  25. {name:'lastmod', type:'date', dateFormat:'timestamp'}
  26. ]
  27. });
  28. store.load();
  29. var tpl = new Ext.XTemplate(
  30. '&lt;tpl for="."&gt;',
  31. '&lt;div class="thumb-wrap" id="{name}"&gt;',
  32. '&lt;div class="thumb"&gt;&lt;img src="{url}" title="{name}"&gt;&lt;/div&gt;',
  33. '&lt;span class="x-editable"&gt;{shortName}&lt;/span&gt;&lt;/div&gt;',
  34. '&lt;/tpl&gt;',
  35. '&lt;div class="x-clear"&gt;&lt;/div&gt;'
  36. );
  37. var panel = new Ext.Panel({
  38. id:'images-view',
  39. frame:true,
  40. width:535,
  41. autoHeight:true,
  42. collapsible:true,
  43. layout:'fit',
  44. title:'Simple DataView',
  45. items: new Ext.DataView({
  46. store: store,
  47. tpl: tpl,
  48. autoHeight:true,
  49. multiSelect: true,
  50. overClass:'x-view-over',
  51. itemSelector:'div.thumb-wrap',
  52. emptyText: 'No images to display'
  53. })
  54. });
  55. panel.render(document.body);
  56. </code></pre>
  57. * @constructor
  58. * Create a new DataView
  59. * @param {Object} config The config object
  60. * @xtype dataview
  61. */
  62. Ext.DataView = Ext.extend(Ext.BoxComponent, {
  63. /**
  64. * @cfg {String/Array} tpl
  65. * The HTML fragment or an array of fragments that will make up the template used by this DataView. This should
  66. * be specified in the same format expected by the constructor of {@link Ext.XTemplate}.
  67. */
  68. /**
  69. * @cfg {Ext.data.Store} store
  70. * The {@link Ext.data.Store} to bind this DataView to.
  71. */
  72. /**
  73. * @cfg {String} itemSelector
  74. * <b>This is a required setting</b>. A simple CSS selector (e.g. <tt>div.some-class</tt> or
  75. * <tt>span:first-child</tt>) that will be used to determine what nodes this DataView will be
  76. * working with.
  77. */
  78. /**
  79. * @cfg {Boolean} multiSelect
  80. * True to allow selection of more than one item at a time, false to allow selection of only a single item
  81. * at a time or no selection at all, depending on the value of {@link #singleSelect} (defaults to false).
  82. */
  83. /**
  84. * @cfg {Boolean} singleSelect
  85. * True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false).
  86. * Note that if {@link #multiSelect} = true, this value will be ignored.
  87. */
  88. /**
  89. * @cfg {Boolean} simpleSelect
  90. * True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl,
  91. * false to force the user to hold Ctrl or Shift to select more than on item (defaults to false).
  92. */
  93. /**
  94. * @cfg {String} overClass
  95. * A CSS class to apply to each item in the view on mouseover (defaults to undefined).
  96. */
  97. /**
  98. * @cfg {String} loadingText
  99. * A string to display during data load operations (defaults to undefined). If specified, this text will be
  100. * displayed in a loading div and the view's contents will be cleared while loading, otherwise the view's
  101. * contents will continue to display normally until the new data is loaded and the contents are replaced.
  102. */
  103. /**
  104. * @cfg {String} selectedClass
  105. * A CSS class to apply to each selected item in the view (defaults to 'x-view-selected').
  106. */
  107. selectedClass : "x-view-selected",
  108. /**
  109. * @cfg {String} emptyText
  110. * The text to display in the view when there is no data to display (defaults to '').
  111. */
  112. emptyText : "",
  113. /**
  114. * @cfg {Boolean} deferEmptyText True to defer emptyText being applied until the store's first load
  115. */
  116. deferEmptyText: true,
  117. /**
  118. * @cfg {Boolean} trackOver True to enable mouseenter and mouseleave events
  119. */
  120. trackOver: false,
  121. /**
  122. * @cfg {Boolean} blockRefresh Set this to true to ignore datachanged events on the bound store. This is useful if
  123. * you wish to provide custom transition animations via a plugin (defaults to false)
  124. */
  125. blockRefresh: false,
  126. //private
  127. last: false,
  128. // private
  129. initComponent : function(){
  130. Ext.DataView.superclass.initComponent.call(this);
  131. if(Ext.isString(this.tpl) || Ext.isArray(this.tpl)){
  132. this.tpl = new Ext.XTemplate(this.tpl);
  133. }
  134. this.addEvents(
  135. /**
  136. * @event beforeclick
  137. * Fires before a click is processed. Returns false to cancel the default action.
  138. * @param {Ext.DataView} this
  139. * @param {Number} index The index of the target node
  140. * @param {HTMLElement} node The target node
  141. * @param {Ext.EventObject} e The raw event object
  142. */
  143. "beforeclick",
  144. /**
  145. * @event click
  146. * Fires when a template node is clicked.
  147. * @param {Ext.DataView} this
  148. * @param {Number} index The index of the target node
  149. * @param {HTMLElement} node The target node
  150. * @param {Ext.EventObject} e The raw event object
  151. */
  152. "click",
  153. /**
  154. * @event mouseenter
  155. * Fires when the mouse enters a template node. trackOver:true or an overClass must be set to enable this event.
  156. * @param {Ext.DataView} this
  157. * @param {Number} index The index of the target node
  158. * @param {HTMLElement} node The target node
  159. * @param {Ext.EventObject} e The raw event object
  160. */
  161. "mouseenter",
  162. /**
  163. * @event mouseleave
  164. * Fires when the mouse leaves a template node. trackOver:true or an overClass must be set to enable this event.
  165. * @param {Ext.DataView} this
  166. * @param {Number} index The index of the target node
  167. * @param {HTMLElement} node The target node
  168. * @param {Ext.EventObject} e The raw event object
  169. */
  170. "mouseleave",
  171. /**
  172. * @event containerclick
  173. * Fires when a click occurs and it is not on a template node.
  174. * @param {Ext.DataView} this
  175. * @param {Ext.EventObject} e The raw event object
  176. */
  177. "containerclick",
  178. /**
  179. * @event dblclick
  180. * Fires when a template node is double clicked.
  181. * @param {Ext.DataView} this
  182. * @param {Number} index The index of the target node
  183. * @param {HTMLElement} node The target node
  184. * @param {Ext.EventObject} e The raw event object
  185. */
  186. "dblclick",
  187. /**
  188. * @event contextmenu
  189. * Fires when a template node is right clicked.
  190. * @param {Ext.DataView} this
  191. * @param {Number} index The index of the target node
  192. * @param {HTMLElement} node The target node
  193. * @param {Ext.EventObject} e The raw event object
  194. */
  195. "contextmenu",
  196. /**
  197. * @event containercontextmenu
  198. * Fires when a right click occurs that is not on a template node.
  199. * @param {Ext.DataView} this
  200. * @param {Ext.EventObject} e The raw event object
  201. */
  202. "containercontextmenu",
  203. /**
  204. * @event selectionchange
  205. * Fires when the selected nodes change.
  206. * @param {Ext.DataView} this
  207. * @param {Array} selections Array of the selected nodes
  208. */
  209. "selectionchange",
  210. /**
  211. * @event beforeselect
  212. * Fires before a selection is made. If any handlers return false, the selection is cancelled.
  213. * @param {Ext.DataView} this
  214. * @param {HTMLElement} node The node to be selected
  215. * @param {Array} selections Array of currently selected nodes
  216. */
  217. "beforeselect"
  218. );
  219. this.store = Ext.StoreMgr.lookup(this.store);
  220. this.all = new Ext.CompositeElementLite();
  221. this.selected = new Ext.CompositeElementLite();
  222. },
  223. // private
  224. afterRender : function(){
  225. Ext.DataView.superclass.afterRender.call(this);
  226. this.mon(this.getTemplateTarget(), {
  227. "click": this.onClick,
  228. "dblclick": this.onDblClick,
  229. "contextmenu": this.onContextMenu,
  230. scope:this
  231. });
  232. if(this.overClass || this.trackOver){
  233. this.mon(this.getTemplateTarget(), {
  234. "mouseover": this.onMouseOver,
  235. "mouseout": this.onMouseOut,
  236. scope:this
  237. });
  238. }
  239. if(this.store){
  240. this.bindStore(this.store, true);
  241. }
  242. },
  243. /**
  244. * Refreshes the view by reloading the data from the store and re-rendering the template.
  245. */
  246. refresh : function() {
  247. this.clearSelections(false, true);
  248. var el = this.getTemplateTarget(),
  249. records = this.store.getRange();
  250. el.update('');
  251. if(records.length < 1){
  252. if(!this.deferEmptyText || this.hasSkippedEmptyText){
  253. el.update(this.emptyText);
  254. }
  255. this.all.clear();
  256. }else{
  257. this.tpl.overwrite(el, this.collectData(records, 0));
  258. this.all.fill(Ext.query(this.itemSelector, el.dom));
  259. this.updateIndexes(0);
  260. }
  261. this.hasSkippedEmptyText = true;
  262. },
  263. getTemplateTarget: function(){
  264. return this.el;
  265. },
  266. /**
  267. * Function which can be overridden to provide custom formatting for each Record that is used by this
  268. * DataView's {@link #tpl template} to render each node.
  269. * @param {Array/Object} data The raw data object that was used to create the Record.
  270. * @param {Number} recordIndex the index number of the Record being prepared for rendering.
  271. * @param {Record} record The Record being prepared for rendering.
  272. * @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
  273. * (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
  274. */
  275. prepareData : function(data){
  276. return data;
  277. },
  278. /**
  279. * <p>Function which can be overridden which returns the data object passed to this
  280. * DataView's {@link #tpl template} to render the whole DataView.</p>
  281. * <p>This is usually an Array of data objects, each element of which is processed by an
  282. * {@link Ext.XTemplate XTemplate} which uses <tt>'&lt;tpl for="."&gt;'</tt> to iterate over its supplied
  283. * data object as an Array. However, <i>named</i> properties may be placed into the data object to
  284. * provide non-repeating data such as headings, totals etc.</p>
  285. * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
  286. * @param {Number} startIndex the index number of the Record being prepared for rendering.
  287. * @return {Array} An Array of data objects to be processed by a repeating XTemplate. May also
  288. * contain <i>named</i> properties.
  289. */
  290. collectData : function(records, startIndex){
  291. var r = [],
  292. i = 0,
  293. len = records.length;
  294. for(; i < len; i++){
  295. r[r.length] = this.prepareData(records[i].data, startIndex + i, records[i]);
  296. }
  297. return r;
  298. },
  299. // private
  300. bufferRender : function(records, index){
  301. var div = document.createElement('div');
  302. this.tpl.overwrite(div, this.collectData(records, index));
  303. return Ext.query(this.itemSelector, div);
  304. },
  305. // private
  306. onUpdate : function(ds, record){
  307. var index = this.store.indexOf(record);
  308. if(index > -1){
  309. var sel = this.isSelected(index),
  310. original = this.all.elements[index],
  311. node = this.bufferRender([record], index)[0];
  312. this.all.replaceElement(index, node, true);
  313. if(sel){
  314. this.selected.replaceElement(original, node);
  315. this.all.item(index).addClass(this.selectedClass);
  316. }
  317. this.updateIndexes(index, index);
  318. }
  319. },
  320. // private
  321. onAdd : function(ds, records, index){
  322. if(this.all.getCount() === 0){
  323. this.refresh();
  324. return;
  325. }
  326. var nodes = this.bufferRender(records, index), n, a = this.all.elements;
  327. if(index < this.all.getCount()){
  328. n = this.all.item(index).insertSibling(nodes, 'before', true);
  329. a.splice.apply(a, [index, 0].concat(nodes));
  330. }else{
  331. n = this.all.last().insertSibling(nodes, 'after', true);
  332. a.push.apply(a, nodes);
  333. }
  334. this.updateIndexes(index);
  335. },
  336. // private
  337. onRemove : function(ds, record, index){
  338. this.deselect(index);
  339. this.all.removeElement(index, true);
  340. this.updateIndexes(index);
  341. if (this.store.getCount() === 0){
  342. this.refresh();
  343. }
  344. },
  345. /**
  346. * Refreshes an individual node's data from the store.
  347. * @param {Number} index The item's data index in the store
  348. */
  349. refreshNode : function(index){
  350. this.onUpdate(this.store, this.store.getAt(index));
  351. },
  352. // private
  353. updateIndexes : function(startIndex, endIndex){
  354. var ns = this.all.elements;
  355. startIndex = startIndex || 0;
  356. endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
  357. for(var i = startIndex; i <= endIndex; i++){
  358. ns[i].viewIndex = i;
  359. }
  360. },
  361. /**
  362. * Returns the store associated with this DataView.
  363. * @return {Ext.data.Store} The store
  364. */
  365. getStore : function(){
  366. return this.store;
  367. },
  368. /**
  369. * Changes the data store bound to this view and refreshes it.
  370. * @param {Store} store The store to bind to this view
  371. */
  372. bindStore : function(store, initial){
  373. if(!initial && this.store){
  374. if(store !== this.store && this.store.autoDestroy){
  375. this.store.destroy();
  376. }else{
  377. this.store.un("beforeload", this.onBeforeLoad, this);
  378. this.store.un("datachanged", this.onDataChanged, this);
  379. this.store.un("add", this.onAdd, this);
  380. this.store.un("remove", this.onRemove, this);
  381. this.store.un("update", this.onUpdate, this);
  382. this.store.un("clear", this.refresh, this);
  383. }
  384. if(!store){
  385. this.store = null;
  386. }
  387. }
  388. if(store){
  389. store = Ext.StoreMgr.lookup(store);
  390. store.on({
  391. scope: this,
  392. beforeload: this.onBeforeLoad,
  393. datachanged: this.onDataChanged,
  394. add: this.onAdd,
  395. remove: this.onRemove,
  396. update: this.onUpdate,
  397. clear: this.refresh
  398. });
  399. }
  400. this.store = store;
  401. if(store){
  402. this.refresh();
  403. }
  404. },
  405. /**
  406. * @private
  407. * Calls this.refresh if this.blockRefresh is not true
  408. */
  409. onDataChanged: function() {
  410. if (this.blockRefresh !== true) {
  411. this.refresh.apply(this, arguments);
  412. }
  413. },
  414. /**
  415. * Returns the template node the passed child belongs to, or null if it doesn't belong to one.
  416. * @param {HTMLElement} node
  417. * @return {HTMLElement} The template node
  418. */
  419. findItemFromChild : function(node){
  420. return Ext.fly(node).findParent(this.itemSelector, this.getTemplateTarget());
  421. },
  422. // private
  423. onClick : function(e){
  424. var item = e.getTarget(this.itemSelector, this.getTemplateTarget()),
  425. index;
  426. if(item){
  427. index = this.indexOf(item);
  428. if(this.onItemClick(item, index, e) !== false){
  429. this.fireEvent("click", this, index, item, e);
  430. }
  431. }else{
  432. if(this.fireEvent("containerclick", this, e) !== false){
  433. this.onContainerClick(e);
  434. }
  435. }
  436. },
  437. onContainerClick : function(e){
  438. this.clearSelections();
  439. },
  440. // private
  441. onContextMenu : function(e){
  442. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  443. if(item){
  444. this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
  445. }else{
  446. this.fireEvent("containercontextmenu", this, e);
  447. }
  448. },
  449. // private
  450. onDblClick : function(e){
  451. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  452. if(item){
  453. this.fireEvent("dblclick", this, this.indexOf(item), item, e);
  454. }
  455. },
  456. // private
  457. onMouseOver : function(e){
  458. var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
  459. if(item && item !== this.lastItem){
  460. this.lastItem = item;
  461. Ext.fly(item).addClass(this.overClass);
  462. this.fireEvent("mouseenter", this, this.indexOf(item), item, e);
  463. }
  464. },
  465. // private
  466. onMouseOut : function(e){
  467. if(this.lastItem){
  468. if(!e.within(this.lastItem, true, true)){
  469. Ext.fly(this.lastItem).removeClass(this.overClass);
  470. this.fireEvent("mouseleave", this, this.indexOf(this.lastItem), this.lastItem, e);
  471. delete this.lastItem;
  472. }
  473. }
  474. },
  475. // private
  476. onItemClick : function(item, index, e){
  477. if(this.fireEvent("beforeclick", this, index, item, e) === false){
  478. return false;
  479. }
  480. if(this.multiSelect){
  481. this.doMultiSelection(item, index, e);
  482. e.preventDefault();
  483. }else if(this.singleSelect){
  484. this.doSingleSelection(item, index, e);
  485. e.preventDefault();
  486. }
  487. return true;
  488. },
  489. // private
  490. doSingleSelection : function(item, index, e){
  491. if(e.ctrlKey && this.isSelected(index)){
  492. this.deselect(index);
  493. }else{
  494. this.select(index, false);
  495. }
  496. },
  497. // private
  498. doMultiSelection : function(item, index, e){
  499. if(e.shiftKey && this.last !== false){
  500. var last = this.last;
  501. this.selectRange(last, index, e.ctrlKey);
  502. this.last = last; // reset the last
  503. }else{
  504. if((e.ctrlKey||this.simpleSelect) && this.isSelected(index)){
  505. this.deselect(index);
  506. }else{
  507. this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
  508. }
  509. }
  510. },
  511. /**
  512. * Gets the number of selected nodes.
  513. * @return {Number} The node count
  514. */
  515. getSelectionCount : function(){
  516. return this.selected.getCount();
  517. },
  518. /**
  519. * Gets the currently selected nodes.
  520. * @return {Array} An array of HTMLElements
  521. */
  522. getSelectedNodes : function(){
  523. return this.selected.elements;
  524. },
  525. /**
  526. * Gets the indexes of the selected nodes.
  527. * @return {Array} An array of numeric indexes
  528. */
  529. getSelectedIndexes : function(){
  530. var indexes = [],
  531. selected = this.selected.elements,
  532. i = 0,
  533. len = selected.length;
  534. for(; i < len; i++){
  535. indexes.push(selected[i].viewIndex);
  536. }
  537. return indexes;
  538. },
  539. /**
  540. * Gets an array of the selected records
  541. * @return {Array} An array of {@link Ext.data.Record} objects
  542. */
  543. getSelectedRecords : function(){
  544. return this.getRecords(this.selected.elements);
  545. },
  546. /**
  547. * Gets an array of the records from an array of nodes
  548. * @param {Array} nodes The nodes to evaluate
  549. * @return {Array} records The {@link Ext.data.Record} objects
  550. */
  551. getRecords : function(nodes){
  552. var records = [],
  553. i = 0,
  554. len = nodes.length;
  555. for(; i < len; i++){
  556. records[records.length] = this.store.getAt(nodes[i].viewIndex);
  557. }
  558. return records;
  559. },
  560. /**
  561. * Gets a record from a node
  562. * @param {HTMLElement} node The node to evaluate
  563. * @return {Record} record The {@link Ext.data.Record} object
  564. */
  565. getRecord : function(node){
  566. return this.store.getAt(node.viewIndex);
  567. },
  568. /**
  569. * Clears all selections.
  570. * @param {Boolean} suppressEvent (optional) True to skip firing of the selectionchange event
  571. */
  572. clearSelections : function(suppressEvent, skipUpdate){
  573. if((this.multiSelect || this.singleSelect) && this.selected.getCount() > 0){
  574. if(!skipUpdate){
  575. this.selected.removeClass(this.selectedClass);
  576. }
  577. this.selected.clear();
  578. this.last = false;
  579. if(!suppressEvent){
  580. this.fireEvent("selectionchange", this, this.selected.elements);
  581. }
  582. }
  583. },
  584. /**
  585. * Returns true if the passed node is selected, else false.
  586. * @param {HTMLElement/Number/Ext.data.Record} node The node, node index or record to check
  587. * @return {Boolean} True if selected, else false
  588. */
  589. isSelected : function(node){
  590. return this.selected.contains(this.getNode(node));
  591. },
  592. /**
  593. * Deselects a node.
  594. * @param {HTMLElement/Number/Record} node The node, node index or record to deselect
  595. */
  596. deselect : function(node){
  597. if(this.isSelected(node)){
  598. node = this.getNode(node);
  599. this.selected.removeElement(node);
  600. if(this.last == node.viewIndex){
  601. this.last = false;
  602. }
  603. Ext.fly(node).removeClass(this.selectedClass);
  604. this.fireEvent("selectionchange", this, this.selected.elements);
  605. }
  606. },
  607. /**
  608. * Selects a set of nodes.
  609. * @param {Array/HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node,
  610. * id of a template node, record associated with a node or an array of any of those to select
  611. * @param {Boolean} keepExisting (optional) true to keep existing selections
  612. * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
  613. */
  614. select : function(nodeInfo, keepExisting, suppressEvent){
  615. if(Ext.isArray(nodeInfo)){
  616. if(!keepExisting){
  617. this.clearSelections(true);
  618. }
  619. for(var i = 0, len = nodeInfo.length; i < len; i++){
  620. this.select(nodeInfo[i], true, true);
  621. }
  622. if(!suppressEvent){
  623. this.fireEvent("selectionchange", this, this.selected.elements);
  624. }
  625. } else{
  626. var node = this.getNode(nodeInfo);
  627. if(!keepExisting){
  628. this.clearSelections(true);
  629. }
  630. if(node && !this.isSelected(node)){
  631. if(this.fireEvent("beforeselect", this, node, this.selected.elements) !== false){
  632. Ext.fly(node).addClass(this.selectedClass);
  633. this.selected.add(node);
  634. this.last = node.viewIndex;
  635. if(!suppressEvent){
  636. this.fireEvent("selectionchange", this, this.selected.elements);
  637. }
  638. }
  639. }
  640. }
  641. },
  642. /**
  643. * Selects a range of nodes. All nodes between start and end are selected.
  644. * @param {Number} start The index of the first node in the range
  645. * @param {Number} end The index of the last node in the range
  646. * @param {Boolean} keepExisting (optional) True to retain existing selections
  647. */
  648. selectRange : function(start, end, keepExisting){
  649. if(!keepExisting){
  650. this.clearSelections(true);
  651. }
  652. this.select(this.getNodes(start, end), true);
  653. },
  654. /**
  655. * Gets a template node.
  656. * @param {HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node,
  657. * the id of a template node or the record associated with the node.
  658. * @return {HTMLElement} The node or null if it wasn't found
  659. */
  660. getNode : function(nodeInfo){
  661. if(Ext.isString(nodeInfo)){
  662. return document.getElementById(nodeInfo);
  663. }else if(Ext.isNumber(nodeInfo)){
  664. return this.all.elements[nodeInfo];
  665. }else if(nodeInfo instanceof Ext.data.Record){
  666. var idx = this.store.indexOf(nodeInfo);
  667. return this.all.elements[idx];
  668. }
  669. return nodeInfo;
  670. },
  671. /**
  672. * Gets a range nodes.
  673. * @param {Number} start (optional) The index of the first node in the range
  674. * @param {Number} end (optional) The index of the last node in the range
  675. * @return {Array} An array of nodes
  676. */
  677. getNodes : function(start, end){
  678. var ns = this.all.elements,
  679. nodes = [],
  680. i;
  681. start = start || 0;
  682. end = !Ext.isDefined(end) ? Math.max(ns.length - 1, 0) : end;
  683. if(start <= end){
  684. for(i = start; i <= end && ns[i]; i++){
  685. nodes.push(ns[i]);
  686. }
  687. } else{
  688. for(i = start; i >= end && ns[i]; i--){
  689. nodes.push(ns[i]);
  690. }
  691. }
  692. return nodes;
  693. },
  694. /**
  695. * Finds the index of the passed node.
  696. * @param {HTMLElement/String/Number/Record} nodeInfo An HTMLElement template node, index of a template node, the id of a template node
  697. * or a record associated with a node.
  698. * @return {Number} The index of the node or -1
  699. */
  700. indexOf : function(node){
  701. node = this.getNode(node);
  702. if(Ext.isNumber(node.viewIndex)){
  703. return node.viewIndex;
  704. }
  705. return this.all.indexOf(node);
  706. },
  707. // private
  708. onBeforeLoad : function(){
  709. if(this.loadingText){
  710. this.clearSelections(false, true);
  711. this.getTemplateTarget().update('<div class="loading-indicator">'+this.loadingText+'</div>');
  712. this.all.clear();
  713. }
  714. },
  715. onDestroy : function(){
  716. this.all.clear();
  717. this.selected.clear();
  718. Ext.DataView.superclass.onDestroy.call(this);
  719. this.bindStore(null);
  720. }
  721. });
  722. /**
  723. * Changes the data store bound to this view and refreshes it. (deprecated in favor of bindStore)
  724. * @param {Store} store The store to bind to this view
  725. */
  726. Ext.DataView.prototype.setStore = Ext.DataView.prototype.bindStore;
  727. Ext.reg('dataview', Ext.DataView);
  728. /**
  729. * @class Ext.list.ListView
  730. * @extends Ext.DataView
  731. * <p>Ext.list.ListView is a fast and light-weight implentation of a
  732. * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:</p>
  733. * <div class="mdetail-params"><ul>
  734. * <li>resizable columns</li>
  735. * <li>selectable</li>
  736. * <li>column widths are initially proportioned by percentage based on the container
  737. * width and number of columns</li>
  738. * <li>uses templates to render the data in any required format</li>
  739. * <li>no horizontal scrolling</li>
  740. * <li>no editing</li>
  741. * </ul></div>
  742. * <p>Example usage:</p>
  743. * <pre><code>
  744. // consume JSON of this form:
  745. {
  746. "images":[
  747. {
  748. "name":"dance_fever.jpg",
  749. "size":2067,
  750. "lastmod":1236974993000,
  751. "url":"images\/thumbs\/dance_fever.jpg"
  752. },
  753. {
  754. "name":"zack_sink.jpg",
  755. "size":2303,
  756. "lastmod":1236974993000,
  757. "url":"images\/thumbs\/zack_sink.jpg"
  758. }
  759. ]
  760. }
  761. var store = new Ext.data.JsonStore({
  762. url: 'get-images.php',
  763. root: 'images',
  764. fields: [
  765. 'name', 'url',
  766. {name:'size', type: 'float'},
  767. {name:'lastmod', type:'date', dateFormat:'timestamp'}
  768. ]
  769. });
  770. store.load();
  771. var listView = new Ext.list.ListView({
  772. store: store,
  773. multiSelect: true,
  774. emptyText: 'No images to display',
  775. reserveScrollOffset: true,
  776. columns: [{
  777. header: 'File',
  778. width: .5,
  779. dataIndex: 'name'
  780. },{
  781. header: 'Last Modified',
  782. width: .35,
  783. dataIndex: 'lastmod',
  784. tpl: '{lastmod:date("m-d h:i a")}'
  785. },{
  786. header: 'Size',
  787. dataIndex: 'size',
  788. tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()
  789. align: 'right'
  790. }]
  791. });
  792. // put it in a Panel so it looks pretty
  793. var panel = new Ext.Panel({
  794. id:'images-view',
  795. width:425,
  796. height:250,
  797. collapsible:true,
  798. layout:'fit',
  799. title:'Simple ListView <i>(0 items selected)</i>',
  800. items: listView
  801. });
  802. panel.render(document.body);
  803. // little bit of feedback
  804. listView.on('selectionchange', function(view, nodes){
  805. var l = nodes.length;
  806. var s = l != 1 ? 's' : '';
  807. panel.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
  808. });
  809. * </code></pre>
  810. * @constructor
  811. * @param {Object} config
  812. * @xtype listview
  813. */
  814. Ext.list.ListView = Ext.extend(Ext.DataView, {
  815. /**
  816. * Set this property to <tt>true</tt> to disable the header click handler disabling sort
  817. * (defaults to <tt>false</tt>).
  818. * @type Boolean
  819. * @property disableHeaders
  820. */
  821. /**
  822. * @cfg {Boolean} hideHeaders
  823. * <tt>true</tt> to hide the {@link #internalTpl header row} (defaults to <tt>false</tt> so
  824. * the {@link #internalTpl header row} will be shown).
  825. */
  826. /**
  827. * @cfg {String} itemSelector
  828. * Defaults to <tt>'dl'</tt> to work with the preconfigured <b><tt>{@link Ext.DataView#tpl tpl}</tt></b>.
  829. * This setting specifies the CSS selector (e.g. <tt>div.some-class</tt> or <tt>span:first-child</tt>)
  830. * that will be used to determine what nodes the ListView will be working with.
  831. */
  832. itemSelector: 'dl',
  833. /**
  834. * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to
  835. * <tt>'x-list-selected'</tt>). An example overriding the default styling:
  836. <pre><code>
  837. .x-list-selected {background-color: yellow;}
  838. </code></pre>
  839. * @type String
  840. */
  841. selectedClass:'x-list-selected',
  842. /**
  843. * @cfg {String} overClass The CSS class applied when over a row (defaults to
  844. * <tt>'x-list-over'</tt>). An example overriding the default styling:
  845. <pre><code>
  846. .x-list-over {background-color: orange;}
  847. </code></pre>
  848. * @type String
  849. */
  850. overClass:'x-list-over',
  851. /**
  852. * @cfg {Boolean} reserveScrollOffset
  853. * By default will defer accounting for the configured <b><tt>{@link #scrollOffset}</tt></b>
  854. * for 10 milliseconds. Specify <tt>true</tt> to account for the configured
  855. * <b><tt>{@link #scrollOffset}</tt></b> immediately.
  856. */
  857. /**
  858. * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to
  859. * <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
  860. * calculated.
  861. */
  862. scrollOffset : undefined,
  863. /**
  864. * @cfg {Boolean/Object} columnResize
  865. * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.ColumnResizer}
  866. * to enable the columns to be resizable (defaults to <tt>true</tt>).
  867. */
  868. columnResize: true,
  869. /**
  870. * @cfg {Array} columns An array of column configuration objects, for example:
  871. * <pre><code>
  872. {
  873. align: 'right',
  874. dataIndex: 'size',
  875. header: 'Size',
  876. tpl: '{size:fileSize}',
  877. width: .35
  878. }
  879. * </code></pre>
  880. * Acceptable properties for each column configuration object are:
  881. * <div class="mdetail-params"><ul>
  882. * <li><b><tt>align</tt></b> : String<div class="sub-desc">Set the CSS text-align property
  883. * of the column. Defaults to <tt>'left'</tt>.</div></li>
  884. * <li><b><tt>dataIndex</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
  885. * {@link Ext.grid.Column#dataIndex dataIndex} for details.</div></li>
  886. * <li><b><tt>header</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
  887. * {@link Ext.grid.Column#header header} for details.</div></li>
  888. * <li><b><tt>tpl</tt></b> : String<div class="sub-desc">Specify a string to pass as the
  889. * configuration string for {@link Ext.XTemplate}. By default an {@link Ext.XTemplate}
  890. * will be implicitly created using the <tt>dataIndex</tt>.</div></li>
  891. * <li><b><tt>width</tt></b> : Number<div class="sub-desc">Percentage of the container width
  892. * this column should be allocated. Columns that have no width specified will be
  893. * allocated with an equal percentage to fill 100% of the container width. To easily take
  894. * advantage of the full container width, leave the width of at least one column undefined.
  895. * Note that if you do not want to take up the full width of the container, the width of
  896. * every column needs to be explicitly defined.</div></li>
  897. * </ul></div>
  898. */
  899. /**
  900. * @cfg {Boolean/Object} columnSort
  901. * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.Sorter}
  902. * to enable the columns to be sortable (defaults to <tt>true</tt>).
  903. */
  904. columnSort: true,
  905. /**
  906. * @cfg {String/Array} internalTpl
  907. * The template to be used for the header row. See {@link #tpl} for more details.
  908. */
  909. /*
  910. * IE has issues when setting percentage based widths to 100%. Default to 99.
  911. */
  912. maxColumnWidth: Ext.isIE ? 99 : 100,
  913. initComponent : function(){
  914. if(this.columnResize){
  915. this.colResizer = new Ext.list.ColumnResizer(this.colResizer);
  916. this.colResizer.init(this);
  917. }
  918. if(this.columnSort){
  919. this.colSorter = new Ext.list.Sorter(this.columnSort);
  920. this.colSorter.init(this);
  921. }
  922. if(!this.internalTpl){
  923. this.internalTpl = new Ext.XTemplate(
  924. '<div class="x-list-header"><div class="x-list-header-inner">',
  925. '<tpl for="columns">',
  926. '<div style="width:{[values.width*100]}%;text-align:{align};"><em unselectable="on" id="',this.id, '-xlhd-{#}">',
  927. '{header}',
  928. '</em></div>',
  929. '</tpl>',
  930. '<div class="x-clear"></div>',
  931. '</div></div>',
  932. '<div class="x-list-body"><div class="x-list-body-inner">',
  933. '</div></div>'
  934. );
  935. }
  936. if(!this.tpl){
  937. this.tpl = new Ext.XTemplate(
  938. '<tpl for="rows">',
  939. '<dl>',
  940. '<tpl for="parent.columns">',
  941. '<dt style="width:{[values.width*100]}%;text-align:{align};">',
  942. '<em unselectable="on"<tpl if="cls"> class="{cls}</tpl>">',
  943. '{[values.tpl.apply(parent)]}',
  944. '</em></dt>',
  945. '</tpl>',
  946. '<div class="x-clear"></div>',
  947. '</dl>',
  948. '</tpl>'
  949. );
  950. };
  951. var cs = this.columns,
  952. allocatedWidth = 0,
  953. colsWithWidth = 0,
  954. len = cs.length,
  955. columns = [];
  956. for(var i = 0; i < len; i++){
  957. var c = cs[i];
  958. if(!c.isColumn) {
  959. c.xtype = c.xtype ? (/^lv/.test(c.xtype) ? c.xtype : 'lv' + c.xtype) : 'lvcolumn';
  960. c = Ext.create(c);
  961. }
  962. if(c.width) {
  963. allocatedWidth += c.width*100;
  964. if(allocatedWidth > this.maxColumnWidth){
  965. c.width -= (allocatedWidth - this.maxColumnWidth) / 100;
  966. }
  967. colsWithWidth++;
  968. }
  969. columns.push(c);
  970. }
  971. cs = this.columns = columns;
  972. // auto calculate missing column widths
  973. if(colsWithWidth < len){
  974. var remaining = len - colsWithWidth;
  975. if(allocatedWidth < this.maxColumnWidth){
  976. var perCol = ((this.maxColumnWidth-allocatedWidth) / remaining)/100;
  977. for(var j = 0; j < len; j++){
  978. var c = cs[j];
  979. if(!c.width){
  980. c.width = perCol;
  981. }
  982. }
  983. }
  984. }
  985. Ext.list.ListView.superclass.initComponent.call(this);
  986. },
  987. onRender : function(){
  988. this.autoEl = {
  989. cls: 'x-list-wrap'
  990. };
  991. Ext.list.ListView.superclass.onRender.apply(this, arguments);
  992. this.internalTpl.overwrite(this.el, {columns: this.columns});
  993. this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);
  994. this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);
  995. if(this.hideHeaders){
  996. this.el.dom.firstChild.style.display = 'none';
  997. }
  998. },
  999. getTemplateTarget : function(){
  1000. return this.innerBody;
  1001. },
  1002. /**
  1003. * <p>Function which can be overridden which returns the data object passed to this
  1004. * view's {@link #tpl template} to render the whole ListView. The returned object
  1005. * shall contain the following properties:</p>
  1006. * <div class="mdetail-params"><ul>
  1007. * <li><b>columns</b> : String<div class="sub-desc">See <tt>{@link #columns}</tt></div></li>
  1008. * <li><b>rows</b> : String<div class="sub-desc">See
  1009. * <tt>{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}</div></li>
  1010. * </ul></div>
  1011. * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
  1012. * @param {Number} startIndex the index number of the Record being prepared for rendering.
  1013. * @return {Object} A data object containing properties to be processed by a repeating
  1014. * XTemplate as described above.
  1015. */
  1016. collectData : function(){
  1017. var rs = Ext.list.ListView.superclass.collectData.apply(this, arguments);
  1018. return {
  1019. columns: this.columns,
  1020. rows: rs
  1021. };
  1022. },
  1023. verifyInternalSize : function(){
  1024. if(this.lastSize){
  1025. this.onResize(this.lastSize.width, this.lastSize.height);
  1026. }
  1027. },
  1028. // private
  1029. onResize : function(w, h){
  1030. var body = this.innerBody.dom,
  1031. header = this.innerHd.dom,
  1032. scrollWidth = w - Ext.num(this.scrollOffset, Ext.getScrollBarWidth()) + 'px',
  1033. parentNode;
  1034. if(!body){
  1035. return;
  1036. }
  1037. parentNode = body.parentNode;
  1038. if(Ext.isNumber(w)){
  1039. if(this.reserveScrollOffset || ((parentNode.offsetWidth - parentNode.clientWidth) > 10)){
  1040. body.style.width = scrollWidth;
  1041. header.style.width = scrollWidth;
  1042. }else{
  1043. body.style.width = w + 'px';
  1044. header.style.width = w + 'px';
  1045. setTimeout(function(){
  1046. if((parentNode.offsetWidth - parentNode.clientWidth) > 10){
  1047. body.style.width = scrollWidth;
  1048. header.style.width = scrollWidth;
  1049. }
  1050. }, 10);
  1051. }
  1052. }
  1053. if(Ext.isNumber(h)){
  1054. parentNode.style.height = Math.max(0, h - header.parentNode.offsetHeight) + 'px';
  1055. }
  1056. },
  1057. updateIndexes : function(){
  1058. Ext.list.ListView.superclass.updateIndexes.apply(this, arguments);
  1059. this.verifyInternalSize();
  1060. },
  1061. findHeaderIndex : function(header){
  1062. header = header.dom || header;
  1063. var parentNode = header.parentNode,
  1064. children = parentNode.parentNode.childNodes,
  1065. i = 0,
  1066. c;
  1067. for(; c = children[i]; i++){
  1068. if(c == parentNode){
  1069. return i;
  1070. }
  1071. }
  1072. return -1;
  1073. },
  1074. setHdWidths : function(){
  1075. var els = this.innerHd.dom.getElementsByTagName('div'),
  1076. i = 0,
  1077. columns = this.columns,
  1078. len = columns.length;
  1079. for(; i < len; i++){
  1080. els[i].style.width = (columns[i].width*100) + '%';
  1081. }
  1082. }
  1083. });
  1084. Ext.reg('listview', Ext.list.ListView);
  1085. // Backwards compatibility alias
  1086. Ext.ListView = Ext.list.ListView;/**
  1087. * @class Ext.list.Column
  1088. * <p>This class encapsulates column configuration data to be used in the initialization of a
  1089. * {@link Ext.list.ListView ListView}.</p>
  1090. * <p>While subclasses are provided to render data in different ways, this class renders a passed
  1091. * data field unchanged and is usually used for textual columns.</p>
  1092. */
  1093. Ext.list.Column = Ext.extend(Object, {
  1094. /**
  1095. * @private
  1096. * @cfg {Boolean} isColumn
  1097. * Used by ListView constructor method to avoid reprocessing a Column
  1098. * if <code>isColumn</code> is not set ListView will recreate a new Ext.list.Column
  1099. * Defaults to true.
  1100. */
  1101. isColumn: true,
  1102. /**
  1103. * @cfg {String} align
  1104. * Set the CSS text-align property of the column. Defaults to <tt>'left'</tt>.
  1105. */
  1106. align: 'left',
  1107. /**
  1108. * @cfg {String} header Optional. The header text to be used as innerHTML
  1109. * (html tags are accepted) to display in the ListView. <b>Note</b>: to
  1110. * have a clickable header with no text displayed use <tt>'&#160;'</tt>.
  1111. */
  1112. header: '',
  1113. /**
  1114. * @cfg {Number} width Optional. Percentage of the container width
  1115. * this column should be allocated. Columns that have no width specified will be
  1116. * allocated with an equal percentage to fill 100% of the container width. To easily take
  1117. * advantage of the full container width, leave the width of at least one column undefined.
  1118. * Note that if you do not want to take up the full width of the container, the width of
  1119. * every column needs to be explicitly defined.
  1120. */
  1121. width: null,
  1122. /**
  1123. * @cfg {String} cls Optional. This option can be used to add a CSS class to the cell of each
  1124. * row for this column.
  1125. */
  1126. cls: '',
  1127. /**
  1128. * @cfg {String} tpl Optional. Specify a string to pass as the
  1129. * configuration string for {@link Ext.XTemplate}. By default an {@link Ext.XTemplate}
  1130. * will be implicitly created using the <tt>dataIndex</tt>.
  1131. */
  1132. /**
  1133. * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
  1134. * ListViews's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
  1135. * which to draw the column's value.</p>
  1136. */
  1137. constructor : function(c){
  1138. if(!c.tpl){
  1139. c.tpl = new Ext.XTemplate('{' + c.dataIndex + '}');
  1140. }
  1141. else if(Ext.isString(c.tpl)){
  1142. c.tpl = new Ext.XTemplate(c.tpl);
  1143. }
  1144. Ext.apply(this, c);
  1145. }
  1146. });
  1147. Ext.reg('lvcolumn', Ext.list.Column);
  1148. /**
  1149. * @class Ext.list.NumberColumn
  1150. * @extends Ext.list.Column
  1151. * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
  1152. * {@link Ext.list.Column#xtype xtype} config option of {@link Ext.list.Column} for more details.</p>
  1153. */
  1154. Ext.list.NumberColumn = Ext.extend(Ext.list.Column, {
  1155. /**
  1156. * @cfg {String} format
  1157. * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
  1158. * (defaults to <tt>'0,000.00'</tt>).
  1159. */
  1160. format: '0,000.00',
  1161. constructor : function(c) {
  1162. c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':number("' + (c.format || this.format) + '")}');
  1163. Ext.list.NumberColumn.superclass.constructor.call(this, c);
  1164. }
  1165. });
  1166. Ext.reg('lvnumbercolumn', Ext.list.NumberColumn);
  1167. /**
  1168. * @class Ext.list.DateColumn
  1169. * @extends Ext.list.Column
  1170. * <p>A Column definition class which renders a passed date according to the default locale, or a configured
  1171. * {@link #format}. See the {@link Ext.list.Column#xtype xtype} config option of {@link Ext.list.Column}
  1172. * for more details.</p>
  1173. */
  1174. Ext.list.DateColumn = Ext.extend(Ext.list.Column, {
  1175. format: 'm/d/Y',
  1176. constructor : function(c) {
  1177. c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':date("' + (c.format || this.format) + '")}');
  1178. Ext.list.DateColumn.superclass.constructor.call(this, c);
  1179. }
  1180. });
  1181. Ext.reg('lvdatecolumn', Ext.list.DateColumn);
  1182. /**
  1183. * @class Ext.list.BooleanColumn
  1184. * @extends Ext.list.Column
  1185. * <p>A Column definition class which renders boolean data fields. See the {@link Ext.list.Column#xtype xtype}
  1186. * config option of {@link Ext.list.Column} for more details.</p>
  1187. */
  1188. Ext.list.BooleanColumn = Ext.extend(Ext.list.Column, {
  1189. /**
  1190. * @cfg {String} trueText
  1191. * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
  1192. */
  1193. trueText: 'true',
  1194. /**
  1195. * @cfg {String} falseText
  1196. * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
  1197. * <tt>'false'</tt>).
  1198. */
  1199. falseText: 'false',
  1200. /**
  1201. * @cfg {String} undefinedText
  1202. * The string returned by the renderer when the column value is undefined (defaults to <tt>'&#160;'</tt>).
  1203. */
  1204. undefinedText: '&#160;',
  1205. constructor : function(c) {
  1206. c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':this.format}');
  1207. var t = this.trueText, f = this.falseText, u = this.undefinedText;
  1208. c.tpl.format = function(v){
  1209. if(v === undefined){
  1210. return u;
  1211. }
  1212. if(!v || v === 'false'){
  1213. return f;
  1214. }
  1215. return t;
  1216. };
  1217. Ext.list.DateColumn.superclass.constructor.call(this, c);
  1218. }
  1219. });
  1220. Ext.reg('lvbooleancolumn', Ext.list.BooleanColumn);/**
  1221. * @class Ext.list.ColumnResizer
  1222. * @extends Ext.util.Observable
  1223. * <p>Supporting Class for Ext.list.ListView</p>
  1224. * @constructor
  1225. * @param {Object} config
  1226. */
  1227. Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, {
  1228. /**
  1229. * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)
  1230. */
  1231. minPct: .05,
  1232. constructor: function(config){
  1233. Ext.apply(this, config);
  1234. Ext.list.ColumnResizer.superclass.constructor.call(this);
  1235. },
  1236. init : function(listView){
  1237. this.view = listView;
  1238. listView.on('render', this.initEvents, this);
  1239. },
  1240. initEvents : function(view){
  1241. view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);
  1242. this.tracker = new Ext.dd.DragTracker({
  1243. onBeforeStart: this.onBeforeStart.createDelegate(this),
  1244. onStart: this.onStart.createDelegate(this),
  1245. onDrag: this.onDrag.createDelegate(this),
  1246. onEnd: this.onEnd.createDelegate(this),
  1247. tolerance: 3,
  1248. autoStart: 300
  1249. });
  1250. this.tracker.initEl(view.innerHd);
  1251. view.on('beforedestroy', this.tracker.destroy, this.tracker);
  1252. },
  1253. handleHdMove : function(e, t){
  1254. var handleWidth = 5,
  1255. x = e.getPageX(),
  1256. header = e.getTarget('em', 3, true);
  1257. if(header){
  1258. var region = header.getRegion(),
  1259. style = header.dom.style,
  1260. parentNode = header.dom.parentNode;
  1261. if(x - region.left <= handleWidth && parentNode != parentNode.parentNode.firstChild){
  1262. this.activeHd = Ext.get(parentNode.previousSibling.firstChild);
  1263. style.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
  1264. } else if(region.right - x <= handleWidth && parentNode != parentNode.parentNode.lastChild.previousSibling){
  1265. this.activeHd = header;
  1266. style.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
  1267. } else{
  1268. delete this.activeHd;
  1269. style.cursor = '';
  1270. }
  1271. }
  1272. },
  1273. onBeforeStart : function(e){
  1274. this.dragHd = this.activeHd;
  1275. return !!this.dragHd;
  1276. },
  1277. onStart: function(e){
  1278. var me = this,
  1279. view = me.view,
  1280. dragHeader = me.dragHd,
  1281. x = me.tracker.getXY()[0];
  1282. me.proxy = view.el.createChild({cls:'x-list-resizer'});
  1283. me.dragX = dragHeader.getX();
  1284. me.headerIndex = view.findHeaderIndex(dragHeader);
  1285. me.headersDisabled = view.disableHeaders;
  1286. view.disableHeaders = true;
  1287. me.proxy.setHeight(view.el.getHeight());
  1288. me.proxy.setX(me.dragX);
  1289. me.proxy.setWidth(x - me.dragX);
  1290. this.setBoundaries();
  1291. },
  1292. // Sets up the boundaries for the drag/drop operation
  1293. setBoundaries: function(relativeX){
  1294. var view = this.view,
  1295. headerIndex = this.headerIndex,
  1296. width = view.innerHd.getWidth(),
  1297. relativeX = view.innerHd.getX(),
  1298. minWidth = Math.ceil(width * this.minPct),
  1299. maxWidth = width - minWidth,
  1300. numColumns = view.columns.length,
  1301. headers = view.innerHd.select('em', true),
  1302. minX = minWidth + relativeX,
  1303. maxX = maxWidth + relativeX,
  1304. header;
  1305. if (numColumns == 2) {
  1306. this.minX = minX;
  1307. this.maxX = maxX;
  1308. }else{
  1309. header = headers.item(headerIndex + 2);
  1310. this.minX = headers.item(headerIndex).getX() + minWidth;
  1311. this.maxX = header ? header.getX() - minWidth : maxX;
  1312. if (headerIndex == 0) {
  1313. // First
  1314. this.minX = minX;
  1315. } else if (headerIndex == numColumns - 2) {
  1316. // Last
  1317. this.maxX = maxX;
  1318. }
  1319. }
  1320. },
  1321. onDrag: function(e){
  1322. var me = this,
  1323. cursorX = me.tracker.getXY()[0].constrain(me.minX, me.maxX);
  1324. me.proxy.setWidth(cursorX - this.dragX);
  1325. },
  1326. onEnd: function(e){
  1327. /* calculate desired width by measuring proxy and then remove it */
  1328. var newWidth = this.proxy.getWidth(),
  1329. index = this.headerIndex,
  1330. view = this.view,
  1331. columns = view.columns,
  1332. width = view.innerHd.getWidth(),
  1333. newPercent = Math.ceil(newWidth * view.maxColumnWidth / width) / 100,
  1334. disabled = this.headersDisabled,
  1335. headerCol = columns[index],
  1336. otherCol = columns[index + 1],
  1337. totalPercent = headerCol.width + otherCol.width;
  1338. this.proxy.remove();
  1339. headerCol.width = newPercent;
  1340. otherCol.width = totalPercent - newPercent;
  1341. delete this.dragHd;
  1342. view.setHdWidths();
  1343. view.refresh();
  1344. setTimeout(function(){
  1345. view.disableHeaders = disabled;
  1346. }, 100);
  1347. }
  1348. });
  1349. // Backwards compatibility alias
  1350. Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;/**
  1351. * @class Ext.list.Sorter
  1352. * @extends Ext.util.Observable
  1353. * <p>Supporting Class for Ext.list.ListView</p>
  1354. * @constructor
  1355. * @param {Object} config
  1356. */
  1357. Ext.list.Sorter = Ext.extend(Ext.util.Observable, {
  1358. /**
  1359. * @cfg {Array} sortClasses
  1360. * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
  1361. */
  1362. sortClasses : ["sort-asc", "sort-desc"],
  1363. constructor: function(config){
  1364. Ext.apply(this, config);
  1365. Ext.list.Sorter.superclass.constructor.call(this);
  1366. },
  1367. init : function(listView){
  1368. this.view = listView;
  1369. listView.on('render', this.initEvents, this);
  1370. },
  1371. initEvents : function(view){
  1372. view.mon(view.innerHd, 'click', this.onHdClick, this);
  1373. view.innerHd.setStyle('cursor', 'pointer');
  1374. view.mon(view.store, 'datachanged', this.updateSortState, this);
  1375. this.updateSortState.defer(10, this, [view.store]);
  1376. },
  1377. updateSortState : function(store){
  1378. var state = store.getSortState();
  1379. if(!state){
  1380. return;
  1381. }
  1382. this.sortState = state;
  1383. var cs = this.view.columns, sortColumn = -1;
  1384. for(var i = 0, len = cs.length; i < len; i++){
  1385. if(cs[i].dataIndex == state.field){
  1386. sortColumn = i;
  1387. break;
  1388. }
  1389. }
  1390. if(sortColumn != -1){
  1391. var sortDir = state.direction;
  1392. this.updateSortIcon(sortColumn, sortDir);
  1393. }
  1394. },
  1395. updateSortIcon : function(col, dir){
  1396. var sc = this.sortClasses;
  1397. var hds = this.view.innerHd.select('em').removeClass(sc);
  1398. hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
  1399. },
  1400. onHdClick : function(e){
  1401. var hd = e.getTarget('em', 3);
  1402. if(hd && !this.view.disableHeaders){
  1403. var index = this.view.findHeaderIndex(hd);
  1404. this.view.store.sort(this.view.columns[index].dataIndex);
  1405. }
  1406. }
  1407. });
  1408. // Backwards compatibility alias
  1409. Ext.ListView.Sorter = Ext.list.Sorter;