diff --git a/erpnext/public/js/hub/components/detail_view.js b/erpnext/public/js/hub/components/detail_view.js index 1f0d5426f2..9ef48d4d0a 100644 --- a/erpnext/public/js/hub/components/detail_view.js +++ b/erpnext/public/js/hub/components/detail_view.js @@ -1,3 +1,5 @@ +import { get_rating_html } from './reviews'; + function get_detail_view_html(item, allow_edit) { const title = item.item_name || item.name; const seller = item.company; @@ -23,6 +25,13 @@ function get_detail_view_html(item, allow_edit) { stats = `${views_message}${dot_spacer}${rating_html} (${rating_count})`; } + let favourite_button = !item.favourited + ? `` + : ``; let menu_items = ''; @@ -59,9 +68,7 @@ function get_detail_view_html(item, allow_edit) {
- + ${favourite_button} diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js index 733df62e6a..262ed212f5 100644 --- a/erpnext/public/js/hub/components/item_card.js +++ b/erpnext/public/js/hub/components/item_card.js @@ -82,19 +82,7 @@ function get_local_item_card_html(item) { return item_html; } - -function get_rating_html(rating) { - let rating_html = ``; - for (var i = 0; i < 5; i++) { - let star_class = 'fa-star'; - if (i >= rating) star_class = 'fa-star-o'; - rating_html += ``; - } - return rating_html; -} - export { get_item_card_html, - get_local_item_card_html, - get_rating_html + get_local_item_card_html } diff --git a/erpnext/public/js/hub/components/reviews.js b/erpnext/public/js/hub/components/reviews.js index 616f2fb705..e34d68038f 100644 --- a/erpnext/public/js/hub/components/reviews.js +++ b/erpnext/public/js/hub/components/reviews.js @@ -1,5 +1,3 @@ -import { get_rating_html } from './item_card'; - function get_review_html(review) { let username = review.username || review.user || __("Anonymous"); @@ -66,6 +64,17 @@ function get_timeline_item(data, image_html, edit_html, rating_html) {
`; } -export { - get_review_html +function get_rating_html(rating) { + let rating_html = ``; + for (var i = 0; i < 5; i++) { + let star_class = 'fa-star'; + if (i >= rating) star_class = 'fa-star-o'; + rating_html += ``; + } + return rating_html; +} + +export { + get_review_html, + get_rating_html } diff --git a/erpnext/public/js/hub/hub_call.js b/erpnext/public/js/hub/hub_call.js index 6786cf6f90..6bc1701551 100644 --- a/erpnext/public/js/hub/hub_call.js +++ b/erpnext/public/js/hub/hub_call.js @@ -35,9 +35,9 @@ hub.call = function call_hub_method(method, args={}) { } erpnext.hub.cache[key] = r.message; - resolve(r.message) + resolve(r.message); } - reject(r) + reject(r); }) .fail(reject) }); diff --git a/erpnext/public/js/hub/pages/item.js b/erpnext/public/js/hub/pages/item.js index 207c94cb90..ee43391a22 100644 --- a/erpnext/public/js/hub/pages/item.js +++ b/erpnext/public/js/hub/pages/item.js @@ -70,10 +70,18 @@ erpnext.hub.Item = class Item extends SubPage { add_to_favourites(favourite_button) { - $(favourite_button).html('Added to Favourites').addClass('disabled'); - return hub.call('remove_item_from_seller_favourites', { + $(favourite_button).addClass('disabled'); + + hub.call('add_item_to_seller_favourites', { hub_item_code: this.hub_item_code, hub_seller: hub.settings.company_email + }) + .then(() => { + $(favourite_button).html('Saved'); + frappe.show_alert(__('Saved to Favourites')); + }) + .catch(e => { + console.log(e); }); } @@ -143,7 +151,9 @@ erpnext.hub.Item = class Item extends SubPage { $timeline.empty(); - this.reviews.sort((a, b) => { + const reviews = this.reviews || []; + + reviews.sort((a, b) => { if (a.modified > b.modified) { return -1; } @@ -155,7 +165,7 @@ erpnext.hub.Item = class Item extends SubPage { return 0; }); - this.reviews.forEach(review => { + reviews.forEach(review => { $(get_review_html(review)).appendTo($timeline); }); }