Search in sources :

Example 51 with FormLinkImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl in project openolat by klemens.

the class ConditionConfigEasyController method validateGroupFields.

/**
 * @param retVal
 * @return
 */
private boolean validateGroupFields() {
    boolean retVal = true;
    if (groupSwitch.getSelectedKeys().size() == 1) {
        List<Long> activeGroupSelection = null;
        List<Long> activeAreaSelection = null;
        groupChooseSubContainer.clearError();
        if (!isEmpty(easyGroupList)) {
            // check whether groups exist
            activeGroupSelection = getKeys(easyGroupList);
            Set<Long> missingGroups = new HashSet<Long>();
            List<BusinessGroupShort> existingGroups = businessGroupService.loadShortBusinessGroups(activeGroupSelection);
            a_a: for (Long activeGroupKey : activeGroupSelection) {
                for (BusinessGroupShort group : existingGroups) {
                    if (group.getKey().equals(activeGroupKey)) {
                        continue a_a;
                    }
                }
                missingGroups.add(activeGroupKey);
            }
            if (missingGroups.size() > 0) {
                retVal = false;
                String labelKey = missingGroups.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissGrps = toString(missingGroups);
                String[] params = new String[] { "-", csvMissGrps };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorGroupItemLayout = FormLayoutContainer.createCustomFormLayout("errorgroupitem", getTranslator(), vc_errorPage);
                groupChooseSubContainer.setErrorComponent(errorGroupItemLayout, this.flc);
                // FIXING LINK ONLY IF A DEFAULTCONTEXT EXISTS
                fixGroupError = new FormLinkImpl("error.fix", "create");
                // link
                fixGroupError.setCustomEnabledLinkCSS("btn btn-default");
                errorGroupItemLayout.add(fixGroupError);
                fixGroupError.setErrorKey(labelKey, params);
                fixGroupError.showError(true);
                fixGroupError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingGroups.size() > 1) {
                    fixGroupError.setUserObject(new String[] { csvMissGrps, "dummy" });
                } else {
                    fixGroupError.setUserObject(new String[] { csvMissGrps });
                }
                groupChooseSubContainer.showError(true);
            } else {
                // no more errors
                groupChooseSubContainer.clearError();
            }
        }
        areaChooseSubContainer.clearError();
        if (!isEmpty(easyAreaList)) {
            // check whether areas exist
            activeAreaSelection = getKeys(easyAreaList);
            List<Long> missingAreas = new ArrayList<Long>();
            List<BGArea> cnt = areaManager.loadAreas(activeAreaSelection);
            a_a: for (Long activeAreaKey : activeAreaSelection) {
                for (BGArea element : cnt) {
                    if (element.getKey().equals(activeAreaKey)) {
                        continue a_a;
                    }
                }
                missingAreas.add(activeAreaKey);
            }
            if (missingAreas.size() > 0) {
                retVal = false;
                String labelKey = missingAreas.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissAreas = toString(missingAreas);
                String[] params = new String[] { "-", csvMissAreas };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorAreaItemLayout = FormLayoutContainer.createCustomFormLayout("errorareaitem", getTranslator(), vc_errorPage);
                areaChooseSubContainer.setErrorComponent(errorAreaItemLayout, this.flc);
                // FXINGIN LINK ONLY IF DEFAULT CONTEXT EXISTS
                // erstellen
                fixAreaError = new FormLinkImpl("error.fix", "create");
                // link
                fixAreaError.setCustomEnabledLinkCSS("btn btn-default");
                errorAreaItemLayout.add(fixAreaError);
                fixAreaError.setErrorKey(labelKey, params);
                fixAreaError.showError(true);
                fixAreaError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingAreas.size() > 1) {
                    fixAreaError.setUserObject(new String[] { csvMissAreas, "dummy" });
                } else {
                    fixAreaError.setUserObject(new String[] { csvMissAreas });
                }
                areaChooseSubContainer.showError(true);
            } else {
                areaChooseSubContainer.clearError();
            }
        }
        boolean easyGroupOK = (!isEmpty(easyGroupList) && activeGroupSelection != null && !activeGroupSelection.isEmpty());
        boolean easyAreaOK = (!isEmpty(easyAreaList) && activeAreaSelection != null && !activeAreaSelection.isEmpty());
        if (easyGroupOK || easyAreaOK) {
            // clear general error
            groupSubContainer.clearError();
        } else {
            // error concerns both fields -> set it as switch error
            groupSubContainer.setErrorKey("form.easy.error.group", null);
            retVal = false;
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) BGArea(org.olat.group.area.BGArea) BusinessGroupShort(org.olat.group.BusinessGroupShort) HashSet(java.util.HashSet)

Example 52 with FormLinkImpl

use of org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl in project openolat by klemens.

the class BGCopySingleGroupStep method getStepTitle.

@Override
public FormItem getStepTitle() {
    String groupName = StringHelper.escapeHtml(groupToCopy.getName());
    String title = getTranslator().translate("copy.wizard.bgstep", new String[] { groupName });
    FormLink fl = new FormLinkImpl("copy.wizard." + groupToCopy.getKey(), null, title, Link.FLEXIBLEFORMLNK + Link.NONTRANSLATED);
    fl.setTranslator(getTranslator());
    return fl;
}
Also used : FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Aggregations

FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)52 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)8 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 BGArea (org.olat.group.area.BGArea)4 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Locale (java.util.Locale)2 TimeZone (java.util.TimeZone)2 ValidationError (org.olat.core.gui.components.form.ValidationError)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 AutoCompleterImpl (org.olat.core.gui.components.form.flexible.impl.elements.AutoCompleterImpl)2 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)2