diff --git a/client/ui/utils.js b/client/ui/utils.js index 4e8269c6..dd38f281 100644 --- a/client/ui/utils.js +++ b/client/ui/utils.js @@ -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; diff --git a/client/view/form.js b/client/view/form.js index f02d74d9..409f03c7 100644 --- a/client/view/form.js +++ b/client/view/form.js @@ -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) { diff --git a/client/view/formLayout.js b/client/view/formLayout.js index 47e9533b..ef11c1e5 100644 --- a/client/view/formLayout.js +++ b/client/view/formLayout.js @@ -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) {