2018-08-01 10:27:13 +00:00
|
|
|
import SubPage from './subpage';
|
2018-08-13 16:06:07 +00:00
|
|
|
import { make_search_bar } from '../components/search_bar';
|
|
|
|
import { get_item_card_container_html } from '../components/items_container';
|
|
|
|
import { get_item_card_html } from '../components/item_card';
|
2018-08-01 08:39:07 +00:00
|
|
|
|
|
|
|
erpnext.hub.Home = class Home extends SubPage {
|
|
|
|
make_wrapper() {
|
|
|
|
super.make_wrapper();
|
|
|
|
|
|
|
|
make_search_bar({
|
|
|
|
wrapper: this.$wrapper,
|
|
|
|
on_search: keyword => {
|
|
|
|
frappe.set_route('marketplace', 'search', keyword);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.get_items_and_render();
|
|
|
|
}
|
|
|
|
|
|
|
|
get_items_and_render() {
|
2018-08-17 08:59:22 +00:00
|
|
|
this.$wrapper.find('.hub-items-container').empty();
|
2018-08-01 08:39:07 +00:00
|
|
|
this.get_data()
|
|
|
|
.then(data => {
|
|
|
|
this.render(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get_data() {
|
|
|
|
return hub.call('get_data_for_homepage', { country: frappe.defaults.get_user_default('country') });
|
|
|
|
}
|
|
|
|
|
|
|
|
render(data) {
|
|
|
|
let html = get_item_card_container_html(data.random_items, __('Explore'));
|
|
|
|
this.$wrapper.append(html);
|
|
|
|
|
|
|
|
if (data.items_by_country.length) {
|
|
|
|
html = get_item_card_container_html(data.items_by_country, __('Near you'));
|
|
|
|
this.$wrapper.append(html);
|
|
|
|
}
|
2018-08-06 13:01:26 +00:00
|
|
|
|
|
|
|
const category_items = data.category_items;
|
|
|
|
|
|
|
|
if (category_items) {
|
|
|
|
Object.keys(category_items).map(category => {
|
|
|
|
const items = category_items[category];
|
2018-08-07 07:11:21 +00:00
|
|
|
const see_all_link = `<p data-route="marketplace/category/${category}">See All</p>`;
|
|
|
|
|
|
|
|
html = get_item_card_container_html(
|
|
|
|
items,
|
|
|
|
__(category),
|
|
|
|
get_item_card_html,
|
|
|
|
see_all_link
|
|
|
|
);
|
2018-08-06 13:01:26 +00:00
|
|
|
this.$wrapper.append(html);
|
|
|
|
});
|
|
|
|
}
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
2018-08-06 13:01:26 +00:00
|
|
|
}
|