From 71b41b47713a4617fb4bc93e1c0a203648866d85 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 20 Aug 2018 15:36:13 +0530 Subject: [PATCH] [hub] response data in hub call event trigger --- .../js/hub/components/item_publish_dialog.js | 16 +++++++++++++--- erpnext/public/js/hub/hub_call.js | 11 ++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/erpnext/public/js/hub/components/item_publish_dialog.js b/erpnext/public/js/hub/components/item_publish_dialog.js index 2c215799a4..a5d312c7b8 100644 --- a/erpnext/public/js/hub/components/item_publish_dialog.js +++ b/erpnext/public/js/hub/components/item_publish_dialog.js @@ -28,12 +28,22 @@ function ItemPublishDialog(primary_action, secondary_action) { secondary_action: secondary_action.fn }); - const hub_call_key = 'get_categories{}'; - erpnext.hub.on(`response:${hub_call_key}`, () => { + function set_hub_category_options(data) { dialog.fields_dict.hub_category.set_data( - erpnext.hub.cache[hub_call_key].map(d => d.name) + data.map(d => d.name) ); + } + + const hub_call_key = 'get_categories{}'; + const categories_cache = erpnext.hub.cache[hub_call_key]; + + if(categories_cache) { + set_hub_category_options(categories_cache); + } + + erpnext.hub.on(`response:${hub_call_key}`, (data) => { + set_hub_category_options(data.response); }); return dialog; diff --git a/erpnext/public/js/hub/hub_call.js b/erpnext/public/js/hub/hub_call.js index 2ed19f2739..d83aeeb6e4 100644 --- a/erpnext/public/js/hub/hub_call.js +++ b/erpnext/public/js/hub/hub_call.js @@ -24,16 +24,17 @@ hub.call = function call_hub_method(method, args={}, setup_cache_invalidation = }) .then(r => { if (r.message) { - if (r.message.error) { + const response = r.message; + if (response.error) { frappe.throw({ title: __('Marketplace Error'), - message: r.message.error + message: response.error }); } - erpnext.hub.cache[key] = r.message; - erpnext.hub.trigger(`response:${key}`); - resolve(r.message); + erpnext.hub.cache[key] = response; + erpnext.hub.trigger(`response:${key}`, { response }); + resolve(response); } reject(r); })