2
0
mirror of https://github.com/frappe/books.git synced 2025-01-25 16:18:33 +00:00
books/client/desk/formpage.js

49 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-01-30 17:33:04 +05:30
const Page = require('frappejs/client/view/page');
const view = require('frappejs/client/view');
2018-02-08 15:08:47 +05:30
const frappe = require('frappejs');
2018-01-30 17:33:04 +05:30
module.exports = class FormPage extends Page {
2018-02-19 22:11:10 +05:30
constructor(doctype) {
2018-03-05 22:15:21 +05:30
let meta = frappe.getMeta(doctype);
2018-02-22 13:06:28 +05:30
super({title: `Edit ${meta.name}`, hasRoute: true});
2018-03-08 19:01:22 +05:30
this.wrapper.classList.add('page-form');
2018-02-19 22:11:10 +05:30
this.meta = meta;
2018-02-20 12:09:41 +05:30
this.doctype = doctype;
2018-02-19 22:11:10 +05:30
this.form = new (view.getFormClass(doctype))({
doctype: doctype,
parent: this.body,
container: this,
actions: ['save', 'delete', 'duplicate', 'settings', 'print']
2018-02-19 22:11:10 +05:30
});
2018-03-08 19:01:22 +05:30
if (this.meta.pageSettings && this.meta.pageSettings.hideTitle) {
this.titleElement.classList.add('hide');
}
2018-02-19 22:11:10 +05:30
// if name is different after saving, change the route
this.form.on('save', async (params) => {
2018-03-07 16:07:58 +05:30
let route = frappe.router.getRoute();
2018-02-19 22:11:10 +05:30
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 22:11:10 +05:30
}
});
this.form.on('delete', async (params) => {
2018-02-20 12:09:41 +05:30
this.hide();
2018-02-19 22:11:10 +05:30
await frappe.router.setRoute('list', this.form.doctype);
});
}
2018-03-05 22:15:21 +05:30
async show(params) {
super.show();
2018-02-19 22:11:10 +05:30
try {
2018-03-05 22:15:21 +05:30
await this.form.setDoc(params.doctype, params.name);
frappe.desk.setActiveDoc(this.form.doc);
2018-02-19 22:11:10 +05:30
} catch (e) {
this.renderError(e.status_code, e.message);
}
}
2018-01-30 17:33:04 +05:30
}