2017-12-10 16:32:41 +00:00
|
|
|
frappe.provide('erpnext.hub');
|
|
|
|
|
|
|
|
erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList {
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
|
|
|
this.page_title = __('Hub');
|
|
|
|
this.method = 'erpnext.hub_node.get_items';
|
|
|
|
|
|
|
|
const route = frappe.get_route();
|
|
|
|
this.page_name = route[1];
|
2018-01-25 03:48:32 +00:00
|
|
|
|
|
|
|
return this.get_hub_item_meta()
|
|
|
|
.then(r => {
|
|
|
|
this.meta = r.message || this.meta;
|
|
|
|
this.doctype = 'Hub Item';
|
|
|
|
frappe.model.sync(this.meta);
|
|
|
|
});
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 03:48:32 +00:00
|
|
|
get_hub_item_meta() {
|
|
|
|
return new Promise(resolve =>
|
|
|
|
frappe.call('erpnext.hub_node.get_hub_item_meta', {}, resolve));
|
|
|
|
}
|
2017-12-10 16:32:41 +00:00
|
|
|
|
2018-01-25 03:48:32 +00:00
|
|
|
setup_fields() {
|
|
|
|
this.fields = ['name', 'hub_item_code', 'image', 'item_name', 'item_code'];
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_breadcrumbs() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_side_bar() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_filter_area() {
|
2018-01-25 03:48:32 +00:00
|
|
|
this.custom_filter_configs = [
|
|
|
|
{
|
|
|
|
fieldtype: 'Data',
|
|
|
|
label: 'Company',
|
|
|
|
condition: 'like',
|
|
|
|
fieldname: 'company_name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldtype: 'Link',
|
|
|
|
label: 'Country',
|
|
|
|
options: 'Country',
|
|
|
|
condition: 'like',
|
|
|
|
fieldname: 'country'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
this.filter_area = new FilterArea(this);
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_sort_selector() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-25 03:48:32 +00:00
|
|
|
setup_view() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-10 16:32:41 +00:00
|
|
|
get_args() {
|
|
|
|
return {
|
|
|
|
start: this.start,
|
|
|
|
limit: this.page_length,
|
|
|
|
category: this.category || '',
|
|
|
|
order_by: this.order_by,
|
|
|
|
company: this.company || '',
|
2018-01-25 03:48:32 +00:00
|
|
|
text: this.search_text || '',
|
|
|
|
fields: this.fields
|
2017-12-10 16:32:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
update_data(r) {
|
|
|
|
const data = r.message;
|
2018-01-25 03:48:32 +00:00
|
|
|
console.log('update data', data);
|
2017-12-10 16:32:41 +00:00
|
|
|
|
|
|
|
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({
|
|
|
|
name: 'freeze',
|
|
|
|
item_name: 'freeze'
|
|
|
|
})).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;
|
|
|
|
console.log('this.data render', 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
|
|
|
}
|
|
|
|
|
|
|
|
card_html(item) {
|
|
|
|
item._name = encodeURI(item.name);
|
|
|
|
const encoded_name = item._name;
|
|
|
|
const title = strip_html(item['item_name' || 'item_code']);
|
|
|
|
|
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">
|
|
|
|
${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>
|
|
|
|
</div>
|
|
|
|
</a>
|
2017-12-10 16:32:41 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2018-01-25 03:48:32 +00:00
|
|
|
};
|