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.

106 lines
3.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. /* Fix for Opera, which does not seem to include the map function on Array's */
  16. if (!Array.prototype.map) {
  17. Array.prototype.map = function(fun){
  18. var len = this.length;
  19. if (typeof fun != 'function') {
  20. throw new TypeError();
  21. }
  22. var res = new Array(len);
  23. var thisp = arguments[1];
  24. for (var i = 0; i < len; i++) {
  25. if (i in this) {
  26. res[i] = fun.call(thisp, this[i], i, this);
  27. }
  28. }
  29. return res;
  30. };
  31. }
  32. Ext.ns('Ext.ux.data');
  33. <div id="cls-Ext.ux.data.PagingMemoryProxy"></div>/**
  34. * @class Ext.ux.data.PagingMemoryProxy
  35. * @extends Ext.data.MemoryProxy
  36. * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
  37. */
  38. Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
  39. constructor : function(data){
  40. Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
  41. this.data = data;
  42. },
  43. doRequest : function(action, rs, params, reader, callback, scope, options){
  44. params = params ||
  45. {};
  46. var result;
  47. try {
  48. result = reader.readRecords(this.data);
  49. }
  50. catch (e) {
  51. this.fireEvent('loadexception', this, options, null, e);
  52. callback.call(scope, null, options, false);
  53. return;
  54. }
  55. // filtering
  56. if (params.filter !== undefined) {
  57. result.records = result.records.filter(function(el){
  58. if (typeof(el) == 'object') {
  59. var att = params.filterCol || 0;
  60. return String(el.data[att]).match(params.filter) ? true : false;
  61. }
  62. else {
  63. return String(el).match(params.filter) ? true : false;
  64. }
  65. });
  66. result.totalRecords = result.records.length;
  67. }
  68. // sorting
  69. if (params.sort !== undefined) {
  70. // use integer as params.sort to specify column, since arrays are not named
  71. // params.sort=0; would also match a array without columns
  72. var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
  73. var fn = function(v1, v2){
  74. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  75. };
  76. result.records.sort(function(a, b){
  77. var v = 0;
  78. if (typeof(a) == 'object') {
  79. v = fn(a.data[params.sort], b.data[params.sort]) * dir;
  80. }
  81. else {
  82. v = fn(a, b) * dir;
  83. }
  84. if (v == 0) {
  85. v = (a.index < b.index ? -1 : 1);
  86. }
  87. return v;
  88. });
  89. }
  90. // paging (use undefined cause start can also be 0 (thus false))
  91. if (params.start !== undefined && params.limit !== undefined) {
  92. result.records = result.records.slice(params.start, params.start + params.limit);
  93. }
  94. callback.call(scope, result, options, true);
  95. }
  96. });
  97. //backwards compat.
  98. Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
  99. </pre>
  100. </body>
  101. </html>