mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
section heading in formlayout
This commit is contained in:
parent
eb82b8d435
commit
3bfda11884
@ -26,8 +26,9 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
addLink(label, parent, action, unhide = true) {
|
||||
addButton(label, parent, action, unhide = true) {
|
||||
const link = frappe.ui.add('button', 'btn btn-sm btn-outline-secondary', parent, label);
|
||||
link.type = 'button';
|
||||
link.addEventListener('click', action);
|
||||
if (unhide) {
|
||||
parent.classList.remove('hide');
|
||||
@ -43,8 +44,12 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
activate($parent, $child, commonClass, activeClass='active', index = -1) {
|
||||
let $children = $parent.querySelectorAll(`.${commonClass}.${activeClass}`);
|
||||
activate($parent, $child, commonSelector, activeClass='active', index = -1) {
|
||||
let $children = $parent.querySelectorAll(`${commonSelector}.${activeClass}`);
|
||||
|
||||
if (typeof $child === 'string') {
|
||||
$child = $parent.querySelector($child);
|
||||
}
|
||||
|
||||
this.forEachNode($children, (node, i) => {
|
||||
if(index >= 0 && i <= index) return;
|
||||
|
@ -209,7 +209,7 @@ module.exports = class BaseForm extends Observable {
|
||||
this.container.clearLinks();
|
||||
for(let link of links) {
|
||||
// make the link
|
||||
utils.addLink(link.label, this.container.linksElement, () => {
|
||||
utils.addButton(link.label, this.container.linksElement, () => {
|
||||
let options = link.action(this);
|
||||
|
||||
if (options) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
const frappe = require('frappejs');
|
||||
const controls = require('./controls');
|
||||
const Observable = require('frappejs/utils/observable');
|
||||
|
||||
module.exports = class FormLayout extends Observable {
|
||||
constructor({fields, layout, events = []}) {
|
||||
constructor({fields, doc, layout, events = []}) {
|
||||
super();
|
||||
Object.assign(this, arguments[0]);
|
||||
this.controls = {};
|
||||
@ -10,21 +11,14 @@ module.exports = class FormLayout extends Observable {
|
||||
this.sections = [];
|
||||
this.links = [];
|
||||
|
||||
this.doc = {
|
||||
get(fieldname) {
|
||||
return this[fieldname]
|
||||
},
|
||||
|
||||
set(fieldname, value) {
|
||||
this[fieldname] = value;
|
||||
}
|
||||
};
|
||||
|
||||
this.form = document.createElement('div');
|
||||
this.form.classList.add('form-body');
|
||||
|
||||
this.makeLayout();
|
||||
this.bindEvents(this.doc);
|
||||
|
||||
if (doc) {
|
||||
this.bindEvents(doc);
|
||||
}
|
||||
}
|
||||
|
||||
makeLayout() {
|
||||
@ -39,16 +33,24 @@ module.exports = class FormLayout extends Observable {
|
||||
|
||||
makeSection(section) {
|
||||
const sectionElement = frappe.ui.add('div', 'form-section', this.form);
|
||||
const sectionHead = frappe.ui.add('div', 'form-section-head', sectionElement);
|
||||
const sectionBody = frappe.ui.add('div', 'form-section-body', sectionElement);
|
||||
|
||||
if (section.title) {
|
||||
const head = frappe.ui.add('h6', 'uppercase', sectionHead);
|
||||
head.textContent = section.title;
|
||||
}
|
||||
|
||||
if (section.columns) {
|
||||
sectionElement.classList.add('row');
|
||||
sectionBody.classList.add('row');
|
||||
for (let column of section.columns) {
|
||||
let columnElement = frappe.ui.add('div', 'col', sectionElement);
|
||||
let columnElement = frappe.ui.add('div', 'col', sectionBody);
|
||||
this.makeControls(this.getFieldsFromLayoutElement(column.fields), columnElement);
|
||||
}
|
||||
} else {
|
||||
this.makeControls(this.getFieldsFromLayoutElement(section.fields), sectionElement);
|
||||
this.makeControls(this.getFieldsFromLayoutElement(section.fields), sectionBody);
|
||||
}
|
||||
this.sections.push(sectionElement);
|
||||
this.sections.push(sectionBody);
|
||||
}
|
||||
|
||||
getFieldsFromLayoutElement(fields) {
|
||||
|
Loading…
Reference in New Issue
Block a user