MainController.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.getData());
  11. }
  12. },
  13. setActiveTab: function(nodeData) {
  14. var me = this,
  15. refs = me.getReferences(),
  16. mainTab = refs.mainTabPanel,
  17. // existingItem = mainTab.child(type),
  18. newView,
  19. id = 'tab-' + nodeData.id,
  20. title = nodeData.text;
  21. existingItem = mainTab.down('[id=' + id + ']'),
  22. lastView = mainTab.getActiveTab();
  23. if (!existingItem) {
  24. newView = Ext.create('saas.view.core.tab.Panel', {
  25. id: id,
  26. title: title,
  27. tabConfig: nodeData
  28. });
  29. }
  30. if (!newView || !newView.isWindow) {
  31. // !newView means we have an existing view, but if the newView isWindow
  32. // we don't add it to the card layout.
  33. if (existingItem) {
  34. // We don't have a newView, so activate the existing view.
  35. if (existingItem !== lastView) {
  36. mainTab.setActiveTab(existingItem);
  37. }
  38. newView = existingItem;
  39. }
  40. else {
  41. // newView is set (did not exist already), so add it and make it the
  42. // activeItem.
  43. Ext.suspendLayouts();
  44. mainTab.setActiveTab(mainTab.add(newView));
  45. Ext.resumeLayouts(true);
  46. }
  47. }
  48. if (newView.isFocusable(true)) {
  49. newView.focus();
  50. }
  51. },
  52. onToggleNavigationSize: function () {
  53. var me = this,
  54. refs = me.getReferences(),
  55. navigationList = refs.navigationTreeList,
  56. wrapContainer = refs.mainContainerWrap,
  57. collapsing = !navigationList.getMicro(),
  58. new_width = collapsing ? 64 : 250;
  59. if (Ext.isIE9m || !Ext.os.is.Desktop) {
  60. Ext.suspendLayouts();
  61. refs.mainLogo.setWidth(new_width);
  62. navigationList.setWidth(new_width);
  63. navigationList.setMicro(collapsing);
  64. Ext.resumeLayouts(); // do not flush the layout here...
  65. // No animation for IE9 or lower...
  66. wrapContainer.layout.animatePolicy = wrapContainer.layout.animate = null;
  67. wrapContainer.updateLayout(); // ... since this will flush them
  68. }
  69. else {
  70. if (!collapsing) {
  71. // If we are leaving micro mode (expanding), we do that first so that the
  72. // text of the items in the navlist will be revealed by the animation.
  73. navigationList.setMicro(false);
  74. }
  75. navigationList.canMeasure = false;
  76. // Start this layout first since it does not require a layout
  77. refs.mainLogo.animate({dynamic: true, to: {width: new_width}});
  78. // Directly adjust the width config and then run the main wrap container layout
  79. // as the root layout (it and its chidren). This will cause the adjusted size to
  80. // be flushed to the element and animate to that new size.
  81. navigationList.width = new_width;
  82. wrapContainer.updateLayout({isRoot: true});
  83. navigationList.el.addCls('nav-tree-animating');
  84. // We need to switch to micro mode on the navlist *after* the animation (this
  85. // allows the "sweep" to leave the item text in place until it is no longer
  86. // visible.
  87. if (collapsing) {
  88. navigationList.on({
  89. afterlayoutanimation: function () {
  90. navigationList.setMicro(true);
  91. navigationList.el.removeCls('nav-tree-animating');
  92. navigationList.canMeasure = true;
  93. },
  94. single: true
  95. });
  96. }
  97. }
  98. },
  99. });