2018-08-01 10:59:40 +00:00
|
|
|
import SubPage from './subpage';
|
2018-08-26 12:57:04 +00:00
|
|
|
// import { get_item_card_container_html } from '../components/items_container';
|
2018-08-25 15:52:55 +00:00
|
|
|
import { get_buying_item_message_card_html } from '../components/item_card';
|
|
|
|
import { get_selling_item_message_card_html } from '../components/item_card';
|
2018-08-27 04:42:45 +00:00
|
|
|
// import { get_empty_state } from '../components/empty_state';
|
2018-08-01 10:59:40 +00:00
|
|
|
|
2018-08-25 15:52:55 +00:00
|
|
|
erpnext.hub.Buying = class Buying extends SubPage {
|
2018-08-17 13:09:36 +00:00
|
|
|
refresh() {
|
2018-08-25 15:52:55 +00:00
|
|
|
this.get_items_for_messages().then((items) => {
|
2018-08-17 13:09:36 +00:00
|
|
|
this.empty();
|
2018-08-24 05:55:04 +00:00
|
|
|
if (items.length) {
|
|
|
|
items.map(item => {
|
2018-08-25 15:52:55 +00:00
|
|
|
item.route = `marketplace/buying/${item.hub_item_code}`
|
2018-08-20 13:03:46 +00:00
|
|
|
})
|
2018-08-25 15:52:55 +00:00
|
|
|
this.render(items, __('Buying'));
|
2018-08-20 13:03:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 05:55:04 +00:00
|
|
|
if (!items.length && !items.length) {
|
2018-08-17 13:09:36 +00:00
|
|
|
this.render_empty_state();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render(items = [], title) {
|
2018-08-26 12:57:04 +00:00
|
|
|
// const html = get_item_card_container_html(items, title, get_buying_item_message_card_html);
|
2018-08-17 13:09:36 +00:00
|
|
|
this.$wrapper.append(html);
|
|
|
|
}
|
|
|
|
|
|
|
|
render_empty_state() {
|
2018-08-27 04:42:45 +00:00
|
|
|
// const empty_state = get_empty_state(__('You haven\'t interacted with any seller yet.'));
|
|
|
|
// this.$wrapper.html(empty_state);
|
2018-08-17 13:09:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-25 15:52:55 +00:00
|
|
|
get_items_for_messages() {
|
|
|
|
return hub.call('get_buying_items_for_messages', {}, 'action:send_message');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.hub.Selling = class Selling extends SubPage {
|
|
|
|
refresh() {
|
|
|
|
this.get_items_for_messages().then((items) => {
|
|
|
|
this.empty();
|
|
|
|
if (items.length) {
|
|
|
|
items.map(item => {
|
|
|
|
item.route = `marketplace/selling/${item.hub_item_code}`
|
|
|
|
})
|
|
|
|
this.render(items, __('Selling'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!items.length && !items.length) {
|
|
|
|
this.render_empty_state();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render(items = [], title) {
|
2018-08-26 12:57:04 +00:00
|
|
|
// const html = get_item_card_container_html(items, title, get_selling_item_message_card_html);
|
2018-08-25 15:52:55 +00:00
|
|
|
this.$wrapper.append(html);
|
2018-08-17 13:09:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-25 15:52:55 +00:00
|
|
|
render_empty_state() {
|
|
|
|
const empty_state = get_empty_state(__('You haven\'t interacted with any seller yet.'));
|
|
|
|
this.$wrapper.html(empty_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
get_items_for_messages() {
|
|
|
|
return hub.call('get_selling_items_for_messages', {});
|
2018-08-17 13:09:36 +00:00
|
|
|
}
|
2018-08-01 13:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_message_area_html() {
|
2018-08-17 13:09:36 +00:00
|
|
|
return `
|
|
|
|
<div class="message-area border padding flex flex-column">
|
|
|
|
<div class="message-list">
|
|
|
|
</div>
|
|
|
|
<div class="message-input">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
2018-08-01 13:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_list_item_html(seller) {
|
2018-08-17 13:09:36 +00:00
|
|
|
const active_class = frappe.get_route()[2] === seller.email ? 'active' : '';
|
|
|
|
|
|
|
|
return `
|
|
|
|
<div class="message-list-item ${active_class}" data-route="marketplace/messages/${seller.email}">
|
|
|
|
<div class="list-item-left">
|
|
|
|
<img src="${seller.image || 'https://picsum.photos/200?random'}">
|
|
|
|
</div>
|
|
|
|
<div class="list-item-body">
|
|
|
|
${seller.company}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
2018-08-01 13:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_message_html(message) {
|
2018-08-17 13:09:36 +00:00
|
|
|
return `
|
|
|
|
<div>
|
|
|
|
<h5>${message.sender}</h5>
|
|
|
|
<p>${message.content}</p>
|
|
|
|
</div>
|
|
|
|
`;
|
2018-08-26 12:57:04 +00:00
|
|
|
}
|