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.

402 lines
17 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-list-ListView-method-constructor'><span id='Ext-list-ListView'>/**
  19. </span></span> * @class Ext.list.ListView
  20. * @extends Ext.DataView
  21. * &lt;p&gt;Ext.list.ListView is a fast and light-weight implentation of a
  22. * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:&lt;/p&gt;
  23. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  24. * &lt;li&gt;resizable columns&lt;/li&gt;
  25. * &lt;li&gt;selectable&lt;/li&gt;
  26. * &lt;li&gt;column widths are initially proportioned by percentage based on the container
  27. * width and number of columns&lt;/li&gt;
  28. * &lt;li&gt;uses templates to render the data in any required format&lt;/li&gt;
  29. * &lt;li&gt;no horizontal scrolling&lt;/li&gt;
  30. * &lt;li&gt;no editing&lt;/li&gt;
  31. * &lt;/ul&gt;&lt;/div&gt;
  32. * &lt;p&gt;Example usage:&lt;/p&gt;
  33. * &lt;pre&gt;&lt;code&gt;
  34. // consume JSON of this form:
  35. {
  36. &quot;images&quot;:[
  37. {
  38. &quot;name&quot;:&quot;dance_fever.jpg&quot;,
  39. &quot;size&quot;:2067,
  40. &quot;lastmod&quot;:1236974993000,
  41. &quot;url&quot;:&quot;images\/thumbs\/dance_fever.jpg&quot;
  42. },
  43. {
  44. &quot;name&quot;:&quot;zack_sink.jpg&quot;,
  45. &quot;size&quot;:2303,
  46. &quot;lastmod&quot;:1236974993000,
  47. &quot;url&quot;:&quot;images\/thumbs\/zack_sink.jpg&quot;
  48. }
  49. ]
  50. }
  51. var store = new Ext.data.JsonStore({
  52. url: 'get-images.php',
  53. root: 'images',
  54. fields: [
  55. 'name', 'url',
  56. {name:'size', type: 'float'},
  57. {name:'lastmod', type:'date', dateFormat:'timestamp'}
  58. ]
  59. });
  60. store.load();
  61. var listView = new Ext.list.ListView({
  62. store: store,
  63. multiSelect: true,
  64. emptyText: 'No images to display',
  65. reserveScrollOffset: true,
  66. columns: [{
  67. header: 'File',
  68. width: .5,
  69. dataIndex: 'name'
  70. },{
  71. header: 'Last Modified',
  72. width: .35,
  73. dataIndex: 'lastmod',
  74. tpl: '{lastmod:date(&quot;m-d h:i a&quot;)}'
  75. },{
  76. header: 'Size',
  77. dataIndex: 'size',
  78. tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()
  79. align: 'right'
  80. }]
  81. });
  82. // put it in a Panel so it looks pretty
  83. var panel = new Ext.Panel({
  84. id:'images-view',
  85. width:425,
  86. height:250,
  87. collapsible:true,
  88. layout:'fit',
  89. title:'Simple ListView &lt;i&gt;(0 items selected)&lt;/i&gt;',
  90. items: listView
  91. });
  92. panel.render(document.body);
  93. // little bit of feedback
  94. listView.on('selectionchange', function(view, nodes){
  95. var l = nodes.length;
  96. var s = l != 1 ? 's' : '';
  97. panel.setTitle('Simple ListView &lt;i&gt;('+l+' item'+s+' selected)&lt;/i&gt;');
  98. });
  99. * &lt;/code&gt;&lt;/pre&gt;
  100. * @constructor
  101. * @param {Object} config
  102. * @xtype listview
  103. */
  104. Ext.list.ListView = Ext.extend(Ext.DataView, {
  105. <span id='Ext-list-ListView-property-disableHeaders'> /**
  106. </span> * Set this property to &lt;tt&gt;true&lt;/tt&gt; to disable the header click handler disabling sort
  107. * (defaults to &lt;tt&gt;false&lt;/tt&gt;).
  108. * @type Boolean
  109. * @property disableHeaders
  110. */
  111. <span id='Ext-list-ListView-cfg-hideHeaders'> /**
  112. </span> * @cfg {Boolean} hideHeaders
  113. * &lt;tt&gt;true&lt;/tt&gt; to hide the {@link #internalTpl header row} (defaults to &lt;tt&gt;false&lt;/tt&gt; so
  114. * the {@link #internalTpl header row} will be shown).
  115. */
  116. <span id='Ext-list-ListView-cfg-itemSelector'> /**
  117. </span> * @cfg {String} itemSelector
  118. * Defaults to &lt;tt&gt;'dl'&lt;/tt&gt; to work with the preconfigured &lt;b&gt;&lt;tt&gt;{@link Ext.DataView#tpl tpl}&lt;/tt&gt;&lt;/b&gt;.
  119. * This setting specifies the CSS selector (e.g. &lt;tt&gt;div.some-class&lt;/tt&gt; or &lt;tt&gt;span:first-child&lt;/tt&gt;)
  120. * that will be used to determine what nodes the ListView will be working with.
  121. */
  122. itemSelector: 'dl',
  123. <span id='Ext-list-ListView-cfg-selectedClass'> /**
  124. </span> * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to
  125. * &lt;tt&gt;'x-list-selected'&lt;/tt&gt;). An example overriding the default styling:
  126. &lt;pre&gt;&lt;code&gt;
  127. .x-list-selected {background-color: yellow;}
  128. &lt;/code&gt;&lt;/pre&gt;
  129. * @type String
  130. */
  131. selectedClass:'x-list-selected',
  132. <span id='Ext-list-ListView-cfg-overClass'> /**
  133. </span> * @cfg {String} overClass The CSS class applied when over a row (defaults to
  134. * &lt;tt&gt;'x-list-over'&lt;/tt&gt;). An example overriding the default styling:
  135. &lt;pre&gt;&lt;code&gt;
  136. .x-list-over {background-color: orange;}
  137. &lt;/code&gt;&lt;/pre&gt;
  138. * @type String
  139. */
  140. overClass:'x-list-over',
  141. <span id='Ext-list-ListView-cfg-reserveScrollOffset'> /**
  142. </span> * @cfg {Boolean} reserveScrollOffset
  143. * By default will defer accounting for the configured &lt;b&gt;&lt;tt&gt;{@link #scrollOffset}&lt;/tt&gt;&lt;/b&gt;
  144. * for 10 milliseconds. Specify &lt;tt&gt;true&lt;/tt&gt; to account for the configured
  145. * &lt;b&gt;&lt;tt&gt;{@link #scrollOffset}&lt;/tt&gt;&lt;/b&gt; immediately.
  146. */
  147. <span id='Ext-list-ListView-cfg-scrollOffset'> /**
  148. </span> * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to
  149. * &lt;tt&gt;undefined&lt;/tt&gt;). If an explicit value isn't specified, this will be automatically
  150. * calculated.
  151. */
  152. scrollOffset : undefined,
  153. <span id='Ext-list-ListView-cfg-columnResize'> /**
  154. </span> * @cfg {Boolean/Object} columnResize
  155. * Specify &lt;tt&gt;true&lt;/tt&gt; or specify a configuration object for {@link Ext.list.ListView.ColumnResizer}
  156. * to enable the columns to be resizable (defaults to &lt;tt&gt;true&lt;/tt&gt;).
  157. */
  158. columnResize: true,
  159. <span id='Ext-list-ListView-cfg-columns'> /**
  160. </span> * @cfg {Array} columns An array of column configuration objects, for example:
  161. * &lt;pre&gt;&lt;code&gt;
  162. {
  163. align: 'right',
  164. dataIndex: 'size',
  165. header: 'Size',
  166. tpl: '{size:fileSize}',
  167. width: .35
  168. }
  169. * &lt;/code&gt;&lt;/pre&gt;
  170. * Acceptable properties for each column configuration object are:
  171. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  172. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;align&lt;/tt&gt;&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;Set the CSS text-align property
  173. * of the column. Defaults to &lt;tt&gt;'left'&lt;/tt&gt;.&lt;/div&gt;&lt;/li&gt;
  174. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;dataIndex&lt;/tt&gt;&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;See {@link Ext.grid.Column}.
  175. * {@link Ext.grid.Column#dataIndex dataIndex} for details.&lt;/div&gt;&lt;/li&gt;
  176. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;header&lt;/tt&gt;&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;See {@link Ext.grid.Column}.
  177. * {@link Ext.grid.Column#header header} for details.&lt;/div&gt;&lt;/li&gt;
  178. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;tpl&lt;/tt&gt;&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;Specify a string to pass as the
  179. * configuration string for {@link Ext.XTemplate}. By default an {@link Ext.XTemplate}
  180. * will be implicitly created using the &lt;tt&gt;dataIndex&lt;/tt&gt;.&lt;/div&gt;&lt;/li&gt;
  181. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;width&lt;/tt&gt;&lt;/b&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;Percentage of the container width
  182. * this column should be allocated. Columns that have no width specified will be
  183. * allocated with an equal percentage to fill 100% of the container width. To easily take
  184. * advantage of the full container width, leave the width of at least one column undefined.
  185. * Note that if you do not want to take up the full width of the container, the width of
  186. * every column needs to be explicitly defined.&lt;/div&gt;&lt;/li&gt;
  187. * &lt;/ul&gt;&lt;/div&gt;
  188. */
  189. <span id='Ext-list-ListView-cfg-columnSort'> /**
  190. </span> * @cfg {Boolean/Object} columnSort
  191. * Specify &lt;tt&gt;true&lt;/tt&gt; or specify a configuration object for {@link Ext.list.ListView.Sorter}
  192. * to enable the columns to be sortable (defaults to &lt;tt&gt;true&lt;/tt&gt;).
  193. */
  194. columnSort: true,
  195. <span id='Ext-list-ListView-cfg-internalTpl'> /**
  196. </span> * @cfg {String/Array} internalTpl
  197. * The template to be used for the header row. See {@link #tpl} for more details.
  198. */
  199. <span id='Ext-list-ListView-property-maxColumnWidth'> /*
  200. </span> * IE has issues when setting percentage based widths to 100%. Default to 99.
  201. */
  202. maxColumnWidth: Ext.isIE9m ? 99 : 100,
  203. <span id='Ext-list-ListView-method-initComponent'> initComponent : function(){
  204. </span> if(this.columnResize){
  205. this.colResizer = new Ext.list.ColumnResizer(this.colResizer);
  206. this.colResizer.init(this);
  207. }
  208. if(this.columnSort){
  209. this.colSorter = new Ext.list.Sorter(this.columnSort);
  210. this.colSorter.init(this);
  211. }
  212. if(!this.internalTpl){
  213. this.internalTpl = new Ext.XTemplate(
  214. '&lt;div class=&quot;x-list-header&quot;&gt;&lt;div class=&quot;x-list-header-inner&quot;&gt;',
  215. '&lt;tpl for=&quot;columns&quot;&gt;',
  216. '&lt;div style=&quot;width:{[values.width*100]}%;text-align:{align};&quot;&gt;&lt;em class=&quot;x-unselectable&quot; unselectable=&quot;on&quot; id=&quot;',this.id, '-xlhd-{#}&quot;&gt;',
  217. '{header}',
  218. '&lt;/em&gt;&lt;/div&gt;',
  219. '&lt;/tpl&gt;',
  220. '&lt;div class=&quot;x-clear&quot;&gt;&lt;/div&gt;',
  221. '&lt;/div&gt;&lt;/div&gt;',
  222. '&lt;div class=&quot;x-list-body&quot;&gt;&lt;div class=&quot;x-list-body-inner&quot;&gt;',
  223. '&lt;/div&gt;&lt;/div&gt;'
  224. );
  225. }
  226. if(!this.tpl){
  227. this.tpl = new Ext.XTemplate(
  228. '&lt;tpl for=&quot;rows&quot;&gt;',
  229. '&lt;dl&gt;',
  230. '&lt;tpl for=&quot;parent.columns&quot;&gt;',
  231. '&lt;dt style=&quot;width:{[values.width*100]}%;text-align:{align};&quot;&gt;',
  232. '&lt;em unselectable=&quot;on&quot;&lt;tpl if=&quot;cls&quot;&gt; class=&quot;{cls}&lt;/tpl&gt;&quot;&gt;',
  233. '{[values.tpl.apply(parent)]}',
  234. '&lt;/em&gt;&lt;/dt&gt;',
  235. '&lt;/tpl&gt;',
  236. '&lt;div class=&quot;x-clear&quot;&gt;&lt;/div&gt;',
  237. '&lt;/dl&gt;',
  238. '&lt;/tpl&gt;'
  239. );
  240. };
  241. var cs = this.columns,
  242. allocatedWidth = 0,
  243. colsWithWidth = 0,
  244. len = cs.length,
  245. columns = [];
  246. for(var i = 0; i &lt; len; i++){
  247. var c = cs[i];
  248. if(!c.isColumn) {
  249. c.xtype = c.xtype ? (/^lv/.test(c.xtype) ? c.xtype : 'lv' + c.xtype) : 'lvcolumn';
  250. c = Ext.create(c);
  251. }
  252. if(c.width) {
  253. allocatedWidth += c.width*100;
  254. if(allocatedWidth &gt; this.maxColumnWidth){
  255. c.width -= (allocatedWidth - this.maxColumnWidth) / 100;
  256. }
  257. colsWithWidth++;
  258. }
  259. columns.push(c);
  260. }
  261. cs = this.columns = columns;
  262. // auto calculate missing column widths
  263. if(colsWithWidth &lt; len){
  264. var remaining = len - colsWithWidth;
  265. if(allocatedWidth &lt; this.maxColumnWidth){
  266. var perCol = ((this.maxColumnWidth-allocatedWidth) / remaining)/100;
  267. for(var j = 0; j &lt; len; j++){
  268. var c = cs[j];
  269. if(!c.width){
  270. c.width = perCol;
  271. }
  272. }
  273. }
  274. }
  275. Ext.list.ListView.superclass.initComponent.call(this);
  276. },
  277. <span id='Ext-list-ListView-method-onRender'> onRender : function(){
  278. </span> this.autoEl = {
  279. cls: 'x-list-wrap'
  280. };
  281. Ext.list.ListView.superclass.onRender.apply(this, arguments);
  282. this.internalTpl.overwrite(this.el, {columns: this.columns});
  283. this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);
  284. this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);
  285. if(this.hideHeaders){
  286. this.el.dom.firstChild.style.display = 'none';
  287. }
  288. },
  289. <span id='Ext-list-ListView-method-getTemplateTarget'> getTemplateTarget : function(){
  290. </span> return this.innerBody;
  291. },
  292. <span id='Ext-list-ListView-method-collectData'> /**
  293. </span> * &lt;p&gt;Function which can be overridden which returns the data object passed to this
  294. * view's {@link #tpl template} to render the whole ListView. The returned object
  295. * shall contain the following properties:&lt;/p&gt;
  296. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  297. * &lt;li&gt;&lt;b&gt;columns&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;See &lt;tt&gt;{@link #columns}&lt;/tt&gt;&lt;/div&gt;&lt;/li&gt;
  298. * &lt;li&gt;&lt;b&gt;rows&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;See
  299. * &lt;tt&gt;{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}&lt;/div&gt;&lt;/li&gt;
  300. * &lt;/ul&gt;&lt;/div&gt;
  301. * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
  302. * @param {Number} startIndex the index number of the Record being prepared for rendering.
  303. * @return {Object} A data object containing properties to be processed by a repeating
  304. * XTemplate as described above.
  305. */
  306. collectData : function(){
  307. var rs = Ext.list.ListView.superclass.collectData.apply(this, arguments);
  308. return {
  309. columns: this.columns,
  310. rows: rs
  311. };
  312. },
  313. <span id='Ext-list-ListView-method-verifyInternalSize'> verifyInternalSize : function(){
  314. </span> if(this.lastSize){
  315. this.onResize(this.lastSize.width, this.lastSize.height);
  316. }
  317. },
  318. <span id='Ext-list-ListView-method-onResize'> // private
  319. </span> onResize : function(w, h){
  320. var body = this.innerBody.dom,
  321. header = this.innerHd.dom,
  322. scrollWidth = w - Ext.num(this.scrollOffset, Ext.getScrollBarWidth()) + 'px',
  323. parentNode;
  324. if(!body){
  325. return;
  326. }
  327. parentNode = body.parentNode;
  328. if(Ext.isNumber(w)){
  329. if(this.reserveScrollOffset || ((parentNode.offsetWidth - parentNode.clientWidth) &gt; 10)){
  330. body.style.width = scrollWidth;
  331. header.style.width = scrollWidth;
  332. }else{
  333. body.style.width = w + 'px';
  334. header.style.width = w + 'px';
  335. setTimeout(function(){
  336. if((parentNode.offsetWidth - parentNode.clientWidth) &gt; 10){
  337. body.style.width = scrollWidth;
  338. header.style.width = scrollWidth;
  339. }
  340. }, 10);
  341. }
  342. }
  343. if(Ext.isNumber(h)){
  344. parentNode.style.height = Math.max(0, h - header.parentNode.offsetHeight) + 'px';
  345. }
  346. },
  347. <span id='Ext-list-ListView-method-updateIndexes'> updateIndexes : function(){
  348. </span> Ext.list.ListView.superclass.updateIndexes.apply(this, arguments);
  349. this.verifyInternalSize();
  350. },
  351. <span id='Ext-list-ListView-method-findHeaderIndex'> findHeaderIndex : function(header){
  352. </span> header = header.dom || header;
  353. var parentNode = header.parentNode,
  354. children = parentNode.parentNode.childNodes,
  355. i = 0,
  356. c;
  357. for(; c = children[i]; i++){
  358. if(c == parentNode){
  359. return i;
  360. }
  361. }
  362. return -1;
  363. },
  364. <span id='Ext-list-ListView-method-setHdWidths'> setHdWidths : function(){
  365. </span> var els = this.innerHd.dom.getElementsByTagName('div'),
  366. i = 0,
  367. columns = this.columns,
  368. len = columns.length;
  369. for(; i &lt; len; i++){
  370. els[i].style.width = (columns[i].width*100) + '%';
  371. }
  372. }
  373. });
  374. Ext.reg('listview', Ext.list.ListView);
  375. // Backwards compatibility alias
  376. Ext.ListView = Ext.list.ListView;</pre>
  377. </body>
  378. </html>