You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
4.1 KiB

  1. define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
  2. var validatoroptions = {
  3. invalid: function (form, errors) {
  4. $.each(errors, function (i, j) {
  5. Layer.msg(j);
  6. });
  7. }
  8. };
  9. var Controller = {
  10. login: function () {
  11. //本地验证未通过时提示
  12. $("#login-form").data("validator-options", validatoroptions);
  13. $(document).on("change", "input[name=type]", function () {
  14. var type = $(this).val();
  15. $("div.form-group[data-type]").addClass("hide");
  16. $("div.form-group[data-type='" + type + "']").removeClass("hide");
  17. $('#resetpwd-form').validator("setField", {
  18. captcha: "required;length(4);integer[+];remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")",
  19. });
  20. $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type);
  21. });
  22. //为表单绑定事件
  23. Form.api.bindevent($("#login-form"), function (data, ret) {
  24. setTimeout(function () {
  25. location.href = ret.url ? ret.url : "/";
  26. }, 1000);
  27. });
  28. Form.api.bindevent($("#resetpwd-form"), function (data) {
  29. Layer.closeAll();
  30. });
  31. $(document).on("click", ".btn-forgot", function () {
  32. var id = "resetpwdtpl";
  33. var content = Template(id, {});
  34. Layer.open({
  35. type: 1,
  36. title: __('Reset password'),
  37. area: ["450px", "355px"],
  38. content: content,
  39. success: function (layero) {
  40. Form.api.bindevent($("#resetpwd-form", layero), function (data) {
  41. Layer.closeAll();
  42. });
  43. }
  44. });
  45. });
  46. },
  47. register: function () {
  48. //本地验证未通过时提示
  49. $("#register-form").data("validator-options", validatoroptions);
  50. //为表单绑定事件
  51. Form.api.bindevent($("#register-form"), function (data, ret) {
  52. setTimeout(function () {
  53. location.href = ret.url ? ret.url : "/";
  54. }, 1000);
  55. }, function (data) {
  56. $("input[name=captcha]").next(".input-group-addon").find("img").trigger("click");
  57. });
  58. },
  59. changepwd: function () {
  60. //本地验证未通过时提示
  61. $("#changepwd-form").data("validator-options", validatoroptions);
  62. //为表单绑定事件
  63. Form.api.bindevent($("#changepwd-form"), function (data, ret) {
  64. setTimeout(function () {
  65. location.href = ret.url ? ret.url : "/";
  66. }, 1000);
  67. });
  68. },
  69. profile: function () {
  70. // 给上传按钮添加上传成功事件
  71. $("#plupload-avatar").data("upload-success", function (data) {
  72. var url = Fast.api.cdnurl(data.url);
  73. $(".profile-user-img").prop("src", url);
  74. Toastr.success(__('Upload successful'));
  75. });
  76. Form.api.bindevent($("#profile-form"));
  77. $(document).on("click", ".btn-change", function () {
  78. var that = this;
  79. var id = $(this).data("type") + "tpl";
  80. var content = Template(id, {});
  81. Layer.open({
  82. type: 1,
  83. title: "修改",
  84. area: ["400px", "250px"],
  85. content: content,
  86. success: function (layero) {
  87. var form = $("form", layero);
  88. Form.api.bindevent(form, function (data) {
  89. location.reload();
  90. Layer.closeAll();
  91. });
  92. }
  93. });
  94. });
  95. }
  96. };
  97. return Controller;
  98. });