From 2de046fbed103cec165623acb0d295ecefb6b22e Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 1 Aug 2018 15:57:28 +0530 Subject: [PATCH] Add generic action handler to subpage --- erpnext/public/js/hub/pages/item.js | 45 ++++++++++++----------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/erpnext/public/js/hub/pages/item.js b/erpnext/public/js/hub/pages/item.js index dabddeaab7..b3c63c85f2 100644 --- a/erpnext/public/js/hub/pages/item.js +++ b/erpnext/public/js/hub/pages/item.js @@ -1,4 +1,4 @@ -import SubPage from './base_page'; +import SubPage from './subpage'; import { get_rating_html } from '../helpers'; erpnext.hub.Item = class Item extends SubPage { @@ -90,20 +90,23 @@ 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 = ''; + let menu_items = ''; if(this.own_item) { - edit_buttons_html = `
- - -
`; + menu_items = ` +
  • ${__('Edit Details')}
  • +
  • ${__('Unpublish')}
  • `; + } else { + menu_items = ` +
  • ${__('Report this item')}
  • + `; } const html = `
    - +
    @@ -126,7 +129,6 @@ erpnext.hub.Item = class Item extends SubPage { ` : `

    ${__('No description')}

    ` }

    - ${edit_buttons_html}
    @@ -173,10 +174,6 @@ 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() @@ -186,21 +183,17 @@ 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() { + edit_details() { + if (!this.edit_dialog) { + this.edit_dialog = new frappe.ui.Dialog({ + title: "Edit Your Product", + fields: [] + }); + } this.edit_dialog.show(); } - on_unpublish() { + unpublish_item() { if(!this.unpublish_dialog) { this.unpublish_dialog = new frappe.ui.Dialog({ title: "Edit Your Product",