feat(marketplace): edit item dialog
diff --git a/erpnext/public/js/hub/components/edit_details_dialog.js b/erpnext/public/js/hub/components/edit_details_dialog.js
new file mode 100644
index 0000000..b341901
--- /dev/null
+++ b/erpnext/public/js/hub/components/edit_details_dialog.js
@@ -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
+};
\ No newline at end of file
diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue
index 841d004..b8399e3 100644
--- a/erpnext/public/js/hub/pages/Item.vue
+++ b/erpnext/public/js/hub/pages/Item.vue
@@ -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 @@
make_dialogs() {
this.make_contact_seller_dialog();
this.make_report_item_dialog();
+ this.make_editing_dialog();
},
add_to_saved_items() {
@@ -284,6 +286,36 @@
});
},
+ 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 @@
},
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() {