2017-12-10 16:32:41 +00:00
|
|
|
frappe.provide('erpnext.hub');
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
erpnext.hub.HubDetailsPage = class HubDetailsPage extends frappe.views.BaseList {
|
2017-12-10 16:32:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
setup_fields() {
|
|
|
|
return this.get_meta()
|
|
|
|
.then(r => {
|
|
|
|
this.meta = r.message.meta || this.meta;
|
|
|
|
this.categories = r.message.categories || [];
|
|
|
|
this.bootstrap_data(r.message);
|
|
|
|
|
|
|
|
this.getFormFields();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bootstrap_data() { }
|
|
|
|
|
|
|
|
get_meta() {
|
|
|
|
return new Promise(resolve =>
|
|
|
|
frappe.call('erpnext.hub_node.get_meta', {doctype: 'Hub ' + this.doctype}, resolve));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-04-03 05:14:13 +00:00
|
|
|
|
|
|
|
this.attachFooter();
|
|
|
|
this.attachTimeline();
|
|
|
|
this.attachReviewArea();
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
// let category = this.quick_view.get_values().hub_category;
|
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
// frappe.call({
|
|
|
|
// method: 'erpnext.hub_node.update_category',
|
|
|
|
// args: {
|
|
|
|
// hub_item_code: values.hub_item_code,
|
|
|
|
// category: category,
|
|
|
|
// },
|
|
|
|
// callback: (r) => {
|
|
|
|
// resolve();
|
|
|
|
// },
|
|
|
|
// freeze: true
|
|
|
|
// }).fail(reject);
|
|
|
|
// });
|
|
|
|
|
|
|
|
get_timeline() {
|
|
|
|
return `<div class="timeline">
|
|
|
|
<div class="timeline-head">
|
|
|
|
</div>
|
|
|
|
<div class="timeline-new-email">
|
|
|
|
<button class="btn btn-default btn-reply-email btn-xs">
|
|
|
|
${__("Reply")}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="timeline-items"></div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_footer() {
|
|
|
|
return `<div class="form-footer">
|
|
|
|
<div class="after-save">
|
|
|
|
<div class="form-comments"></div>
|
|
|
|
</div>
|
|
|
|
<div class="pull-right scroll-to-top">
|
|
|
|
<a onclick="frappe.utils.scroll_to(0)"><i class="fa fa-chevron-up text-muted"></i></a>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
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>`;
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
this.sidebar.remove_item('image');
|
2017-12-10 16:32:41 +00:00
|
|
|
this.sidebar.add_item({
|
2018-04-03 05:14:13 +00:00
|
|
|
name: 'image',
|
2018-02-14 14:23:18 +00:00
|
|
|
label: image_html
|
2017-12-10 16:32:41 +00:00
|
|
|
});
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
if(!this.form) {
|
|
|
|
let fields = this.formFields;
|
|
|
|
this.form = new frappe.ui.FieldGroup({
|
|
|
|
parent: this.$result,
|
|
|
|
fields
|
|
|
|
});
|
|
|
|
this.form.make();
|
|
|
|
}
|
2017-12-10 16:32:41 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
if(this.data.hub_category) {
|
|
|
|
this.form.fields_dict.set_category.hide();
|
|
|
|
}
|
2017-12-10 16:32:41 +00:00
|
|
|
|
|
|
|
this.form.set_values(this.data);
|
2018-04-03 05:14:13 +00:00
|
|
|
this.$result.show();
|
|
|
|
|
|
|
|
this.$timelineList.empty();
|
|
|
|
if(this.data.reviews.length) {
|
|
|
|
this.data.reviews.map(review => {
|
|
|
|
this.addReviewToTimeline(review);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
this.postRender()
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
postRender() {}
|
2017-12-10 16:32:41 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
attachFooter() {
|
|
|
|
let footerHtml = `<div class="form-footer">
|
|
|
|
<div class="form-comments"></div>
|
|
|
|
<div class="pull-right scroll-to-top">
|
|
|
|
<a onclick="frappe.utils.scroll_to(0)"><i class="fa fa-chevron-up text-muted"></i></a>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
let parent = $('<div>').appendTo(this.page.main.parent());
|
|
|
|
this.$footer = $(footerHtml).appendTo(parent);
|
2017-12-10 16:32:41 +00:00
|
|
|
}
|
2018-02-14 14:23:18 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
attachTimeline() {
|
|
|
|
let timelineHtml = `<div class="timeline">
|
|
|
|
<div class="timeline-head">
|
|
|
|
</div>
|
|
|
|
<div class="timeline-new-email">
|
|
|
|
<button class="btn btn-default btn-reply-email btn-xs">
|
|
|
|
${ __("Reply") }
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="timeline-items"></div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
let parent = this.$footer.find(".form-comments");
|
|
|
|
this.$timeline = $(timelineHtml).appendTo(parent);
|
|
|
|
|
|
|
|
this.$timelineList = this.$timeline.find(".timeline-items");
|
2018-02-14 14:23:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
attachReviewArea() {
|
|
|
|
this.comment_area = new frappe.ui.ReviewArea({
|
|
|
|
parent: this.$footer.find('.timeline-head'),
|
|
|
|
mentions: [],
|
|
|
|
on_submit: (val) => {
|
|
|
|
val.user = frappe.session.user;
|
|
|
|
val.username = frappe.session.user_fullname;
|
|
|
|
frappe.call({
|
|
|
|
method: 'erpnext.hub_node.send_review',
|
|
|
|
args: {
|
|
|
|
hub_item_code: this.data.hub_item_code,
|
|
|
|
review: val
|
|
|
|
},
|
|
|
|
callback: (r) => {
|
|
|
|
this.refresh();
|
|
|
|
this.comment_area.reset();
|
|
|
|
},
|
|
|
|
freeze: true
|
|
|
|
});
|
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
});
|
2018-04-03 05:14:13 +00:00
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
addReviewToTimeline(data) {
|
|
|
|
let username = data.username || data.user || __("Anonymous")
|
|
|
|
let imageHtml = data.user_image
|
|
|
|
? `<div class="avatar-frame" style="background-image: url(${data.user_image})"></div>`
|
|
|
|
: `<div class="standard-image" style="background-color: #fafbfc">${frappe.get_abbr(username)}</div>`
|
|
|
|
|
|
|
|
let editHtml = data.own
|
|
|
|
? `<div class="pull-right hidden-xs close-btn-container">
|
|
|
|
<span class="small text-muted">
|
|
|
|
${'data.delete'}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="pull-right edit-btn-container">
|
|
|
|
<span class="small text-muted">
|
|
|
|
${'data.edit'}
|
|
|
|
</span>
|
|
|
|
</div>`
|
|
|
|
: '';
|
|
|
|
|
|
|
|
let ratingHtml = '';
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
for(var i = 0; i < 5; i++) {
|
|
|
|
let starIcon = 'fa-star-o'
|
|
|
|
if(i < data.rating) {
|
|
|
|
starIcon = 'fa-star';
|
|
|
|
}
|
|
|
|
ratingHtml += `<i class="fa fa-fw ${starIcon} star-icon" data-idx='${i}'></i>`;
|
2018-02-15 04:47:07 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
$(this.getTimelineItem(data, imageHtml, editHtml, ratingHtml))
|
|
|
|
.appendTo(this.$timelineList);
|
|
|
|
}
|
|
|
|
|
|
|
|
getTimelineItem(data, imageHtml, editHtml, ratingHtml) {
|
|
|
|
return `<div class="media timeline-item user-content" data-doctype="${''}" data-name="${''}">
|
|
|
|
<span class="pull-left avatar avatar-medium hidden-xs" style="margin-top: 1px">
|
|
|
|
${imageHtml}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<div class="pull-left media-body">
|
|
|
|
<div class="media-content-wrapper">
|
|
|
|
<div class="action-btns">${editHtml}</div>
|
|
|
|
|
|
|
|
<div class="comment-header clearfix small ${'linksActive'}">
|
|
|
|
<span class="pull-left avatar avatar-small visible-xs">
|
|
|
|
${imageHtml}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<div class="asset-details">
|
|
|
|
<span class="author-wrap">
|
|
|
|
<i class="octicon octicon-quote hidden-xs fa-fw"></i>
|
|
|
|
<span>${data.username}</span>
|
|
|
|
</span>
|
|
|
|
<a href="#Form/${''}" class="text-muted">
|
|
|
|
<span class="text-muted hidden-xs">–</span>
|
|
|
|
<span class="indicator-right ${'green'}
|
|
|
|
delivery-status-indicator">
|
|
|
|
<span class="hidden-xs">${data.pretty_date}</span>
|
|
|
|
</span>
|
|
|
|
</a>
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
<a class="text-muted reply-link pull-right timeline-content-show"
|
|
|
|
title="${__('Reply')}"> ${''} </a>
|
|
|
|
<span class="comment-likes hidden-xs">
|
|
|
|
<i class="octicon octicon-heart like-action text-extra-muted not-liked fa-fw">
|
|
|
|
</i>
|
|
|
|
<span class="likes-count text-muted">10</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="reply timeline-content-show">
|
|
|
|
<div class="timeline-item-content">
|
|
|
|
<p class="text-muted small">
|
|
|
|
<b>${data.subject}</b>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
<p class="text-muted small">
|
|
|
|
${ratingHtml}
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
<p>
|
|
|
|
${data.content}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
2018-02-15 04:47:07 +00:00
|
|
|
}
|
2018-02-14 14:23:18 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
prepareFormFields(fields, fieldnames) {
|
|
|
|
return fields
|
|
|
|
.filter(field => fieldnames.includes(field.fieldname))
|
|
|
|
.map(field => {
|
|
|
|
let {
|
|
|
|
label,
|
|
|
|
fieldname,
|
|
|
|
fieldtype,
|
|
|
|
} = field;
|
|
|
|
let read_only = 1;
|
|
|
|
return {
|
|
|
|
label,
|
|
|
|
fieldname,
|
|
|
|
fieldtype,
|
|
|
|
read_only,
|
|
|
|
};
|
2018-02-14 14:23:18 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-03 05:14:13 +00:00
|
|
|
};
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
erpnext.hub.ItemPage = class ItemPage extends erpnext.hub.HubDetailsPage {
|
|
|
|
constructor(opts) {
|
|
|
|
super(opts);
|
|
|
|
|
|
|
|
this.show();
|
2018-02-15 04:47:07 +00:00
|
|
|
}
|
2018-02-14 14:23:18 +00:00
|
|
|
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
2018-04-03 05:14:13 +00:00
|
|
|
this.doctype = 'Item';
|
|
|
|
this.image_field_name = 'image';
|
2018-02-14 14:23:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
postRender() {
|
|
|
|
this.categoryDialog = new frappe.ui.Dialog({
|
|
|
|
title: __('Suggest Category'),
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
label: __('Category'),
|
|
|
|
fieldname: 'category',
|
|
|
|
fieldtype: 'Autocomplete',
|
|
|
|
options: this.categories,
|
|
|
|
reqd: 1
|
|
|
|
}
|
|
|
|
],
|
|
|
|
primary_action_label: __("Send"),
|
|
|
|
primary_action: () => {
|
|
|
|
let values = this.categoryDialog.get_values();
|
|
|
|
frappe.call({
|
|
|
|
method: 'erpnext.hub_node.update_category',
|
|
|
|
args: {
|
|
|
|
hub_item_code: this.data.hub_item_code,
|
|
|
|
category: values.category
|
|
|
|
},
|
|
|
|
callback: () => {
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
freeze: true
|
|
|
|
}).fail(() => {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getFormFields() {
|
|
|
|
let colOneFieldnames = ['item_name', 'item_code', 'description'];
|
|
|
|
let colTwoFieldnames = ['seller', 'company_name', 'country'];
|
|
|
|
let colOneFields = this.prepareFormFields(this.meta.fields, colOneFieldnames);
|
|
|
|
let colTwoFields = this.prepareFormFields(this.meta.fields, colTwoFieldnames);
|
|
|
|
|
|
|
|
let miscFields = [
|
|
|
|
{
|
|
|
|
label: __('Category'),
|
|
|
|
fieldname: 'hub_category',
|
2018-02-15 04:47:07 +00:00
|
|
|
fieldtype: 'Data',
|
|
|
|
read_only: 1
|
2018-04-03 05:14:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: __('Suggest Category?'),
|
|
|
|
fieldname: 'set_category',
|
|
|
|
fieldtype: 'Button',
|
|
|
|
click: () => {
|
|
|
|
this.categoryDialog.show();
|
|
|
|
}
|
|
|
|
},
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
{
|
|
|
|
fieldname: 'cb1',
|
|
|
|
fieldtype: 'Column Break'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
this.formFields = colOneFields.concat(miscFields, colTwoFields);
|
2018-02-15 04:47:07 +00:00
|
|
|
}
|
2018-04-03 05:14:13 +00:00
|
|
|
}
|
2018-02-15 04:47:07 +00:00
|
|
|
|
2018-04-03 05:14:13 +00:00
|
|
|
erpnext.hub.CompanyPage = class CompanyPage extends erpnext.hub.HubDetailsPage {
|
|
|
|
constructor(opts) {
|
|
|
|
super(opts);
|
|
|
|
|
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_defaults() {
|
|
|
|
super.setup_defaults();
|
|
|
|
this.doctype = 'Company';
|
|
|
|
this.image_field_name = 'company_logo';
|
|
|
|
}
|
|
|
|
|
|
|
|
getFormFields() {
|
|
|
|
let fieldnames = ['company_name', 'description', 'route', 'country', 'seller', 'site_name'];;
|
|
|
|
this.formFields = this.prepareFormFields(this.meta.fields, fieldnames);
|
2018-02-14 14:23:18 +00:00
|
|
|
}
|
|
|
|
}
|