mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
implement templates for control
This commit is contained in:
parent
2422e33ec0
commit
4d3a176d98
@ -106,11 +106,11 @@ module.exports = class Desk {
|
||||
return this.pages.forms[doctype];
|
||||
}
|
||||
|
||||
showFormModal(doctype, name) {
|
||||
async showFormModal(doctype, name) {
|
||||
if (!this.pages.formModals[doctype]) {
|
||||
this.pages.formModals[doctype] = new FormModal(doctype);
|
||||
}
|
||||
this.pages.formModals[doctype].showWith(doctype, name);
|
||||
await this.pages.formModals[doctype].showWith(doctype, name);
|
||||
return this.pages.formModals[doctype];
|
||||
}
|
||||
|
||||
|
@ -18,20 +18,37 @@ class BaseControl {
|
||||
if (this.setup) {
|
||||
this.setup();
|
||||
}
|
||||
this.make();
|
||||
if (this.template) {
|
||||
this.wrapper = frappe.ui.add('div', 'field-template', this.parent);
|
||||
this.renderTemplate();
|
||||
} else {
|
||||
this.make();
|
||||
}
|
||||
}
|
||||
|
||||
bind(doc) {
|
||||
this.doc = doc;
|
||||
this.setDocValue();
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
refresh() {
|
||||
this.setDocValue();
|
||||
if (this.template) {
|
||||
this.renderTemplate();
|
||||
} else {
|
||||
this.setDocValue();
|
||||
}
|
||||
}
|
||||
|
||||
renderTemplate() {
|
||||
if (this.form.doc) {
|
||||
this.wrapper.innerHTML = this.template(this.form.doc, this.doc);
|
||||
} else {
|
||||
this.wrapper.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
setDocValue() {
|
||||
if (this.doc) {
|
||||
if (this.doc && !this.template) {
|
||||
this.setInputValue(this.doc.get(this.fieldname));
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,14 @@ class LinkControl extends BaseControl {
|
||||
if (e.text && e.text.value === '__newItem') {
|
||||
e.preventDefault();
|
||||
const newDoc = await frappe.getNewDoc(this.target);
|
||||
const formModal = frappe.desk.showFormModal(this.target, newDoc.name);
|
||||
const formModal = await frappe.desk.showFormModal(this.target, newDoc.name);
|
||||
if (formModal.form.doc.meta.hasField('name')) {
|
||||
formModal.form.doc.set('name', this.input.value);
|
||||
}
|
||||
|
||||
formModal.once('submit', async () => {
|
||||
await this.updateDocValue(formModal.form.doc.name);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -27,7 +27,7 @@ class TableControl extends BaseControl {
|
||||
this.datatable = new DataTable(this.wrapper.querySelector('.datatable-wrapper'), {
|
||||
columns: this.getColumns(),
|
||||
data: this.getTableData(),
|
||||
takeAvailableSpace: true,
|
||||
layout: 'fluid',
|
||||
addCheckboxColumn: true,
|
||||
getEditor: this.getTableInput.bind(this),
|
||||
});
|
||||
@ -127,7 +127,6 @@ class TableControl extends BaseControl {
|
||||
id: field.fieldname,
|
||||
field: field,
|
||||
content: field.label,
|
||||
width: 120,
|
||||
editable: (this.disabled || field.disabled) ? false : true,
|
||||
sortable: false,
|
||||
resizable: true,
|
||||
|
@ -132,7 +132,7 @@ module.exports = class BaseForm extends Observable {
|
||||
// only single value changed
|
||||
let control = this.controls[params.fieldname];
|
||||
if (control && control.getInputValue() !== control.format(params.fieldname)) {
|
||||
control.setDocValue();
|
||||
control.refresh();
|
||||
}
|
||||
} else {
|
||||
// multiple values changed
|
||||
|
@ -13,6 +13,10 @@ module.exports = class BaseMeta extends BaseDocument {
|
||||
}
|
||||
}
|
||||
|
||||
hasField(fieldname) {
|
||||
return this.getField(fieldname) ? true : false;
|
||||
}
|
||||
|
||||
getField(fieldname) {
|
||||
if (!this._field_map) {
|
||||
this._field_map = {};
|
||||
|
Loading…
Reference in New Issue
Block a user