brotherton-erpnext/erpnext/public/js/hub/components/ReviewArea.vue

76 lines
1.5 KiB
Vue
Raw Normal View History

<template>
<div>
2018-08-29 21:12:13 +00:00
<div ref="review-area" class="timeline-head"></div>
2018-08-30 10:38:52 +00:00
<div class="timeline-items">
<review-timeline-item v-for="review in reviews"
:key="review.user"
:username="review.username"
:avatar="review.user_image"
:comment_when="when(review.modified)"
:rating="review.rating"
:subject="review.subject"
:content="review.content"
>
</review-timeline-item>
</div>
</div>
</template>
<script>
2018-08-30 10:38:52 +00:00
import ReviewTimelineItem from '../components/ReviewTimelineItem.vue';
export default {
2018-08-30 10:38:52 +00:00
props: ['hub_item_name'],
data() {
return {
reviews: []
}
},
components: {
ReviewTimelineItem
},
created() {
this.get_item_reviews();
},
mounted() {
this.make_input();
},
methods: {
2018-08-30 10:38:52 +00:00
when(datetime) {
return comment_when(datetime);
},
get_item_reviews() {
hub.call('get_item_reviews', { hub_item_name: this.hub_item_name })
.then(reviews => {
this.reviews = reviews;
})
.catch(() => {});
},
make_input() {
2018-08-29 21:12:13 +00:00
this.review_area = new frappe.ui.ReviewArea({
parent: this.$refs['review-area'],
mentions: [],
on_submit: this.on_submit_review.bind(this)
});
},
on_submit_review(values) {
2018-08-30 09:42:18 +00:00
values.user = hub.settings.company_email;
2018-08-29 21:12:13 +00:00
this.review_area.reset();
hub.call('add_item_review', {
2018-08-30 09:42:18 +00:00
hub_item_name: this.hub_item_name,
review: JSON.stringify(values)
})
2018-08-30 09:42:18 +00:00
.then(this.push_review.bind(this));
},
2018-08-30 10:38:52 +00:00
push_review(review){
this.reviews.unshift(review);
}
}
}
</script>