2018-08-25 08:39:01 +00:00
|
|
|
import Vue from 'vue/dist/vue.js';
|
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
// pages
|
|
|
|
import './pages/item';
|
2018-08-01 20:12:23 +00:00
|
|
|
import './pages/seller';
|
2018-08-01 08:39:07 +00:00
|
|
|
import './pages/profile';
|
2018-08-01 10:59:40 +00:00
|
|
|
import './pages/messages';
|
2018-08-20 13:03:46 +00:00
|
|
|
import './pages/buying_messages';
|
2018-08-01 08:39:07 +00:00
|
|
|
import './pages/not_found';
|
|
|
|
|
2018-08-26 07:11:02 +00:00
|
|
|
import PageContainer from './PageContainer.vue';
|
2018-08-25 16:24:49 +00:00
|
|
|
import Home from './pages/Home.vue';
|
2018-08-25 08:39:01 +00:00
|
|
|
import SavedProducts from './pages/SavedProducts.vue';
|
|
|
|
import Publish from './pages/Publish.vue';
|
2018-08-25 10:24:43 +00:00
|
|
|
import Category from './pages/Category.vue';
|
2018-08-25 15:01:48 +00:00
|
|
|
import Search from './pages/Search.vue';
|
2018-08-25 10:24:43 +00:00
|
|
|
import PublishedProducts from './pages/PublishedProducts.vue';
|
2018-08-25 08:39:01 +00:00
|
|
|
|
2018-08-19 18:55:26 +00:00
|
|
|
// components
|
|
|
|
import { ProfileDialog } from './components/profile_dialog';
|
|
|
|
|
2018-08-01 08:39:07 +00:00
|
|
|
// helpers
|
|
|
|
import './hub_call';
|
2018-08-17 10:34:14 +00:00
|
|
|
import EventEmitter from './event_emitter';
|
2018-08-01 08:39:07 +00:00
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
frappe.provide('hub');
|
|
|
|
frappe.provide('erpnext.hub');
|
|
|
|
|
2018-08-17 10:34:14 +00:00
|
|
|
$.extend(erpnext.hub, EventEmitter.prototype);
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
erpnext.hub.Marketplace = class Marketplace {
|
|
|
|
constructor({ parent }) {
|
|
|
|
this.$parent = $(parent);
|
|
|
|
this.page = parent.page;
|
|
|
|
|
|
|
|
frappe.db.get_doc('Hub Settings')
|
|
|
|
.then(doc => {
|
2018-07-27 20:24:06 +00:00
|
|
|
hub.settings = doc;
|
2018-07-26 13:07:01 +00:00
|
|
|
this.registered = doc.registered;
|
|
|
|
|
|
|
|
this.setup_header();
|
|
|
|
this.make_sidebar();
|
|
|
|
this.make_body();
|
|
|
|
this.setup_events();
|
|
|
|
this.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_header() {
|
|
|
|
this.page.set_title(__('Marketplace'));
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_events() {
|
|
|
|
this.$parent.on('click', '[data-route]', (e) => {
|
|
|
|
const $target = $(e.currentTarget);
|
|
|
|
const route = $target.data().route;
|
|
|
|
frappe.set_route(route);
|
|
|
|
});
|
2018-08-19 18:55:26 +00:00
|
|
|
|
|
|
|
// generic action handler
|
|
|
|
this.$parent.on('click', '[data-action]', e => {
|
|
|
|
const $target = $(e.currentTarget);
|
|
|
|
const action = $target.data().action;
|
|
|
|
|
|
|
|
if (action && this[action]) {
|
|
|
|
this[action].apply(this, $target);
|
|
|
|
}
|
|
|
|
})
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
make_sidebar() {
|
|
|
|
this.$sidebar = this.$parent.find('.layout-side-section').addClass('hidden-xs');
|
|
|
|
|
|
|
|
this.make_sidebar_nav_buttons();
|
|
|
|
this.make_sidebar_categories();
|
|
|
|
}
|
|
|
|
|
|
|
|
make_sidebar_nav_buttons() {
|
|
|
|
let $nav_group = this.$sidebar.find('[data-nav-buttons]');
|
|
|
|
if (!$nav_group.length) {
|
|
|
|
$nav_group = $('<ul class="list-unstyled hub-sidebar-group" data-nav-buttons>').appendTo(this.$sidebar);
|
|
|
|
}
|
|
|
|
$nav_group.empty();
|
|
|
|
|
|
|
|
const user_specific_items_html = this.registered
|
2018-08-25 07:48:30 +00:00
|
|
|
? `<li class="hub-sidebar-item" data-route="marketplace/saved-products">
|
|
|
|
${__('Saved Products')}
|
2018-08-01 10:59:40 +00:00
|
|
|
</li>
|
|
|
|
<li class="hub-sidebar-item text-muted" data-route="marketplace/profile">
|
2018-07-26 13:07:01 +00:00
|
|
|
${__('Your Profile')}
|
|
|
|
</li>
|
|
|
|
<li class="hub-sidebar-item text-muted" data-route="marketplace/publish">
|
|
|
|
${__('Publish Products')}
|
2018-08-01 10:59:40 +00:00
|
|
|
</li>
|
2018-08-25 15:52:55 +00:00
|
|
|
<li class="hub-sidebar-item text-muted" data-route="marketplace/selling">
|
2018-08-24 05:55:04 +00:00
|
|
|
${__('Selling')}
|
|
|
|
</li>
|
2018-08-25 15:52:55 +00:00
|
|
|
<li class="hub-sidebar-item text-muted" data-route="marketplace/buying">
|
2018-08-24 05:55:04 +00:00
|
|
|
${__('Buying')}
|
|
|
|
</li>
|
|
|
|
`
|
2018-07-26 13:07:01 +00:00
|
|
|
|
2018-08-19 18:55:26 +00:00
|
|
|
: `<li class="hub-sidebar-item text-muted" data-action="show_register_dialog">
|
2018-07-26 13:07:01 +00:00
|
|
|
${__('Become a seller')}
|
|
|
|
</li>`;
|
|
|
|
|
|
|
|
$nav_group.append(`
|
|
|
|
<li class="hub-sidebar-item" data-route="marketplace/home">
|
|
|
|
${__('Browse')}
|
|
|
|
</li>
|
|
|
|
${user_specific_items_html}
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
make_sidebar_categories() {
|
2018-07-31 13:36:11 +00:00
|
|
|
hub.call('get_categories')
|
2018-07-31 12:32:13 +00:00
|
|
|
.then(categories => {
|
2018-07-31 13:36:11 +00:00
|
|
|
categories = categories.map(d => d.name);
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
const sidebar_items = [
|
|
|
|
`<li class="hub-sidebar-item bold is-title">
|
|
|
|
${__('Category')}
|
|
|
|
</li>`,
|
|
|
|
`<li class="hub-sidebar-item active" data-route="marketplace/home">
|
|
|
|
${__('All')}
|
|
|
|
</li>`,
|
|
|
|
...(this.registered
|
|
|
|
? [`<li class="hub-sidebar-item active" data-route="marketplace/my-products">
|
|
|
|
${__('Your Products')}
|
|
|
|
</li>`]
|
|
|
|
: []),
|
|
|
|
...categories.map(category => `
|
|
|
|
<li class="hub-sidebar-item text-muted" data-route="marketplace/category/${category}">
|
|
|
|
${__(category)}
|
|
|
|
</li>
|
|
|
|
`)
|
|
|
|
];
|
|
|
|
|
|
|
|
this.$sidebar.append(`
|
|
|
|
<ul class="list-unstyled">
|
|
|
|
${sidebar_items.join('')}
|
|
|
|
</ul>
|
|
|
|
`);
|
|
|
|
|
|
|
|
this.update_sidebar();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
make_body() {
|
|
|
|
this.$body = this.$parent.find('.layout-main-section');
|
2018-08-26 07:11:02 +00:00
|
|
|
// this.$page_container = $('<div class="hub-page-container">').appendTo(this.$body);
|
|
|
|
|
|
|
|
// new Vue({
|
|
|
|
// el: '.hub-page-container',
|
|
|
|
// render: h => h(PageContainer)
|
|
|
|
// });
|
|
|
|
|
2018-08-20 13:03:46 +00:00
|
|
|
erpnext.hub.on('seller-registered', () => {
|
2018-07-26 13:07:01 +00:00
|
|
|
this.registered = 1;
|
|
|
|
this.make_sidebar_nav_buttons();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
update_sidebar() {
|
2018-08-01 13:49:53 +00:00
|
|
|
const route = frappe.get_route();
|
2018-08-21 13:42:10 +00:00
|
|
|
const route_str = route.join('/');
|
|
|
|
const part_route_str = route.slice(0, 2).join('/');
|
|
|
|
const $sidebar_item = this.$sidebar.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`);
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
|
|
|
|
const $siblings = this.$sidebar.find('[data-route]');
|
|
|
|
$siblings.removeClass('active').addClass('text-muted');
|
|
|
|
$sidebar_item.addClass('active').removeClass('text-muted');
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
const route = frappe.get_route();
|
|
|
|
this.subpages = this.subpages || {};
|
|
|
|
|
|
|
|
for (let page in this.subpages) {
|
|
|
|
this.subpages[page].hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (route[1] === 'home' && !this.subpages.home) {
|
2018-08-25 16:24:49 +00:00
|
|
|
this.subpages.home = new erpnext.hub.HomePage(this.$body);
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 15:37:56 +00:00
|
|
|
if (route[1] === 'search' && !this.subpages.search) {
|
2018-07-27 10:03:00 +00:00
|
|
|
this.subpages.search = new erpnext.hub.SearchPage(this.$body);
|
|
|
|
}
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
if (route[1] === 'category' && route[2] && !this.subpages.category) {
|
2018-08-25 10:24:43 +00:00
|
|
|
this.subpages.category = new erpnext.hub.CategoryPage(this.$body);
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (route[1] === 'item' && route[2] && !this.subpages.item) {
|
|
|
|
this.subpages.item = new erpnext.hub.Item(this.$body);
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:12:23 +00:00
|
|
|
if (route[1] === 'seller' && !this.subpages['seller']) {
|
|
|
|
this.subpages['seller'] = new erpnext.hub.Seller(this.$body);
|
|
|
|
}
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
if (route[1] === 'register' && !this.subpages.register) {
|
2018-07-26 13:16:38 +00:00
|
|
|
if (this.registered) {
|
|
|
|
frappe.set_route('marketplace', 'home');
|
|
|
|
return;
|
|
|
|
}
|
2018-07-26 13:07:01 +00:00
|
|
|
this.subpages.register = new erpnext.hub.Register(this.$body);
|
|
|
|
}
|
|
|
|
|
2018-08-01 10:59:40 +00:00
|
|
|
// registered seller routes
|
2018-08-25 07:48:30 +00:00
|
|
|
if (route[1] === 'saved-products' && !this.subpages['saved-products']) {
|
2018-08-25 08:39:01 +00:00
|
|
|
this.subpages['saved-products'] = new erpnext.hub.SavedProductsPage(this.$body);
|
2018-08-01 10:59:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 13:16:38 +00:00
|
|
|
if (route[1] === 'profile' && !this.subpages.profile) {
|
2018-07-27 20:24:06 +00:00
|
|
|
this.subpages.profile = new erpnext.hub.Profile(this.$body);
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 13:16:38 +00:00
|
|
|
if (route[1] === 'publish' && !this.subpages.publish) {
|
2018-08-25 08:39:01 +00:00
|
|
|
this.subpages.publish = new erpnext.hub.PublishPage(this.$body);
|
2018-07-27 20:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (route[1] === 'my-products' && !this.subpages['my-products']) {
|
2018-08-25 10:24:43 +00:00
|
|
|
this.subpages['my-products'] = new erpnext.hub.PublishedProductsPage(this.$body);
|
2018-07-26 13:16:38 +00:00
|
|
|
}
|
2018-07-26 13:07:01 +00:00
|
|
|
|
2018-08-24 05:55:04 +00:00
|
|
|
if (route[1] === 'buying' && !this.subpages['buying']) {
|
2018-08-25 15:52:55 +00:00
|
|
|
this.subpages['buying'] = new erpnext.hub.Buying(this.$body);
|
2018-08-01 10:59:40 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 05:55:04 +00:00
|
|
|
if (route[1] === 'selling' && !this.subpages['selling']) {
|
2018-08-25 15:52:55 +00:00
|
|
|
this.subpages['selling'] = new erpnext.hub.Selling(this.$body, 'Selling');
|
2018-08-20 13:03:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 10:59:40 +00:00
|
|
|
// dont allow unregistered users to access registered routes
|
2018-08-25 07:48:30 +00:00
|
|
|
const registered_routes = ['saved-products', 'profile', 'publish', 'my-products', 'messages'];
|
2018-08-01 10:59:40 +00:00
|
|
|
if (!hub.settings.registered && registered_routes.includes(route[1])) {
|
|
|
|
frappe.set_route('marketplace', 'home');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
if (!Object.keys(this.subpages).includes(route[1])) {
|
2018-07-26 13:52:58 +00:00
|
|
|
if (!this.subpages.not_found) {
|
|
|
|
this.subpages.not_found = new erpnext.hub.NotFound(this.$body);
|
|
|
|
}
|
|
|
|
route[1] = 'not_found';
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.update_sidebar();
|
|
|
|
frappe.utils.scroll_to(0);
|
|
|
|
this.subpages[route[1]].show();
|
|
|
|
}
|
2018-08-19 18:55:26 +00:00
|
|
|
|
|
|
|
show_register_dialog() {
|
2018-08-19 19:48:41 +00:00
|
|
|
this.register_dialog = ProfileDialog(
|
|
|
|
__('Become a Seller'),
|
|
|
|
{
|
|
|
|
label: __('Register'),
|
|
|
|
on_submit: this.register_seller.bind(this)
|
|
|
|
}
|
|
|
|
);
|
2018-08-19 18:55:26 +00:00
|
|
|
|
2018-08-19 19:48:41 +00:00
|
|
|
this.register_dialog.show();
|
2018-08-19 18:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
register_seller(form_values) {
|
|
|
|
frappe.call({
|
|
|
|
method: 'erpnext.hub_node.doctype.hub_settings.hub_settings.register_seller',
|
2018-08-22 06:39:40 +00:00
|
|
|
args: form_values
|
2018-08-19 18:55:26 +00:00
|
|
|
}).then(() => {
|
2018-08-19 19:48:41 +00:00
|
|
|
this.register_dialog.hide();
|
2018-08-19 18:55:26 +00:00
|
|
|
frappe.set_route('marketplace', 'publish');
|
|
|
|
|
2018-08-20 13:03:46 +00:00
|
|
|
erpnext.hub.trigger('seller-registered');
|
2018-08-19 18:55:26 +00:00
|
|
|
});
|
|
|
|
}
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
2018-08-25 08:39:01 +00:00
|
|
|
|
2018-08-25 16:24:49 +00:00
|
|
|
erpnext.hub.HomePage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area-home">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(Home)
|
|
|
|
}).$mount('#vue-area-home');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="home"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="home"]').hide();
|
|
|
|
}
|
|
|
|
}
|
2018-08-25 08:39:01 +00:00
|
|
|
|
|
|
|
erpnext.hub.SavedProductsPage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area-saved">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(SavedProducts)
|
|
|
|
}).$mount('#vue-area-saved');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="saved-products"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="saved-products"]').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.hub.PublishPage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(Publish)
|
|
|
|
}).$mount('#vue-area');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="publish"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="publish"]').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-08-25 10:24:43 +00:00
|
|
|
|
|
|
|
erpnext.hub.CategoryPage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area-category">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(Category)
|
|
|
|
}).$mount('#vue-area-category');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="category"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="category"]').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.hub.PublishedProductsPage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area-published-products">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(PublishedProducts)
|
|
|
|
}).$mount('#vue-area-published-products');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="published-products"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="published-products"]').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:01:48 +00:00
|
|
|
erpnext.hub.SearchPage = class {
|
|
|
|
constructor(parent) {
|
|
|
|
this.$wrapper = $(`<div id="vue-area-search">`).appendTo($(parent));
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
render: h => h(Search)
|
|
|
|
}).$mount('#vue-area-search');
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
$('[data-page-name="search"]').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
$('[data-page-name="search"]').hide();
|
|
|
|
}
|
|
|
|
}
|