[hub] response data in hub call event trigger

This commit is contained in:
Prateeksha Singh 2018-08-20 15:36:13 +05:30
parent e72a2fa9de
commit 71b41b4771
2 changed files with 19 additions and 8 deletions

View File

@ -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;

View File

@ -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);
})