From 460e2798cde8901df6c818d24a193f1cb33ea605 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 14 Aug 2018 11:42:40 +0530 Subject: [PATCH] [hub] Favourites UI - remove from listing - add to favourites --- erpnext/public/js/hub/components/item_card.js | 25 ++++++--- erpnext/public/js/hub/pages/favourites.js | 52 ++++++++++++++++++- erpnext/public/less/hub.less | 12 +++++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js index 262ed212f5..f7f5975db6 100644 --- a/erpnext/public/js/hub/components/item_card.js +++ b/erpnext/public/js/hub/components/item_card.js @@ -17,15 +17,24 @@ function get_item_card_html(item) { const item_html = `
-
-
-
${title}
-
${subtitle}
+
+ +
+
+
${title}
+
${subtitle}
+
+ +
+
`; @@ -62,9 +71,11 @@ function get_local_item_card_html(item) { const item_html = `
-
-
${title}
-
${subtitle}
+
+
+
${title}
+
${subtitle}
+
diff --git a/erpnext/public/js/hub/pages/favourites.js b/erpnext/public/js/hub/pages/favourites.js index d4a8cb3ee0..6c2fd65580 100644 --- a/erpnext/public/js/hub/pages/favourites.js +++ b/erpnext/public/js/hub/pages/favourites.js @@ -2,6 +2,22 @@ import SubPage from './subpage'; import { get_item_card_container_html } from '../components/items_container'; erpnext.hub.Favourites = class Favourites extends SubPage { + 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); + } + }); + } + refresh() { this.get_favourites() .then(items => { @@ -18,6 +34,40 @@ erpnext.hub.Favourites = class Favourites extends SubPage { render(items) { this.$wrapper.find('.hub-card-container').empty(); const html = get_item_card_container_html(items, __('Favourites')); - this.$wrapper.append(html) + this.$wrapper.append(html); + + this.$wrapper.find('.hub-card').addClass('closable'); } + + on_item_remove(hub_item_code, $hub_card = '') { + const $message = $(__(`${hub_item_code} removed. + Undo`)); + + 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); + } + + 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) { } } diff --git a/erpnext/public/less/hub.less b/erpnext/public/less/hub.less index 7ac168486a..51fe340535 100644 --- a/erpnext/public/less/hub.less +++ b/erpnext/public/less/hub.less @@ -68,6 +68,18 @@ body[data-route^="marketplace/"] { &:hover .hub-card-overlay { display: block; } + + .octicon-x { + display: none; + margin-left: 10px; + font-size: 20px; + } + } + + .hub-card.closable { + .octicon-x { + display: block; + } } .hub-card.is-local {