Search in sources :

Example 46 with FormItem

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

the class ShibbolethRegistrationUserPropertiesFrom method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
            propFormItems.put(userPropertyHandler.getName(), fi);
            if (fi instanceof TextElement) {
                String value = shibbolethAttributes.getValueForUserPropertyName(userPropertyHandler.getName());
                if (StringHelper.containsNonWhitespace(value)) {
                    TextElement formElement = (TextElement) fi;
                    formElement.setValue(value);
                    formElement.setEnabled(false);
                }
            }
        }
    }
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("save", buttonLayout);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 47 with FormItem

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

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 48 with FormItem

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

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 49 with FormItem

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

the class StepsMainRunController method initForm.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
	 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
	 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.add("stepLinks", stepTitleLinks);
    // steps/wizard navigation .. as start most of buttons are disabled
    // they must be enabled by the first step according to its rules
    // cancel button is not possible to disable
    prevButton = new FormLinkImpl("back");
    prevButton.setCustomEnabledLinkCSS("btn btn-default o_wizard_button_prev");
    prevButton.setCustomDisabledLinkCSS("btn btn-default o_wizard_button_prev");
    prevButton.setIconLeftCSS("o_icon o_icon_previous_step o_icon-fw");
    nextButton = new FormLinkImpl("next");
    nextButton.setCustomEnabledLinkCSS("btn btn-default o_wizard_button_next");
    nextButton.setCustomDisabledLinkCSS("btn btn-default o_wizard_button_next");
    nextButton.setIconRightCSS("o_icon o_icon_next_step o_icon-fw");
    finishButton = new FormLinkImpl("finish");
    finishButton.setCustomEnabledLinkCSS("btn btn-default o_wizard_button_finish");
    finishButton.setCustomDisabledLinkCSS("btn btn-default o_wizard_button_finish");
    cancelButton = new FormLinkImpl("cancel");
    cancelButton.setCustomEnabledLinkCSS("btn btn-default o_wizard_button_cancel");
    cancelButton.setCustomDisabledLinkCSS("btn btn-default o_wizard_button_cancel");
    closeLink = new FormLinkImpl("closeIcon", "close", "", Link.NONTRANSLATED);
    closeLink.setIconLeftCSS("o_icon o_icon_close");
    formLayout.add(prevButton);
    formLayout.add(nextButton);
    formLayout.add(finishButton);
    formLayout.add(cancelButton);
    formLayout.add(closeLink);
    // add all step titles, but disabled.
    Step tmp = startStep;
    do {
        FormItem title = tmp.getStepTitle();
        title.setEnabled(false);
        stepTitleLinks.add(title);
        tmp = tmp.nextStep();
    } while (tmp != Step.NOSTEP);
    // init buttons and the like
    // start with -1 to be on zero after calling
    currentStepIndex = -1;
    // update current step index to velocity
    flc.contextPut("currentStep", currentStepIndex + 1);
    // next step the first time
    addNextStep(startStep.getStepController(ureq, getWindowControl(), this.stepsContext, this.mainForm), startStep);
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)

Example 50 with FormItem

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

the class GTAAvailableTaskController method loadModel.

private void loadModel() {
    File taskFolder = gtaManager.getTasksDirectory(courseEnv, gtaNode);
    List<AvailableTask> availableTasks = new ArrayList<>(taskDefs.size());
    List<String> usedSlotes;
    if (GTACourseNode.GTASK_SAMPLING_UNIQUE.equals(gtaNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_SAMPLING))) {
        usedSlotes = gtaManager.getAssignedTasks(taskList);
    } else {
        usedSlotes = Collections.emptyList();
    }
    for (TaskDefinition taskDef : taskDefs) {
        String filename = taskDef.getFilename();
        if (usedSlotes.contains(filename)) {
            continue;
        }
        FormLink descriptionLink = null;
        if (StringHelper.containsNonWhitespace(taskDef.getDescription())) {
            descriptionLink = uifactory.addFormLink("preview-" + CodeHelper.getRAMUniqueID(), "description", "task.description", null, flc, Link.LINK);
            descriptionLink.setIconLeftCSS("o_icon o_icon_description");
        }
        FormItem download = null;
        boolean preview = gtaNode.getModuleConfiguration().getBooleanSafe(GTACourseNode.GTASK_PREVIEW);
        if (preview) {
            if (taskDef.getFilename().endsWith(".html")) {
                download = uifactory.addFormLink("prev-html-" + CodeHelper.getRAMUniqueID(), "preview-html", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
                download.setUserObject(filename);
            } else {
                File taskFile = new File(taskFolder, filename);
                download = uifactory.addDownloadLink("prev-" + CodeHelper.getRAMUniqueID(), filename, null, taskFile, tableEl);
            }
        }
        AvailableTask wrapper = new AvailableTask(taskDef, descriptionLink, download);
        availableTasks.add(wrapper);
        if (descriptionLink != null) {
            descriptionLink.setUserObject(wrapper);
        }
    }
    taskModel.setObjects(availableTasks);
    tableEl.reset();
    if (availableTasks.isEmpty()) {
        flc.contextPut("noMoreTasks", Boolean.TRUE);
    } else {
        flc.contextPut("noMoreTasks", Boolean.FALSE);
    }
}
Also used : TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) File(java.io.File)

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