2
0
mirror of https://github.com/frappe/books.git synced 2025-01-25 16:18:33 +00:00
books/client/index.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

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