From fe67508d609c86dca1025ccb4d069896844f56a5 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 20 Aug 2018 01:18:41 +0530 Subject: [PATCH] [hub][feat] Edit your Profile, recycle profile dialog --- .../js/hub/components/profile_dialog.js | 4 +- erpnext/public/js/hub/marketplace.js | 15 ++++--- erpnext/public/js/hub/pages/profile.js | 41 +++++++++++++++---- erpnext/public/js/hub/pages/subpage.js | 10 +++++ 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/erpnext/public/js/hub/components/profile_dialog.js b/erpnext/public/js/hub/components/profile_dialog.js index 0800b8a287..800e8c66f0 100644 --- a/erpnext/public/js/hub/components/profile_dialog.js +++ b/erpnext/public/js/hub/components/profile_dialog.js @@ -1,4 +1,4 @@ -const ProfileDialog = (title = __('Edit Profile'), action={}) => { +const ProfileDialog = (title = __('Edit Profile'), action={}, initial_values={}) => { const fields = [ { fieldtype: 'Link', @@ -63,6 +63,8 @@ const ProfileDialog = (title = __('Edit Profile'), action={}) => { } }); + dialog.set_values(initial_values); + // Post create const default_company = frappe.defaults.get_default('company'); dialog.set_value('company', default_company); diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index cadaea0791..1986cfb441 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -230,12 +230,15 @@ erpnext.hub.Marketplace = class Marketplace { } show_register_dialog() { - this.profile_dialog = ProfileDialog(__('Become a Seller'), { - label: __('Register'), - on_submit: this.register_seller.bind(this) - }); + this.register_dialog = ProfileDialog( + __('Become a Seller'), + { + label: __('Register'), + on_submit: this.register_seller.bind(this) + } + ); - this.profile_dialog.show(); + this.register_dialog.show(); } register_seller(form_values) { @@ -244,7 +247,7 @@ erpnext.hub.Marketplace = class Marketplace { args: form_values, btn: $(e.currentTarget) }).then(() => { - this.profile_dialog.hide(); + this.register_dialog.hide(); frappe.set_route('marketplace', 'publish'); // custom jquery event diff --git a/erpnext/public/js/hub/pages/profile.js b/erpnext/public/js/hub/pages/profile.js index 637e7b9c60..a57bc7ceec 100644 --- a/erpnext/public/js/hub/pages/profile.js +++ b/erpnext/public/js/hub/pages/profile.js @@ -1,5 +1,6 @@ import SubPage from './subpage'; import { get_detail_skeleton_html } from '../components/skeleton_state'; +import { ProfileDialog } from '../components/profile_dialog'; erpnext.hub.Profile = class Profile extends SubPage { make_wrapper() { @@ -10,21 +11,16 @@ erpnext.hub.Profile = class Profile extends SubPage { refresh() { this.show_skeleton(); this.get_hub_seller_profile(this.keyword) - .then(profile => this.render(profile)); + .then(profile => { + this.edit_profile_dialog.set_values(profile); + this.render(profile); + }); } get_hub_seller_profile() { return hub.call('get_hub_seller_profile', { hub_seller: hub.settings.company_email }); } - make_edit_profile_dialog() { - // this.edit_profile_dialog = new - } - - edit_profile() { - // - } - show_skeleton() { this.$wrapper.html(get_detail_skeleton_html()); } @@ -98,6 +94,33 @@ erpnext.hub.Profile = class Profile extends SubPage { this.$wrapper.html(profile_html); } + make_edit_profile_dialog() { + this.edit_profile_dialog = ProfileDialog( + __('Edit Profile'), + { + label: __('Update'), + on_submit: this.update_profile.bind(this) + } + ); + } + + edit_profile() { + this.edit_profile_dialog.set_values({ + company_email: hub.settings.company_email + }); + this.edit_profile_dialog.show(); + } + + update_profile(new_values) { + hub.call('update_profile', { + hub_seller: hub.settings.company_email, + updated_profile: new_values + }).then(new_profile => { + this.edit_profile_dialog.hide(); + this.render(new_profile); + }); + } + get_timeline_log_item(pretty_date, message, icon) { return `
diff --git a/erpnext/public/js/hub/pages/subpage.js b/erpnext/public/js/hub/pages/subpage.js index 3f4ed07171..7c75b1379e 100644 --- a/erpnext/public/js/hub/pages/subpage.js +++ b/erpnext/public/js/hub/pages/subpage.js @@ -3,6 +3,16 @@ export default class SubPage { this.$parent = $(parent); this.make_wrapper(options); + // generic action handler + this.$wrapper.on('click', '[data-action]', e => { + const $target = $(e.currentTarget); + const action = $target.data().action; + + if (action && this[action]) { + this[action].apply(this, $target); + } + }) + // handle broken images after every render if (this.render) { this._render = this.render.bind(this);