`); let url = new URL("https://open-edu.eu/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).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'); });