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 $('body').on('click', '.post-product-comment', function (event) { 29 event.preventDefault(); 30 showPostCommentModal(); 31 }); 32 33 const postCommentModal = $('#post-product-comment-modal'); 34 postCommentModal.on('hidden.bs.modal', function () { 35 postCommentModal.modal('hide');
36 clearPostCommentForm(); 37 }); 38 39 const commentPostedModal = $('#product-comment-posted-modal'); 40 const commentPostErrorModal = $('#product-comment-post-error'); 41 42 const criterionsList = $('#criterions_list'); 43 criterionsList.append('<div id="ratingNotChosen">* ' + productCommentMandatoryMessage + '</div>'); 44 const criterionsInfo = $('#ratingNotChosen'); 45 46 function showPostCommentModal() { 47 commentPostedModal.modal('hide'); 48 commentPostErrorModal.modal('hide'); 49 postCommentModal.modal('show'); 50 ratingChosen = false; 51 criterionsInfo.hide(); 52 } 53 54 function showCommentPostedModal() { 55 postCommentModal.modal('hide'); 56 commentPostErrorModal.modal('hide'); 57 clearPostCommentForm(); 58 commentPostedModal.modal('show'); 59 } 60 61 function showPostErrorModal(errorMessage) { 62 postCommentModal.modal('hide'); 63 commentPostedModal.modal('hide'); 64 clearPostCommentForm(); 65 $('#product-comment-post-error-message').html(errorMessage); 66 commentPostErrorModal.modal('show'); 67 } 68 69 function clearPostCommentForm(
69) { 70 $('#post-product-comment-form input[type="text"]').val(''); 71 $('#post-product-comment-form input[type="text"]').removeClass('valid error'); 72 $('#post-product-comment-form textarea').val(''); 73 $('#post-product-comment-form textarea').removeClass('valid error'); 74 $('#post-product-comment-form .criterion-rating input').val(3).trigger('change'); 75 } 76 77 function initCommentModal() { 78 $('#post-product-comment-modal .grade-stars').rating(); 79 $('body').on('click', '.post-product-comment', function (event) { 80 event.preventDefault(); 81 showPostCommentModal(); 82 }); 83 84 $('#post-product-comment-form').on('submit', submitCommentForm); 85 } 86 87 function submitCommentForm(event) { 88 event.preventDefault(); 89 var formData = $(this).serializeArray(); 90 if (!validateFormData(formData)) { 91 return; 92 } 93 $.post($(this).attr('action'), $(this).serialize(), function(jsonData) { 94 if (jsonData) { 95 if (jsonData.success) { 96 clearPostCommentForm(); 97 showCommentPostedModal(); 98 } else { 99 if (jsonData.errors) { 100 var errorList = '<ul>'; 101 for (var i = 0; i < jsonData.errors.length; ++i) { 102 errorList += '<li>' + jsonData.errors[i] + '</li>'; 103 } 104 errorList += '</ul>'; 105 showPostErrorModal(errorList); 106 } else { 107 const decodedErrorMessage = $("<div/>").html(jsonData.error).text(); 108 showPostErrorModal(decodedErrorMessage); 109 } 110 } 111 } else { 112 showPostErrorModal(productCommentPostErrorMessage); 113 } 114 }).fail(function() { 115 showPostErrorModal(productCommentPostErrorMessage); 116 }); 117 } 118 119 function validateFormData(formData) { 120 var isValid = true; 121 formData.forEach(function(formField) { 122 const fieldSelector = '#post-product-comment-form [name="'+formField.name+'"]'; 123 if (!formField.value) { 124 $(fieldSelector).addClass('error'); 125 $(fieldSelector).removeClass('valid'); 126 isValid = false; 127 } else { 128 $(fieldSelector).removeClass('error'); 129 $(fieldSelector).addClass('valid'); 130 } 131 132 if (!ratingChosen) { 133 criterionsInfo.show(); 134 isValid = false; 135 } else { 136 criterionsInfo.hide(); 137 } 138 }); 139 140 return isValid; 141 } 142 143 initCommentModal(); 144});
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.