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

49 lines
1.6 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) {
2018-03-05 16:45:21 +00:00
let meta = frappe.getMeta(doctype);
2018-02-22 07:36:28 +00:00
super({title: `Edit ${meta.name}`, hasRoute: true});
2018-03-08 13:31:22 +00:00
this.wrapper.classList.add('page-form');
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: ['save', 'delete', 'duplicate', 'settings', 'print']
2018-02-19 16:41:10 +00:00
});
2018-03-08 13:31:22 +00:00
if (this.meta.pageSettings && this.meta.pageSettings.hideTitle) {
this.titleElement.classList.add('hide');
}
2018-02-19 16:41:10 +00:00
// if name is different after saving, change the route
this.form.on('save', async (params) => {
2018-03-07 10:37:58 +00:00
let route = frappe.router.getRoute();
2018-02-19 16:41:10 +00:00
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);
frappe.ui.showAlert({message: 'Added', color: 'green'});
2018-02-19 16:41:10 +00:00
}
});
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);
});
}
2018-03-05 16:45:21 +00:00
async show(params) {
super.show();
2018-02-19 16:41:10 +00:00
try {
2018-03-05 16:45:21 +00:00
await this.form.setDoc(params.doctype, params.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
}