Changeset 212
- Timestamp:
- 2007-04-05 22:17:56 (2 years ago)
- Files:
-
- trunk/components/filterManager.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/components/filterManager.js
r173 r212 270 270 this._filters = filters; 271 271 this._idx = 0; 272 this._filters.sort(function(a,b) {273 if (a.defFilter && !b.defFilter) {274 return -1;275 }276 else if (!a.defFilter && b.defFilter) {277 return 1;278 }279 else if (a.defFilter) {280 if (a.id < b.id) {281 return -1;282 }283 return 1;284 }285 var i = a.label.toLowerCase(), ii = b.label.toLowerCase();286 return i < ii ? -1 : (i > ii ? 1 : 0);287 });288 272 } 289 273 FilterEnumerator.prototype = { … … 385 369 this._mustReload = false; 386 370 387 //error("DTAFM: reload");388 371 this._filters = {}; 372 this._all = []; 389 373 this._count = 0; 390 374 … … 410 394 filter.load(localizedLabel); 411 395 this._filters[filter.id] = filter; 396 this._all.push(filter); 412 397 this._count++; 413 398 } … … 416 401 } 417 402 } 403 this._all.sort( 404 function(a,b) { 405 if (a.defFilter && !b.defFilter) { 406 return -1; 407 } 408 else if (!a.defFilter && b.defFilter) { 409 return 1; 410 } 411 else if (a.defFilter) { 412 if (a.id < b.id) { 413 return -1; 414 } 415 return 1; 416 } 417 var i = a.label.toLowerCase(), ii = b.label.toLowerCase(); 418 return i < ii ? -1 : (i > ii ? 1 : 0); 419 } 420 ); 421 this._active = this._all.filter(function(f) { return f.active; }); 418 422 419 423 // notify all observers … … 424 428 425 429 enumAll: function FM_enumAll() { 426 var a = []; 427 for (x in this._filters) { 428 a.push(this._filters[x]); 429 } 430 return new FilterEnumerator(a); 430 return new FilterEnumerator(this._all); 431 431 }, 432 432 enumActive: function FM_enumActive(type) { 433 var a = []; 434 for (x in this._filters) { 435 if (this._filters[x].active && this._filters[x].type & type) { 436 a.push(this._filters[x]); 437 } 438 } 439 return new FilterEnumerator(a); 433 return new FilterEnumerator(this._active); 440 434 }, 441 435 … … 448 442 449 443 matchActive: function FM_matchActive(test, type) { 450 var e = this.enumActive(type); 451 // we're a friend :p 452 return e._filters.some(function(i) { return i.match(test); }); 444 return this._active.some(function(i) { return i.match(test); }); 453 445 }, 454 446 … … 487 479 488 480 save: function FM_save() { 489 var e = this.enumAll(); 490 while (e.hasMoreElements()) { 491 var f = e.getNext(); 492 try { 493 f.save(); 494 } catch (ex) { 495 error(ex); 496 } 497 } 481 this._all.forEach( 482 function(f) { 483 try { 484 f.save(); 485 } catch (ex) { 486 error(ex); 487 } 488 }, 489 this 490 ); 498 491 }, 499 492
