brotherton-erpnext/erpnext/public/js/hub/Sidebar.vue

106 lines
2.7 KiB
Vue
Raw Normal View History

2018-08-26 16:50:16 +00:00
<template>
<div ref="sidebar-container">
<ul class="list-unstyled hub-sidebar-group" data-nav-buttons>
<li class="hub-sidebar-item" v-for="item in items" :key="item.label" v-route="item.route" v-show="item.condition === undefined || item.condition()">
{{ item.label }}
</li>
</ul>
<ul class="list-unstyled hub-sidebar-group" data-categories>
<li class="hub-sidebar-item is-title bold text-muted">
{{ __('Categories') }}
</li>
2018-08-26 16:50:16 +00:00
<li class="hub-sidebar-item" v-for="category in categories" :key="category.label" v-route="category.route">
{{ category.label }}
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
hub_registered: hub.settings.registered && frappe.session.user === hub.settings.company_email,
2018-08-26 16:50:16 +00:00
items: [
{
label: __('Browse'),
route: 'marketplace/home'
},
{
2018-08-30 10:05:06 +00:00
label: __('Saved Items'),
route: 'marketplace/saved-items',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
{
label: __('Your Profile'),
route: 'marketplace/profile',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
{
2018-08-30 10:05:06 +00:00
label: __('Your Items'),
route: 'marketplace/published-items',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
{
2018-08-30 10:05:06 +00:00
label: __('Publish Items'),
2018-08-26 16:50:16 +00:00
route: 'marketplace/publish',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
{
label: __('Selling'),
route: 'marketplace/selling',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
{
label: __('Buying'),
route: 'marketplace/buying',
condition: () => this.hub_registered
2018-08-26 16:50:16 +00:00
},
],
categories: [],
2018-08-26 16:50:16 +00:00
}
},
created() {
this.get_categories()
.then(categories => {
this.categories = categories.map(c => {
return {
label: __(c.name),
route: 'marketplace/category/' + c.name
}
});
this.categories.unshift({
label: __('All'),
route: 'marketplace/home'
});
this.$nextTick(() => {
this.update_sidebar_state();
});
});
erpnext.hub.on('seller-registered', () => {
this.hub_registered = true;
})
2018-08-26 16:50:16 +00:00
},
mounted() {
this.update_sidebar_state();
frappe.route.on('change', () => this.update_sidebar_state());
},
methods: {
get_categories() {
return hub.call('get_categories');
},
update_sidebar_state() {
const container = $(this.$refs['sidebar-container']);
const route = frappe.get_route();
const route_str = route.join('/');
const part_route_str = route.slice(0, 2).join('/');
const $sidebar_item = container.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`);
const $siblings = container.find('[data-route]');
$siblings.removeClass('active').addClass('text-muted');
$sidebar_item.addClass('active').removeClass('text-muted');
},
2018-08-26 16:50:16 +00:00
}
}
</script>