”
modalPopup.closeOnEsc = false;
modalPopup.setHeader(“Why did you not like this content?”);
modalPopup.setContentText(modalText);
modalPopup.addCancelOkButton(“Submit”, resetRatingAndFeedbackForm, sendRating);
modalPopup.removeCloseModalIcon();
modalPopup.disableDismissPopup();
modalPopup.open();
} else {
sendRating(index);
}
}
function sendRating() {
var requestPayload = {
“post_id”: 1187505,
“rating_value”: ratingValue
}
if (ratingValue > 3) {
requestPayload.rating_feedback_type = null;
requestPayload.rating_feedback = null;
} else {
if (!$(‘input[name=”drone”]:checked’) || !$(‘input[name=”drone”]:checked’).value) {
showErrorMessage(‘option’);
return;
}
if (!$(“.post-rating-feedback-note textarea”) || !$(“.post-rating-feedback-note textarea”).value) {
showErrorMessage(‘note’);
return;
}
var selectedOption = $(‘input[name=”drone”]:checked’).value;
var feedbackNote = $(“.post-rating-feedback-note textarea”).value;
requestPayload.rating_feedback_type = selectedOption;
requestPayload.rating_feedback = feedbackNote;
}
pureJSAjaxPost(addratingAPI, requestPayload, onsaveRatingSuccess, onsaveRatingFail, function() {}, true);
}
function resetRatingAndFeedbackForm() {
var activeStars = Array.from($all(‘.rating span.rating-star.active’));
for (var i=0; i = 0) {
return true;
} else {
return false;
}
}
function getRatingCountByPostId(postId) {
return new Promise(function(resolve, reject) {
pureJSAjaxGet(
getRatingCountBaseURL + postId + ‘/rating/count’,
function(data) {
try {
data = JSON.parse(data);
if (data.meta_value) {
resolve(data.meta_value);
}
reject(“Failed to fetch rating count for the post:” + postId);
} catch (err) {
reject(“Failed to fetch rating count for the post:” + postId);
}
},
function(err) {
reject(“Failed to fetch rating count for the post:” + postId);
}, true);
});
}
function showErrorMessage(messageType) {
var messageContainerId = ‘#’ + messageType + ‘-error’;
$(messageContainerId).classList.remove(‘hidden’);
window.setInterval(function () {
$(messageContainerId).classList.add(“hidden”);
}, 5000);
}
if (!isPostRatedByUser()) {
getRatingCountByPostId(1187505)
.then(function(ratingCount) {
if (ratingCount