2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/client/desk/formpage.js

47 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-01-30 12:03:04 +00:00
const Page = require('frappejs/client/view/page');
const view = require('frappejs/client/view');
2018-02-08 09:38:47 +00:00
const frappe = require('frappejs');
2018-01-30 12:03:04 +00:00
module.exports = class FormPage extends Page {
2018-02-19 16:41:10 +00:00
constructor(doctype) {
let meta = frappe.getMeta(doctype)
2018-02-22 07:36:28 +00:00
super({title: `Edit ${meta.name}`, hasRoute: true});
2018-02-19 16:41:10 +00:00
this.meta = meta;
2018-02-20 06:39:41 +00:00
this.doctype = doctype;
2018-02-19 16:41:10 +00:00
this.form = new (view.getFormClass(doctype))({
doctype: doctype,
parent: this.body,
container: this,
actions: ['submit', 'delete', 'duplicate', 'settings', 'print']
2018-02-19 16:41:10 +00:00
});
this.on('show', async (params) => {
await this.showDoc(params.doctype, params.name);
});
// if name is different after saving, change the route
this.form.on('submit', async (params) => {
let route = frappe.router.get_route();
if (this.form.doc.name && !(route && route[2] === this.form.doc.name)) {
await frappe.router.setRoute('edit', this.form.doc.doctype, this.form.doc.name);
this.form.showAlert('Added', 'success');
}
});
this.form.on('delete', async (params) => {
2018-02-20 06:39:41 +00:00
this.hide();
2018-02-19 16:41:10 +00:00
await frappe.router.setRoute('list', this.form.doctype);
});
}
async showDoc(doctype, name) {
try {
await this.form.setDoc(doctype, name);
frappe.desk.setActiveDoc(this.form.doc);
2018-02-19 16:41:10 +00:00
} catch (e) {
this.renderError(e.status_code, e.message);
}
}
2018-01-30 12:03:04 +00:00
}