2017-12-10 16:32:41 +00:00
|
|
|
frappe.provide('erpnext.hub');
|
|
|
|
|
|
|
|
erpnext.hub.HubForm = class HubForm extends frappe.views.BaseList {
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
2018-02-14 14:23:18 +00:00
|
|
|
this.method = 'erpnext.hub_node.get_details';
|
2018-02-15 04:47:07 +00:00
|
|
|
const route = frappe.get_route();
|
|
|
|
this.page_name = route[2];
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_breadcrumbs() {
|
|
|
|
frappe.breadcrumbs.add({
|
|
|
|
label: __('Hub'),
|
2018-02-14 14:23:18 +00:00
|
|
|
route: '#Hub/' + this.doctype,
|
2017-12-10 16:32:41 +00:00
|
|
|
type: 'Custom'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_side_bar() {
|
|
|
|
this.sidebar = new frappe.ui.Sidebar({
|
|
|
|
wrapper: this.$page.find('.layout-side-section'),
|
|
|
|
css_class: 'hub-form-sidebar'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-14 14:23:18 +00:00
|
|
|
setup_filter_area() { }
|
2017-12-10 16:32:41 +00:00
|
|
|
|
2018-02-14 14:23:18 +00:00
|
|
|
setup_sort_selector() { }
|
2017-12-10 16:32:41 +00:00
|
|
|
|
|
|
|
get_args() {
|
|
|
|
return {
|
2018-02-14 14:23:18 +00:00
|
|
|
hub_sync_id: this.unique_id,
|
|
|
|
doctype: 'Hub ' + this.doctype
|
2017-12-10 16:32:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-25 03:48:32 +00:00
|
|
|
prepare_data(r) {
|
|
|
|
this.data = r.message;
|
|
|
|
}
|
|
|
|
|
2017-12-10 16:32:41 +00:00
|
|
|
update_data(r) {
|
2018-01-25 03:48:32 +00:00
|
|
|
this.data = r.message;
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-02-14 14:23:18 +00:00
|
|
|
const image_html = this.data[this.image_field_name] ?
|
|
|
|
`<img src="${this.data[this.image_field_name]}">
|
|
|
|
<span class="helper"></span>` :
|
|
|
|
`<div class="standard-image">${frappe.get_abbr(this.page_title)}</div>`;
|
|
|
|
|
2017-12-10 16:32:41 +00:00
|
|
|
this.sidebar.add_item({
|
2018-02-14 14:23:18 +00:00
|
|
|
label: image_html
|
2017-12-10 16:32:41 +00:00
|
|
|
});
|
|
|
|
|
2018-02-15 04:47:07 +00:00
|
|
|
let fields = this.get_field_configs();
|
2017-12-10 16:32:41 +00:00
|
|
|
|
|
|
|
this.form = new frappe.ui.FieldGroup({
|
|
|
|
parent: this.$result,
|
|
|
|
fields
|
|
|
|
});
|
|
|
|
|
|
|
|
this.form.make();
|
|
|
|
this.form.set_values(this.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle_result_area() {
|
2018-02-14 14:23:18 +00:00
|
|
|
this.$result.toggle(this.unique_id);
|
2017-12-10 16:32:41 +00:00
|
|
|
this.$paging_area.toggle(this.data.length > 0);
|
|
|
|
this.$no_result.toggle(this.data.length == 0);
|
|
|
|
|
|
|
|
const show_more = (this.start + this.page_length) <= this.data.length;
|
|
|
|
this.$paging_area.find('.btn-more')
|
|
|
|
.toggle(show_more);
|
|
|
|
}
|
|
|
|
};
|
2018-02-14 14:23:18 +00:00
|
|
|
|
|
|
|
erpnext.hub.ItemPage = class ItemPage extends erpnext.hub.HubForm{
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
|
|
|
this.doctype = 'Item';
|
|
|
|
this.image_field_name = 'image';
|
|
|
|
}
|
|
|
|
|
2018-02-15 04:47:07 +00:00
|
|
|
get_field_configs() {
|
|
|
|
let fields = [];
|
|
|
|
this.fields.map(fieldname => {
|
|
|
|
fields.push({
|
|
|
|
label: toTitle(frappe.model.unscrub(fieldname)),
|
|
|
|
fieldname,
|
|
|
|
fieldtype: 'Data',
|
|
|
|
read_only: 1
|
2018-02-14 14:23:18 +00:00
|
|
|
});
|
2018-02-15 04:47:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let category_field = {
|
|
|
|
label: 'Hub Category',
|
|
|
|
fieldname: 'hub_category',
|
|
|
|
fieldtype: 'Data'
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.data.company_name === this.hub_settings.company) {
|
|
|
|
this.page.set_primary_action(__('Update'), () => {
|
|
|
|
this.update_on_hub();
|
|
|
|
}, 'octicon octicon-plus');
|
|
|
|
} else {
|
|
|
|
category_field.read_only = 1;
|
|
|
|
}
|
|
|
|
|
2018-02-15 05:17:59 +00:00
|
|
|
fields.unshift(category_field);
|
2018-02-15 04:47:07 +00:00
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
2018-02-14 14:23:18 +00:00
|
|
|
|
2018-02-15 04:47:07 +00:00
|
|
|
update_on_hub() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
frappe.call({
|
|
|
|
method: 'erpnext.hub_node.update_category',
|
|
|
|
args: { item: this.unique_id, category: this.form.get_value('hub_category') },
|
|
|
|
callback: resolve,
|
|
|
|
freeze: true
|
|
|
|
}).fail(reject);
|
2018-02-14 14:23:18 +00:00
|
|
|
});
|
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
|
|
|
|
setup_fields() {
|
|
|
|
this.fields = ['hub_item_code', 'item_name', 'item_code', 'description',
|
|
|
|
'seller', 'company_name', 'country'];
|
|
|
|
}
|
2018-02-14 14:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.hub.CompanyPage = class CompanyPage extends erpnext.hub.HubForm{
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
|
|
|
this.doctype = 'Company';
|
|
|
|
this.image_field_name = 'company_logo';
|
|
|
|
}
|
|
|
|
|
2018-02-15 04:47:07 +00:00
|
|
|
get_field_configs() {
|
|
|
|
let fields = [];
|
|
|
|
this.fields.map(fieldname => {
|
|
|
|
fields.push({
|
|
|
|
label: toTitle(frappe.model.unscrub(fieldname)),
|
|
|
|
fieldname,
|
|
|
|
fieldtype: 'Data',
|
|
|
|
read_only: 1
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
2018-02-14 14:23:18 +00:00
|
|
|
setup_fields() {
|
|
|
|
this.fields = ['company_name', 'description', 'route', 'country', 'seller', 'site_name'];
|
|
|
|
}
|
|
|
|
}
|