2018-08-01 10:27:28 +00:00
|
|
|
import SubPage from './subpage';
|
2018-08-13 16:06:07 +00:00
|
|
|
import { get_detail_view_html } from '../components/detail_view';
|
|
|
|
import { get_detail_skeleton_html } from '../components/skeleton_state';
|
|
|
|
import { get_review_html } from '../components/reviews';
|
2018-08-01 08:39:07 +00:00
|
|
|
|
|
|
|
erpnext.hub.Item = class Item extends SubPage {
|
|
|
|
refresh() {
|
|
|
|
this.show_skeleton();
|
|
|
|
this.hub_item_code = frappe.get_route()[2];
|
|
|
|
|
|
|
|
this.own_item = false;
|
|
|
|
|
|
|
|
this.get_item(this.hub_item_code)
|
|
|
|
.then(item => {
|
|
|
|
this.own_item = item.hub_seller === hub.settings.company_email;
|
|
|
|
this.item = item;
|
|
|
|
this.render(item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
show_skeleton() {
|
2018-08-13 16:06:07 +00:00
|
|
|
this.$wrapper.html(get_detail_skeleton_html());
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
get_item(hub_item_code) {
|
2018-08-01 12:02:13 +00:00
|
|
|
return hub.call('get_item_details', {
|
|
|
|
hub_seller: hub.settings.company_email,
|
|
|
|
hub_item_code
|
|
|
|
});
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
render(item) {
|
|
|
|
const html = get_detail_view_html(item, this.own_item);
|
2018-08-01 08:39:07 +00:00
|
|
|
this.$wrapper.html(html);
|
|
|
|
|
|
|
|
this.make_review_area();
|
|
|
|
|
|
|
|
this.get_reviews()
|
|
|
|
.then(reviews => {
|
|
|
|
this.reviews = reviews;
|
2018-08-13 16:06:07 +00:00
|
|
|
this.render_reviews();
|
2018-08-01 08:39:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
2018-08-01 10:27:28 +00:00
|
|
|
edit_details() {
|
|
|
|
if (!this.edit_dialog) {
|
|
|
|
this.edit_dialog = new frappe.ui.Dialog({
|
|
|
|
title: "Edit Your Product",
|
|
|
|
fields: []
|
|
|
|
});
|
|
|
|
}
|
2018-08-01 08:39:07 +00:00
|
|
|
this.edit_dialog.show();
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
2018-08-01 10:27:28 +00:00
|
|
|
unpublish_item() {
|
2018-08-01 08:39:07 +00:00
|
|
|
if(!this.unpublish_dialog) {
|
|
|
|
this.unpublish_dialog = new frappe.ui.Dialog({
|
|
|
|
title: "Edit Your Product",
|
|
|
|
fields: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.unpublish_dialog.show();
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
|
|
|
add_to_favourites(favourite_button) {
|
2018-08-13 20:01:03 +00:00
|
|
|
$(favourite_button).addClass('disabled');
|
|
|
|
|
|
|
|
hub.call('add_item_to_seller_favourites', {
|
2018-08-13 16:06:07 +00:00
|
|
|
hub_item_code: this.hub_item_code,
|
|
|
|
hub_seller: hub.settings.company_email
|
2018-08-13 20:01:03 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
$(favourite_button).html('Saved');
|
|
|
|
frappe.show_alert(__('Saved to <b><a href="#marketplace/favourites">Favourites</a></b>'));
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log(e);
|
2018-08-13 16:06:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 10:59:40 +00:00
|
|
|
contact_seller() {
|
|
|
|
const d = new frappe.ui.Dialog({
|
|
|
|
title: __('Send a message'),
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
fieldname: 'to',
|
|
|
|
fieldtype: 'Read Only',
|
|
|
|
label: __('To'),
|
|
|
|
default: this.item.company
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldtype: 'Text',
|
|
|
|
fieldname: 'message',
|
|
|
|
label: __('Message')
|
|
|
|
}
|
|
|
|
],
|
|
|
|
primary_action: ({ message }) => {
|
|
|
|
if (!message) return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
d.show();
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
make_review_area() {
|
|
|
|
this.comment_area = new frappe.ui.ReviewArea({
|
|
|
|
parent: this.$wrapper.find('.timeline-head').empty(),
|
|
|
|
mentions: [],
|
2018-08-13 16:06:07 +00:00
|
|
|
on_submit: this.on_submit_review.bind(this)
|
2018-08-01 08:39:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
|
|
|
|
on_submit_review(values) {
|
|
|
|
values.user = frappe.session.user;
|
|
|
|
values.username = frappe.session.user_fullname;
|
|
|
|
|
|
|
|
hub.call('add_item_review', {
|
|
|
|
hub_item_code: this.hub_item_code,
|
|
|
|
review: JSON.stringify(values)
|
|
|
|
})
|
|
|
|
.then(this.push_review_in_review_area.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
push_review_in_review_area(review) {
|
|
|
|
this.reviews = this.reviews || [];
|
|
|
|
this.reviews.push(review);
|
|
|
|
this.render_reviews();
|
|
|
|
|
|
|
|
this.comment_area.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
get_reviews() {
|
|
|
|
return hub.call('get_item_reviews', { hub_item_code: this.hub_item_code }).catch(() => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-13 16:06:07 +00:00
|
|
|
render_reviews() {
|
|
|
|
const $timeline = this.$wrapper.find('.timeline-items');
|
|
|
|
|
|
|
|
$timeline.empty();
|
|
|
|
|
2018-08-13 20:01:03 +00:00
|
|
|
const reviews = this.reviews || [];
|
|
|
|
|
|
|
|
reviews.sort((a, b) => {
|
2018-08-01 08:39:07 +00:00
|
|
|
if (a.modified > b.modified) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.modified < b.modified) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2018-08-13 20:01:03 +00:00
|
|
|
reviews.forEach(review => {
|
2018-08-13 16:06:07 +00:00
|
|
|
$(get_review_html(review)).appendTo($timeline);
|
|
|
|
});
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
2018-08-01 12:02:13 +00:00
|
|
|
}
|