AddrBookTree.js 3.1 KB

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