`); let url = new URL("https://azhealthsciences.com/reviews/find"); url.searchParams.set('item_id', courseId); url.searchParams.set('item_type', 'course'); $.ajax({ url: url.href, method: 'get', success: ({review}) => { const stars = review?.stars ?? null; const comment = review?.comment ?? null; if (stars){$(`input[name="rating"][value=${stars}]`).prop('checked', true); }else { $(`input[name="rating"]`).prop('checked', false); }$('#review_comment').val(comment); $('.loader').removeClass('show'); }, error: () => { $('.loader').removeClass('show'); }}); }); $('#review_form').on('submit', function (e){e.preventDefault(); $('.loader').addClass('show'); $('span.invalid').remove(); const formData = new FormData($(this)[0]); $.ajax({ url: $(this).attr('action'),method: 'post', headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, data: formData, contentType: false, processData: false, success: () => { $('#rating-modal').modal('hide'); toastr.success('Your review has been successfully sent.'); updateReviews(window.lastSelectedReviewCount); }, error: error => { if (error.status === 422){const errors = error.responseJSON.errors; for (let field in errors){$(this).find(`.error-wrapper[data-for=${field}]`) .append(`${errors[field][0]}`); }}}, complete: () => { $('.loader').removeClass('show'); }}); }); }); $(document).ready(function (){updateQuestions(1); $('#load_questions').on('click', function (e){e.preventDefault(); $('.loader').addClass('show'); updateQuestions(); }); function updateQuestions(count){window.lastSelectedQuestionsCount = count; let url = new URL("https://azhealthsciences.com/questions"); url.searchParams.set('item_id', "4"); url.searchParams.set('item_type', 'course'); if (count){url.searchParams.set('limit', count); }$.ajax({ url: url.href, method: 'get', success: ({questions, has_more}) => { $('#questions_container').html(questions.join('')); if (!has_more){$('#load_questions').hide(); }}, complete: () => { $('.loader').removeClass('show'); }}); }$('#questions-form').on('submit', function (e){e.preventDefault(); $('.loader').addClass('show'); $('span.invalid').remove(); const formData = new FormData($(this)[0]); $.ajax({ url: $(this).attr('action'),method: 'post', headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, data: formData, contentType: false, processData: false, success: () => { toastr.success('Your question was sent.'); updateQuestions(window.lastSelectedQuestionsCount); }, error: error => { if (error.status === 422){const errors = error.responseJSON.errors; for (let field in errors){$(this).append(`${errors[field][0]}`); }}}, complete: () => { $('.loader').removeClass('show'); $(this).find('textarea').val('') }}); }); $(document).on('submit', '.replay-form', function (e){e.preventDefault(); $('.loader').addClass('show'); $('span.invalid').remove(); const formData = new FormData($(this)[0]); $.ajax({ url: $(this).attr('action'),method: 'post', headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, data: formData, contentType: false, processData: false, success: () => { toastr.success('Your reply was sent.'); updateQuestions(window.lastSelectedQuestionsCount); }, error: error => { if (error.status === 422){const errors = error.responseJSON.errors; for (let field in errors){$(this).find('textarea').after(`${errors[field][0]}`); }}}, complete: () => { $('.loader').removeClass('show'); $(this).find('textarea').val(''); $(this).closest('.replay-modal').modal('hide'); }}); }); }); $(document).on('click', '.copy-btn', function (e){e.preventDefault(); $(this).attr('disabled', true); setTimeout(() => { $(this).attr('disabled', false); }, 5000); navigator.clipboard.writeText($(this).data('text')); toastr.success('Course URL has been successfully copied'); });