Ext.ux.SpringSecurityLoginWindow.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Ext.namespace("Ext.lingo");
  2. SpringSecurityLoginWindow = Ext.extend(Ext.Window, {
  3. title: '登陆',
  4. width: 265,
  5. height: 240,
  6. collapsible: true,
  7. closable: false,
  8. modal: true,
  9. defaults: {
  10. border: false
  11. },
  12. buttonAlign: 'center',
  13. listeners: {
  14. show: function() {
  15. Ext.getDom('captcha').src = 'captcha.jpg?' + new Date().getTime();
  16. }
  17. },
  18. createFormPanel: function() {
  19. return new Ext.form.FormPanel({
  20. bodyStyle: 'padding-top:6px',
  21. defaultType: 'textfield',
  22. labelAlign: 'right',
  23. labelWidth: 60,
  24. labelPad: 0,
  25. frame: true,
  26. defaults: {
  27. allowBlank: false,
  28. width: 158,
  29. selectOnFocus: true
  30. },
  31. items: [{
  32. cls: 'user',
  33. name: 'j_username',
  34. fieldLabel: '用户名',
  35. blankText: '用户名不能为空'
  36. },{
  37. cls: 'key',
  38. name: 'j_password',
  39. fieldLabel: '密 码',
  40. blankText: '密码不能为空',
  41. inputType: 'password'
  42. },{
  43. xtype: 'checkbox',
  44. name: '_spring_security_remember_me',
  45. fieldLabel: '记住信息'
  46. },{
  47. name: '_captcha_parameter',
  48. fieldLabel: '验证码'
  49. },{
  50. xtype: 'panel',
  51. anchor: '100%',
  52. bodyStyle: 'text-align:right;padding-right: 20px;',
  53. html: '<img id="captcha" src="captcha.jpg" title="点击刷新图片" alt="点击刷新图片" onclick="document.getElementById(\'captcha\').src=\'captcha.jpg?\' + new Date().getTime();this.blur();" style="cursor:pointer;border:0px;"><br><a onclick="document.getElementById(\'captcha\').src=\'captcha.jpg?\' + new Date().getTime();this.blur();" href="javascript:void(0);">刷新图片</a>'
  54. }]
  55. });
  56. },
  57. login: function() {
  58. if (this.formPanel.form.isValid()) {
  59. this.formPanel.form.submit({
  60. waitTitle: "请稍候",
  61. waitMsg : '正在登录......',
  62. url: this.url + '?' + new Date(),
  63. success: function(form, action) {
  64. this.hide();
  65. if (this.callback) {
  66. this.callback.call(this, action.result);
  67. }
  68. },
  69. failure: function(form, action) {
  70. if (action.failureType == Ext.form.Action.SERVER_INVALID) {
  71. Ext.MessageBox.alert('错误', action.result.errors.msg);
  72. }
  73. Ext.getDom('captcha').src = 'captcha.jpg?' + new Date().getTime();
  74. form.findField("j_password").setRawValue("");
  75. form.findField("j_username").focus(true);
  76. },
  77. scope: this
  78. });
  79. }
  80. },
  81. initComponent : function(){
  82. this.keys = {
  83. key: Ext.EventObject.ENTER,
  84. fn: this.login,
  85. scope: this
  86. };
  87. LoginWindow.superclass.initComponent.call(this);
  88. this.formPanel = this.createFormPanel();
  89. this.add(this.formPanel);
  90. this.addButton('登陆', this.login, this);
  91. this.addButton('重填', function() {
  92. this.formPanel.getForm().reset();
  93. }, this);
  94. }
  95. });