feat(marketplace): edit item dialog

This commit is contained in:
Mangesh-Khairnar 2019-12-02 01:09:59 +05:30
parent 370cdc0170
commit c131bd1b25
2 changed files with 81 additions and 1 deletions

View File

@ -0,0 +1,45 @@
function EditDetailsDialog(primary_action, defaults) {
let dialog = new frappe.ui.Dialog({
title: __('Update Details'),
fields: [
{
"label": "Item Name",
"fieldname": "item_name",
"fieldtype": "Data",
"default": defaults.item_name,
"reqd": 1
},
{
"label": "Hub Category",
"fieldname": "hub_category",
"fieldtype": "Autocomplete",
"default": defaults.hub_category,
"options": [],
"reqd": 1
},
{
"label": "Description",
"fieldname": "description",
"fieldtype": "Text",
"default": defaults.description,
"options": [],
"reqd": 1
}
],
primary_action_label: primary_action.label || __('Update Details'),
primary_action: primary_action.fn,
});
hub.call('get_categories')
.then(categories => {
categories = categories.map(d => d.name);
dialog.fields_dict.hub_category.df.options = categories;
dialog.fields_dict.hub_category.set_options();
});
return dialog;
}
export {
EditDetailsDialog
};

View File

@ -35,6 +35,7 @@
<script>
import ReviewArea from '../components/ReviewArea.vue';
import { get_rating_html } from '../components/reviews';
import { EditDetailsDialog } from '../components/edit_details_dialog';
export default {
name: 'item-page',
@ -200,6 +201,7 @@ export default {
make_dialogs() {
this.make_contact_seller_dialog();
this.make_report_item_dialog();
this.make_editing_dialog();
},
add_to_saved_items() {
@ -284,6 +286,36 @@ export default {
});
},
make_editing_dialog() {
this.edit_details_dialog = EditDetailsDialog(
{
fn: (values) => {
this.update_details(values);
this.edit_details_dialog.hide();
}
}, {
'item_name': this.item.item_name,
'hub_category': this.item.hub_category,
'description': this.item.description,
}
);
},
update_details(values) {
frappe.call(
'erpnext.hub_node.api.update_item',
{
ref_doctype: 'Hub Item',
ref_doc: this.item.name,
data: values
}
)
.then((r) => {
this.get_item_details();
frappe.show_alert(__(`${this.item.item_name} Updated`));
})
},
contact_seller() {
this.contact_seller_dialog.show();
},
@ -296,7 +328,10 @@ export default {
},
edit_details() {
frappe.msgprint(__('This feature is under development...'));
if (!hub.is_seller_registered()) {
frappe.throw(__('Please login as a Marketplace User to edit this item.'));
}
this.edit_details_dialog.show();
},
unpublish_item() {