Add detail page favourited state

This commit is contained in:
Prateeksha Singh 2018-08-14 01:31:03 +05:30
parent c5a9972785
commit 1a0fb5b63a
5 changed files with 40 additions and 26 deletions

View File

@ -1,3 +1,5 @@
import { get_rating_html } from './reviews';
function get_detail_view_html(item, allow_edit) { function get_detail_view_html(item, allow_edit) {
const title = item.item_name || item.name; const title = item.item_name || item.name;
const seller = item.company; 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})`; stats = `${views_message}${dot_spacer}${rating_html} (${rating_count})`;
} }
let favourite_button = !item.favourited
? `<button class="btn btn-default text-muted favourite-button" data-action="add_to_favourites">
${__('Save')} <i class="octicon octicon-heart text-extra-muted"></i>
</button>`
: `<button class="btn btn-default text-muted favourite-button disabled" data-action="add_to_favourites">
${__('Saved')}
</button>`;
let menu_items = ''; let menu_items = '';
@ -59,9 +68,7 @@ function get_detail_view_html(item, allow_edit) {
</div> </div>
<div class="page-actions detail-page-actions"> <div class="page-actions detail-page-actions">
<button class="btn btn-default text-muted favourite-button" data-action="add_to_favourites"> ${favourite_button}
${__('Add to Favourites')} <i class="octicon octicon-heart text-extra-muted"></i>
</button>
<button class="btn btn-primary" data-action="contact_seller"> <button class="btn btn-primary" data-action="contact_seller">
${__('Contact Seller')} ${__('Contact Seller')}
</button> </button>

View File

@ -82,19 +82,7 @@ function get_local_item_card_html(item) {
return item_html; 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 += `<i class='fa fa-fw ${star_class} star-icon' data-index=${i}></i>`;
}
return rating_html;
}
export { export {
get_item_card_html, get_item_card_html,
get_local_item_card_html, get_local_item_card_html
get_rating_html
} }

View File

@ -1,5 +1,3 @@
import { get_rating_html } from './item_card';
function get_review_html(review) { function get_review_html(review) {
let username = review.username || review.user || __("Anonymous"); let username = review.username || review.user || __("Anonymous");
@ -66,6 +64,17 @@ function get_timeline_item(data, image_html, edit_html, rating_html) {
</div>`; </div>`;
} }
export { function get_rating_html(rating) {
get_review_html 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 += `<i class='fa fa-fw ${star_class} star-icon' data-index=${i}></i>`;
}
return rating_html;
}
export {
get_review_html,
get_rating_html
} }

View File

@ -35,9 +35,9 @@ hub.call = function call_hub_method(method, args={}) {
} }
erpnext.hub.cache[key] = r.message; erpnext.hub.cache[key] = r.message;
resolve(r.message) resolve(r.message);
} }
reject(r) reject(r);
}) })
.fail(reject) .fail(reject)
}); });

View File

@ -70,10 +70,18 @@ erpnext.hub.Item = class Item extends SubPage {
add_to_favourites(favourite_button) { add_to_favourites(favourite_button) {
$(favourite_button).html('Added to Favourites').addClass('disabled'); $(favourite_button).addClass('disabled');
return hub.call('remove_item_from_seller_favourites', {
hub.call('add_item_to_seller_favourites', {
hub_item_code: this.hub_item_code, hub_item_code: this.hub_item_code,
hub_seller: hub.settings.company_email hub_seller: hub.settings.company_email
})
.then(() => {
$(favourite_button).html('Saved');
frappe.show_alert(__('Saved to <b><a href="#marketplace/favourites">Favourites</a></b>'));
})
.catch(e => {
console.log(e);
}); });
} }
@ -143,7 +151,9 @@ erpnext.hub.Item = class Item extends SubPage {
$timeline.empty(); $timeline.empty();
this.reviews.sort((a, b) => { const reviews = this.reviews || [];
reviews.sort((a, b) => {
if (a.modified > b.modified) { if (a.modified > b.modified) {
return -1; return -1;
} }
@ -155,7 +165,7 @@ erpnext.hub.Item = class Item extends SubPage {
return 0; return 0;
}); });
this.reviews.forEach(review => { reviews.forEach(review => {
$(get_review_html(review)).appendTo($timeline); $(get_review_html(review)).appendTo($timeline);
}); });
} }