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.

112 lines
4.2 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.data.ArrayReader"></div>/**
  16. * @class Ext.data.ArrayReader
  17. * @extends Ext.data.JsonReader
  18. * <p>Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
  19. * Each element of that Array represents a row of data fields. The
  20. * fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
  21. * of the field definition if it exists, or the field's ordinal position in the definition.</p>
  22. * <p>Example code:</p>
  23. * <pre><code>
  24. var Employee = Ext.data.Record.create([
  25. {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
  26. {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
  27. ]);
  28. var myReader = new Ext.data.ArrayReader({
  29. {@link #idIndex}: 0
  30. }, Employee);
  31. </code></pre>
  32. * <p>This would consume an Array like this:</p>
  33. * <pre><code>
  34. [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
  35. * </code></pre>
  36. * @constructor
  37. * Create a new ArrayReader
  38. * @param {Object} meta Metadata configuration options.
  39. * @param {Array/Object} recordType
  40. * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
  41. * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
  42. * constructor created from {@link Ext.data.Record#create}.</p>
  43. */
  44. Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
  45. <div id="cfg-Ext.data.ArrayReader-successProperty"></div>/**
  46. * @cfg {String} successProperty
  47. * @hide
  48. */
  49. <div id="cfg-Ext.data.ArrayReader-id"></div>/**
  50. * @cfg {Number} id (optional) The subscript within row Array that provides an ID for the Record.
  51. * Deprecated. Use {@link #idIndex} instead.
  52. */
  53. <div id="cfg-Ext.data.ArrayReader-idIndex"></div>/**
  54. * @cfg {Number} idIndex (optional) The subscript within row Array that provides an ID for the Record.
  55. */
  56. <div id="method-Ext.data.ArrayReader-readRecords"></div>/**
  57. * Create a data block containing Ext.data.Records from an Array.
  58. * @param {Object} o An Array of row objects which represents the dataset.
  59. * @return {Object} data A data block which is used by an Ext.data.Store object as
  60. * a cache of Ext.data.Records.
  61. */
  62. readRecords : function(o){
  63. this.arrayData = o;
  64. var s = this.meta,
  65. sid = s ? Ext.num(s.idIndex, s.id) : null,
  66. recordType = this.recordType,
  67. fields = recordType.prototype.fields,
  68. records = [],
  69. success = true,
  70. v;
  71. var root = this.getRoot(o);
  72. for(var i = 0, len = root.length; i < len; i++) {
  73. var n = root[i],
  74. values = {},
  75. id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
  76. for(var j = 0, jlen = fields.length; j < jlen; j++) {
  77. var f = fields.items[j],
  78. k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
  79. v = n[k] !== undefined ? n[k] : f.defaultValue;
  80. v = f.convert(v, n);
  81. values[f.name] = v;
  82. }
  83. var record = new recordType(values, id);
  84. record.json = n;
  85. records[records.length] = record;
  86. }
  87. var totalRecords = records.length;
  88. if(s.totalProperty) {
  89. v = parseInt(this.getTotal(o), 10);
  90. if(!isNaN(v)) {
  91. totalRecords = v;
  92. }
  93. }
  94. if(s.successProperty){
  95. v = this.getSuccess(o);
  96. if(v === false || v === 'false'){
  97. success = false;
  98. }
  99. }
  100. return {
  101. success : success,
  102. records : records,
  103. totalRecords : totalRecords
  104. };
  105. }
  106. });</pre>
  107. </body>
  108. </html>