2021-04-07 18:19:04 +00:00
|
|
|
{% from "erpnext/templates/includes/macros.html" import user_review, ratings_summary %}
|
2021-03-25 06:22:50 +00:00
|
|
|
|
2021-07-13 18:16:24 +00:00
|
|
|
<div class="mt-4 ratings-reviews-section">
|
|
|
|
<!-- Title and Action -->
|
|
|
|
<div class="w-100 mt-4 mb-2 d-flex">
|
|
|
|
<div class="reviews-header col-9">
|
|
|
|
{{ _("Customer Reviews") }}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="write-a-review-btn col-3">
|
|
|
|
<!-- Write a Review for legitimate users -->
|
|
|
|
{% if frappe.session.user != "Guest" and user_is_customer %}
|
|
|
|
<button class="btn btn-write-review"
|
|
|
|
data-web-item="{{ doc.name }}">
|
|
|
|
{{ _("Write a Review") }}
|
|
|
|
</button>
|
|
|
|
{% endif %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Summary -->
|
|
|
|
{{ ratings_summary(reviews, reviews_per_rating, average_rating, average_whole_rating, for_summary=True, total_reviews=total_reviews) }}
|
2021-03-25 06:22:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
<!-- Reviews and Comments -->
|
2021-07-13 18:16:24 +00:00
|
|
|
<div class="mt-8">
|
2021-03-25 06:22:50 +00:00
|
|
|
{% if reviews %}
|
2021-04-07 18:19:04 +00:00
|
|
|
{{ user_review(reviews) }}
|
2021-03-25 06:22:50 +00:00
|
|
|
|
|
|
|
{% if total_reviews > 4 %}
|
|
|
|
<div class="mt-6 mb-6"style="color: var(--primary);">
|
2021-08-25 07:39:35 +00:00
|
|
|
<a href="/customer_reviews?web_item={{ doc.name }}">{{ _("View all reviews") }}</a>
|
2021-03-25 06:22:50 +00:00
|
|
|
</div>
|
|
|
|
{% endif %}
|
2021-04-07 18:19:04 +00:00
|
|
|
|
2021-03-25 06:22:50 +00:00
|
|
|
{% else %}
|
|
|
|
<h6 class="text-muted mt-6">
|
|
|
|
{{ _("No Reviews") }}
|
|
|
|
</h6>
|
|
|
|
{% endif %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
frappe.ready(() => {
|
|
|
|
$('.page_content').on('click', '.btn-write-review', (e) => {
|
|
|
|
// Bind action on write a review button
|
|
|
|
const $btn = $(e.currentTarget);
|
|
|
|
|
|
|
|
let d = new frappe.ui.Dialog({
|
|
|
|
title: __("Write a Review"),
|
|
|
|
fields: [
|
|
|
|
{fieldname: "title", fieldtype: "Data", label: "Headline", reqd: 1},
|
|
|
|
{fieldname: "rating", fieldtype: "Rating", label: "Overall Rating", reqd: 1},
|
|
|
|
{fieldtype: "Section Break"},
|
|
|
|
{fieldname: "comment", fieldtype: "Small Text", label: "Your Review"}
|
|
|
|
],
|
|
|
|
primary_action: function() {
|
|
|
|
var data = d.get_values();
|
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.e_commerce.doctype.item_review.item_review.add_item_review",
|
|
|
|
args: {
|
|
|
|
web_item: "{{ doc.name }}",
|
|
|
|
title: data.title,
|
|
|
|
rating: data.rating,
|
|
|
|
comment: data.comment
|
|
|
|
},
|
|
|
|
freeze: true,
|
|
|
|
freeze_message: __("Submitting Review ..."),
|
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
|
|
|
frappe.msgprint({
|
2021-07-13 18:16:24 +00:00
|
|
|
message: __("Thank you for the review"),
|
2021-03-25 06:22:50 +00:00
|
|
|
title: __("Review Submitted"),
|
|
|
|
indicator: "green"
|
|
|
|
});
|
|
|
|
d.hide();
|
2021-04-07 18:19:04 +00:00
|
|
|
location.reload();
|
2021-03-25 06:22:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
primary_action_label: __('Submit')
|
|
|
|
});
|
|
|
|
d.show();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|