2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 19:39:07 +00:00
books/client/desk/formpage.js

43 lines
1.1 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-01-31 10:13:33 +00:00
const frappejs = require('frappejs');
2018-01-30 12:03:04 +00:00
module.exports = class FormPage extends Page {
constructor(doctype) {
let meta = frappe.get_meta(doctype)
super(`Edit ${meta.name}`);
this.meta = meta;
this.form = new (view.get_form_class(doctype))({
doctype: doctype,
parent: this.body
});
this.on('show', async (params) => {
await this.show_doc(params.doctype, params.name);
});
2018-01-31 10:13:33 +00:00
// if name is different after saving, change the route
this.form.on('submit', async (params) => {
let route = frappe.router.get_route();
if (!(route && route[2] === this.form.doc.name)) {
await frappe.router.set_route('edit', this.form.doc.doctype, this.form.doc.name);
this.form.show_alert('Added', 'success');
}
});
this.form.on('delete', async (params) => {
await frappe.router.set_route('list', this.form.doctype);
});
2018-01-30 12:03:04 +00:00
}
async show_doc(doctype, name) {
try {
this.doc = await frappe.get_doc(doctype, name);
this.form.use(this.doc);
} catch (e) {
this.render_error(e.status_code, e.message);
}
}
}