EmpTree.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. Ext.define('erp.view.hr.attendance.EmpTree', {
  2. extend : 'Ext.tree.Panel',
  3. alias : 'widget.EmpTree',
  4. id : 'tree-panel',
  5. border : false,
  6. enableDD : false,
  7. split : true,
  8. width : '100%',
  9. height : '100%',
  10. expandedNodes : [],
  11. title : "<font color=#a1a1a1; size=2>设置员工考勤项目</font>",
  12. toggleCollapse : function() {
  13. if (this.collapsed) {
  14. this.expand(this.animCollapse);
  15. } else {
  16. this.title = '设置员工考勤项目';
  17. this.collapse(this.collapseDirection, this.animCollapse);
  18. }
  19. return this;
  20. },
  21. rootVisible : false,
  22. singleExpand : true,
  23. animate : true,
  24. containerScroll : true,
  25. collapsible : true,
  26. autoScroll : true,
  27. useArrows : true,
  28. store : Ext.create('Ext.data.TreeStore', {
  29. root : {
  30. text : 'root',
  31. id : 'root',
  32. expanded : true
  33. }
  34. }),
  35. dockedItems : [ {
  36. id : 'toolbar',
  37. xtype : 'erpAttendApplyRange',
  38. dock : 'right',
  39. displayInfo : true
  40. } ],
  41. bodyStyle : 'background-color:#f1f1f1;',
  42. initComponent : function() {
  43. this.getTreeRootNode(0);
  44. this.callParent(arguments);
  45. },
  46. getTreeRootNode : function(parentid) {
  47. Ext.Ajax.request({// 拿到tree数据
  48. url : basePath + 'hr/attendance/getAllHrOrgsTree.action',
  49. params : {
  50. },
  51. callback : function(options, success, response) {
  52. var res = new Ext.decode(response.responseText);
  53. if (res.tree) {
  54. var tree = res.tree;
  55. Ext.getCmp('tree-panel').store.setRootNode({
  56. text : 'root',
  57. id : 'root',
  58. expanded : true,
  59. children : tree
  60. });
  61. } else if (res.exceptionInfo) {
  62. showError(res.exceptionInfo);
  63. }
  64. Ext.getCmp('tree-panel').listenerNode();
  65. }
  66. });
  67. },
  68. listenerNode : function(node) {
  69. var me = this;
  70. var n = node || Ext.getCmp('tree-panel').store.tree.root;
  71. Ext.each(n, function(e) {
  72. e.on('beforecollapse', function(p, o) {
  73. });
  74. if (e.data['leaf'] == false) {
  75. me.listenerNode(e);
  76. }
  77. });
  78. },
  79. openCloseFun : function() {
  80. var o = Ext.getCmp("open");
  81. var c = Ext.getCmp("close");
  82. var tree = Ext.getCmp('tree-panel');
  83. if (o.hidden == false && c.hidden == true) {
  84. tree.expandAll();
  85. o.hide();
  86. c.show();
  87. } else {
  88. tree.collapseAll();
  89. o.show();
  90. c.hide();
  91. }
  92. },
  93. listeners : {// 滚动条有时候没反应,添加此监听器
  94. scrollershow : function(scroller) {
  95. if (scroller && scroller.scrollEl) {
  96. scroller.clearManagedListeners();
  97. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  98. }
  99. }
  100. },
  101. /**
  102. * 找到所有已展开的节点,包括当前被选中的节点
  103. *
  104. * @param record
  105. * 当前被选中的节点
  106. */
  107. getExpandedItems : function(record) {
  108. var me = this;
  109. me.getRecordParents(record);
  110. if (record.isLeaf()) {
  111. me.expandedNodes.push(record);
  112. }
  113. },
  114. getRecordParents : function(record, parent) {
  115. var me = this;
  116. if (!parent) {
  117. parent = me.store.tree.root;
  118. me.expandedNodes = [];
  119. }
  120. if (parent.childNodes.length > 0) {
  121. Ext.each(parent.childNodes, function() {
  122. if (this.isExpanded()) {
  123. me.expandedNodes.push(this);
  124. if (this.childNodes.length > 0) {
  125. me.getRecordParents(record, this);
  126. }
  127. }
  128. });
  129. }
  130. },
  131. getExpandItem : function(root) {
  132. var me = this;
  133. if (!root) {
  134. root = this.store.tree.root;
  135. }
  136. var node = null;
  137. if (root.childNodes.length > 0) {
  138. Ext.each(root.childNodes, function() {
  139. if (this.isExpanded()) {
  140. node = this;
  141. if (this.childNodes.length > 0) {
  142. var n = me.getExpandItem(this);
  143. node = n == null ? node : n;
  144. }
  145. }
  146. });
  147. }
  148. return node;
  149. }
  150. });