blob: cff580e5ff0b3f310fbd9efb5c610aa40ca27e04 [file] [log] [blame]
Faris Ansarif089dad2018-08-26 22:20:16 +05301<template>
2 <div ref="sidebar-container">
3 <ul class="list-unstyled hub-sidebar-group" data-nav-buttons>
4 <li class="hub-sidebar-item" v-for="item in items" :key="item.label" v-route="item.route" v-show="item.condition === undefined || item.condition()">
5 {{ item.label }}
6 </li>
7 </ul>
8 <ul class="list-unstyled hub-sidebar-group" data-categories>
Faris Ansari725603c2018-08-27 19:51:36 +05309 <li class="hub-sidebar-item is-title bold text-muted">
10 {{ __('Categories') }}
11 </li>
Faris Ansarif089dad2018-08-26 22:20:16 +053012 <li class="hub-sidebar-item" v-for="category in categories" :key="category.label" v-route="category.route">
13 {{ category.label }}
14 </li>
15 </ul>
16 </div>
17</template>
18<script>
19export default {
20 data() {
21 return {
Faris Ansari062cd622018-08-30 14:35:56 +053022 hub_registered: hub.settings.registered && frappe.session.user === hub.settings.company_email,
Faris Ansarif089dad2018-08-26 22:20:16 +053023 items: [
24 {
25 label: __('Browse'),
26 route: 'marketplace/home'
27 },
28 {
Faris Ansari8e044872018-08-30 15:35:06 +053029 label: __('Saved Items'),
30 route: 'marketplace/saved-items',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053031 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053032 },
33 {
34 label: __('Your Profile'),
35 route: 'marketplace/profile',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053036 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053037 },
38 {
Faris Ansari8e044872018-08-30 15:35:06 +053039 label: __('Your Items'),
40 route: 'marketplace/published-items',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053041 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053042 },
43 {
Faris Ansari8e044872018-08-30 15:35:06 +053044 label: __('Publish Items'),
Faris Ansarif089dad2018-08-26 22:20:16 +053045 route: 'marketplace/publish',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053046 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053047 },
48 {
49 label: __('Selling'),
50 route: 'marketplace/selling',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053051 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053052 },
53 {
54 label: __('Buying'),
55 route: 'marketplace/buying',
Suraj Shettyf994e3e2018-08-28 15:03:01 +053056 condition: () => this.hub_registered
Faris Ansarif089dad2018-08-26 22:20:16 +053057 },
58 ],
Suraj Shettyf994e3e2018-08-28 15:03:01 +053059 categories: [],
Faris Ansarif089dad2018-08-26 22:20:16 +053060 }
61 },
62 created() {
63 this.get_categories()
64 .then(categories => {
65 this.categories = categories.map(c => {
66 return {
67 label: __(c.name),
68 route: 'marketplace/category/' + c.name
69 }
70 });
71 this.categories.unshift({
72 label: __('All'),
73 route: 'marketplace/home'
74 });
75 this.$nextTick(() => {
76 this.update_sidebar_state();
77 });
78 });
Suraj Shettyf994e3e2018-08-28 15:03:01 +053079
80 erpnext.hub.on('seller-registered', () => {
81 this.hub_registered = true;
82 })
Faris Ansarif089dad2018-08-26 22:20:16 +053083 },
84 mounted() {
85 this.update_sidebar_state();
86 frappe.route.on('change', () => this.update_sidebar_state());
87 },
88 methods: {
89 get_categories() {
90 return hub.call('get_categories');
91 },
92 update_sidebar_state() {
93 const container = $(this.$refs['sidebar-container']);
94 const route = frappe.get_route();
95 const route_str = route.join('/');
96 const part_route_str = route.slice(0, 2).join('/');
97 const $sidebar_item = container.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`);
98
99 const $siblings = container.find('[data-route]');
100 $siblings.removeClass('active').addClass('text-muted');
101 $sidebar_item.addClass('active').removeClass('text-muted');
Suraj Shettyf994e3e2018-08-28 15:03:01 +0530102 },
Faris Ansarif089dad2018-08-26 22:20:16 +0530103 }
104}
105</script>