10e37925401d464b8900dd8009d54db941096d4e.svn-base 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.tree.TreeFilter = function(A, B) {
  7. this.tree = A;
  8. this.filtered = {};
  9. Ext.apply(this, B)
  10. };
  11. Ext.tree.TreeFilter.prototype = {
  12. clearBlank : false,
  13. reverse : false,
  14. autoClear : false,
  15. remove : false,
  16. filter : function(D, A, B) {
  17. A = A || "text";
  18. var C;
  19. if (typeof D == "string") {
  20. var E = D.length;
  21. if (E == 0 && this.clearBlank) {
  22. this.clear();
  23. return
  24. }
  25. D = D.toLowerCase();
  26. C = function(F) {
  27. return F.attributes[A].substr(0, E).toLowerCase() == D
  28. }
  29. } else {
  30. if (D.exec) {
  31. C = function(F) {
  32. return D.test(F.attributes[A])
  33. }
  34. } else {
  35. throw "Illegal filter type, must be string or regex"
  36. }
  37. }
  38. this.filterBy(C, null, B)
  39. },
  40. filterBy : function(D, C, B) {
  41. B = B || this.tree.root;
  42. if (this.autoClear) {
  43. this.clear()
  44. }
  45. var A = this.filtered, H = this.reverse;
  46. var E = function(J) {
  47. if (J == B) {
  48. return true
  49. }
  50. if (A[J.id]) {
  51. return false
  52. }
  53. var I = D.call(C || J, J);
  54. if (!I || H) {
  55. A[J.id] = J;
  56. J.ui.hide();
  57. return false
  58. }
  59. return true
  60. };
  61. B.cascade(E);
  62. if (this.remove) {
  63. for (var G in A) {
  64. if (typeof G != "function") {
  65. var F = A[G];
  66. if (F && F.parentNode) {
  67. F.parentNode.removeChild(F)
  68. }
  69. }
  70. }
  71. }
  72. },
  73. clear : function() {
  74. var B = this.tree;
  75. var A = this.filtered;
  76. for (var D in A) {
  77. if (typeof D != "function") {
  78. var C = A[D];
  79. if (C) {
  80. C.ui.show()
  81. }
  82. }
  83. }
  84. this.filtered = {}
  85. }
  86. };