2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +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');
2018-01-12 12:25:07 +00:00
module.exports = {
async start({server, columns = 2, makeDesk = 1}) {
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
this.setCall();
2018-02-19 16:41:10 +00:00
frappe.db = await new HTTPClient({server: server});
this.socket = io.connect('http://localhost:8000'); // eslint-disable-line
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();
}
2018-01-12 12:25:07 +00:00
}
};