NavigationToolbar.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Ext.define('erp.view.common.main.NavigationToolbar',{
  2. extend: 'Ext.Toolbar',
  3. alias: 'widget.erpNavigationToolbar',
  4. items: [{
  5. width:215,
  6. xtype: 'triggerfield',
  7. triggerCls: 'x-form-search-trigger',
  8. fieldStyle: 'color:#777;background: #f1f2f5;border-color: #d9d9d9; -moz-border-radius:3px 0 0 3px; -webkit-border-radius:3px 0 0 3px; border-radius:3px 0 0 3px;',
  9. focusCls: 'x-form-field-cir',
  10. emptyText: $I18N.common.main.quickSearch,
  11. enableKeyEvents : true,
  12. listeners : {
  13. specialkey : function(field, e){
  14. if(e.getKey() == Ext.EventObject.ENTER){
  15. this.onTriggerClick();
  16. }
  17. }
  18. },
  19. id:'navigationSearch',
  20. autoShow:true,
  21. onTriggerClick: function(){
  22. var f=this,tree=Ext.getCmp('navigation-panel');
  23. if(f.value == '' || f.value == null){
  24. tree.getTreeRootNode(0);
  25. return;
  26. }
  27. tree.setLoading(true, tree.body);
  28. Ext.Ajax.request({//拿到tree数据
  29. url : basePath +'common/searchTree.action',
  30. timeout:120000,
  31. params: {
  32. search: f.value
  33. },
  34. callback : function(options,success,response){
  35. tree.setLoading(false);
  36. var res = new Ext.decode(response.responseText);
  37. if(res.tree){
  38. var root = tree.getRootNode();
  39. root.removeAll();
  40. var fn = function(node, ch) {
  41. for(var i in ch) {
  42. var n = ch[i], chs = n.children;
  43. n.children = [];
  44. n.expanded = true;
  45. var d = node.appendChild(n);
  46. if(d && chs && chs.length > 0 && String(chs) != '[]') {
  47. fn(d, chs);
  48. }
  49. }
  50. };
  51. fn(root, res.tree);
  52. } else if(res.redirectUrl){
  53. window.location.href = res.redirectUrl;
  54. } else if(res.exceptionInfo){
  55. Ext.Msg.alert("ERROR:" + res.exceptionInfo);
  56. }
  57. }
  58. });
  59. }
  60. }, '->',{
  61. iconCls: 'tree-back',
  62. cls: 'x-btn-tb',
  63. width: 16,
  64. tooltip: $I18N.common.main.treeBack,
  65. hidden: false,
  66. handler: function(){
  67. Ext.getCmp('navigation-panel').getTreeRootNode(0);
  68. Ext.getCmp('navigationSearch').setValue(null);
  69. }
  70. },'->'],
  71. initComponent : function(){
  72. this.callParent(arguments);
  73. }
  74. });