MainController.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. menuItemClick: function(view, record, item, index, e, eOpts) {
  15. var me = this,
  16. target = e.target,
  17. clsName = target.className;
  18. debugger;
  19. return;
  20. if(clsName == 'item-text') {
  21. me.setActiveTab(record);
  22. }
  23. },
  24. setActiveTab: function(nodeData) {
  25. var me = this,
  26. refs = me.getReferences(),
  27. mainTab = refs.mainTabPanel,
  28. // existingItem = mainTab.child(type),
  29. newView,
  30. id = 'maintab-' + nodeData.id,
  31. title = nodeData.text;
  32. existingItem = mainTab.down('[id=' + id + ']'),
  33. lastView = mainTab.getActiveTab();
  34. if (!existingItem) {
  35. newView = Ext.create('saas.view.core.tab.Panel', {
  36. id: id,
  37. title: title,
  38. tabConfig: nodeData
  39. });
  40. }
  41. if (!newView || !newView.isWindow) {
  42. // !newView means we have an existing view, but if the newView isWindow
  43. // we don't add it to the card layout.
  44. if (existingItem) {
  45. // We don't have a newView, so activate the existing view.
  46. if (existingItem !== lastView) {
  47. mainTab.setActiveTab(existingItem);
  48. }
  49. newView = existingItem;
  50. }
  51. else {
  52. // newView is set (did not exist already), so add it and make it the
  53. // activeItem.
  54. Ext.suspendLayouts();
  55. mainTab.setActiveTab(mainTab.add(newView));
  56. Ext.resumeLayouts(true);
  57. }
  58. }
  59. if (newView.isFocusable(true)) {
  60. newView.focus();
  61. }
  62. },
  63. onToggleNavigationSize: function () {
  64. var me = this,
  65. refs = me.getReferences(),
  66. navigationList = refs.navigationTreeList,
  67. wrapContainer = refs.mainContainerWrap,
  68. navCollapsed = !navigationList.navCollapsed,
  69. new_width = navCollapsed ? 64 : 160,
  70. ope = navCollapsed ? 'addCls' : 'removeCls';
  71. refs.mainLogo.animate({dynamic: true, to: {width: new_width}});
  72. navigationList.body.animate({dynamic: true, to: {width: new_width}});
  73. navigationList.animate({dynamic: true, to: {width: new_width}});
  74. navigationList.el[ope]('nav-collapsed');
  75. navigationList.navCollapsed = navCollapsed;
  76. }
  77. });