HrOrgTree.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Ext.define('erp.view.core.tree.HrOrgTree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.orgtreepanel',
  4. id:'orgtreepanel',
  5. region:'west',
  6. width:'20%',
  7. frame:false,
  8. animCollapse: false,
  9. constrainHeader: true,
  10. border: false,
  11. autoShow: true,
  12. collapsible : true,
  13. useArrows: true,
  14. title:'人事架构',
  15. rootVisible: false,
  16. layout:'fit',
  17. bodyStyle:'background-color:#f1f1f1;',
  18. initComponent : function(){
  19. this.getNodes(0,this);
  20. this.callParent(arguments);
  21. },
  22. getNodes: function(pid,p){
  23. var me = this;
  24. Ext.Ajax.request({//拿到tree数据
  25. url : basePath + 'hr/getTreeNode.action',
  26. params: {
  27. parentId: pid
  28. },
  29. callback : function(options,success,response){
  30. var res = new Ext.decode(response.responseText);
  31. if(res.result){
  32. var tree = res.result;
  33. Ext.getCmp('orgtreepanel').store.setRootNode({
  34. text: 'root',
  35. id: 'root',
  36. expanded: true,
  37. children: tree
  38. });
  39. }else if(res.exceptionInfo){
  40. showError(res.exceptionInfo);
  41. }
  42. }
  43. });
  44. },
  45. loadChild:function(record){
  46. var tree=this;
  47. tree.setLoading(true, tree.body);
  48. Ext.Ajax.request({//拿到tree数据
  49. url : basePath + 'hr/getTreeNode.action',
  50. params: {
  51. parentId: record.get('id')
  52. },
  53. callback : function(options,success,response){
  54. tree.setLoading(false);
  55. var res = new Ext.decode(response.responseText);
  56. if(res.result){
  57. record.appendChild(res.result);
  58. record.expand(false,true);
  59. } else if(res.exceptionInfo){
  60. showError(res.exceptionInfo);
  61. }
  62. }
  63. });
  64. },
  65. listeners: {
  66. scrollershow: function(scroller) {
  67. if (scroller && scroller.scrollEl) {
  68. scroller.clearManagedListeners();
  69. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  70. }
  71. }
  72. },
  73. OpenUrl:function(record){
  74. var me = this,id=record.get('id');
  75. var panel = Ext.getCmp(id),main = Ext.getCmp("content-panel");
  76. if(!panel){
  77. var url = me.parseUrl(record.raw['url']);//解析url里的特殊描述
  78. panel = {
  79. title : record.get('qtip').length>5?(record.get('qtip').substring(0,5)+'..'):record.get('qtip'),
  80. tag : 'iframe',
  81. tabConfig: {tooltip:record.get('qtip')},
  82. border : false,
  83. frame: false,
  84. layout : 'fit',
  85. iconCls : record.data.iconCls,
  86. html : '<iframe id="iframe_' + id + '" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  87. closable : true,
  88. listeners : {
  89. close : function(){
  90. var main = Ext.getCmp("content-panel");
  91. main.setActiveTab(Ext.getCmp("HomePage"));
  92. }
  93. }
  94. };
  95. this.openTab(panel, record.get('id'), url);
  96. } else{
  97. main.setActiveTab(panel);
  98. }
  99. },
  100. parseUrl: function(url){
  101. var id = url.substring(url.lastIndexOf('?')+1);//将作为新tab的id
  102. if (id == null) {
  103. id = url.substring(0,url.lastIndexOf('.'));
  104. }
  105. if(contains(url, 'session:em_uu', true)){//对url中session值的处理
  106. url = url.replace(/session:em_uu/g,em_uu);
  107. }
  108. if(contains(url, 'session:em_code', true)){//对url中em_code值的处理
  109. url = url.replace(/session:em_code/g, "'" + em_code + "'");
  110. }
  111. if(contains(url, 'sysdate', true)){//对url中系统时间sysdate的处理
  112. url = url.replace(/sysdate/g, "to_date('" + Ext.Date.toString(new Date()) + "','yyyy-mm-dd')");
  113. }
  114. if(contains(url, 'session:em_name', true)){
  115. url = url.replace(/session:em_name/g,"'"+em_name+"'" );
  116. }
  117. return url;
  118. },
  119. openTab : function (panel, id, url){
  120. var o = (typeof panel == "string" ? panel : id || panel.id);
  121. var main = Ext.getCmp("content-panel");
  122. var tab = main.getComponent(o);
  123. if (tab) {
  124. main.setActiveTab(tab);
  125. } else if(typeof panel!="string"){
  126. panel.id = o;
  127. var p = main.add(panel);
  128. main.setActiveTab(p);
  129. }
  130. }
  131. });