brotherton-erpnext/erpnext/public/js/hub/hub_page.js

244 lines
5.7 KiB
JavaScript
Raw Normal View History

2017-12-10 16:32:41 +00:00
frappe.provide('erpnext.hub');
2018-02-07 18:20:01 +00:00
erpnext.hub.HubListing = class HubListing extends frappe.views.BaseList {
2017-12-10 16:32:41 +00:00
setup_defaults() {
super.setup_defaults();
this.page_title = __('Hub');
2018-02-07 18:20:01 +00:00
this.method = 'erpnext.hub_node.get_list';
2017-12-10 16:32:41 +00:00
const route = frappe.get_route();
this.page_name = route[1];
2018-02-07 18:20:01 +00:00
}
2018-01-25 03:48:32 +00:00
2018-02-07 18:20:01 +00:00
setup_fields() {
return this.get_meta()
2018-01-25 03:48:32 +00:00
.then(r => {
this.meta = r.message || this.meta;
frappe.model.sync(this.meta);
});
2017-12-10 16:32:41 +00:00
}
2018-02-07 18:20:01 +00:00
get_meta() {
2018-01-25 03:48:32 +00:00
return new Promise(resolve =>
2018-02-07 18:20:01 +00:00
frappe.call('erpnext.hub_node.get_meta', {doctype: this.doctype}, resolve));
2017-12-10 16:32:41 +00:00
}
set_breadcrumbs() { }
2017-12-10 16:32:41 +00:00
2018-02-14 14:23:18 +00:00
setup_side_bar() {
this.sidebar = new frappe.ui.Sidebar({
wrapper: this.page.wrapper.find('.layout-side-section'),
css_class: 'hub-sidebar'
});
}
2017-12-10 16:32:41 +00:00
setup_sort_selector() { }
2017-12-10 16:32:41 +00:00
setup_view() { }
2018-01-25 03:48:32 +00:00
2017-12-10 16:32:41 +00:00
get_args() {
return {
2018-02-07 18:20:01 +00:00
doctype: this.doctype,
2017-12-10 16:32:41 +00:00
start: this.start,
limit: this.page_length,
order_by: this.order_by,
fields: this.fields,
filters: this.get_filters_for_args()
2017-12-10 16:32:41 +00:00
};
}
update_data(r) {
const data = r.message;
if (this.start === 0) {
this.data = data;
} else {
this.data = this.data.concat(data);
}
2018-01-25 03:48:32 +00:00
}
freeze(toggle) {
this.$freeze.toggle(toggle);
if (this.$freeze.find('.image-view-container').length) return;
const html = Array.from(new Array(4)).map(d => this.card_html({
2018-02-07 18:20:01 +00:00
name: 'Loading...',
item_name: 'Loading...'
2018-01-25 03:48:32 +00:00
})).join('');
this.$freeze.html(`<div class="image-view-container border-top">${html}</div>`);
2017-12-10 16:32:41 +00:00
}
render() {
this.render_image_view();
}
render_image_view() {
2018-01-25 03:48:32 +00:00
let data = this.data;
if (this.start === 0) {
this.$result.html('<div class="image-view-container small padding-top">');
data = this.data.slice(this.start);
}
2017-12-10 16:32:41 +00:00
2018-01-25 03:48:32 +00:00
var html = data.map(this.card_html.bind(this)).join("");
this.$result.find('.image-view-container').append(html);
2017-12-10 16:32:41 +00:00
}
2018-02-07 18:20:01 +00:00
}
erpnext.hub.ItemListing = class ItemListing extends erpnext.hub.HubListing {
setup_defaults() {
super.setup_defaults();
this.doctype = 'Hub Item';
this.fields = ['name', 'hub_item_code', 'image', 'item_name', 'item_code', 'company_name'];
this.filters = [];
this.custom_filter_configs = [
{
fieldtype: 'Data',
label: 'Company',
condition: 'like',
fieldname: 'company_name',
},
{
fieldtype: 'Link',
label: 'Country',
options: 'Country',
condition: 'like',
fieldname: 'country'
}
];
}
2018-02-14 14:23:18 +00:00
setup_side_bar() {
super.setup_side_bar();
this.category_tree = new frappe.ui.Tree({
parent: this.sidebar.$sidebar,
label: 'All Categories',
expandable: true,
2018-02-15 03:20:31 +00:00
args: {parent: this.current_category},
2018-02-14 14:23:18 +00:00
method: 'erpnext.hub_node.get_categories',
on_click: (node) => {
this.update_category(node.label);
}
});
2018-02-15 04:47:07 +00:00
this.sidebar.add_item({
label: __('Companies'),
on_click: () => frappe.set_route('Hub', 'Company')
});
2018-02-15 05:24:23 +00:00
this.sidebar.add_item({
label: this.hub_settings.company,
on_click: () => frappe.set_route('Form', 'Company', this.hub_settings.company)
}, __("Account"));
2018-02-15 04:47:07 +00:00
this.sidebar.add_item({
label: __("My Orders"),
on_click: () => frappe.set_route('List', 'Request for Quotation')
}, __("Account"));
2018-02-14 14:23:18 +00:00
}
update_category(label) {
this.current_category = (label=='All Categories') ? undefined : label;
this.refresh();
}
2018-02-07 18:20:01 +00:00
get_filters_for_args() {
let filters = {};
this.filter_area.get().forEach(f => {
let field = f[1] !== 'name' ? f[1] : 'item_name';
filters[field] = [f[2], f[3]];
});
if(this.current_category) {
filters['hub_category'] = this.current_category;
}
return filters;
}
2017-12-10 16:32:41 +00:00
card_html(item) {
item._name = encodeURI(item.name);
const encoded_name = item._name;
const title = strip_html(item['item_name' || 'item_code']);
const company_name = item['company_name'];
2017-12-10 16:32:41 +00:00
2018-01-25 03:48:32 +00:00
const route = `#Hub/Item/${item.hub_item_code}`;
const image_html = item.image ?
`<img src="${item.image}">
<span class="helper"></span>` :
`<div class="standard-image">${frappe.get_abbr(title)}</div>`;
2017-12-10 16:32:41 +00:00
return `
2018-01-25 03:48:32 +00:00
<div class="hub-item-wrapper margin-bottom" style="width: 200px;">
<a href="${route}">
<div class="hub-item-image">
<div class="img-wrapper" style="height: 200px; width: 200px">
2018-02-14 14:23:18 +00:00
${ image_html }
2017-12-10 16:32:41 +00:00
</div>
</div>
2018-01-25 03:48:32 +00:00
<div class="hub-item-title">
<h5 class="bold">
${ title }
</h5>
2018-02-15 04:47:07 +00:00
2018-01-25 03:48:32 +00:00
</div>
</a>
2018-02-15 04:47:07 +00:00
<a href="${'#Hub/Company/'+company_name}"><p>${ company_name }</p></a>
2017-12-10 16:32:41 +00:00
</div>
`;
}
};
2018-02-07 18:20:01 +00:00
erpnext.hub.CompanyListing = class CompanyListing extends erpnext.hub.HubListing {
setup_defaults() {
super.setup_defaults();
this.doctype = 'Hub Company';
2018-02-14 14:23:18 +00:00
this.fields = ['company_logo', 'name', 'site_name', 'seller_city', 'seller_description', 'seller', 'country', 'company_name'];
2018-02-07 18:20:01 +00:00
this.filters = [];
this.custom_filter_configs = [
{
fieldtype: 'Link',
label: 'Country',
options: 'Country',
condition: 'like',
fieldname: 'country'
}
];
}
get_filters_for_args() {
let filters = {};
this.filter_area.get().forEach(f => {
let field = f[1] !== 'name' ? f[1] : 'company_name';
filters[field] = [f[2], f[3]];
});
return filters;
}
2018-02-14 14:23:18 +00:00
card_html(company) {
company._name = encodeURI(company.name);
const route = `#Hub/Company/${company.company_name}`;
2018-02-07 18:20:01 +00:00
2018-02-14 14:23:18 +00:00
let image_html = company.company_logo ?
`<img src="${company.company_logo}"><span class="helper"></span>` :
`<div class="standard-image">${frappe.get_abbr(company.company_name)}</div>`;
2018-02-07 18:20:01 +00:00
return `
<div class="hub-item-wrapper margin-bottom" style="width: 200px;">
<a href="${route}">
<div class="hub-item-image">
<div class="img-wrapper" style="height: 200px; width: 200px">
2018-02-14 14:23:18 +00:00
${ image_html }
2018-02-07 18:20:01 +00:00
</div>
</div>
<div class="hub-item-title">
<h5 class="bold">
2018-02-14 14:23:18 +00:00
${ company.company_name }
2018-02-07 18:20:01 +00:00
</h5>
</div>
</a>
</div>
`;
}
2018-01-25 03:48:32 +00:00
};