2018-08-25 07:48:30 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="marketplace-page"
|
|
|
|
:data-page-name="page_name"
|
|
|
|
>
|
|
|
|
<h5>{{ page_title }}</h5>
|
|
|
|
|
|
|
|
<item-cards-container
|
2018-08-25 16:24:49 +00:00
|
|
|
:container_name="page_title"
|
2018-08-25 07:48:30 +00:00
|
|
|
:items="items"
|
|
|
|
:item_id_fieldname="item_id_fieldname"
|
|
|
|
:on_click="go_to_item_details_page"
|
|
|
|
:editable="true"
|
|
|
|
@remove-item="on_item_remove"
|
|
|
|
:empty_state_message="empty_state_message"
|
|
|
|
>
|
|
|
|
</item-cards-container>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2018-08-30 10:05:06 +00:00
|
|
|
name: 'saved-items-page',
|
2018-08-25 07:48:30 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
page_name: frappe.get_route()[1],
|
|
|
|
items: [],
|
2018-08-27 08:41:48 +00:00
|
|
|
item_id_fieldname: 'name',
|
2018-08-25 07:48:30 +00:00
|
|
|
|
|
|
|
// Constants
|
2018-08-30 10:05:06 +00:00
|
|
|
page_title: __('Saved Items'),
|
|
|
|
empty_state_message: __(`You haven't saved any items yet.`)
|
2018-08-25 07:48:30 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.get_items();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
get_items() {
|
|
|
|
hub.call(
|
2018-09-02 20:55:41 +00:00
|
|
|
'get_saved_items_of_user', {},
|
2018-08-28 11:54:31 +00:00
|
|
|
'action:item_save'
|
2018-08-25 07:48:30 +00:00
|
|
|
)
|
|
|
|
.then((items) => {
|
2018-08-25 08:39:01 +00:00
|
|
|
this.items = items;
|
2018-08-25 07:48:30 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2018-08-27 08:41:48 +00:00
|
|
|
go_to_item_details_page(hub_item_name) {
|
|
|
|
frappe.set_route(`marketplace/item/${hub_item_name}`);
|
2018-08-25 07:48:30 +00:00
|
|
|
},
|
|
|
|
|
2018-08-27 08:41:48 +00:00
|
|
|
on_item_remove(hub_item_name) {
|
2018-08-25 07:48:30 +00:00
|
|
|
const grace_period = 5000;
|
|
|
|
let reverted = false;
|
|
|
|
let alert;
|
|
|
|
|
|
|
|
const undo_remove = () => {
|
2018-08-27 08:41:48 +00:00
|
|
|
this.toggle_item(hub_item_name);;
|
2018-08-25 07:48:30 +00:00
|
|
|
reverted = true;
|
|
|
|
alert.hide();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-28 11:54:31 +00:00
|
|
|
const item_name = this.items.filter(item => item.hub_item_name === hub_item_name);
|
|
|
|
|
|
|
|
alert = frappe.show_alert(__(`<span>${item_name} removed.
|
2018-08-26 07:39:19 +00:00
|
|
|
<a href="#" data-action="undo-remove"><b>Undo</b></a></span>`),
|
2018-08-25 07:48:30 +00:00
|
|
|
grace_period/1000,
|
|
|
|
{
|
|
|
|
'undo-remove': undo_remove.bind(this)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-08-27 08:41:48 +00:00
|
|
|
this.toggle_item(hub_item_name, false);
|
2018-08-25 07:48:30 +00:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
if(!reverted) {
|
2018-08-30 10:05:06 +00:00
|
|
|
this.remove_item_from_saved_items(hub_item_name);
|
2018-08-25 07:48:30 +00:00
|
|
|
}
|
|
|
|
}, grace_period);
|
|
|
|
},
|
|
|
|
|
2018-08-30 10:05:06 +00:00
|
|
|
remove_item_from_saved_items(hub_item_name) {
|
2018-08-28 11:54:31 +00:00
|
|
|
erpnext.hub.trigger('action:item_save');
|
2018-09-02 20:55:41 +00:00
|
|
|
hub.call('remove_item_from_user_saved_items', {
|
2018-08-27 08:41:48 +00:00
|
|
|
hub_item_name,
|
2018-09-02 20:55:41 +00:00
|
|
|
hub_user: frappe.session.user
|
2018-08-25 07:48:30 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.get_items();
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// By default show
|
2018-08-27 08:41:48 +00:00
|
|
|
toggle_item(hub_item_name, show=true) {
|
2018-08-25 07:48:30 +00:00
|
|
|
this.items = this.items.map(item => {
|
2018-08-27 08:41:48 +00:00
|
|
|
if(item.name === hub_item_name) {
|
2018-08-25 07:48:30 +00:00
|
|
|
item.seen = show;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped></style>
|