Search in sources :

Example 1 with SAVE

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;
}
Also used : LazyElement(org.jboss.gwt.elemento.core.LazyElement) Elements.a(org.jboss.gwt.elemento.core.Elements.a) Messages(org.jboss.hal.resources.Messages) Elements.setVisible(org.jboss.gwt.elemento.core.Elements.setVisible) Icons(org.jboss.hal.resources.Icons) CSS.fieldsSectionHeaderPf(org.jboss.hal.resources.CSS.fieldsSectionHeaderPf) Elements.fieldset(org.jboss.gwt.elemento.core.Elements.fieldset) VIEW(org.jboss.hal.ballroom.form.Form.Operation.VIEW) KeyboardEvent(elemental2.dom.KeyboardEvent) EventType.keyup(org.jboss.gwt.elemento.core.EventType.keyup) HTMLElement(elemental2.dom.HTMLElement) CLEAR(org.jboss.hal.ballroom.form.Form.Operation.CLEAR) Map(java.util.Map) HTMLHRElement(elemental2.dom.HTMLHRElement) CSS.fieldSectionTogglePf(org.jboss.hal.resources.CSS.fieldSectionTogglePf) CSS.form(org.jboss.hal.resources.CSS.form) HTMLLegendElement(elemental2.dom.HTMLLegendElement) Set(java.util.Set) EventType.click(org.jboss.gwt.elemento.core.EventType.click) EDIT(org.jboss.hal.ballroom.form.Form.Operation.EDIT) List(java.util.List) HTMLUListElement(elemental2.dom.HTMLUListElement) CSS.faAngleDown(org.jboss.hal.resources.CSS.faAngleDown) Attachable(org.jboss.hal.ballroom.Attachable) Elements.li(org.jboss.gwt.elemento.core.Elements.li) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) CSS.btnHal(org.jboss.hal.resources.CSS.btnHal) Elements.div(org.jboss.gwt.elemento.core.Elements.div) Iterables(com.google.common.collect.Iterables) Elements.ul(org.jboss.gwt.elemento.core.Elements.ul) EDITING(org.jboss.hal.ballroom.form.Form.State.EDITING) CSS.alert(org.jboss.hal.resources.CSS.alert) CSS.btnDefault(org.jboss.hal.resources.CSS.btnDefault) HashMap(java.util.HashMap) GWT(com.google.gwt.core.client.GWT) CSS.clickable(org.jboss.hal.resources.CSS.clickable) CSS.editing(org.jboss.hal.resources.CSS.editing) CSS.helpBlock(org.jboss.hal.resources.CSS.helpBlock) ArrayList(java.util.ArrayList) Elements.hr(org.jboss.gwt.elemento.core.Elements.hr) CSS.formGroup(org.jboss.hal.resources.CSS.formGroup) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) READONLY(org.jboss.hal.ballroom.form.Form.State.READONLY) CSS.btnPrimary(org.jboss.hal.resources.CSS.btnPrimary) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) Lists(com.google.common.collect.Lists) Elements.section(org.jboss.gwt.elemento.core.Elements.section) EventCallbackFn(org.jboss.gwt.elemento.core.EventCallbackFn) ImmutableList(com.google.common.collect.ImmutableList) SAVE(org.jboss.hal.ballroom.form.Form.Operation.SAVE) CSS.fieldsSectionPf(org.jboss.hal.resources.CSS.fieldsSectionPf) Constants(org.jboss.hal.resources.Constants) CSS.alertDanger(org.jboss.hal.resources.CSS.alertDanger) CSS.separator(org.jboss.hal.resources.CSS.separator) EmptyState(org.jboss.hal.ballroom.EmptyState) CANCEL(org.jboss.hal.ballroom.form.Form.Operation.CANCEL) EMPTY(org.jboss.hal.ballroom.form.Form.State.EMPTY) Elements.button(org.jboss.gwt.elemento.core.Elements.button) Iterator(java.util.Iterator) HTMLFieldSetElement(elemental2.dom.HTMLFieldSetElement) Ids(org.jboss.hal.resources.Ids) CSS.readonly(org.jboss.hal.resources.CSS.readonly) CSS.btn(org.jboss.hal.resources.CSS.btn) Elements.legend(org.jboss.gwt.elemento.core.Elements.legend) REMOVE(org.jboss.hal.ballroom.form.Form.Operation.REMOVE) CSS.formSection(org.jboss.hal.resources.CSS.formSection) Collectors.toList(java.util.stream.Collectors.toList) CSS.halFormOffset(org.jboss.hal.resources.CSS.halFormOffset) CSS.pullRight(org.jboss.hal.resources.CSS.pullRight) HTMLDivElement(elemental2.dom.HTMLDivElement) CSS.formHorizontal(org.jboss.hal.resources.CSS.formHorizontal) EventType.bind(org.jboss.gwt.elemento.core.EventType.bind) RESET(org.jboss.hal.ballroom.form.Form.Operation.RESET) CSS.formButtons(org.jboss.hal.resources.CSS.formButtons) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) MEDIUM_TIMEOUT(org.jboss.hal.resources.UIConstants.MEDIUM_TIMEOUT) HTMLElement(elemental2.dom.HTMLElement) ArrayList(java.util.ArrayList) HTMLLegendElement(elemental2.dom.HTMLLegendElement) HTMLFieldSetElement(elemental2.dom.HTMLFieldSetElement)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 GWT (com.google.gwt.core.client.GWT)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)1 DomGlobal.setTimeout (elemental2.dom.DomGlobal.setTimeout)1 HTMLDivElement (elemental2.dom.HTMLDivElement)1 HTMLElement (elemental2.dom.HTMLElement)1 HTMLFieldSetElement (elemental2.dom.HTMLFieldSetElement)1 HTMLHRElement (elemental2.dom.HTMLHRElement)1 HTMLLegendElement (elemental2.dom.HTMLLegendElement)1 HTMLUListElement (elemental2.dom.HTMLUListElement)1 KeyboardEvent (elemental2.dom.KeyboardEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1