MainController.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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('school.view.main.MainController', {
  6. extend: 'Ext.app.ViewController',
  7. alias: 'controller.main',
  8. onToggleNavigationSize: function () {
  9. var me = this,
  10. viewModel = me.getViewModel(),
  11. refs = me.getReferences(),
  12. navigationList = refs.navigationTreeList,
  13. navCollapsed = !navigationList.navCollapsed,
  14. new_width = navCollapsed ? viewModel.get('smallNavWidth') : viewModel.get('navWidth'),
  15. newLogoImgStyle = navCollapsed ? { width: 51, height: 32, top: 8, left: 6 } : { width: 45, height: 30, top: 10, left: 10 },
  16. newLogoTextStyle = navCollapsed ? {
  17. 0: { opacity: 0 },
  18. 70: { opacity: 0 }
  19. } : {
  20. 10: { opacity: 0 },
  21. 90: { opacity: 1 }
  22. },
  23. newNavIconStyle = navCollapsed ? { marginLeft: 6, fontSize: 28 } : { marginLeft: 16, fontSize: 24 },
  24. newNavTextStyle = navCollapsed ? { opacity: 0 } : { opacity: 1 },
  25. ope = navCollapsed ? 'addCls' : 'removeCls',
  26. toggleIconCls = navCollapsed ? 'sa-arrows-right' : 'sa-arrows-left';
  27. var mainLogo = refs.mainLogo;
  28. var logoImg = mainLogo.el.dom.getElementsByTagName('img')[0];
  29. var logoText = mainLogo.el.dom.getElementsByClassName('logo-text')[0];
  30. var navItems = navigationList.el.dom.getElementsByClassName('x-navitem');
  31. var toggleIcon = Ext.getCmp('main-navigation-toggle-btn');
  32. Ext.suspendLayouts();
  33. toggleIcon.setIconCls('x-sa ' + toggleIconCls);
  34. mainLogo.animate({dynamic: true, duration: 500, to: {width: new_width}});
  35. Ext.fly(logoImg).animate({dynamic: true, duration: 500, to: newLogoImgStyle});
  36. Ext.fly(logoText).animate({dynamic: true, duration: 500, keyframes: newLogoTextStyle});
  37. navigationList.body.animate({dynamic: true, duration: 500, to: {width: new_width}});
  38. navigationList.animate({dynamic: true, duration: 500, to: {width: new_width}});
  39. for(var i = 0; i < navItems.length; i++) {
  40. var item = navItems[i];
  41. var icon = item.getElementsByClassName('nav-inner-icon')[0];
  42. var text = item.getElementsByClassName('nav-inner-text')[0];
  43. Ext.fly(icon).animate({dynamic: true, duration: 500, to: newNavIconStyle});
  44. Ext.fly(text).animate({dynamic: true, duration: 500, to: newNavTextStyle});
  45. }
  46. navigationList.el[ope]('nav-collapsed');
  47. navigationList.navCollapsed = navCollapsed;
  48. Ext.resumeLayouts(true);
  49. },
  50. onResetPassword: function() {
  51. var win = Ext.getCmp('resetpassword');
  52. if(!win) {
  53. win = Ext.create('Ext.window.Window', {
  54. title: '修改密码',
  55. width: 400,
  56. height: 260,
  57. padding: 20,
  58. modal: true,
  59. items: [{
  60. xtype: 'form',
  61. items: [{
  62. xtype: 'textfield',
  63. cls: 'auth-textbox',
  64. fieldLabel: '新密码',
  65. emptyText: '请输入新密码',
  66. inputType: 'password',
  67. name: 'password1',
  68. allowBlank : false,
  69. listeners: {
  70. change: function(field) {
  71. var form = field.up('form'),
  72. field2 = form.getForm().findField('password2');
  73. field2.isValid();
  74. }
  75. }
  76. }, {
  77. xtype: 'textfield',
  78. cls: 'auth-textbox',
  79. fieldLabel: '新密码确认',
  80. emptyText: '请再次输入新密码',
  81. inputType: 'password',
  82. name: 'password2',
  83. allowBlank : false,
  84. validator: function (val) {
  85. var field = this,
  86. form = field.up('form'),
  87. field1 = form.getForm().findField('password1'),
  88. value1 = field1.getValue();
  89. var errMsg = "两次输入密码不一致";
  90. return (value1 == val) ? true : errMsg;
  91. }
  92. }],
  93. bbar: ['->', {
  94. xtype: 'button',
  95. text: '确认修改',
  96. formBind: true,
  97. handler: function(btn) {
  98. var window = btn.up('window'),
  99. form = window.down('form'),
  100. values = form.getValues(),
  101. userId = school.util.BaseUtil.getCurrentUser().id;
  102. window.setLoading(true);
  103. school.util.BaseUtil.request({
  104. url: '/api/account/account/password/reset?password=' + values.password1 + '&userId=' + userId,
  105. method: 'POST',
  106. }).then(function(res) {
  107. window.setLoading(false);
  108. school.util.BaseUtil.showSuccessToast('修改密码成功');
  109. }).catch(function(e) {
  110. window.setLoading(false);
  111. school.util.BaseUtil.showErrorToast('修改密码失败: ' + e.message);
  112. });
  113. }
  114. }, '->']
  115. }]
  116. });
  117. }
  118. win.show();
  119. },
  120. onLogout: function() {
  121. this.fireEvent('logout');
  122. }
  123. });