2018-01-16 06:09:17 +00:00
|
|
|
const common = require('frappejs/common');
|
2018-02-19 16:41:10 +00:00
|
|
|
const HTTPClient = require('frappejs/backends/http');
|
2018-01-16 06:09:17 +00:00
|
|
|
const frappe = require('frappejs');
|
2018-01-12 12:25:07 +00:00
|
|
|
frappe.ui = require('./ui');
|
|
|
|
const Desk = require('./desk');
|
2018-02-22 11:21:42 +00:00
|
|
|
const Observable = require('frappejs/utils/observable');
|
2018-04-14 19:14:02 +00:00
|
|
|
const { getPDF } = require('frappejs/client/pdf');
|
2018-01-12 12:25:07 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2018-04-30 14:27:41 +00:00
|
|
|
async start({server, columns = 2, makeDesk = false}) {
|
2018-01-12 12:25:07 +00:00
|
|
|
window.frappe = frappe;
|
|
|
|
frappe.init();
|
2018-02-16 13:13:46 +00:00
|
|
|
frappe.registerLibs(common);
|
2018-03-05 16:45:21 +00:00
|
|
|
frappe.registerModels(require('frappejs/models'), 'client');
|
2018-01-12 12:25:07 +00:00
|
|
|
frappe.fetch = window.fetch.bind();
|
2018-03-26 12:56:21 +00:00
|
|
|
|
2018-02-19 16:41:10 +00:00
|
|
|
frappe.db = await new HTTPClient({server: server});
|
2018-04-30 14:27:41 +00:00
|
|
|
this.socket = io.connect(`http://${server}`); // eslint-disable-line
|
2018-02-19 16:41:10 +00:00
|
|
|
frappe.db.bindSocketClient(this.socket);
|
2018-01-15 11:55:31 +00:00
|
|
|
|
2018-02-22 11:21:42 +00:00
|
|
|
frappe.docs = new Observable();
|
2018-02-21 09:38:56 +00:00
|
|
|
await frappe.getSingle('SystemSettings');
|
2018-01-12 12:25:07 +00:00
|
|
|
|
2018-03-27 16:49:23 +00:00
|
|
|
if(makeDesk) {
|
|
|
|
this.makeDesk(columns);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async makeDesk(columns) {
|
2018-02-14 16:44:50 +00:00
|
|
|
frappe.desk = new Desk(columns);
|
2018-01-12 12:25:07 +00:00
|
|
|
await frappe.login();
|
2018-03-26 12:56:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setCall() {
|
2018-03-26 13:02:35 +00:00
|
|
|
frappe.call = async (method, args) => {
|
2018-03-26 12:56:21 +00:00
|
|
|
let url = `/api/method/${method}`;
|
2018-03-26 13:02:35 +00:00
|
|
|
let response = await fetch(url, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(args || {})
|
|
|
|
});
|
2018-03-26 12:56:21 +00:00
|
|
|
|
|
|
|
return await response.json();
|
|
|
|
}
|
2018-04-14 19:14:02 +00:00
|
|
|
|
|
|
|
frappe.getPDF = getPDF;
|
2018-01-12 12:25:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|