1/** 2 * Copyright since 2007 PrestaShop SA and Contributors 3 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA 4 * 5 * NOTICE OF LICENSE 6 * 7 * This source file is subject to the Academic Free License 3.0 (AFL-3.0) 8 * that is bundled with this package in the file LICENSE.md. 9 * It is also available through the world-wide-web at this URL: 10 * https://opensource.org/licenses/AFL-3.0 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * DISCLAIMER 16 * 17 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 18 * versions in the future. If you wish to customize PrestaShop for your 19 * needs please refer to https://devdocs.prestashop.com/ for more information. 20 * 21 * @author PrestaShop SA and Contributors <[email protected]> 22 * @copyright Since 2007 PrestaShop SA and Contributors 23 * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) 24 */ 25 26jQuery(document).ready(function () { 27 const $ = jQuery; 28 const commentsList = $('#product-comments-list'); 29 const emptyProductComment = $('#empty-product-comment'); 30 const commentsListUrl = commentsList.data('list-comments-url'); 31 const updateCommentUsefulnessUrl = commentsList.data('update-comment-usefulness-url'); 32 const reportCommentUrl = commentsList.data('report-comment-url'); 33 const commentPrototype = commentsList.data('comment-item-prototype'); 34 35 emptyProductComment.hide(); 36 $('.grade-stars').rating(); 37 38 document.addEventListener('updateRating', function() { 39 $('.grade-stars').rating(); 40 }); 41 42 const updateCommentPostErrorModal = $('#update-comment-usefulness-post-error'); 43 44 const confirmAbuseModal = $('#report-comment-confirmation'); 45 const reportCommentPostErrorModal = $('#report-comment-post-error'); 46 const reportCommentPostedModal = $('#report-comment-posted'); 47 48 function showUpdatePostCommentErrorModal(errorMessage) { 49 $('#update-comment-usefulness-post-error-message').html(errorMessage); 50 updateCommentPostErrorModal.modal('show'); 51 } 52 53 function showReportCommentErrorModal(errorMessage) { 54 $('#report-comment-post-error-message').html(errorMessage); 55 reportCommentPostErrorModal.modal('show'); 56 } 57 58 function paginateComments(page) { 59 $.get(commentsListUrl, {page: page}, function(jsonResponse) { 60 if (jsonResponse.comments && jsonResponse.comments.length > 0) { 61 populateComments(jsonResponse.comments); 62 if (jsonResponse.comments_nb > jsonResponse.comments_per_page) { 63 $('#product-comments-list-pagination').pagination({ 64 currentPage: page, 65 items: jsonResponse.comments_nb, 66 itemsOnPage: jsonResponse.comments_per_page, 67 cssStyle: '', 68 prevText: '<i class="fa fa-angle-left"></i>', 69 nextText: '<i class="fa fa-angle-right"></i>', 70 useAnchors: false, 71 displayedPages: 2, 72 onPageClick: paginateComments 73 }); 74 } else { 75 $('#product-comments-list-pagination').hide(); 76 } 77 } else { 78 commentsList.html(''); 79 emptyProductComment.show(); 80 commentsList.append(emptyProductComment); 81 } 82 }); 83 } 84 85 function populateComments(comments) { 86 commentsList.html(''); 87 comments.forEach(addComment); 88 } 89 90 function addComment(comment) { 91 var commentTemplate = commentPrototype; 92 var customerName = comment.customer_name; 93 if (!customerName) { 94 customerName = comment.firstname+' '+comment.lastname; 95 } 96 commentTemplate = commentTemplate.replace(/@COMMENT_ID@/, comment.id_product_comment); 97 commentTemplate = commentTemplate.replace(/@PRODUCT_ID@/, comment.id_product); 98 commentTemplate = commentTemplate.replace(/@CUSTOMER_NAME@/, customerName); 99 commentTemplate = commentTemplate.replace(/@COMMENT_DATE@/, comment.date_add); 100 commentTemplate = commentTemplate.replace(/@COMMENT_TITLE@/, comment.title); 101 commentTemplate = commentTemplate.replace(/@COMMENT_COMMENT@/, comment.content); 102 commentTemplate = commentTemplate.replace(/@COMMENT_USEFUL_ADVICES@/, comment.usefulness); 103 commentTemplate = commentTemplate.replace(/@COMMENT_NOT_USEFUL_ADVICES@/, (comment.total_usefulness - comment.usefulness)); 104 commentTemplate = commentTemplate.replace(/@COMMENT_TOTAL_ADVICES@/, comment.total_usefulness); 105 106 const $comment = $(commentTemplate); 107 $('.grade-stars', $comment).rating({ 108 grade: comment.grade 109 }); 110 $('.useful-review', $comment).click(function() { 111 updateCommentUsefulness($comment, comment.id_product_comment, 1); 112 }); 113 $('.not-useful-review', $comment).click(function() { 114 updateCommentUsefulness($comment, comment.id_product_comment, 0); 115 }); 116 $('.report-abuse', $comment).click(function() { 117 confirmCommentAbuse(comment.id_product_comment); 118 }); 119 120 commentsList.append($comment); 121 } 122 123 function updateCommentUsefulness($comment, commentId, usefulness) { 124 $.post(updateCommentUsefulnessUrl, {id_product_comment: commentId, usefulness: usefulness}, function(jsonData){ 125 if (jsonData) { 126 if (jsonData.success) { 127 $('.useful-review-value', $comment).html(jsonData.usefulness); 128 $('.not-useful-review-value', $comment).html(jsonData.total_usefulness - jsonData.usefulness); 129 } else { 130 const decodedErrorMessage = $("<div/>").html(jsonData.error).text(); 131 showUpdatePostCommentErrorModal(decodedErrorMessage); 132 } 133 } else { 134 showUpdatePostCommentErrorModal(productCommentUpdatePostErrorMessage); 135 } 136 }).fail(function() { 137 showUpdatePostCommentErrorModal(productCommentUpdatePostErrorMessage); 138 }); 139 } 140 141 function confirmCommentAbuse(commentId) { 142 confirmAbuseModal.modal('show'); 143 confirmAbuseModal.one('modal:confirm', function(event, confirm) { 144 if (!confirm) { 145 return; 146 } 147 $.post(reportCommentUrl, {id_product_comment: commentId}, function(jsonData){ 148 if (jsonData) { 149 if (jsonData.success) { 150 reportCommentPostedModal.modal('show'); 151 } else { 152 showReportCommentErrorModal(jsonData.error); 153 } 154 } else { 155 showReportCommentErrorModal(productCommentAbuseReportErrorMessage); 156 } 157 }).fail(function() { 158 showReportCommentErrorModal(productCommentAbuseReportErrorMessage); 159 }); 160 }) 161 } 162 163 //paginateComments(1); 164});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.