5300457789ae2117d008a7de4e5a199f427bf98d.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.TreeEventModel = function(tree) {
  7. this.tree = tree;
  8. this.tree.on('render', this.initEvents, this);
  9. }
  10. Ext.tree.TreeEventModel.prototype = {
  11. initEvents : function() {
  12. var el = this.tree.getTreeEl();
  13. el.on('click', this.delegateClick, this);
  14. el.on('mouseover', this.delegateOver, this);
  15. el.on('mouseout', this.delegateOut, this);
  16. el.on('dblclick', this.delegateDblClick, this);
  17. el.on('contextmenu', this.delegateContextMenu, this);
  18. },
  19. getNode : function(e) {
  20. var t;
  21. if (t = e.getTarget('.x-tree-node-el', 10)) {
  22. var id = Ext.fly(t, '_treeEvents').getAttributeNS('ext',
  23. 'tree-node-id');
  24. if (id) {
  25. return this.tree.getNodeById(id);
  26. }
  27. }
  28. return null;
  29. },
  30. getNodeTarget : function(e) {
  31. var t = e.getTarget('.x-tree-node-icon', 1);
  32. if (!t) {
  33. t = e.getTarget('.x-tree-node-el', 6);
  34. }
  35. return t;
  36. },
  37. delegateOut : function(e, t) {
  38. if (!this.beforeEvent(e)) {
  39. return;
  40. }
  41. t = this.getNodeTarget(e);
  42. if (t && !e.within(t, true)) {
  43. this.onNodeOut(e, this.getNode(e));
  44. }
  45. },
  46. delegateOver : function(e, t) {
  47. if (!this.beforeEvent(e)) {
  48. return;
  49. }
  50. t = this.getNodeTarget(e);
  51. if (t) {
  52. this.onNodeOver(e, this.getNode(e));
  53. }
  54. },
  55. delegateClick : function(e, t) {
  56. if (!this.beforeEvent(e)) {
  57. return;
  58. }
  59. if (e.getTarget('input[type=checkbox]', 1)) {
  60. this.onCheckboxClick(e, this.getNode(e));
  61. } else if (e.getTarget('.x-tree-ec-icon', 1)) {
  62. this.onIconClick(e, this.getNode(e));
  63. } else if (this.getNodeTarget(e)) {
  64. this.onNodeClick(e, this.getNode(e));
  65. }
  66. },
  67. delegateDblClick : function(e, t) {
  68. if (this.beforeEvent(e) && this.getNodeTarget(e)) {
  69. this.onNodeDblClick(e, this.getNode(e));
  70. }
  71. },
  72. delegateContextMenu : function(e, t) {
  73. if (this.beforeEvent(e) && this.getNodeTarget(e)) {
  74. this.onNodeContextMenu(e, this.getNode(e));
  75. }
  76. },
  77. onNodeClick : function(e, node) {
  78. node.ui.onClick(e);
  79. },
  80. onNodeOver : function(e, node) {
  81. node.ui.onOver(e);
  82. },
  83. onNodeOut : function(e, node) {
  84. node.ui.onOut(e);
  85. },
  86. onIconClick : function(e, node) {
  87. node.ui.ecClick(e);
  88. },
  89. onCheckboxClick : function(e, node) {
  90. node.ui.onCheckChange(e);
  91. },
  92. onNodeDblClick : function(e, node) {
  93. node.ui.onDblClick(e);
  94. },
  95. onNodeContextMenu : function(e, node) {
  96. node.ui.onContextMenu(e);
  97. },
  98. beforeEvent : function(e) {
  99. if (this.disabled) {
  100. e.stopEvent();
  101. return false;
  102. }
  103. return true;
  104. },
  105. disable : function() {
  106. this.disabled = true;
  107. },
  108. enable : function() {
  109. this.disabled = false;
  110. }
  111. };