Search in sources :

Example 1 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class Form method evalFormRequest.

/**
 * @param ureq
 */
public void evalFormRequest(UserRequest ureq) {
    // Initialize temporary request parameters
    if (isMultipartEnabled() && isMultipartContent(ureq.getHttpReq())) {
        doInitRequestMultipartDataParameter(ureq);
    } else {
        doInitRequestParameter(ureq);
    }
    String dispatchUri = getRequestParameter("dispatchuri");
    String dispatchAction = getRequestParameter("dispatchevent");
    boolean invalidDispatchUri = dispatchUri == null || dispatchUri.equals(FORM_UNDEFINED);
    boolean invalidDispatchAct = dispatchAction == null || dispatchAction.equals(FORM_UNDEFINED);
    // see also OLAT-3141
    boolean implicitFormSubmit = false;
    if (invalidDispatchAct && invalidDispatchUri) {
        // case if:
        // enter was pressed in Safari / IE
        // crawler tries form links
        SubmitFormComponentVisitor efcv = new SubmitFormComponentVisitor();
        new FormComponentTraverser(efcv, formLayout, false).visitAll(ureq);
        Submit submitFormItem = efcv.getSubmit();
        if (submitFormItem != null) {
            // if we have submit form item
            // assume a click on this item
            dispatchUri = FormBaseComponentIdProvider.DISPPREFIX + submitFormItem.getComponent().getDispatchID();
            action = FormEvent.ONCLICK;
        } else {
            // instead of
            // throw new AssertException("You have an input field but no submit item defined! this is no good if enter is pressed.");
            // assume a desired implicit form submit
            // see also OLAT-3141
            implicitFormSubmit = true;
        }
    } else {
        try {
            action = Integer.valueOf(dispatchAction);
        } catch (Exception e) {
            throw new InvalidRequestParameterException();
        }
    }
    hasAlreadyFired = false;
    isValidAndSubmitted = false;
    // 
    // step 1: call evalFormRequest(ureq) on each FormComponent this gives
    // ....... for each element the possibility to intermediate save a value.
    // ....... As a sideeffect the formcomponent to be dispatched is found.
    EvaluatingFormComponentVisitor efcv = new EvaluatingFormComponentVisitor(dispatchUri);
    FormComponentTraverser ct = new FormComponentTraverser(efcv, formLayout, false);
    ct.visitAll(ureq);
    // step 2: dispatch to the form component
    // ......... only one component to be dispatched can be found, e.g. clicked
    // ......... element....................................................
    // ......... dispatch changes server model -> rerendered
    // ......... dispatch may also request a form validation by
    // ......... calling the submit
    FormItem dispatchFormItem = efcv.getDispatchToComponent();
    // .......... the code goes further with step 3.........................
    if (implicitFormSubmit) {
        // implicit Submit (Press Enter without on a Field without submit item.)
        // see also OLAT-3141
        submit(ureq);
    } else {
        if (dispatchFormItem == null) {
            // source not found. This "never happens". Try to produce some hints.
            String fbc = new String();
            for (FormBasicController i : formListeners) {
                if (fbc.length() > 0) {
                    fbc += ",";
                }
                fbc += (i.getClass().getName());
            }
            log.warn("OLAT-5061: Could not determine request source in FlexiForm >" + formName + "<. Check >" + fbc + "<", null);
            // TODO: what now?
            // Assuming the same as "implicitFormSubmit" for now.
            submit(ureq);
        } else {
            // ****************************************
            // explicit Submit or valid form dispatch *
            // ****************************************
            dispatchFormItem.doDispatchFormRequest(ureq);
            // step 3: find parent container of dispatched component
            // .......... check dependency rules
            // .......... apply dependency rules
            FindParentFormComponentVisitor fpfcv = new FindParentFormComponentVisitor(dispatchFormItem);
            ct = new FormComponentTraverser(fpfcv, formLayout, false);
            ct.visitAll(ureq);
            fpfcv.getParent().evalDependencyRuleSetFor(ureq, dispatchFormItem);
        }
    }
    // 
    action = -1;
    // End of request dispatch: cleanup temp files: ureq requestParams and multipart files
    doClearRequestParameterAndMultipartData();
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Submit(org.olat.core.gui.components.form.flexible.elements.Submit) AssertException(org.olat.core.logging.AssertException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class FormLayoutContainer method dispose.

/**
 * Dispose all child elements from this container
 *
 * @see org.olat.core.gui.control.Disposable#dispose()
 */
@Override
public void dispose() {
    // cleanup temporary files)
    for (FormItem formItem : getFormItems()) {
        if (formItem instanceof Disposable) {
            Disposable disposableFormItem = (Disposable) formItem;
            disposableFormItem.dispose();
        }
    }
}
Also used : Disposable(org.olat.core.gui.control.Disposable) FormItem(org.olat.core.gui.components.form.flexible.FormItem)

Example 3 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class FormLayoutContainer method add.

@Override
public void add(String name, Collection<FormItem> foItems) {
    // remove if already in
    if (formLayoutContainer.getContext().containsKey(name)) {
        // remove existing collection
        formLayoutContainer.contextRemove(name);
        // remove all associated form items
        for (FormItem formItem : foItems) {
            remove(formItem);
        }
    }
    // make collection accessible with <name> in the container.
    // collection contains then only the names.
    List<String> foItemsCollectionAsNames = new ArrayList<String>();
    formLayoutContainer.contextPut(name, foItemsCollectionAsNames);
    // add all items as form items to the container
    for (FormItem formItem : foItems) {
        String foName = formItem.getName();
        add(foName, formItem);
        foItemsCollectionAsNames.add(foName);
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList)

Example 4 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class FlexiTableCustomRenderer method renderRow.

@Override
protected void renderRow(Renderer renderer, StringOutput sb, FlexiTableComponent ftC, String rowIdPrefix, int row, URLBuilder ubu, Translator translator, RenderResult renderResult) {
    sb.append("<div class='");
    if (ftC.getFlexiTableElement().getCssDelegate() != null) {
        String cssClass = ftC.getFlexiTableElement().getCssDelegate().getRowCssClass(FlexiTableRendererType.custom, row);
        if (cssClass == null) {
            sb.append("o_table_row row");
        } else {
            sb.append(cssClass);
        }
    } else {
        sb.append("o_table_row row");
    }
    sb.append("'>");
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    VelocityContainer container = ftE.getRowRenderer();
    container.contextPut("f", new FormDecorator(ftE.getRootForm()));
    FlexiTableDataModel<?> dataModel = ftE.getTableDataModel();
    Object rowObject = ftE.getTableDataModel().getObject(row);
    container.contextPut("row", rowObject);
    container.contextPut("rowIndex", row);
    FlexiTableColumnModel columnsModel = ftE.getTableDataModel().getTableColumnModel();
    int numOfCols = columnsModel.getColumnCount();
    // link to the table element the form elements in the data model
    for (int j = 0; j < numOfCols; j++) {
        FlexiColumnModel fcm = columnsModel.getColumnModel(j);
        int columnIndex = fcm.getColumnIndex();
        Object cellValue = columnIndex >= 0 ? dataModel.getValueAt(row, columnIndex) : null;
        if (cellValue instanceof FormItem) {
            FormItem formItem = (FormItem) cellValue;
            formItem.setTranslator(translator);
            if (ftE.getRootForm() != formItem.getRootForm()) {
                formItem.setRootForm(ftE.getRootForm());
            }
            ftE.addFormItem(formItem);
            container.put(formItem.getComponent().getComponentName(), formItem.getComponent());
        }
    }
    FlexiTableComponentDelegate cmpDelegate = ftE.getComponentDelegate();
    if (cmpDelegate != null) {
        Iterable<Component> cmps = cmpDelegate.getComponents(row, rowObject);
        if (cmps != null) {
            for (Component cmp : cmps) {
                container.put(cmp.getComponentName(), cmp);
            }
        }
    }
    container.getHTMLRendererSingleton().render(renderer, sb, container, ubu, translator, renderResult, null);
    container.contextRemove("row");
    container.contextRemove("f");
    sb.append("</div>");
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) FormDecorator(org.olat.core.gui.components.form.flexible.impl.FormDecorator) Component(org.olat.core.gui.components.Component)

Example 5 with FormItem

use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.

the class EMailCalloutCtrl method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Roles roles = ureq.getUserSession().getRoles();
    boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(roles);
    boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles);
    if (autoCompleteAllowed) {
        ListProvider provider = new UserSearchListProvider();
        autocompleterC = new FlexiAutoCompleterController(ureq, getWindowControl(), provider, null, isAdministrativeUser, allowExternalAddress, 60, 3, null, mainForm);
        autocompleterC.setFormElement(false);
        listenTo(autocompleterC);
        FormItem item = autocompleterC.getInitialFormItem();
        formLayout.add(item);
    } else if (allowExternalAddress) {
        emailEl = uifactory.addTextElement("email" + CodeHelper.getRAMUniqueID(), "email", null, 256, "", formLayout);
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserSearchListProvider(org.olat.admin.user.UserSearchListProvider) ListProvider(org.olat.core.gui.control.generic.ajax.autocompletion.ListProvider) UserSearchListProvider(org.olat.admin.user.UserSearchListProvider) Roles(org.olat.core.id.Roles) FlexiAutoCompleterController(org.olat.core.gui.control.generic.ajax.autocompletion.FlexiAutoCompleterController)

Aggregations

FormItem (org.olat.core.gui.components.form.flexible.FormItem)142 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)62 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)34 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)30 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 Identity (org.olat.core.id.Identity)20 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)16 User (org.olat.core.id.User)16 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)14 UserManager (org.olat.user.UserManager)12 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)12 HashSet (java.util.HashSet)10 Translator (org.olat.core.gui.translator.Translator)10 File (java.io.File)8 Map (java.util.Map)8 Component (org.olat.core.gui.components.Component)8 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)8 Date (java.util.Date)6 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)6