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.

680 lines
27 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.util.MixedCollection"></div>/**
  16. * @class Ext.util.MixedCollection
  17. * @extends Ext.util.Observable
  18. * A Collection class that maintains both numeric indexes and keys and exposes events.
  19. * @constructor
  20. * @param {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  21. * function should add function references to the collection. Defaults to
  22. * <tt>false</tt>.
  23. * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
  24. * and return the key value for that item. This is used when available to look up the key on items that
  25. * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
  26. * equivalent to providing an implementation for the {@link #getKey} method.
  27. */
  28. Ext.util.MixedCollection = function(allowFunctions, keyFn){
  29. this.items = [];
  30. this.map = {};
  31. this.keys = [];
  32. this.length = 0;
  33. this.addEvents(
  34. <div id="event-Ext.util.MixedCollection-clear"></div>/**
  35. * @event clear
  36. * Fires when the collection is cleared.
  37. */
  38. 'clear',
  39. <div id="event-Ext.util.MixedCollection-add"></div>/**
  40. * @event add
  41. * Fires when an item is added to the collection.
  42. * @param {Number} index The index at which the item was added.
  43. * @param {Object} o The item added.
  44. * @param {String} key The key associated with the added item.
  45. */
  46. 'add',
  47. <div id="event-Ext.util.MixedCollection-replace"></div>/**
  48. * @event replace
  49. * Fires when an item is replaced in the collection.
  50. * @param {String} key he key associated with the new added.
  51. * @param {Object} old The item being replaced.
  52. * @param {Object} new The new item.
  53. */
  54. 'replace',
  55. <div id="event-Ext.util.MixedCollection-remove"></div>/**
  56. * @event remove
  57. * Fires when an item is removed from the collection.
  58. * @param {Object} o The item being removed.
  59. * @param {String} key (optional) The key associated with the removed item.
  60. */
  61. 'remove',
  62. 'sort'
  63. );
  64. this.allowFunctions = allowFunctions === true;
  65. if(keyFn){
  66. this.getKey = keyFn;
  67. }
  68. Ext.util.MixedCollection.superclass.constructor.call(this);
  69. };
  70. Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
  71. <div id="cfg-Ext.util.MixedCollection-allowFunctions"></div>/**
  72. * @cfg {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  73. * function should add function references to the collection. Defaults to
  74. * <tt>false</tt>.
  75. */
  76. allowFunctions : false,
  77. <div id="method-Ext.util.MixedCollection-add"></div>/**
  78. * Adds an item to the collection. Fires the {@link #add} event when complete.
  79. * @param {String} key <p>The key to associate with the item, or the new item.</p>
  80. * <p>If a {@link #getKey} implementation was specified for this MixedCollection,
  81. * or if the key of the stored items is in a property called <tt><b>id</b></tt>,
  82. * the MixedCollection will be able to <i>derive</i> the key for the new item.
  83. * In this case just pass the new item in this parameter.</p>
  84. * @param {Object} o The item to add.
  85. * @return {Object} The item added.
  86. */
  87. add : function(key, o){
  88. if(arguments.length == 1){
  89. o = arguments[0];
  90. key = this.getKey(o);
  91. }
  92. if(typeof key != 'undefined' && key !== null){
  93. var old = this.map[key];
  94. if(typeof old != 'undefined'){
  95. return this.replace(key, o);
  96. }
  97. this.map[key] = o;
  98. }
  99. this.length++;
  100. this.items.push(o);
  101. this.keys.push(key);
  102. this.fireEvent('add', this.length-1, o, key);
  103. return o;
  104. },
  105. <div id="method-Ext.util.MixedCollection-getKey"></div>/**
  106. * MixedCollection has a generic way to fetch keys if you implement getKey. The default implementation
  107. * simply returns <b><code>item.id</code></b> but you can provide your own implementation
  108. * to return a different value as in the following examples:<pre><code>
  109. // normal way
  110. var mc = new Ext.util.MixedCollection();
  111. mc.add(someEl.dom.id, someEl);
  112. mc.add(otherEl.dom.id, otherEl);
  113. //and so on
  114. // using getKey
  115. var mc = new Ext.util.MixedCollection();
  116. mc.getKey = function(el){
  117. return el.dom.id;
  118. };
  119. mc.add(someEl);
  120. mc.add(otherEl);
  121. // or via the constructor
  122. var mc = new Ext.util.MixedCollection(false, function(el){
  123. return el.dom.id;
  124. });
  125. mc.add(someEl);
  126. mc.add(otherEl);
  127. * </code></pre>
  128. * @param {Object} item The item for which to find the key.
  129. * @return {Object} The key for the passed item.
  130. */
  131. getKey : function(o){
  132. return o.id;
  133. },
  134. <div id="method-Ext.util.MixedCollection-replace"></div>/**
  135. * Replaces an item in the collection. Fires the {@link #replace} event when complete.
  136. * @param {String} key <p>The key associated with the item to replace, or the replacement item.</p>
  137. * <p>If you supplied a {@link #getKey} implementation for this MixedCollection, or if the key
  138. * of your stored items is in a property called <tt><b>id</b></tt>, then the MixedCollection
  139. * will be able to <i>derive</i> the key of the replacement item. If you want to replace an item
  140. * with one having the same key value, then just pass the replacement item in this parameter.</p>
  141. * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate
  142. * with that key.
  143. * @return {Object} The new item.
  144. */
  145. replace : function(key, o){
  146. if(arguments.length == 1){
  147. o = arguments[0];
  148. key = this.getKey(o);
  149. }
  150. var old = this.map[key];
  151. if(typeof key == 'undefined' || key === null || typeof old == 'undefined'){
  152. return this.add(key, o);
  153. }
  154. var index = this.indexOfKey(key);
  155. this.items[index] = o;
  156. this.map[key] = o;
  157. this.fireEvent('replace', key, old, o);
  158. return o;
  159. },
  160. <div id="method-Ext.util.MixedCollection-addAll"></div>/**
  161. * Adds all elements of an Array or an Object to the collection.
  162. * @param {Object/Array} objs An Object containing properties which will be added
  163. * to the collection, or an Array of values, each of which are added to the collection.
  164. * Functions references will be added to the collection if <code>{@link #allowFunctions}</code>
  165. * has been set to <tt>true</tt>.
  166. */
  167. addAll : function(objs){
  168. if(arguments.length > 1 || Ext.isArray(objs)){
  169. var args = arguments.length > 1 ? arguments : objs;
  170. for(var i = 0, len = args.length; i < len; i++){
  171. this.add(args[i]);
  172. }
  173. }else{
  174. for(var key in objs){
  175. if(this.allowFunctions || typeof objs[key] != 'function'){
  176. this.add(key, objs[key]);
  177. }
  178. }
  179. }
  180. },
  181. <div id="method-Ext.util.MixedCollection-each"></div>/**
  182. * Executes the specified function once for every item in the collection, passing the following arguments:
  183. * <div class="mdetail-params"><ul>
  184. * <li><b>item</b> : Mixed<p class="sub-desc">The collection item</p></li>
  185. * <li><b>index</b> : Number<p class="sub-desc">The item's index</p></li>
  186. * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
  187. * </ul></div>
  188. * The function should return a boolean value. Returning false from the function will stop the iteration.
  189. * @param {Function} fn The function to execute for each item.
  190. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current item in the iteration.
  191. */
  192. each : function(fn, scope){
  193. var items = [].concat(this.items); // each safe for removal
  194. for(var i = 0, len = items.length; i < len; i++){
  195. if(fn.call(scope || items[i], items[i], i, len) === false){
  196. break;
  197. }
  198. }
  199. },
  200. <div id="method-Ext.util.MixedCollection-eachKey"></div>/**
  201. * Executes the specified function once for every key in the collection, passing each
  202. * key, and its associated item as the first two parameters.
  203. * @param {Function} fn The function to execute for each item.
  204. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  205. */
  206. eachKey : function(fn, scope){
  207. for(var i = 0, len = this.keys.length; i < len; i++){
  208. fn.call(scope || window, this.keys[i], this.items[i], i, len);
  209. }
  210. },
  211. <div id="method-Ext.util.MixedCollection-find"></div>/**
  212. * Returns the first item in the collection which elicits a true return value from the
  213. * passed selection function.
  214. * @param {Function} fn The selection function to execute for each item.
  215. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  216. * @return {Object} The first item in the collection which returned true from the selection function.
  217. */
  218. find : function(fn, scope){
  219. for(var i = 0, len = this.items.length; i < len; i++){
  220. if(fn.call(scope || window, this.items[i], this.keys[i])){
  221. return this.items[i];
  222. }
  223. }
  224. return null;
  225. },
  226. <div id="method-Ext.util.MixedCollection-insert"></div>/**
  227. * Inserts an item at the specified index in the collection. Fires the {@link #add} event when complete.
  228. * @param {Number} index The index to insert the item at.
  229. * @param {String} key The key to associate with the new item, or the item itself.
  230. * @param {Object} o (optional) If the second parameter was a key, the new item.
  231. * @return {Object} The item inserted.
  232. */
  233. insert : function(index, key, o){
  234. if(arguments.length == 2){
  235. o = arguments[1];
  236. key = this.getKey(o);
  237. }
  238. if(this.containsKey(key)){
  239. this.suspendEvents();
  240. this.removeKey(key);
  241. this.resumeEvents();
  242. }
  243. if(index >= this.length){
  244. return this.add(key, o);
  245. }
  246. this.length++;
  247. this.items.splice(index, 0, o);
  248. if(typeof key != 'undefined' && key !== null){
  249. this.map[key] = o;
  250. }
  251. this.keys.splice(index, 0, key);
  252. this.fireEvent('add', index, o, key);
  253. return o;
  254. },
  255. <div id="method-Ext.util.MixedCollection-remove"></div>/**
  256. * Remove an item from the collection.
  257. * @param {Object} o The item to remove.
  258. * @return {Object} The item removed or false if no item was removed.
  259. */
  260. remove : function(o){
  261. return this.removeAt(this.indexOf(o));
  262. },
  263. <div id="method-Ext.util.MixedCollection-removeAt"></div>/**
  264. * Remove an item from a specified index in the collection. Fires the {@link #remove} event when complete.
  265. * @param {Number} index The index within the collection of the item to remove.
  266. * @return {Object} The item removed or false if no item was removed.
  267. */
  268. removeAt : function(index){
  269. if(index < this.length && index >= 0){
  270. this.length--;
  271. var o = this.items[index];
  272. this.items.splice(index, 1);
  273. var key = this.keys[index];
  274. if(typeof key != 'undefined'){
  275. delete this.map[key];
  276. }
  277. this.keys.splice(index, 1);
  278. this.fireEvent('remove', o, key);
  279. return o;
  280. }
  281. return false;
  282. },
  283. <div id="method-Ext.util.MixedCollection-removeKey"></div>/**
  284. * Removed an item associated with the passed key fom the collection.
  285. * @param {String} key The key of the item to remove.
  286. * @return {Object} The item removed or false if no item was removed.
  287. */
  288. removeKey : function(key){
  289. return this.removeAt(this.indexOfKey(key));
  290. },
  291. <div id="method-Ext.util.MixedCollection-getCount"></div>/**
  292. * Returns the number of items in the collection.
  293. * @return {Number} the number of items in the collection.
  294. */
  295. getCount : function(){
  296. return this.length;
  297. },
  298. <div id="method-Ext.util.MixedCollection-indexOf"></div>/**
  299. * Returns index within the collection of the passed Object.
  300. * @param {Object} o The item to find the index of.
  301. * @return {Number} index of the item. Returns -1 if not found.
  302. */
  303. indexOf : function(o){
  304. return this.items.indexOf(o);
  305. },
  306. <div id="method-Ext.util.MixedCollection-indexOfKey"></div>/**
  307. * Returns index within the collection of the passed key.
  308. * @param {String} key The key to find the index of.
  309. * @return {Number} index of the key.
  310. */
  311. indexOfKey : function(key){
  312. return this.keys.indexOf(key);
  313. },
  314. <div id="method-Ext.util.MixedCollection-item"></div>/**
  315. * Returns the item associated with the passed key OR index.
  316. * Key has priority over index. This is the equivalent
  317. * of calling {@link #key} first, then if nothing matched calling {@link #itemAt}.
  318. * @param {String/Number} key The key or index of the item.
  319. * @return {Object} If the item is found, returns the item. If the item was not found, returns <tt>undefined</tt>.
  320. * If an item was found, but is a Class, returns <tt>null</tt>.
  321. */
  322. item : function(key){
  323. var mk = this.map[key],
  324. item = mk !== undefined ? mk : (typeof key == 'number') ? this.items[key] : undefined;
  325. return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
  326. },
  327. <div id="method-Ext.util.MixedCollection-itemAt"></div>/**
  328. * Returns the item at the specified index.
  329. * @param {Number} index The index of the item.
  330. * @return {Object} The item at the specified index.
  331. */
  332. itemAt : function(index){
  333. return this.items[index];
  334. },
  335. <div id="method-Ext.util.MixedCollection-key"></div>/**
  336. * Returns the item associated with the passed key.
  337. * @param {String/Number} key The key of the item.
  338. * @return {Object} The item associated with the passed key.
  339. */
  340. key : function(key){
  341. return this.map[key];
  342. },
  343. <div id="method-Ext.util.MixedCollection-contains"></div>/**
  344. * Returns true if the collection contains the passed Object as an item.
  345. * @param {Object} o The Object to look for in the collection.
  346. * @return {Boolean} True if the collection contains the Object as an item.
  347. */
  348. contains : function(o){
  349. return this.indexOf(o) != -1;
  350. },
  351. <div id="method-Ext.util.MixedCollection-containsKey"></div>/**
  352. * Returns true if the collection contains the passed Object as a key.
  353. * @param {String} key The key to look for in the collection.
  354. * @return {Boolean} True if the collection contains the Object as a key.
  355. */
  356. containsKey : function(key){
  357. return typeof this.map[key] != 'undefined';
  358. },
  359. <div id="method-Ext.util.MixedCollection-clear"></div>/**
  360. * Removes all items from the collection. Fires the {@link #clear} event when complete.
  361. */
  362. clear : function(){
  363. this.length = 0;
  364. this.items = [];
  365. this.keys = [];
  366. this.map = {};
  367. this.fireEvent('clear');
  368. },
  369. <div id="method-Ext.util.MixedCollection-first"></div>/**
  370. * Returns the first item in the collection.
  371. * @return {Object} the first item in the collection..
  372. */
  373. first : function(){
  374. return this.items[0];
  375. },
  376. <div id="method-Ext.util.MixedCollection-last"></div>/**
  377. * Returns the last item in the collection.
  378. * @return {Object} the last item in the collection..
  379. */
  380. last : function(){
  381. return this.items[this.length-1];
  382. },
  383. /**
  384. * @private
  385. * Performs the actual sorting based on a direction and a sorting function. Internally,
  386. * this creates a temporary array of all items in the MixedCollection, sorts it and then writes
  387. * the sorted array data back into this.items and this.keys
  388. * @param {String} property Property to sort by ('key', 'value', or 'index')
  389. * @param {String} dir (optional) Direction to sort 'ASC' or 'DESC'. Defaults to 'ASC'.
  390. * @param {Function} fn (optional) Comparison function that defines the sort order.
  391. * Defaults to sorting by numeric value.
  392. */
  393. _sort : function(property, dir, fn){
  394. var i, len,
  395. dsc = String(dir).toUpperCase() == 'DESC' ? -1 : 1,
  396. //this is a temporary array used to apply the sorting function
  397. c = [],
  398. keys = this.keys,
  399. items = this.items;
  400. //default to a simple sorter function if one is not provided
  401. fn = fn || function(a, b) {
  402. return a - b;
  403. };
  404. //copy all the items into a temporary array, which we will sort
  405. for(i = 0, len = items.length; i < len; i++){
  406. c[c.length] = {
  407. key : keys[i],
  408. value: items[i],
  409. index: i
  410. };
  411. }
  412. //sort the temporary array
  413. c.sort(function(a, b){
  414. var v = fn(a[property], b[property]) * dsc;
  415. if(v === 0){
  416. v = (a.index < b.index ? -1 : 1);
  417. }
  418. return v;
  419. });
  420. //copy the temporary array back into the main this.items and this.keys objects
  421. for(i = 0, len = c.length; i < len; i++){
  422. items[i] = c[i].value;
  423. keys[i] = c[i].key;
  424. }
  425. this.fireEvent('sort', this);
  426. },
  427. <div id="method-Ext.util.MixedCollection-sort"></div>/**
  428. * Sorts this collection by <b>item</b> value with the passed comparison function.
  429. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  430. * @param {Function} fn (optional) Comparison function that defines the sort order.
  431. * Defaults to sorting by numeric value.
  432. */
  433. sort : function(dir, fn){
  434. this._sort('value', dir, fn);
  435. },
  436. <div id="method-Ext.util.MixedCollection-reorder"></div>/**
  437. * Reorders each of the items based on a mapping from old index to new index. Internally this
  438. * just translates into a sort. The 'sort' event is fired whenever reordering has occured.
  439. * @param {Object} mapping Mapping from old item index to new item index
  440. */
  441. reorder: function(mapping) {
  442. this.suspendEvents();
  443. var items = this.items,
  444. index = 0,
  445. length = items.length,
  446. order = [],
  447. remaining = [],
  448. oldIndex;
  449. //object of {oldPosition: newPosition} reversed to {newPosition: oldPosition}
  450. for (oldIndex in mapping) {
  451. order[mapping[oldIndex]] = items[oldIndex];
  452. }
  453. for (index = 0; index < length; index++) {
  454. if (mapping[index] == undefined) {
  455. remaining.push(items[index]);
  456. }
  457. }
  458. for (index = 0; index < length; index++) {
  459. if (order[index] == undefined) {
  460. order[index] = remaining.shift();
  461. }
  462. }
  463. this.clear();
  464. this.addAll(order);
  465. this.resumeEvents();
  466. this.fireEvent('sort', this);
  467. },
  468. <div id="method-Ext.util.MixedCollection-keySort"></div>/**
  469. * Sorts this collection by <b>key</b>s.
  470. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  471. * @param {Function} fn (optional) Comparison function that defines the sort order.
  472. * Defaults to sorting by case insensitive string.
  473. */
  474. keySort : function(dir, fn){
  475. this._sort('key', dir, fn || function(a, b){
  476. var v1 = String(a).toUpperCase(), v2 = String(b).toUpperCase();
  477. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  478. });
  479. },
  480. <div id="method-Ext.util.MixedCollection-getRange"></div>/**
  481. * Returns a range of items in this collection
  482. * @param {Number} startIndex (optional) The starting index. Defaults to 0.
  483. * @param {Number} endIndex (optional) The ending index. Defaults to the last item.
  484. * @return {Array} An array of items
  485. */
  486. getRange : function(start, end){
  487. var items = this.items;
  488. if(items.length < 1){
  489. return [];
  490. }
  491. start = start || 0;
  492. end = Math.min(typeof end == 'undefined' ? this.length-1 : end, this.length-1);
  493. var i, r = [];
  494. if(start <= end){
  495. for(i = start; i <= end; i++) {
  496. r[r.length] = items[i];
  497. }
  498. }else{
  499. for(i = start; i >= end; i--) {
  500. r[r.length] = items[i];
  501. }
  502. }
  503. return r;
  504. },
  505. <div id="method-Ext.util.MixedCollection-filter"></div>/**
  506. * Filter the <i>objects</i> in this collection by a specific property.
  507. * Returns a new collection that has been filtered.
  508. * @param {String} property A property on your objects
  509. * @param {String/RegExp} value Either string that the property values
  510. * should start with or a RegExp to test against the property
  511. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
  512. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison (defaults to False).
  513. * @return {MixedCollection} The new filtered collection
  514. */
  515. filter : function(property, value, anyMatch, caseSensitive){
  516. if(Ext.isEmpty(value, false)){
  517. return this.clone();
  518. }
  519. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  520. return this.filterBy(function(o){
  521. return o && value.test(o[property]);
  522. });
  523. },
  524. <div id="method-Ext.util.MixedCollection-filterBy"></div>/**
  525. * Filter by a function. Returns a <i>new</i> collection that has been filtered.
  526. * The passed function will be called with each object in the collection.
  527. * If the function returns true, the value is included otherwise it is filtered.
  528. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
  529. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  530. * @return {MixedCollection} The new filtered collection
  531. */
  532. filterBy : function(fn, scope){
  533. var r = new Ext.util.MixedCollection();
  534. r.getKey = this.getKey;
  535. var k = this.keys, it = this.items;
  536. for(var i = 0, len = it.length; i < len; i++){
  537. if(fn.call(scope||this, it[i], k[i])){
  538. r.add(k[i], it[i]);
  539. }
  540. }
  541. return r;
  542. },
  543. <div id="method-Ext.util.MixedCollection-findIndex"></div>/**
  544. * Finds the index of the first matching object in this collection by a specific property/value.
  545. * @param {String} property The name of a property on your objects.
  546. * @param {String/RegExp} value A string that the property values
  547. * should start with or a RegExp to test against the property.
  548. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  549. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning.
  550. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison.
  551. * @return {Number} The matched index or -1
  552. */
  553. findIndex : function(property, value, start, anyMatch, caseSensitive){
  554. if(Ext.isEmpty(value, false)){
  555. return -1;
  556. }
  557. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  558. return this.findIndexBy(function(o){
  559. return o && value.test(o[property]);
  560. }, null, start);
  561. },
  562. <div id="method-Ext.util.MixedCollection-findIndexBy"></div>/**
  563. * Find the index of the first matching object in this collection by a function.
  564. * If the function returns <i>true</i> it is considered a match.
  565. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key).
  566. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  567. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  568. * @return {Number} The matched index or -1
  569. */
  570. findIndexBy : function(fn, scope, start){
  571. var k = this.keys, it = this.items;
  572. for(var i = (start||0), len = it.length; i < len; i++){
  573. if(fn.call(scope||this, it[i], k[i])){
  574. return i;
  575. }
  576. }
  577. return -1;
  578. },
  579. /**
  580. * Returns a regular expression based on the given value and matching options. This is used internally for finding and filtering,
  581. * and by Ext.data.Store#filter
  582. * @private
  583. * @param {String} value The value to create the regex for. This is escaped using Ext.escapeRe
  584. * @param {Boolean} anyMatch True to allow any match - no regex start/end line anchors will be added. Defaults to false
  585. * @param {Boolean} caseSensitive True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.
  586. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  587. */
  588. createValueMatcher : function(value, anyMatch, caseSensitive, exactMatch) {
  589. if (!value.exec) { // not a regex
  590. var er = Ext.escapeRe;
  591. value = String(value);
  592. if (anyMatch === true) {
  593. value = er(value);
  594. } else {
  595. value = '^' + er(value);
  596. if (exactMatch === true) {
  597. value += '$';
  598. }
  599. }
  600. value = new RegExp(value, caseSensitive ? '' : 'i');
  601. }
  602. return value;
  603. },
  604. <div id="method-Ext.util.MixedCollection-clone"></div>/**
  605. * Creates a shallow copy of this collection
  606. * @return {MixedCollection}
  607. */
  608. clone : function(){
  609. var r = new Ext.util.MixedCollection();
  610. var k = this.keys, it = this.items;
  611. for(var i = 0, len = it.length; i < len; i++){
  612. r.add(k[i], it[i]);
  613. }
  614. r.getKey = this.getKey;
  615. return r;
  616. }
  617. });
  618. <div id="method-Ext.util.MixedCollection-get"></div>/**
  619. * This method calls {@link #item item()}.
  620. * Returns the item associated with the passed key OR index. Key has priority
  621. * over index. This is the equivalent of calling {@link #key} first, then if
  622. * nothing matched calling {@link #itemAt}.
  623. * @param {String/Number} key The key or index of the item.
  624. * @return {Object} If the item is found, returns the item. If the item was
  625. * not found, returns <tt>undefined</tt>. If an item was found, but is a Class,
  626. * returns <tt>null</tt>.
  627. */
  628. Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item;
  629. </pre>
  630. </body>
  631. </html>