2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/client/desk/formmodal.js

39 lines
997 B
JavaScript
Raw Normal View History

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);
this.show();
this.$modal.find('input:first').focus();
}
}