use of org.jboss.hal.ballroom.form.Form.Operation.SAVE in project console by hal.
the class AbstractForm method editPanel.
private HTMLElement editPanel() {
HTMLElement editPanel = div().id(Ids.build(id, EDITING.name().toLowerCase())).css(form, formHorizontal, editing).element();
editPanel.appendChild(errorPanel);
boolean hasRequiredField = false;
boolean hasOptionalField = false;
for (FormItem formItem : getFormItems()) {
if (formItem.isRequired() || !separateOptionalFields) {
editPanel.appendChild(formItem.element(EDITING));
}
hasRequiredField = hasRequiredField || formItem.isRequired();
hasOptionalField = hasOptionalField || !formItem.isRequired();
}
if (hasRequiredField) {
editPanel.appendChild(div().css(formGroup).add(div().css(halFormOffset).add(span().css(helpBlock).innerHtml(MESSAGES.requiredHelp()))).element());
}
// panel
if (separateOptionalFields && hasOptionalField) {
List<HTMLElement> optionalFields = new ArrayList<>();
HTMLFieldSetElement fieldsetElement = fieldset().css(fieldsSectionPf).element();
HTMLElement expanderElement = span().css(fontAwesome("angle-right"), fontAwesome("angle-down"), fieldSectionTogglePf).element();
// as we add fa-angle-right and fa-angle-down, remove the later so the angle-right becomes visible
expanderElement.classList.remove(faAngleDown);
HTMLLegendElement legend = legend().css(fieldsSectionHeaderPf).add(expanderElement).add(a().css(fieldSectionTogglePf, clickable).textContent(CONSTANTS.optionalFields()).on(click, event -> {
// toggle the fa-angle-down to show either angle-right or angle-down
expanderElement.classList.toggle(faAngleDown);
optionalFields.forEach(field -> setVisible(field, expanderElement.classList.contains(faAngleDown)));
})).element();
fieldsetElement.appendChild(legend);
for (FormItem formItem : getFormItems()) {
if (!formItem.isRequired()) {
HTMLElement field = formItem.element(EDITING);
optionalFields.add(field);
fieldsetElement.appendChild(field);
setVisible(field, false);
}
}
editPanel.appendChild(fieldsetElement);
}
HTMLElement buttons = div().css(formGroup, formButtons).add(div().css(halFormOffset).add(div().css(pullRight).add(button().css(btn, btnHal, btnDefault).textContent(CONSTANTS.cancel()).on(click, event -> cancel())).add(button().css(btn, btnHal, btnPrimary).textContent(CONSTANTS.save()).on(click, event -> save())))).element();
editPanel.appendChild(buttons);
return editPanel;
}
Aggregations