2018-08-25 08:39:01 +00:00
|
|
|
import Vue from 'vue/dist/vue.js';
|
2018-08-26 14:18:52 +00:00
|
|
|
import './vue-plugins';
|
2018-08-25 08:39:01 +00:00
|
|
|
|
2018-08-19 18:55:26 +00:00
|
|
|
// components
|
2018-08-27 05:19:42 +00:00
|
|
|
import PageContainer from './PageContainer.vue';
|
2018-08-26 16:50:16 +00:00
|
|
|
import Sidebar from './Sidebar.vue';
|
2018-08-19 18:55:26 +00:00
|
|
|
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')
|
2018-08-28 09:34:33 +00:00
|
|
|
.then(doc => {
|
2018-07-27 20:24:06 +00:00
|
|
|
hub.settings = doc;
|
2018-08-28 09:34:33 +00:00
|
|
|
const is_registered = hub.settings.registered
|
2018-07-26 13:07:01 +00:00
|
|
|
this.setup_header();
|
|
|
|
this.make_sidebar();
|
|
|
|
this.make_body();
|
|
|
|
this.setup_events();
|
|
|
|
this.refresh();
|
2018-08-28 09:34:33 +00:00
|
|
|
if (!is_registered) {
|
|
|
|
this.page.set_primary_action('Become A Seller', this.show_register_dialog.bind(this))
|
|
|
|
}
|
2018-07-26 13:07:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2018-08-26 16:50:16 +00:00
|
|
|
new Vue({
|
|
|
|
el: $('<div>').appendTo(this.$sidebar)[0],
|
|
|
|
render: h => h(Sidebar)
|
|
|
|
});
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
make_body() {
|
|
|
|
this.$body = this.$parent.find('.layout-main-section');
|
2018-08-26 14:18:52 +00:00
|
|
|
this.$page_container = $('<div class="hub-page-container">').appendTo(this.$body);
|
2018-08-26 07:11:02 +00:00
|
|
|
|
2018-08-26 14:18:52 +00:00
|
|
|
new Vue({
|
|
|
|
el: '.hub-page-container',
|
|
|
|
render: h => h(PageContainer)
|
|
|
|
});
|
2018-08-26 07:11:02 +00:00
|
|
|
|
2018-08-20 13:03:46 +00:00
|
|
|
erpnext.hub.on('seller-registered', () => {
|
2018-08-28 09:34:33 +00:00
|
|
|
this.page.clear_primary_action()
|
|
|
|
frappe.db.get_doc('Hub Settings').then((doc)=> {
|
|
|
|
hub.settings = doc;
|
|
|
|
});
|
2018-07-26 13:07:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
2018-08-26 14:18:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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-08-28 09:34:33 +00:00
|
|
|
|
2018-07-26 13:07:01 +00:00
|
|
|
}
|