MainController.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. if(items.length > 1) {
  26. companyMenu.insert(0, items);
  27. viewModel.set('hasManyCompany', true);
  28. }else {
  29. viewModel.set('hasManyCompany', false);
  30. }
  31. },
  32. onToggleNavigationSize: function () {
  33. var me = this,
  34. viewModel = me.getViewModel(),
  35. refs = me.getReferences(),
  36. navigationList = refs.navigationTreeList,
  37. navCollapsed = !navigationList.navCollapsed,
  38. new_width = navCollapsed ? viewModel.get('smallNavWidth') : viewModel.get('navWidth'),
  39. newLogoImgStyle = navCollapsed ? { width: 36, height: 36, top: 12, left: 12 } : { width: 32, height: 32, top: 16, left: 28 },
  40. newLogoTextStyle = navCollapsed ? {
  41. 5: { opacity: 0 },
  42. 10: { opacity: 0 },
  43. 100: { opacity: 0, display: 'none' }
  44. } : {
  45. 10: { opacity: 0 },
  46. 50: { opacity: 1 }
  47. },
  48. newNavIconStyle = navCollapsed ? { marginLeft: 6, fontSize: 28 } : { marginLeft: 22, fontSize: 24 },
  49. newNavTextStyle = navCollapsed ? { opacity: 0 } : { opacity: 1 },
  50. ope = navCollapsed ? 'addCls' : 'removeCls',
  51. toggleIconCls = navCollapsed ? 'sa-arrows-right' : 'sa-arrows-left';
  52. var mainLogo = refs.mainLogo;
  53. var logoImg = mainLogo.el.dom.getElementsByTagName('img')[0];
  54. var logoText = mainLogo.el.dom.getElementsByClassName('logo-text')[0];
  55. var navItems = navigationList.el.dom.getElementsByClassName('x-navitem');
  56. var toggleIcon = Ext.getCmp('main-navigation-toggle-btn');
  57. Ext.suspendLayouts();
  58. toggleIcon.setIconCls('x-sa ' + toggleIconCls);
  59. mainLogo.animate({dynamic: true, duration: 500, to: {width: new_width}});
  60. Ext.fly(logoImg).animate({dynamic: true, duration: 500, to: newLogoImgStyle});
  61. Ext.fly(logoText).animate({dynamic: true, duration: 500, keyframes: newLogoTextStyle});
  62. navigationList.body.animate({dynamic: true, duration: 500, to: {width: new_width}});
  63. navigationList.animate({dynamic: true, duration: 500, to: {width: new_width}});
  64. for(var i = 0; i < navItems.length; i++) {
  65. var item = navItems[i];
  66. var icon = item.getElementsByClassName('nav-inner-icon')[0];
  67. var text = item.getElementsByClassName('nav-inner-text')[0];
  68. Ext.fly(icon).animate({dynamic: true, duration: 500, to: newNavIconStyle});
  69. Ext.fly(text).animate({dynamic: true, duration: 500, to: newNavTextStyle});
  70. }
  71. navigationList.el[ope]('nav-collapsed');
  72. navigationList.navCollapsed = navCollapsed;
  73. Ext.resumeLayouts(true);
  74. },
  75. selectCompany: function(item) {
  76. this.fireEvent('selectCompany', item.value);
  77. },
  78. onLogout: function() {
  79. this.fireEvent('logout');
  80. },
  81. feedbackMsg:function(btn){
  82. var me = this,
  83. win = Ext.getCmp("feedbackWin");
  84. if (!win) {
  85. win = Ext.create('Ext.window.Window', {
  86. modal: true,
  87. draggable: false,
  88. resizable: false,
  89. id:"feedbackWin",
  90. height: 343,
  91. width: 756,
  92. title: '意见反馈',
  93. scrollable: true,
  94. constrain: true,
  95. closable: true,
  96. layout: 'fit',
  97. items: [{
  98. xtype: 'sys-feedback-formpanel'
  99. }]
  100. });
  101. };
  102. win.show();
  103. }
  104. });