MainController.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. init: function() {
  9. this.setCompanyMenu();
  10. },
  11. setCompanyMenu: function() {
  12. var me = this, view = me.getView(), viewModel = me.getViewModel(),
  13. account = viewModel.get('account'), companies = account && account.companies,
  14. companyMenu = view.lookup('mainprofile').getMenu(), items = [];
  15. if (companies) {
  16. items = companies.map(function(c){
  17. return {
  18. text: c.name,
  19. value: c.id,
  20. handler: 'selectCompany',
  21. iconCls: c.id == account.companyId ? 'x-fa fa-check' : ''
  22. }
  23. });
  24. }
  25. companyMenu.insert(0, items);
  26. },
  27. onToggleNavigationSize: function () {
  28. var me = this,
  29. viewModel = me.getViewModel(),
  30. refs = me.getReferences(),
  31. navigationList = refs.navigationTreeList,
  32. navCollapsed = !navigationList.navCollapsed,
  33. new_width = navCollapsed ? viewModel.get('smallNavWidth') : viewModel.get('navWidth'),
  34. newLogoImgStyle = navCollapsed ? {
  35. width: 50,
  36. top: 7,
  37. left: 6
  38. } : {
  39. width: 64,
  40. top: 0,
  41. left: 20
  42. },
  43. newLogoTextStyle = navCollapsed ? {
  44. 10: {
  45. opacity: 0.7
  46. },
  47. 30: {
  48. opacity: 0
  49. },
  50. 100: {
  51. opacity: 0
  52. }
  53. } : {
  54. 25: {
  55. opacity: 0
  56. },
  57. 50: {
  58. opacity: 1
  59. }
  60. },
  61. newNavIconStyle = navCollapsed ? {
  62. marginLeft: 6,
  63. fontSize: 28
  64. } : {
  65. marginLeft: 40,
  66. fontSize: 24
  67. },
  68. newNavTextStyle = navCollapsed ? {
  69. opacity: 0
  70. } : {
  71. opacity: 1
  72. },
  73. ope = navCollapsed ? 'addCls' : 'removeCls';
  74. var mainLogo = refs.mainLogo;
  75. var logoImg = mainLogo.el.dom.getElementsByTagName('img')[0];
  76. var logoText = mainLogo.el.dom.getElementsByClassName('logo-text')[0];
  77. var navItems = navigationList.el.dom.getElementsByClassName('x-navitem');
  78. mainLogo.animate({dynamic: true, duration: 500, to: {width: new_width}});
  79. Ext.fly(logoImg).animate({dynamic: true, duration: 500, to: newLogoImgStyle});
  80. Ext.fly(logoText).animate({dynamic: true, duration: 500, keyframes: newLogoTextStyle});
  81. navigationList.body.animate({dynamic: true, duration: 500, to: {width: new_width}});
  82. navigationList.animate({dynamic: true, duration: 500, to: {width: new_width}});
  83. for(var i = 0; i < navItems.length; i++) {
  84. var item = navItems[i];
  85. var icon = item.getElementsByClassName('nav-inner-icon')[0];
  86. var text = item.getElementsByClassName('nav-inner-text')[0];
  87. Ext.fly(icon).animate({dynamic: true, duration: 500, to: newNavIconStyle});
  88. Ext.fly(text).animate({dynamic: true, duration: 500, to: newNavTextStyle});
  89. }
  90. navigationList.el[ope]('nav-collapsed');
  91. navigationList.navCollapsed = navCollapsed;
  92. },
  93. selectCompany: function(item) {
  94. this.fireEvent('selectCompany', item.value);
  95. },
  96. onLogout: function() {
  97. this.fireEvent('logout');
  98. }
  99. });