change-name.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //评卷状态模块
  2. var change_name = function(option, success) {
  3. var object = new ChangeName(option);
  4. success();
  5. return object;
  6. }
  7. function ChangeName(option) {
  8. this.markControl = option.markControl;
  9. this.url = option.url;
  10. this.context = option.markControl.context;
  11. this.userName = option.markControl.container.header.find('#mark-user-name');
  12. this.popover = getDom(this.popover_dom, this.markControl);
  13. this.popover.userNameInput = this.popover.find('input.username-input');
  14. this.popover.passwordInput = this.popover.find('input.password-input');
  15. this.popover.password2Input = this.popover.find('input.password2-input');
  16. this.popover.userNameMessage = this.popover.find('i.username');
  17. this.popover.password2Message = this.popover.find('i.password2');
  18. this.popover.submitButton = this.popover.find('a.btn');
  19. this.popover.cancelButton = this.popover.find('p.image-close');
  20. this.popover.appendTo(this.markControl.container);
  21. var self = this;
  22. this.markControl.container.header.find('a.useinfo').click(function() {
  23. self.toggle(true);
  24. });
  25. this.popover.cancelButton.click(function() {
  26. self.toggle(false);
  27. });
  28. this.popover.submitButton.click(function() {
  29. var logout = false;
  30. var nameText = self.popover.userNameInput.val();
  31. nameText = nameText.replace(/(^\s*)|(\s*$)/g, "");
  32. var pwText = self.popover.passwordInput.val();
  33. pwText = pwText.replace(/(^\s*)|(\s*$)/g, "");
  34. var pw2Text = self.popover.password2Input.val();
  35. pw2Text = pw2Text.replace(/(^\s*)|(\s*$)/g, "");
  36. if (nameText.length == 0) {
  37. self.popover.userNameMessage.html(getMessage("mark.change.name.null"));
  38. return false;
  39. } else if (nameText.length > 8) {
  40. self.popover.userNameMessage.html(getMessage("mark.change.name.length"));
  41. return false;
  42. }
  43. if(pwText.length > 0 || pw2Text.length > 0) {
  44. logout = true;
  45. if (!pw2Text) {
  46. self.popover.password2Message.html(getMessage("mark.change.press.password.again"));
  47. return false;
  48. }
  49. if (pwText != pw2Text) {
  50. self.popover.password2Message.html(getMessage("mark.change.password.same"));
  51. return false;
  52. }
  53. if(pw2Text.length < 4){
  54. self.popover.password2Message.html(getMessage("mark.change.password.length"));
  55. return false;
  56. }
  57. }
  58. $.post(self.url, {
  59. name: nameText,
  60. password:pwText
  61. }, function(result) {
  62. if (result.success == true) {
  63. self.userName.html(result.name);
  64. self.toggle(false);
  65. if(logout){//修改密码后请重新登陆
  66. window.location.href = '/mark/logout';
  67. }
  68. } else {
  69. self.popover.userNameMessage.html(getMessage("mark.change.error"));
  70. }
  71. }).error(function() {
  72. self.popover.userNameMessage.html(getMessage("mark.change.network.error"));
  73. });
  74. });
  75. }
  76. ChangeName.prototype.toggle = function(enable) {
  77. if (enable == true) {
  78. this.enable = true;
  79. this.popover.userNameInput.val(this.userName.html());
  80. this.popover.passwordInput.val('');
  81. this.popover.userNameMessage.html('');
  82. this.popover.password2Message.html('');
  83. this.popover.show();
  84. this.context.listenKeyboard = false;
  85. } else {
  86. this.enable = false;
  87. this.popover.hide();
  88. this.context.listenKeyboard = true;
  89. }
  90. }
  91. ChangeName.prototype.popover_dom = '<div class="message-popover" style="display:none"><div class="popover-header">\
  92. <p class="title" data-i18n-text="mark.change.name">修改个人信息</p><p class="image-close"><img src="{staticServer}/mark-new/images/images-close.png" /></p></div>\
  93. <div class="popover-cont"><span style="color: red;">*</span><input type="text" class="username-input" placeholder="请输入您的姓名" data-i18n-placeholder="mark.change.press.name"/>\
  94. <i class="wrong username"></i></div>\
  95. <div class="popover-cont"><input type="password" class="password-input" placeholder="请输入新的密码" data-i18n-placeholder="mark.change.press.password"/>\
  96. <i class="wrong password"></i></div>\
  97. <div class="popover-cont"><input type="password" class="password2-input" placeholder="请再次输入您的密码" data-i18n-placeholder="mark.change.press.password.again"/> \
  98. <i class="wrong password2"></i></div>\
  99. <a href="#" class="btn btn-small btn-info text-userInfo" data-i18n-text="mark.change.confirm">确定</a>\
  100. </div>';