| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- $(document).ready(function () {
- $("#personal-province").change(function (event) {
- var province = $(this).val();
- var link = $(this).attr('link');
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- $.ajax({
- url: link,
- type: 'post',
- data: { provinceId: province },
- success: function (result) {
- if (result != 0) {
- var listDistrict = "";
- for (var i = 0; i < result.length; i++) {
- listDistrict += '<option value="' + result[i]['id'] + '">' + result[i]['name'] + '</option>';
- };
- $("#personal-district").html(listDistrict);
- }
- }
- })
- });
- });
- var checkChange = 0;
- $(document).on('change keyup', '.setting-personal .personal-info .input-text, .setting-personal .personal-info .input-select', function () {
- checkChange = 1;
- if (checkUpdateInformation()) {
- $('.setting-personal .personal-info .setting-button-save').addClass('button-active');
- } else {
- $('.setting-personal .personal-info .setting-button-save').removeClass('button-active');
- }
- });
- $(document).on('change keyup', '.setting-security .input-text, .setting-security .input-select', function () {
- if (checkUpdateEmail()) {
- $('.setting-security .setting-button-save').addClass('button-active');
- } else {
- $('.setting-security .setting-button-save').removeClass('button-active');
- }
- });
- $(document).on('change keyup', '#modal-update-password .input-text, #modal-update-password .input-select', function () {
- if (checkUpdatePassword()) {
- $('#modal-update-password .setting-button-save').addClass('button-active');
- } else {
- $('#modal-update-password .setting-button-save').removeClass('button-active');
- }
- });
- $(document).on('change', '.setting-language .radio-input', function () {
- $('.setting-language .setting-button-save').addClass('button-active');
- });
- $(document).on('change', '.setting-sound .radio-input', function () {
- $('.setting-sound .setting-button-save').addClass('button-active');
- });
- $(document).on('change', '.input-select', function () {
- $(this).blur();
- });
- function checkUpdateInformation() {
- var name = $("#personal-name").val();
- var phone = $("#personal-phone").val();
- if (phone.length < 10 || phone.length > 20) {
- return false;
- }
- if (name.length < 2 || name.length > 255) {
- return false;
- }
- if (checkChange == 0) {
- return false;
- }
- return true;
- }
- function checkUpdateEmail() {
- var email = $("#security-email").val();
- var emailOld = $("#security-email").attr('valueOld');
- if (checkEmail(email) && email != emailOld) {
- return true;
- }
- return false;
- }
- function checkEmail(email) {
- 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,}))$/;
- return re.test(email);
- }
- function checkUpdatePassword() {
- var oldPassword = $("#old-password").val();
- var newPassword = $("#new-password").val();
- var confirmPassword = $("#confirm-password").val();
- if (oldPassword == undefined || oldPassword.length < 6 || oldPassword.length > 255 || newPassword == undefined || newPassword.length < 6 || newPassword.length > 255) {
- return false;
- }
- if (newPassword != confirmPassword) {
- return false;
- }
- return true;
- }
- // Confirm email
- $(document).on('click', '.setting-security .security-confirm-email .confirm-link', function () {
- var button = $(this);
- showScreenWaiting();
- var link = $(this).attr('link');
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- $.ajax({
- url: link,
- type: "POST"
- }).success(function (data) {
- showNotifyMain(data[1]);
- if (data[0] == 1) {
- activeConfirmText();
- }
- }).error(function (data) {
- showNotifyMain('Cáºp nháºt thất bại! Vui lĂ²ng tải lại trang.');
- }).complete(function () {
- hideScreenWaiting();
- });
- });
- function activeConfirmText() {
- var button = $('.setting-security .security-confirm-email .confirm-link');
- if (button.length > 0) {
- var textComfirm = $(button).attr('comfirmText');
- $(button).fadeOut(function () {
- $(button).parent(".security-confirm-email").addClass('email-send');
- $(button).parent(".security-confirm-email").text(textComfirm);
- $(button).remove();
- });
- }
- }
- $(document).on('click', '#button-update-email', function () {
- if (checkUpdateEmail()) {
- $(this).removeClass('button-active');
- showScreenWaiting();
- var link = $(this).attr('link');
- var email = $("#security-email").val();
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- $.ajax({
- url: link,
- data: {
- reset_email: email
- },
- type: "POST"
- }).success(function (data) {
- showNotifyMain(data[1]);
- if (data[0] == 1) {
- $("#security-email").attr('valueOld', email);
- activeConfirmText();
- } else {
- $("#security-email").val($("#security-email").attr('valueOld'));
- }
- }).error(function (data) {
- showNotifyMain('Cáºp nháºt thất bại! Vui lĂ²ng tải lại trang.');
- }).complete(function () {
- hideScreenWaiting();
- });
- }
- });
- $(document).on("click", "#modal-update-password .setting-button-save.button-active", function () {
- console.log('setting-button-save click');
- //if (checkUpdatePassword()) {
- // var password = $('#new-password').val();
- // var fullname = $('#personal-name').val();
- // var phone = $('#personal-phone').val();
- // var birthday = $('#personal-birthday').val();
- // $.ajax({
- // url: urlConfig("/Home/UpdateProfile"),
- // type: "POST",
- // data: {
- // __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val(),
- // fullname: fullname,
- // phone: phone,
- // birthday: birthday,
- // }
- // }).success(function (data) {
- // if (data.error_code != "0") {
- // // fail
- // $('#message-dialog').modal('show');
- // $('#message-content').html(data.error_content);
- // } else {
- // console.log(data.error_content);
- // if (data.href != null) {
- // location.href = data.href;
- // } else {
- // location.reload();
- // }
- // }
- // });
- //}
- });
|