diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs index cffe2f688..b56dbafbd 100644 --- a/src/Web/Grand.Web/Controllers/ProductController.cs +++ b/src/Web/Grand.Web/Controllers/ProductController.cs @@ -582,6 +582,7 @@ public virtual async Task NewProducts() newmodel.AddProductReview.Rating = model.AddProductReview.Rating; newmodel.AddProductReview.ReviewText = model.AddProductReview.ReviewText; newmodel.AddProductReview.Title = model.AddProductReview.Title; + newmodel.AddProductReview.Result = string.Join(",", ModelState.Values.SelectMany(m => m.Errors).Select(e => e.ErrorMessage).ToList()); return View(newmodel); } diff --git a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml index 5f7e845b3..bd556b44e 100644 --- a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml +++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml @@ -1,60 +1,121 @@ @model ProductReviewsModel
- @Loc["Reviews.Overview.AddNew"] + @Loc["Reviews.Overview.AddNew"]
- -@if (Model.Items.Any()) +@if (Model.AddProductReview.DisplayCaptcha) { -
+
+
+ +
+
+} + + + + \ No newline at end of file diff --git a/src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtml b/src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtml new file mode 100644 index 000000000..5f86243d1 --- /dev/null +++ b/src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtml @@ -0,0 +1,41 @@ +@{ + var productlink = @Url.RouteUrl("Product"); +} + + + + \ No newline at end of file diff --git a/src/Web/Grand.Web/wwwroot/theme/css/product/product.css b/src/Web/Grand.Web/wwwroot/theme/css/product/product.css index b9b252d4b..689e5b4a5 100644 --- a/src/Web/Grand.Web/wwwroot/theme/css/product/product.css +++ b/src/Web/Grand.Web/wwwroot/theme/css/product/product.css @@ -88,6 +88,12 @@ max-width: 165px; } +/* captcha */ + +#captcha-container .captcha-box { + display: none; +} + /* product price */ .product-details-page .overview .actual-price { diff --git a/src/Web/Grand.Web/wwwroot/theme/script/app.js b/src/Web/Grand.Web/wwwroot/theme/script/app.js index 1e0b5fd85..5e83e87f0 100644 --- a/src/Web/Grand.Web/wwwroot/theme/script/app.js +++ b/src/Web/Grand.Web/wwwroot/theme/script/app.js @@ -17,6 +17,7 @@ flycartfirstload: true, PopupAddToCartVueModal: null, PopupQuickViewVueModal: null, + PopupProductReviewVueModal: null, index: null, RelatedProducts: null, } @@ -348,6 +349,84 @@ } } } + }, + addProductReview: function (url) { + axios({ + url: url, + method: 'get', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'X-Response-View': 'Json' + } + }).then(function (response) { + vm.PopupProductReviewVueModal = response.data; + vm.$refs['ModalProductReview'].show(); + }); + }, + modalReviewShown: function () { + if (vm.PopupProductReviewVueModal.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") == null) { + var html = document.getElementById("captcha-box"); + document.getElementById("captcha-popup").prepend(html); + } + }, + modalReviewClose: function () { + if (vm.PopupProductReviewVueModal.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") !== null) { + var html = document.getElementById("captcha-box"); + document.getElementById("captcha-container").prepend(html); + } + }, + submitProductReview: function (id) { + this.$validator.validateAll(['AddProductReview.Title', 'AddProductReview.ReviewText', 'AddProductReview_Rating']).then((result) => { + if (result) { + var form = document.getElementById(id); + var url = form.getAttribute("action"); + var resultTitle = form.getAttribute("data-title"); + var bodyFormData = new FormData(form); + axios({ + method: "post", + url: url, + data: bodyFormData, + headers: { + "Content-Type": "multipart/form-data", + 'X-Response-View': 'Json' + }, + }).then(function (response) { + vm.PopupProductReviewVueModal = response.data; + productreviews.Model = response.data.Items; + + var result = response.data.AddProductReview.Result; + var variant = ""; + + if (response.data.AddProductReview.SuccessfullyAdded) { + + variant = "info"; + vm.$refs['ModalProductReview'].hide(); + + } else { + variant = "danger"; + } + + new Vue({ + el: ".modal-place", + methods: { + toast() { + this.$bvToast.toast(result, { + title: resultTitle, + variant: variant, + autoHideDelay: 3000, + solid: true + }) + } + }, + mounted: function () { + this.toast(); + } + }); + }); + return + } + }); } }, }); diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js index 5cf4bcacc..267eff1c6 100644 --- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js +++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js @@ -967,57 +967,4 @@ var Reservation = { } } -/* END RESERVATION */ - -/* PRODUCT REVIEW */ - -function reviewHelpfullness(element) { - var productId = element.dataset.id; - var reviewId = element.dataset.reviewid; - var toastTitle = element.dataset.title; - var url = element.dataset.url; - - document.getElementById('vote-yes-' + reviewId + '').addEventListener("click", function (e) { - setProductReviewHelpfulness(url, 'true'); - }); - document.getElementById('vote-no-' + reviewId + '').addEventListener("click", function (e) { - setProductReviewHelpfulness(url, 'false'); - }); - - function setProductReviewHelpfulness(url, wasHelpful) { - axios({ - url: url, - method: 'post', - params: { "productReviewId": reviewId, "productId": productId, "washelpful": wasHelpful } - }).then(function (response) { - document.getElementById("helpfulness-vote-yes-" + reviewId + "").innerHTML = response.data.TotalYes - document.getElementById("helpfulness-vote-no-" + reviewId + "").innerHTML = response.data.TotalNo; - new Vue({ - el: ".modal-place", - methods: { - toast() { - this.$bvToast.toast(response.data.Result, { - title: toastTitle, - variant: 'info', - autoHideDelay: 3000, - solid: true - }) - } - }, - mounted: function () { - this.toast(); - } - }); - }).catch(function (error) { - alert(error); - }) - } -} - -document.addEventListener("DOMContentLoaded", function () { - document.querySelectorAll("#product-review-list .product-review-item").forEach(function (element) { - reviewHelpfullness(element); - }); -}) - -/* END REVIEW */ +/* END RESERVATION */ \ No newline at end of file