Web UI for ARGUS server
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.

398 lines
14 KiB

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