2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00
books/client/index.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

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');
const Observable = require('frappejs/utils/observable');
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();
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);
frappe.docs = new Observable();
await frappe.getSingle('SystemSettings');
2018-01-12 12:25:07 +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();
}
frappe.getPDF = getPDF;
2018-01-12 12:25:07 +00:00
}
};