2018-08-01 10:27:13 +00:00
|
|
|
import SubPage from './subpage';
|
2018-08-13 16:06:07 +00:00
|
|
|
import { get_item_card_container_html } from '../components/items_container';
|
2018-08-01 08:39:07 +00:00
|
|
|
|
|
|
|
erpnext.hub.Favourites = class Favourites extends SubPage {
|
2018-08-14 06:12:40 +00:00
|
|
|
make_wrapper() {
|
|
|
|
super.make_wrapper();
|
|
|
|
this.bind_events();
|
|
|
|
}
|
|
|
|
|
|
|
|
bind_events() {
|
|
|
|
this.$wrapper.on('click', '.hub-card', (e) => {
|
|
|
|
const $target = $(e.target);
|
|
|
|
if($target.hasClass('octicon-x')) {
|
|
|
|
e.stopPropagation();
|
|
|
|
const hub_item_code = $target.attr('data-hub-item-code');
|
|
|
|
this.on_item_remove(hub_item_code);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
refresh() {
|
|
|
|
this.get_favourites()
|
|
|
|
.then(items => {
|
|
|
|
this.render(items);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get_favourites() {
|
2018-08-13 16:06:07 +00:00
|
|
|
return hub.call('get_favourite_items_of_seller', {
|
|
|
|
hub_seller: hub.settings.company_email
|
|
|
|
});
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(items) {
|
|
|
|
this.$wrapper.find('.hub-card-container').empty();
|
|
|
|
const html = get_item_card_container_html(items, __('Favourites'));
|
2018-08-14 06:12:40 +00:00
|
|
|
this.$wrapper.append(html);
|
|
|
|
|
|
|
|
this.$wrapper.find('.hub-card').addClass('closable');
|
|
|
|
}
|
|
|
|
|
|
|
|
on_item_remove(hub_item_code, $hub_card = '') {
|
|
|
|
const $message = $(__(`<span>${hub_item_code} removed.
|
|
|
|
<a href="#" data-action="undo-remove"><b>Undo</b></a></span>`));
|
|
|
|
|
|
|
|
frappe.show_alert($message);
|
|
|
|
|
|
|
|
$hub_card = this.$wrapper.find(`.hub-card[data-hub-item-code="${hub_item_code}"]`);
|
|
|
|
|
|
|
|
$hub_card.hide();
|
|
|
|
|
|
|
|
const grace_period = 5000;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.remove_item(hub_item_code, $hub_card);
|
|
|
|
}, grace_period);
|
2018-08-01 08:39:07 +00:00
|
|
|
}
|
2018-08-14 06:12:40 +00:00
|
|
|
|
|
|
|
remove_item(hub_item_code, $hub_card) {
|
|
|
|
hub.call('remove_item_from_seller_favourites', {
|
|
|
|
hub_item_code,
|
|
|
|
hub_seller: hub.settings.company_email
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
$hub_card.remove();
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_remove(hub_item_code) { }
|
2018-08-13 16:06:07 +00:00
|
|
|
}
|