MainController.js 4.2 KB

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