2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 01:14:03 +00:00
books/client/desk/formpage.js

44 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-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 {
constructor(doctype) {
let meta = frappe.getMeta(doctype)
2018-01-30 12:03:04 +00:00
super(`Edit ${meta.name}`);
this.meta = meta;
this.form = new (view.get_form_class(doctype))({
doctype: doctype,
2018-02-08 09:38:47 +00:00
parent: this.body,
page: this
2018-01-30 12:03:04 +00:00
});
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();
2018-02-06 17:14:07 +00:00
if (this.form.doc.name && !(route && route[2] === this.form.doc.name)) {
2018-02-08 09:38:47 +00:00
await frappe.router.setRoute('edit', this.form.doc.doctype, this.form.doc.name);
this.form.showAlert('Added', 'success');
2018-01-31 10:13:33 +00:00
}
});
this.form.on('delete', async (params) => {
2018-02-08 09:38:47 +00:00
await frappe.router.setRoute('list', this.form.doctype);
2018-01-31 10:13:33 +00:00
});
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) {
2018-02-08 09:38:47 +00:00
this.renderError(e.status_code, e.message);
2018-01-30 12:03:04 +00:00
}
}
}