2017-12-10 16:32:41 +00:00
|
|
|
frappe.provide('erpnext.hub.pages');
|
|
|
|
|
2018-07-23 13:14:46 +00:00
|
|
|
frappe.views.marketplaceFactory = class marketplaceFactory extends frappe.views.Factory {
|
|
|
|
show() {
|
|
|
|
const page_name = frappe.get_route_str();
|
|
|
|
|
|
|
|
if (frappe.pages.marketplace) {
|
|
|
|
frappe.container.change_to('marketplace');
|
|
|
|
erpnext.hub.marketplace.refresh();
|
|
|
|
} else {
|
|
|
|
this.make('marketplace');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
make(page_name) {
|
|
|
|
const assets = [
|
2018-07-26 13:05:04 +00:00
|
|
|
'/assets/erpnext/js/hub/marketplace.js'
|
2018-07-23 13:14:46 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
frappe.require(assets, () => {
|
|
|
|
erpnext.hub.marketplace = new erpnext.hub.Marketplace({
|
|
|
|
parent: this.make_page(true, page_name)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frappe.views.HubFactory = class HubFactory extends frappe.views.Factory {
|
|
|
|
|
2017-12-10 16:32:41 +00:00
|
|
|
make(route) {
|
|
|
|
const page_name = frappe.get_route_str();
|
|
|
|
const page = route[1];
|
|
|
|
|
2018-01-25 03:48:32 +00:00
|
|
|
const assets = {
|
|
|
|
'List': [
|
2018-04-03 05:14:13 +00:00
|
|
|
'/assets/erpnext/js/hub/hub_listing.js',
|
2018-01-25 03:48:32 +00:00
|
|
|
],
|
|
|
|
'Form': [
|
2018-04-03 05:14:13 +00:00
|
|
|
'/assets/erpnext/js/hub/hub_form.js'
|
2018-01-25 03:48:32 +00:00
|
|
|
]
|
|
|
|
};
|
2018-02-15 04:47:07 +00:00
|
|
|
frappe.model.with_doc('Hub Settings', 'Hub Settings', () => {
|
|
|
|
this.hub_settings = frappe.get_doc('Hub Settings');
|
2018-01-25 03:48:32 +00:00
|
|
|
|
2018-02-15 04:47:07 +00:00
|
|
|
if (!erpnext.hub.pages[page_name]) {
|
2018-04-03 05:14:13 +00:00
|
|
|
if(!frappe.is_online()) {
|
|
|
|
this.render_offline_card();
|
|
|
|
return;
|
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
if (!route[2]) {
|
|
|
|
frappe.require(assets['List'], () => {
|
2018-04-03 05:14:13 +00:00
|
|
|
if(page === 'Favourites') {
|
|
|
|
erpnext.hub.pages[page_name] = new erpnext.hub['Favourites']({
|
|
|
|
parent: this.make_page(true, page_name),
|
|
|
|
hub_settings: this.hub_settings
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
erpnext.hub.pages[page_name] = new erpnext.hub[page+'Listing']({
|
|
|
|
parent: this.make_page(true, page_name),
|
|
|
|
hub_settings: this.hub_settings
|
|
|
|
});
|
|
|
|
}
|
2018-01-26 10:09:13 +00:00
|
|
|
});
|
2018-05-30 09:42:20 +00:00
|
|
|
} else if (!route[3]){
|
2018-02-15 04:47:07 +00:00
|
|
|
frappe.require(assets['Form'], () => {
|
|
|
|
erpnext.hub.pages[page_name] = new erpnext.hub[page+'Page']({
|
|
|
|
unique_id: route[2],
|
|
|
|
doctype: route[2],
|
|
|
|
parent: this.make_page(true, page_name),
|
|
|
|
hub_settings: this.hub_settings
|
|
|
|
});
|
2017-12-10 16:32:41 +00:00
|
|
|
});
|
2018-05-30 09:42:20 +00:00
|
|
|
} else {
|
|
|
|
frappe.require(assets['List'], () => {
|
|
|
|
frappe.route_options = {};
|
|
|
|
frappe.route_options["company_name"] = route[2]
|
|
|
|
erpnext.hub.pages[page_name] = new erpnext.hub['ItemListing']({
|
|
|
|
parent: this.make_page(true, page_name),
|
|
|
|
hub_settings: this.hub_settings
|
|
|
|
});
|
|
|
|
});
|
2018-02-15 04:47:07 +00:00
|
|
|
}
|
2018-04-03 05:14:13 +00:00
|
|
|
window.hub_page = erpnext.hub.pages[page_name];
|
2018-02-15 04:47:07 +00:00
|
|
|
} else {
|
|
|
|
frappe.container.change_to(page_name);
|
|
|
|
window.hub_page = erpnext.hub.pages[page_name];
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
});
|
2018-07-23 13:14:46 +00:00
|
|
|
}
|
2018-04-03 05:14:13 +00:00
|
|
|
|
|
|
|
render_offline_card() {
|
|
|
|
let html = `<div class='page-card' style='margin: 140px auto;'>
|
|
|
|
<div class='page-card-head'>
|
|
|
|
<span class='indicator red'>${'Failed to connect'}</span>
|
|
|
|
</div>
|
|
|
|
<p>${ __("Please check your network connection.") }</p>
|
|
|
|
<div><a href='#Hub/Item' class='btn btn-primary btn-sm'>
|
|
|
|
${ __("Reload") }</a></div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
let page = $('#body_div');
|
|
|
|
page.append(html);
|
|
|
|
|
|
|
|
return;
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
2018-07-23 13:14:46 +00:00
|
|
|
}
|