Ext.ux.LoginWindow.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Ext.namespace("Ext.lingo");
  2. 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. createFormPanel: function() {
  14. return new Ext.form.FormPanel({
  15. bodyStyle: 'padding-top:6px',
  16. defaultType: 'textfield',
  17. labelAlign: 'right',
  18. labelWidth: 55,
  19. labelPad: 0,
  20. frame: true,
  21. defaults: {
  22. allowBlank: false,
  23. width: 158,
  24. selectOnFocus: true
  25. },
  26. items: [{
  27. cls: 'user',
  28. name: 'j_username',
  29. fieldLabel: '用户名',
  30. blankText: '用户名不能为空'
  31. },{
  32. cls: 'key',
  33. name: 'j_password',
  34. fieldLabel: '密 码',
  35. blankText: '密码不能为空',
  36. inputType: 'password'
  37. }]
  38. });
  39. },
  40. login: function() {
  41. if (this.formPanel.form.isValid()) {
  42. this.formPanel.form.submit({
  43. waitTitle: "请稍候",
  44. waitMsg : '正在登录......',
  45. url: this.url,
  46. success: function(form, action) {
  47. this.hide();
  48. if (this.callback) {
  49. this.callback.call(this, action.result);
  50. }
  51. },
  52. failure: function(form, action) {
  53. if (action.failureType == Ext.form.Action.SERVER_INVALID) {
  54. Ext.MessageBox.alert('错误', action.result.errors.msg);
  55. }
  56. form.findField("j_password").setRawValue("");
  57. form.findField("j_username").focus(true);
  58. },
  59. scope:this
  60. });
  61. }
  62. },
  63. initComponent : function(){
  64. this.keys = {
  65. key: Ext.EventObject.ENTER,
  66. fn: this.login,
  67. scope: this
  68. };
  69. LoginWindow.superclass.initComponent.call(this);
  70. this.formPanel = this.createFormPanel();
  71. this.add(this.formPanel);
  72. this.addButton('登陆', this.login, this);
  73. this.addButton('重填', function() {
  74. this.formPanel.getForm().reset();
  75. }, this);
  76. }
  77. });