2018-02-13 16:12:44 +05:30
|
|
|
const Modal = require('frappejs/client/ui/modal');
|
|
|
|
const view = require('frappejs/client/view');
|
|
|
|
|
|
|
|
module.exports = class FormModal extends Modal {
|
|
|
|
constructor(doctype, name) {
|
|
|
|
super({title: doctype});
|
|
|
|
this.doctype = doctype;
|
2018-02-15 22:09:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
async showWith(doctype, name) {
|
2018-02-21 15:08:56 +05:30
|
|
|
if (!name) name = doctype;
|
2018-02-15 22:09:50 +05:30
|
|
|
this.show();
|
|
|
|
await this.setDoc(doctype, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
async setDoc(doctype, name) {
|
|
|
|
if (!this.form) {
|
|
|
|
this.makeForm();
|
|
|
|
}
|
|
|
|
await this.form.setDoc(doctype, name);
|
2018-02-21 15:08:56 +05:30
|
|
|
let input = this.modal.querySelector('input') || this.modal.querySelector('select');
|
|
|
|
input && input.focus();
|
2018-02-13 16:12:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
makeForm() {
|
2018-02-20 12:09:41 +05:30
|
|
|
this.form = new (view.getFormClass(this.doctype))({
|
|
|
|
doctype: this.doctype,
|
|
|
|
parent: this.getBody(),
|
2018-02-13 16:12:44 +05:30
|
|
|
container: this,
|
2018-02-27 21:59:14 +05:30
|
|
|
actions: ['save']
|
2018-02-13 16:12:44 +05:30
|
|
|
});
|
|
|
|
|
2018-02-27 21:59:14 +05:30
|
|
|
this.form.on('save', async () => {
|
|
|
|
await this.trigger('save');
|
2018-02-13 16:12:44 +05:30
|
|
|
this.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addButton(label, className, action) {
|
|
|
|
if (className === 'primary') {
|
2018-03-05 22:15:21 +05:30
|
|
|
return this.addPrimary(label, action).get(0);
|
2018-02-13 16:12:44 +05:30
|
|
|
} else {
|
2018-03-05 22:15:21 +05:30
|
|
|
return this.addSecondary(label, action).get(0);
|
2018-02-13 16:12:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|