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) {
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
? `<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 = '';
@ -59,9 +68,7 @@ function get_detail_view_html(item, allow_edit) {
</div>
<div class="page-actions detail-page-actions">
<button class="btn btn-default text-muted favourite-button" data-action="add_to_favourites">
${__('Add to Favourites')} <i class="octicon octicon-heart text-extra-muted"></i>
</button>
${favourite_button}
<button class="btn btn-primary" data-action="contact_seller">
${__('Contact Seller')}
</button>

View File

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

View File

@ -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) {
</div>`;
}
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 += `<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;
resolve(r.message)
resolve(r.message);
}
reject(r)
reject(r);
})
.fail(reject)
});

View File

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