2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/client/desk/formmodal.js
Rushabh Mehta 1b42e46462 ui fixes
2018-02-15 15:23:28 +05:30

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