MainController.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * This class is the controller for the main view for the application. It is specified as
  3. * the "controller" of the Main view class.
  4. */
  5. Ext.define('saas.view.main.MainController', {
  6. extend: 'Ext.app.ViewController',
  7. alias: 'controller.main',
  8. onNavigationTreeSelectionChange: function (tree, node) {
  9. if (node && node.get('viewType')) {
  10. this.setActiveTab(node.get('id'), node.get('viewType'), node.get('text'));
  11. }
  12. },
  13. setActiveTab: function(id, type, title) {
  14. var me = this,
  15. refs = me.getReferences(),
  16. mainTab = refs.mainTabPanel,
  17. // existingItem = mainTab.child(type),
  18. existingItem = mainTab.down('[id=' + id + ']'),
  19. newView;
  20. lastView = mainTab.getActiveTab();
  21. if (!existingItem) {
  22. newView = me.createTab({ type: type, title: title, id: id });
  23. }
  24. if (!newView || !newView.isWindow) {
  25. // !newView means we have an existing view, but if the newView isWindow
  26. // we don't add it to the card layout.
  27. if (existingItem) {
  28. // We don't have a newView, so activate the existing view.
  29. if (existingItem !== lastView) {
  30. mainTab.setActiveTab(existingItem);
  31. }
  32. newView = existingItem;
  33. }
  34. else {
  35. // newView is set (did not exist already), so add it and make it the
  36. // activeItem.
  37. Ext.suspendLayouts();
  38. mainTab.setActiveTab(mainTab.add(newView));
  39. Ext.resumeLayouts(true);
  40. }
  41. }
  42. if (newView.isFocusable(true)) {
  43. newView.focus();
  44. }
  45. },
  46. createTab: function(tabConfig) {
  47. var me = this,
  48. type = tabConfig.type;
  49. if(type == 'grid') {
  50. return me.createGrid(tabConfig);
  51. }else if(type == 'form') {
  52. return me.createForm(tabConfig);
  53. }else {
  54. var { id, title } = tabConfig;
  55. return Ext.create('Ext.panel.Panel', {
  56. id,
  57. title,
  58. html: '无效类型'
  59. });
  60. }
  61. },
  62. createGrid: function(tabConfig) {
  63. var me = this;
  64. var { id, title } = tabConfig;
  65. var grid = Ext.create('saas.view.core.grid.Panel', {
  66. id,
  67. title
  68. });
  69. return grid;
  70. },
  71. createForm: function(tabConfig) {
  72. var me = this;
  73. var { id, title } = tabConfig;
  74. var form = Ext.create('saas.view.core.form.Panel', {
  75. id,
  76. title
  77. });
  78. return form;
  79. },
  80. onToggleNavigationSize: function () {
  81. var me = this,
  82. refs = me.getReferences(),
  83. navigationList = refs.navigationTreeList,
  84. wrapContainer = refs.mainContainerWrap,
  85. collapsing = !navigationList.getMicro(),
  86. new_width = collapsing ? 64 : 250;
  87. if (Ext.isIE9m || !Ext.os.is.Desktop) {
  88. Ext.suspendLayouts();
  89. refs.mainLogo.setWidth(new_width);
  90. navigationList.setWidth(new_width);
  91. navigationList.setMicro(collapsing);
  92. Ext.resumeLayouts(); // do not flush the layout here...
  93. // No animation for IE9 or lower...
  94. wrapContainer.layout.animatePolicy = wrapContainer.layout.animate = null;
  95. wrapContainer.updateLayout(); // ... since this will flush them
  96. }
  97. else {
  98. if (!collapsing) {
  99. // If we are leaving micro mode (expanding), we do that first so that the
  100. // text of the items in the navlist will be revealed by the animation.
  101. navigationList.setMicro(false);
  102. }
  103. navigationList.canMeasure = false;
  104. // Start this layout first since it does not require a layout
  105. refs.mainLogo.animate({dynamic: true, to: {width: new_width}});
  106. // Directly adjust the width config and then run the main wrap container layout
  107. // as the root layout (it and its chidren). This will cause the adjusted size to
  108. // be flushed to the element and animate to that new size.
  109. navigationList.width = new_width;
  110. wrapContainer.updateLayout({isRoot: true});
  111. navigationList.el.addCls('nav-tree-animating');
  112. // We need to switch to micro mode on the navlist *after* the animation (this
  113. // allows the "sweep" to leave the item text in place until it is no longer
  114. // visible.
  115. if (collapsing) {
  116. navigationList.on({
  117. afterlayoutanimation: function () {
  118. navigationList.setMicro(true);
  119. navigationList.el.removeCls('nav-tree-animating');
  120. navigationList.canMeasure = true;
  121. },
  122. single: true
  123. });
  124. }
  125. }
  126. },
  127. });