$(document).ready(function() {
  $("#treatNewPass").on("click", function(e) {
    e.preventDefault();
    password = $('#id_password_id').val();
    verifPassword = $('#id_verifPassword_id').val();
	randStringControl = $('input[name="randStringControl"]').val();

    $.ajax({
      url: urlBase + '/public/ajax/publicLostPasswordNewPassTreat/',
      type: 'post',
      data: {
        p_password: password,
        p_verifPassword: verifPassword,
        randStringControl: randStringControl,
      },
      dataType: "json",
      success: function(data) {
        
       if (data.status == 'ok') {
         $('i.fa-lock').addClass('text-success fa-unlock').removeClass('text-warning fa-lock');
         $('#newPassAskForm').addClass('d-none');
         $('#newPassTreatConfirmation').removeClass('d-none');
       } else {
         $('#newPassAskForm div.alert.cleanAndHideOnModalHide').removeClass('d-none');
         $('#newPassAskForm div.alert.cleanAndHideOnModalHide ul').html('');
         $.each(data.msg, function(index, value) {
           $('#newPassAskForm div.alert.cleanAndHideOnModalHide ul').append('<li>' + value + '</li>');
         });
         $('#newPassAskForm .is-invalid').removeClass('is-invalid');
         $.each(data.code, function(index, value) {
           $('#newPassAskForm *[name="' + value + '"]').addClass('is-invalid');
         });
       }        
        

      },
      error: function() {
        alert('Problème, rechargez la page !');
      }
    });

  });
});