From d0a1a4fe9059f6f54bdcb08f2ac389c6987583a4 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Sat, 28 Jul 2018 13:16:09 +0530 Subject: [PATCH] [hub] differentiate self-published items --- erpnext/public/js/hub/marketplace.js | 44 +++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index 741f2280bc..f024e774fd 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -332,8 +332,11 @@ erpnext.hub.Item = class Item extends SubPage { this.show_skeleton(); this.hub_item_code = frappe.get_route()[2]; + this.own_item = false; + this.get_item(this.hub_item_code) .then(item => { + this.own_item = item.hub_seller === hub.settings.company_email; this.item = item; this.render(item); }); @@ -385,6 +388,15 @@ erpnext.hub.Item = class Item extends SubPage { const rating_html = get_rating_html(item.average_rating); const rating_count = item.no_of_ratings > 0 ? `${item.no_of_ratings} reviews` : __('No reviews yet'); + let edit_buttons_html = ''; + + if(this.own_item) { + edit_buttons_html = `
+ + +
`; + } + const html = `
@@ -409,9 +421,10 @@ erpnext.hub.Item = class Item extends SubPage { ${description ? `${__('Description')}

${description}

- ` : __('No description') + ` : `

${__('No description')}

` }

+ ${edit_buttons_html}
@@ -447,6 +460,10 @@ erpnext.hub.Item = class Item extends SubPage { this.$wrapper.html(html); + if(this.own_item) { + this.bind_edit_buttons(); + } + this.make_review_area(); this.get_reviews() @@ -456,6 +473,31 @@ erpnext.hub.Item = class Item extends SubPage { }); } + bind_edit_buttons() { + this.edit_dialog = new frappe.ui.Dialog({ + title: "Edit Your Product", + fields: [] + }); + + this.$wrapper.find('.edit-item').on('click', this.on_edit.bind(this)); + this.$wrapper.find('.unpublish').on('click', this.on_unpublish.bind(this)); + } + + on_edit() { + this.edit_dialog.show(); + } + + on_unpublish() { + if(!this.unpublish_dialog) { + this.unpublish_dialog = new frappe.ui.Dialog({ + title: "Edit Your Product", + fields: [] + }); + } + + this.unpublish_dialog.show(); + } + make_review_area() { this.comment_area = new frappe.ui.ReviewArea({ parent: this.$wrapper.find('.timeline-head').empty(),