mirror of
https://github.com/frappe/books.git
synced 2025-02-04 21:18:32 +00:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const Modal = require('frappejs/client/ui/modal');
|
|
const view = require('frappejs/client/view');
|
|
const frappe = require('frappejs');
|
|
|
|
module.exports = class FormModal extends Modal {
|
|
constructor(doctype, name) {
|
|
super({title: doctype});
|
|
this.doctype = doctype;
|
|
this.makeForm();
|
|
this.showWith(doctype, name);
|
|
}
|
|
|
|
makeForm() {
|
|
this.form = new (view.getFormClass(this.doctype))({
|
|
doctype: this.doctype,
|
|
parent: this.getBody(),
|
|
container: this,
|
|
actions: ['submit']
|
|
});
|
|
|
|
this.form.on('submit', () => {
|
|
this.hide();
|
|
});
|
|
}
|
|
|
|
addButton(label, className, action) {
|
|
if (className === 'primary') {
|
|
this.addPrimary(label, action);
|
|
} else {
|
|
this.addSecondary(label, action);
|
|
}
|
|
}
|
|
|
|
async showWith(doctype, name) {
|
|
await this.form.setDoc(doctype, name);
|
|
if (this.form.doc._notInserted) {
|
|
this.setTitle(frappe._('New {0}', doctype));
|
|
} else {
|
|
this.setTitle(`${doctype} ${name}`);
|
|
}
|
|
this.show();
|
|
this.$modal.find('input:first').focus();
|
|
}
|
|
} |