81 lines
3.3 KiB
JavaScript
81 lines
3.3 KiB
JavaScript
(function ($) {
|
|
"use strict";
|
|
// $("#contactForms").validator().on("submit", function (event) {
|
|
// if (event.isDefaultPrevented()) {
|
|
// formError();
|
|
// submitMSG(false, "Did you fill up the form properly?");
|
|
// } else {
|
|
// event.preventDefault();
|
|
// submitForm();
|
|
// }
|
|
// });
|
|
$("#addJobListForm").on("submit", function (event) {
|
|
event.preventDefault();
|
|
var job_title = $("#job_title").val();
|
|
var employment_type = $("#employment_type").val();
|
|
var industry = $("#industry").val();
|
|
var employee_status = $("#employee_status").val();
|
|
var shift = $("#shift").val();
|
|
var job_posted_date = $("#job_posted_date").val();
|
|
var job_location = $("#job_location").val();
|
|
var job_description = $("#job_description").val();
|
|
if (job_title == "" || employment_type == "" || industry == "" || employee_status == "" || shift == "" || job_posted_date == "" || job_location == "" || job_description == "") {
|
|
formError();
|
|
submitMSG(false, "Did you fill up the form properly?");
|
|
}
|
|
else {
|
|
event.preventDefault();
|
|
submitForm();
|
|
// window.location.reload();
|
|
}
|
|
});
|
|
|
|
function submitForm() {
|
|
var job_title = $("#job_title").val();
|
|
var employment_type = $("#employment_type").val();
|
|
var industry = $("#industry").val();
|
|
var employee_status = $("#employee_status").val();
|
|
var shift = $("#shift").val();
|
|
var job_posted_date = $("#job_posted_date").val();
|
|
var job_location = $("#job_location").val();
|
|
var ref_id = $("#ref_id").val();
|
|
var job_description = $(".ck-editor__editable_inline").html();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "./api/job-listing-add-data.php",
|
|
data: "api_type=Add&ref_id=" + ref_id + "&job_title=" + job_title + "&employment_type=" + employment_type + "&industry=" + industry + "&employee_status=" + employee_status + "&shift=" + shift + "&job_posted_date=" + job_posted_date + "&job_location=" + job_location + "&job_description=" + job_description,
|
|
success: function (text) {
|
|
let data = JSON.parse(text)
|
|
if (data.status == 200) {
|
|
formSuccess(ref_id);
|
|
setTimeout(() => {
|
|
window.location.reload();
|
|
}, 1000);
|
|
} else {
|
|
formError();
|
|
submitMSG(false, text);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function formSuccess(ref_id = null) {
|
|
$("#addJobListForm")[0].reset();
|
|
submitMSG(true, ref_id ? "Job Updated!" : "Job Added!")
|
|
}
|
|
|
|
function formError() {
|
|
$("#addJobListForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
|
|
$(this).removeClass();
|
|
});
|
|
}
|
|
|
|
function submitMSG(valid, msg) {
|
|
if (valid) {
|
|
var msgClasses = "h4 tada animated text-success text-center";
|
|
} else {
|
|
var msgClasses = "h4 text-danger text-center";
|
|
}
|
|
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
|
|
}
|
|
}(jQuery)); |