145 lines
No EOL
5.7 KiB
JavaScript
145 lines
No EOL
5.7 KiB
JavaScript
jQuery(document).ready(function($) {
|
|
|
|
// --- Add New Job Form ---
|
|
|
|
// Show the "Add New Job" form when the button is clicked
|
|
$('.add-new-job-button').on('click', function(e) {
|
|
e.preventDefault();
|
|
$('#add-new-job-form').slideDown();
|
|
$(this).hide(); // Hide the "Add New Job" button itself
|
|
});
|
|
|
|
// Hide the "Add New Job" form when the cancel button is clicked
|
|
$('#add-new-job-form .cancel-add-job').on('click', function(e) {
|
|
e.preventDefault();
|
|
$('#add-new-job-form').slideUp(function() {
|
|
// Optional: Clear form fields on cancel
|
|
// $('#new-job-form')[0].reset();
|
|
// $('.add-job-status').empty();
|
|
});
|
|
$('.add-new-job-button').show(); // Show the "Add New Job" button again
|
|
});
|
|
|
|
// --- Send Invite Form ---
|
|
|
|
// Show the specific "Send Invite" form row when the link is clicked
|
|
$('.send-job-invite').on('click', function(e) {
|
|
e.preventDefault();
|
|
var jobId = $(this).data('job-id');
|
|
var inviteRow = $('#send-invite-row-' + jobId);
|
|
|
|
// Hide any other open invite forms first
|
|
$('.send-invite-form-row').not(inviteRow).slideUp();
|
|
|
|
// Toggle the clicked one
|
|
inviteRow.slideToggle();
|
|
});
|
|
|
|
// Hide the "Send Invite" form row when its cancel button is clicked
|
|
$('.send-invite-form-row .cancel-invite').on('click', function(e) {
|
|
e.preventDefault();
|
|
$(this).closest('.send-invite-form-row').slideUp();
|
|
});
|
|
|
|
// --- AJAX Form Submissions ---
|
|
|
|
// Add New Job AJAX
|
|
$('#new-job-form').on('submit', function(e) {
|
|
e.preventDefault();
|
|
var $form = $(this);
|
|
var $submitButton = $form.find('input[type="submit"]');
|
|
var $spinner = $form.find('.spinner');
|
|
var $statusDiv = $form.find('.add-job-status');
|
|
|
|
$statusDiv.empty().removeClass('error success');
|
|
$spinner.css('visibility', 'visible');
|
|
$submitButton.prop('disabled', true);
|
|
|
|
var formData = {
|
|
action: 'add_new_job',
|
|
nonce: quiztechThemeData.add_job_nonce,
|
|
job_title: $form.find('#job_title').val(),
|
|
job_description: $form.find('#job_description').val()
|
|
};
|
|
|
|
$.post(quiztechThemeData.ajax_url, formData)
|
|
.done(function(response) {
|
|
if (response.success) {
|
|
$statusDiv.text(quiztechThemeData.job_added_success).addClass('success');
|
|
// Optionally: Clear form, hide it, refresh job list via another AJAX call or page reload
|
|
$form[0].reset();
|
|
$('#add-new-job-form').slideUp();
|
|
$('.add-new-job-button').show();
|
|
// Consider adding the new job row dynamically instead of full reload
|
|
location.reload(); // Simple reload for now
|
|
} else {
|
|
$statusDiv.text(response.data.message || quiztechThemeData.error_generic).addClass('error');
|
|
}
|
|
})
|
|
.fail(function() {
|
|
$statusDiv.text(quiztechThemeData.error_generic).addClass('error');
|
|
})
|
|
.always(function() {
|
|
$spinner.css('visibility', 'hidden');
|
|
$submitButton.prop('disabled', false);
|
|
});
|
|
});
|
|
|
|
// Send Invite AJAX
|
|
$('.send-invite-submit').on('click', function(e) {
|
|
e.preventDefault();
|
|
var $button = $(this);
|
|
var jobId = $button.data('job-id');
|
|
var $wrapper = $button.closest('.send-invite-form-wrapper');
|
|
var $emailInput = $wrapper.find('input[name="applicant_email"]');
|
|
var $spinner = $wrapper.find('.spinner');
|
|
var $statusDiv = $wrapper.find('.invite-status');
|
|
var applicantEmail = $emailInput.val();
|
|
|
|
if (!applicantEmail) {
|
|
$emailInput.focus();
|
|
// Maybe add a small visual cue that email is required
|
|
return;
|
|
}
|
|
|
|
$statusDiv.empty().removeClass('error success');
|
|
$spinner.css('visibility', 'visible');
|
|
$button.prop('disabled', true).siblings('.cancel-invite').prop('disabled', true);
|
|
|
|
var formData = {
|
|
action: 'send_job_invite',
|
|
nonce: quiztechThemeData.send_invite_nonce,
|
|
job_id: jobId,
|
|
applicant_email: applicantEmail
|
|
};
|
|
|
|
$.post(quiztechThemeData.ajax_url, formData)
|
|
.done(function(response) {
|
|
if (response.success) {
|
|
$statusDiv.text(quiztechThemeData.invite_sent_success).addClass('success');
|
|
$emailInput.val(''); // Clear email field on success
|
|
// Optionally hide the form row after a delay
|
|
setTimeout(function() {
|
|
$button.closest('.send-invite-form-row').slideUp();
|
|
}, 2000);
|
|
} else {
|
|
var errorMessage = quiztechThemeData.error_generic;
|
|
if (response.data && response.data.message) {
|
|
errorMessage = response.data.message;
|
|
} else if (response.data && response.data === 'error_missing_assessment') {
|
|
// Example of handling specific error code if needed
|
|
errorMessage = quiztechThemeData.error_missing_assessment;
|
|
}
|
|
$statusDiv.text(errorMessage).addClass('error');
|
|
}
|
|
})
|
|
.fail(function() {
|
|
$statusDiv.text(quiztechThemeData.error_generic).addClass('error');
|
|
})
|
|
.always(function() {
|
|
$spinner.css('visibility', 'hidden');
|
|
$button.prop('disabled', false).siblings('.cancel-invite').prop('disabled', false);
|
|
});
|
|
});
|
|
|
|
}); |