MainController.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. refs = me.getReferences(),
  30. navigationList = refs.navigationTreeList,
  31. navCollapsed = !navigationList.navCollapsed,
  32. new_width = navCollapsed ? 64 : 160,
  33. ope = navCollapsed ? 'addCls' : 'removeCls';
  34. refs.mainLogo.animate({dynamic: true, to: {width: new_width}});
  35. navigationList.body.animate({dynamic: true, to: {width: new_width}});
  36. navigationList.animate({dynamic: true, to: {width: new_width}});
  37. navigationList.el[ope]('nav-collapsed');
  38. navigationList.navCollapsed = navCollapsed;
  39. },
  40. selectCompany: function(item) {
  41. this.fireEvent('selectCompany', item.value);
  42. },
  43. onLogout: function() {
  44. this.fireEvent('logout');
  45. }
  46. });