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