MainController.js 4.2 KB

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