LoginWindow.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. Ext.namespace("Ext.ux");
  2. Ext.ux.LoginWindow = Ext.extend(Ext.Window, {
  3. title: '登陆',
  4. width: 265,
  5. height: 140,
  6. collapsible: true,
  7. closable: false,
  8. modal: true,
  9. defaults: {
  10. border: false
  11. },
  12. buttonAlign: 'center',
  13. initComponent : function(){
  14. this.keys = {
  15. key: Ext.EventObject.ENTER,
  16. fn: this.login,
  17. scope: this
  18. };
  19. Ext.ux.LoginWindow.superclass.initComponent.call(this);
  20. this.formPanel = this.createFormPanel();
  21. this.add(this.formPanel);
  22. this.addButton('登陆', this.login, this);
  23. this.addButton('重填', function() {
  24. this.formPanel.getForm().reset();
  25. }, this);
  26. var form = this.formPanel.getForm();
  27. var fn = function() {
  28. //form.suspendEvents();
  29. form.findField('j_username').focus();
  30. //form.resumeEvents();
  31. }
  32. this.on('show', function() {
  33. setTimeout(fn, 200);
  34. }, this);
  35. },
  36. createFormPanel: function() {
  37. return new Ext.form.FormPanel({
  38. bodyStyle: 'padding-top:6px',
  39. defaultType: 'textfield',
  40. labelAlign: 'right',
  41. labelWidth: 55,
  42. labelPad: 0,
  43. frame: true,
  44. defaults: {
  45. allowBlank: false,
  46. width: 158,
  47. selectOnFocus: true
  48. },
  49. items: [{
  50. cls: 'login-username',
  51. name: 'j_username',
  52. fieldLabel: '用户名',
  53. blankText: '用户名不能为空'
  54. },{
  55. cls: 'login-password',
  56. name: 'j_password',
  57. fieldLabel: '密 码',
  58. blankText: '密码不能为空',
  59. inputType: 'password'
  60. }]
  61. });
  62. },
  63. login: function() {
  64. if (this.formPanel.form.isValid()) {
  65. this.formPanel.form.submit({
  66. waitTitle: "请稍候",
  67. waitMsg : '正在登录......',
  68. url: this.url,
  69. success: function(form, action) {
  70. this.hide();
  71. if (this.callback) {
  72. this.callback.call(this, action.result);
  73. }
  74. },
  75. failure: function(form, action) {
  76. if (action.failureType == Ext.form.Action.SERVER_INVALID) {
  77. Ext.Msg.alert('错误', action.result.errors.msg);
  78. }
  79. form.findField("j_password").setRawValue("");
  80. form.findField("j_username").focus(true);
  81. },
  82. scope:this
  83. });
  84. }
  85. }
  86. });