personal.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. $(document).ready(function () {
  2. $("#personal-province").change(function (event) {
  3. var province = $(this).val();
  4. var link = $(this).attr('link');
  5. $.ajaxSetup({
  6. headers: {
  7. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  8. }
  9. });
  10. $.ajax({
  11. url: link,
  12. type: 'post',
  13. data: { provinceId: province },
  14. success: function (result) {
  15. if (result != 0) {
  16. var listDistrict = "";
  17. for (var i = 0; i < result.length; i++) {
  18. listDistrict += '<option value="' + result[i]['id'] + '">' + result[i]['name'] + '</option>';
  19. };
  20. $("#personal-district").html(listDistrict);
  21. }
  22. }
  23. })
  24. });
  25. });
  26. var checkChange = 0;
  27. $(document).on('change keyup', '.setting-personal .personal-info .input-text, .setting-personal .personal-info .input-select', function () {
  28. checkChange = 1;
  29. if (checkUpdateInformation()) {
  30. $('.setting-personal .personal-info .setting-button-save').addClass('button-active');
  31. } else {
  32. $('.setting-personal .personal-info .setting-button-save').removeClass('button-active');
  33. }
  34. });
  35. $(document).on('change keyup', '.setting-security .input-text, .setting-security .input-select', function () {
  36. if (checkUpdateEmail()) {
  37. $('.setting-security .setting-button-save').addClass('button-active');
  38. } else {
  39. $('.setting-security .setting-button-save').removeClass('button-active');
  40. }
  41. });
  42. $(document).on('change keyup', '#modal-update-password .input-text, #modal-update-password .input-select', function () {
  43. if (checkUpdatePassword()) {
  44. $('#modal-update-password .setting-button-save').addClass('button-active');
  45. } else {
  46. $('#modal-update-password .setting-button-save').removeClass('button-active');
  47. }
  48. });
  49. $(document).on('change', '.setting-language .radio-input', function () {
  50. $('.setting-language .setting-button-save').addClass('button-active');
  51. });
  52. $(document).on('change', '.setting-sound .radio-input', function () {
  53. $('.setting-sound .setting-button-save').addClass('button-active');
  54. });
  55. $(document).on('change', '.input-select', function () {
  56. $(this).blur();
  57. });
  58. function checkUpdateInformation() {
  59. var name = $("#personal-name").val();
  60. var phone = $("#personal-phone").val();
  61. if (phone.length < 10 || phone.length > 20) {
  62. return false;
  63. }
  64. if (name.length < 2 || name.length > 255) {
  65. return false;
  66. }
  67. if (checkChange == 0) {
  68. return false;
  69. }
  70. return true;
  71. }
  72. function checkUpdateEmail() {
  73. var email = $("#security-email").val();
  74. var emailOld = $("#security-email").attr('valueOld');
  75. if (checkEmail(email) && email != emailOld) {
  76. return true;
  77. }
  78. return false;
  79. }
  80. function checkEmail(email) {
  81. var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  82. return re.test(email);
  83. }
  84. function checkUpdatePassword() {
  85. var oldPassword = $("#old-password").val();
  86. var newPassword = $("#new-password").val();
  87. var confirmPassword = $("#confirm-password").val();
  88. if (oldPassword == undefined || oldPassword.length < 6 || oldPassword.length > 255 || newPassword == undefined || newPassword.length < 6 || newPassword.length > 255) {
  89. return false;
  90. }
  91. if (newPassword != confirmPassword) {
  92. return false;
  93. }
  94. return true;
  95. }
  96. // Confirm email
  97. $(document).on('click', '.setting-security .security-confirm-email .confirm-link', function () {
  98. var button = $(this);
  99. showScreenWaiting();
  100. var link = $(this).attr('link');
  101. $.ajaxSetup({
  102. headers: {
  103. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  104. }
  105. });
  106. $.ajax({
  107. url: link,
  108. type: "POST"
  109. }).success(function (data) {
  110. showNotifyMain(data[1]);
  111. if (data[0] == 1) {
  112. activeConfirmText();
  113. }
  114. }).error(function (data) {
  115. showNotifyMain('Cập nhật thất bại! Vui lĂ²ng tải lại trang.');
  116. }).complete(function () {
  117. hideScreenWaiting();
  118. });
  119. });
  120. function activeConfirmText() {
  121. var button = $('.setting-security .security-confirm-email .confirm-link');
  122. if (button.length > 0) {
  123. var textComfirm = $(button).attr('comfirmText');
  124. $(button).fadeOut(function () {
  125. $(button).parent(".security-confirm-email").addClass('email-send');
  126. $(button).parent(".security-confirm-email").text(textComfirm);
  127. $(button).remove();
  128. });
  129. }
  130. }
  131. $(document).on('click', '#button-update-email', function () {
  132. if (checkUpdateEmail()) {
  133. $(this).removeClass('button-active');
  134. showScreenWaiting();
  135. var link = $(this).attr('link');
  136. var email = $("#security-email").val();
  137. $.ajaxSetup({
  138. headers: {
  139. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  140. }
  141. });
  142. $.ajax({
  143. url: link,
  144. data: {
  145. reset_email: email
  146. },
  147. type: "POST"
  148. }).success(function (data) {
  149. showNotifyMain(data[1]);
  150. if (data[0] == 1) {
  151. $("#security-email").attr('valueOld', email);
  152. activeConfirmText();
  153. } else {
  154. $("#security-email").val($("#security-email").attr('valueOld'));
  155. }
  156. }).error(function (data) {
  157. showNotifyMain('Cập nhật thất bại! Vui lĂ²ng tải lại trang.');
  158. }).complete(function () {
  159. hideScreenWaiting();
  160. });
  161. }
  162. });
  163. $(document).on("click", "#modal-update-password .setting-button-save.button-active", function () {
  164. console.log('setting-button-save click');
  165. //if (checkUpdatePassword()) {
  166. // var password = $('#new-password').val();
  167. // var fullname = $('#personal-name').val();
  168. // var phone = $('#personal-phone').val();
  169. // var birthday = $('#personal-birthday').val();
  170. // $.ajax({
  171. // url: urlConfig("/Home/UpdateProfile"),
  172. // type: "POST",
  173. // data: {
  174. // __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val(),
  175. // fullname: fullname,
  176. // phone: phone,
  177. // birthday: birthday,
  178. // }
  179. // }).success(function (data) {
  180. // if (data.error_code != "0") {
  181. // // fail
  182. // $('#message-dialog').modal('show');
  183. // $('#message-content').html(data.error_content);
  184. // } else {
  185. // console.log(data.error_content);
  186. // if (data.href != null) {
  187. // location.href = data.href;
  188. // } else {
  189. // location.reload();
  190. // }
  191. // }
  192. // });
  193. //}
  194. });