login.js
上传用户:snow1005
上传日期:2015-11-10
资源大小:3151k
文件大小:4k
源码类别:

Ajax

开发平台:

JavaScript

  1. Ext.onReady(function(){
  2. Ext.EventManager.onWindowResize(centerPanel);
  3. var loginPanel = Ext.get("qo-login-panel");
  4. var loginBtn = Ext.get("submitBtn");
  5. loginBtn.on({
  6. 'click': { fn: login }
  7. , 'mouseover': { fn: function(){ loginBtn.addClass('qo-login-submit-over'); } }
  8. , 'mouseout': { fn: function(){ loginBtn.removeClass('qo-login-submit-over'); } }
  9. });
  10. Ext.get("field3-label").setDisplayed('none');
  11. Ext.get("field3").setDisplayed('none');
  12. centerPanel();
  13. function centerPanel(){
  14. var xy = loginPanel.getAlignToXY(document, 'c-c');
  15. positionPanel(loginPanel, xy[0], xy[1]);
  16. }
  17. function hideLoginFields(){
  18. Ext.get("field1-label").setDisplayed('none');
  19. Ext.get("field1").setDisplayed('none');
  20. Ext.get("field2-label").setDisplayed('none');
  21. Ext.get("field2").setDisplayed('none');
  22. }
  23. function loadGroupField(d){
  24. var combo = Ext.get("field3");
  25. var comboEl = combo.dom;
  26. while(comboEl.options.length){
  27. comboEl.options[0] = null;
  28. }
  29. for(var i = 0, len = d.length; i < len; i++){
  30. comboEl.options[i] = new Option(d[i][1], d[i][0]);
  31. }
  32. }
  33. function login(){
  34. var emailField = Ext.get("field1");
  35. var email = emailField.dom.value;
  36. var pwdField = Ext.get("field2");
  37. var pwd = pwdField.dom.value;
  38. var groupField = Ext.get("field3");
  39. var group = groupField.dom.value;
  40. if(validate(email) === false){
  41. alert("Your email address is required");
  42. return false;
  43. }
  44. if(validate(pwd) === false){
  45. alert("Your password is required");
  46. return false;
  47. }
  48. loginPanel.mask('Please wait...', 'x-mask-loading');
  49. Ext.Ajax.request({
  50. url: 'system/login/login.php'
  51. , params: {
  52. module: 'login'
  53. , user: email
  54. , pass: pwd
  55. , group: group
  56. }
  57. , success: function(o){
  58. loginPanel.unmask();
  59. if(typeof o == 'object'){
  60. var d = Ext.decode(o.responseText);
  61. if(typeof d == 'object'){
  62. if(d.success == true){
  63. var g = d.groups;
  64. if(g && g.length > 0){
  65. hideLoginFields();
  66. showGroupField();
  67. var d = [];
  68. for(var i = 0, len = g.length; i < len; i++){
  69. d.push([g[i].id, g[i].name]);
  70. }
  71. loadGroupField(d);
  72. }else if(d.sessionId !== ""){
  73. loginPanel.mask('Redirecting...', 'x-mask-loading');
  74. // get the path
  75. var path = window.location.pathname,
  76. path = path.substring(0, path.lastIndexOf('/') + 1);
  77. // set the cookie
  78. set_cookie('sessionId', d.sessionId, '', path, '', '' );
  79. // redirect the window
  80. window.location = path;
  81. }
  82. }else{
  83. if(d.errors && d.errors[0].msg){
  84. alert(d.errors[0].msg);
  85. }else{
  86. alert('Errors encountered on the server.');
  87. }
  88. }
  89. }
  90. }
  91. }
  92. , failure: function(){
  93. loginPanel.unmask();
  94. alert('Lost connection to server.');
  95. }
  96. });
  97. }
  98. function positionPanel(el, x, y){
  99.         if(x && typeof x[1] == 'number'){
  100.             y = x[1];
  101.             x = x[0];
  102.         }
  103.         el.pageX = x;
  104.         el.pageY = y;
  105.        
  106.         if(x === undefined || y === undefined){ // cannot translate undefined points
  107.             return;
  108.         }
  109.         
  110.         if(y < 0){ y = 10; }
  111.         
  112.         var p = el.translatePoints(x, y);
  113.         el.setLocation(p.left, p.top);
  114.         return el;
  115.     }
  116.     
  117.     function showGroupField(){
  118. Ext.get("field3-label").setDisplayed(true);
  119. Ext.get("field3").setDisplayed(true);
  120. }
  121.     
  122.     function validate(field){
  123. if(field === ""){
  124. //field.markInvalid();
  125. return false;
  126. }
  127. return true;
  128. }
  129. });