diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/FormUIFactory.java b/src/main/java/org/olat/core/gui/components/form/flexible/FormUIFactory.java index 5f516963ad41c74f3f1da773c29cf4d0dd6ce2ff..95c815f336feeabcb8efc1eaba7b4c394c085d57 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/FormUIFactory.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/FormUIFactory.java @@ -356,7 +356,7 @@ public class FormUIFactory { * @return */ public SingleSelection addRadiosHorizontal(final String name, final String i18nLabel, FormItemContainer formLayout, final String[] theKeys, final String[] theValues) { - SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelectionImpl.createHorizontalLayout(null, name)); + SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelection.Layout.horizontal); ss.setKeysAndValues(theKeys, theValues, null); setLabelIfNotNull(i18nLabel, ss); formLayout.add(ss); @@ -391,7 +391,7 @@ public class FormUIFactory { * @return */ public SingleSelection addRadiosVertical(final String name, final String i18nLabel, FormItemContainer formLayout, final String[] theKeys, final String[] theValues) { - SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelectionImpl.createVerticalLayout(null, name)); + SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelection.Layout.vertical); ss.setKeysAndValues(theKeys, theValues, null); setLabelIfNotNull(i18nLabel, ss); formLayout.add(ss); @@ -441,7 +441,7 @@ public class FormUIFactory { * @return */ public SingleSelection addDropdownSingleselect(final String id, final String name, final String i18nLabel, FormItemContainer formLayout, final String[] theKeys, final String[] theValues, final String[] theCssClasses) { - SingleSelection ss = new SingleSelectionImpl(id, name, SingleSelectionImpl.createSelectboxLayouter(id, name)); + SingleSelection ss = new SingleSelectionImpl(id, name, SingleSelection.Layout.select); ss.setKeysAndValues(theKeys, theValues, theCssClasses); setLabelIfNotNull(i18nLabel, ss); formLayout.add(ss); diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/SingleSelection.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/SingleSelection.java index 0c7813234a15cda860329fd2c3009ce49b36faab..56d9dee85a5c3f10f0e1a52447510451e302d7ce 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/SingleSelection.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/SingleSelection.java @@ -67,4 +67,10 @@ public interface SingleSelection extends SelectionElement { * each key-value pair or NULL not not use special styling */ public void setKeysAndValues(String[] keys, String[] values,String[] cssClasses); + + public enum Layout { + select, + vertical, + horizontal + } } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormJSHelper.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormJSHelper.java index bed51ab10f820f55a29325305ecc9da40680a2e4..b1fd92f631e1df45cfc5c78d02a1e8d7aef6bc34 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormJSHelper.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormJSHelper.java @@ -194,21 +194,16 @@ public class FormJSHelper { public static String getSetFlexiFormDirty(Form form, String id){ StringBuilder result = new StringBuilder(); - result.append("jQuery('#").append(id).append("').on('change keypress',{formId:\"") - .append(form.getDispatchFieldId()).append("\"},setFlexiFormDirtyByListener);"); - return result.toString(); + return result.append("jQuery('#").append(id).append("').on('change keypress',{formId:\"") + .append(form.getDispatchFieldId()).append("\"},setFlexiFormDirtyByListener);") + .toString(); } public static String getSetFlexiFormDirtyForCheckbox(Form form, String id){ - String result; - String prefix = id + ".on('"; - // examples: - // o_fi400.on({'click',setFormDirty,this,{formId:"ofo_100"}}); - // o_fi400.on({'change',setFormDirty,this,{formId:"ofo_100"}}); - String postfix = "',setFlexiFormDirtyByListener,document,{formId:\"" + form.getDispatchFieldId() + "\"});"; - result = prefix + "change" + postfix; - result += prefix + "mouseup" + postfix; - return result; + StringBuilder result = new StringBuilder(); + return result.append(id).append(".on('change mouseup',setFlexiFormDirtyByListener,document,{formId:\"") + .append(form.getDispatchFieldId()).append("\"});") + .toString(); } public static String getFocusFor(String id){ diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormLayoutContainer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormLayoutContainer.java index 6cf446c0da59af9dca65f32647a93e34f41e2af6..e1e8b2f1d4b0078d9a54cd29029caf5913020126 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormLayoutContainer.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormLayoutContainer.java @@ -64,7 +64,6 @@ public class FormLayoutContainer extends FormItemImpl implements FormItemContain private static final String LAYOUT_HORIZONTAL = VELOCITY_ROOT + "/form_horizontal.html"; private static final String LAYOUT_VERTICAL = VELOCITY_ROOT + "/form_vertical.html"; private static final String LAYOUT_BAREBONE = VELOCITY_ROOT + "/form_barebone.html"; - private static final String LAYOUT_SELBOX = VELOCITY_ROOT + "/form_selbox.html"; private static final String LAYOUT_BUTTONGROUP = VELOCITY_ROOT + "/form_buttongroup.html"; /** @@ -557,14 +556,6 @@ public class FormLayoutContainer extends FormItemImpl implements FormItemContain FormLayoutContainer tmp = new FormLayoutContainer(name, formTranslator, LAYOUT_BUTTONGROUP); return tmp; } - - /** - * workaround FIXME:pb - */ - public static FormLayouter createSelbox(String name, Translator formTranslator) { - FormLayouter tmp = new FormLayoutContainer(name, formTranslator, LAYOUT_SELBOX); - return tmp; - } /** * diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/_content/form_selbox.html b/src/main/java/org/olat/core/gui/components/form/flexible/impl/_content/form_selbox.html deleted file mode 100644 index 18ea2a26f478455cd722ff17dd49db1a70d9e8f0..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/_content/form_selbox.html +++ /dev/null @@ -1,3 +0,0 @@ -#foreach ($item in $formitemnames) - $r.render("${item}_SELBOX") -#end \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/JSDateChooser.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/JSDateChooser.java index f6623220effa9c4e13a227342c981165b5602cb3..5586345518227b0ea57ae4e9964fef3798cffa88 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/JSDateChooser.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/JSDateChooser.java @@ -35,6 +35,8 @@ import org.olat.core.gui.GUIInterna; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.form.flexible.elements.DateChooser; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; import org.olat.core.util.Formatter; import org.olat.core.util.StringHelper; import org.olat.core.util.ValidationStatus; @@ -48,8 +50,9 @@ import org.olat.core.util.ValidationStatusImpl; * * @author patrickb */ -public class JSDateChooser extends TextElementImpl implements DateChooser{ +public class JSDateChooser extends TextElementImpl implements DateChooser { + private static final OLog log = Tracing.createLoggerFor(JSDateChooser.class); /** * the java script date chooser */ diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementComponent.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementComponent.java deleted file mode 100644 index f0b986e2f8b13b5d6001424f0a2b6dbc78205c98..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementComponent.java +++ /dev/null @@ -1,91 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ -package org.olat.core.gui.components.form.flexible.impl.elements; - -import org.olat.core.gui.components.ComponentRenderer; -import org.olat.core.gui.components.form.flexible.elements.SingleSelection; -import org.olat.core.gui.components.form.flexible.impl.Form; -import org.olat.core.gui.components.form.flexible.impl.FormBaseComponentImpl; -import org.olat.core.gui.translator.Translator; - -/** - * Description:<br> - * TODO: patrickb Class Description for SingleSelectionElementComponent - * - * <P> - * Initial Date: 31.12.2006 <br> - * @author patrickb - */ -class RadioElementComponent extends FormBaseComponentImpl { - - private static final ComponentRenderer RENDERER = new RadioElementRenderer(); - private SingleSelection selectionWrapper; - private int which; - - public RadioElementComponent(String name, Translator translator, SingleSelection selectionWrapper, int which) { - super(name, translator); - this.selectionWrapper = selectionWrapper; - this.which = which; - } - - @Override - public ComponentRenderer getHTMLRendererSingleton() { - return RENDERER; - } - - String getGroupingName(){ - return selectionWrapper.getName(); - } - - int getWhichWeAre(){ - return which; - } - - String getKey() { - return selectionWrapper.getKey(which); - } - - public String getValue() { - return selectionWrapper.getValue(which); - } - - public boolean isSelected() { - return selectionWrapper.isSelected(which); - } - - public int getAction(){ - return selectionWrapper.getAction(); - } - - public Form getRootForm(){ - return selectionWrapper.getRootForm(); - } - - public String getSelectionElementFormDisId(){ - return selectionWrapper.getFormDispatchId(); - } - -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementRenderer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementRenderer.java deleted file mode 100644 index 4eba37c15f670b3c9cb3772b9535a97b34ffcf7a..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/RadioElementRenderer.java +++ /dev/null @@ -1,129 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ -package org.olat.core.gui.components.form.flexible.impl.elements; - -import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.ComponentRenderer; -import org.olat.core.gui.components.form.flexible.impl.FormJSHelper; -import org.olat.core.gui.render.RenderResult; -import org.olat.core.gui.render.Renderer; -import org.olat.core.gui.render.RenderingState; -import org.olat.core.gui.render.StringOutput; -import org.olat.core.gui.render.URLBuilder; -import org.olat.core.gui.translator.Translator; - -/** - * Description:<br> - * TODO: patrickb Class Description for SingleSelectionElementComponentRenderer - * - * <P> - * Initial Date: 31.12.2006 <br> - * - * @author patrickb - */ -class RadioElementRenderer implements ComponentRenderer { - - /** - * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer, - * org.olat.core.gui.render.StringOutput, - * org.olat.core.gui.components.Component, - * org.olat.core.gui.render.URLBuilder, - * org.olat.core.gui.translator.Translator, - * org.olat.core.gui.render.RenderResult, java.lang.String[]) - */ - public void render(Renderer renderer, StringOutput sb, Component source, - URLBuilder ubu, Translator translator, RenderResult renderResult, - String[] args) { - - RadioElementComponent ssec = (RadioElementComponent) source; - - String subStrName = "name=\"" + ssec.getGroupingName() + "\""; - - String key = ssec.getKey(); - String value = ssec.getValue(); - boolean selected = ssec.isSelected(); - // read write view - sb.append("<div class='radio'>"); - sb.append("<input "); - sb.append("id=\""); - sb.append(ssec.getFormDispatchId()); - sb.append("\" "); - sb.append("type=\"radio\" " + subStrName + " value=\""); - sb.append(key); - sb.append("\" "); - if (selected){ - sb.append(" checked=\"checked\" "); - } - if(!source.isEnabled()){ - //mark as disabled and do not add javascript - sb.append(" disabled=\"disabled\" "); - }else{ - // use the selection elements formDispId instead of the one of this element. - sb.append(FormJSHelper.getRawJSFor(ssec.getRootForm(), ssec.getSelectionElementFormDisId(), ssec.getAction())); - } - sb.append(" />"); - sb.append("<label for=\"").append(ssec.getFormDispatchId()).append("\">"); - sb.append(value); - sb.append("</label>"); - sb.append("</div>"); - - if(source.isEnabled()){ - //add set dirty form only if enabled - sb.append(FormJSHelper.getJSStartWithVarDeclaration(ssec.getFormDispatchId())); - sb.append(FormJSHelper.getSetFlexiFormDirtyForCheckbox(ssec.getRootForm(), ssec.getFormDispatchId())); - sb.append(FormJSHelper.getJSEnd()); - } - - } - - /** - * @see org.olat.core.gui.components.ComponentRenderer#renderBodyOnLoadJSFunctionCall(org.olat.core.gui.render.Renderer, - * org.olat.core.gui.render.StringOutput, - * org.olat.core.gui.components.Component, - * org.olat.core.gui.render.RenderingState) - */ - public void renderBodyOnLoadJSFunctionCall(Renderer renderer, - StringOutput sb, Component source, RenderingState rstate) { - // TODO Auto-generated method stub - - } - - /** - * @see org.olat.core.gui.components.ComponentRenderer#renderHeaderIncludes(org.olat.core.gui.render.Renderer, - * org.olat.core.gui.render.StringOutput, - * org.olat.core.gui.components.Component, - * org.olat.core.gui.render.URLBuilder, - * org.olat.core.gui.translator.Translator, - * org.olat.core.gui.render.RenderingState) - */ - public void renderHeaderIncludes(Renderer renderer, StringOutput sb, - Component source, URLBuilder ubu, Translator translator, - RenderingState rstate) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionComponent.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..16dc98563b8318b49975cc015ce47383fe13eb4b --- /dev/null +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionComponent.java @@ -0,0 +1,115 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.gui.components.form.flexible.impl.elements; + +import org.olat.core.gui.components.ComponentRenderer; +import org.olat.core.gui.components.form.flexible.elements.SingleSelection; +import org.olat.core.gui.components.form.flexible.impl.Form; +import org.olat.core.gui.components.form.flexible.impl.FormBaseComponentImpl; + +/** + * + * Initial date: 12.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +class SingleSelectionComponent extends FormBaseComponentImpl { + + private static final ComponentRenderer RENDERER = new SingleSelectionRenderer(); + private final SingleSelectionImpl element; + + private RadioElementComponent[] radioComponents; + + /** + * @param id A fix identifier for state-less behavior, must be unique or null + */ + public SingleSelectionComponent(String id, SingleSelectionImpl element) { + super(id, element.getName(), null); + this.element = element; + } + + SingleSelectionImpl getSingleSelectionImpl(){ + return element; + } + + + RadioElementComponent[] getRadioComponents() { + return radioComponents; + } + + void setRadioComponents(RadioElementComponent[] radioComponents) { + this.radioComponents = radioComponents; + } + + @Override + public ComponentRenderer getHTMLRendererSingleton() { + return RENDERER; + } + + public static class RadioElementComponent { + + private SingleSelection selectionWrapper; + private int which; + private String name; + + RadioElementComponent(String name, SingleSelection selectionWrapper, int which) { + this.selectionWrapper = selectionWrapper; + this.which = which; + this.name = name; + } + + String getGroupingName(){ + return selectionWrapper.getName(); + } + + int getWhichWeAre(){ + return which; + } + + String getKey() { + return selectionWrapper.getKey(which); + } + + String getFormDispatchId() { + return name; + } + + public String getValue() { + return selectionWrapper.getValue(which); + } + + public boolean isSelected() { + return selectionWrapper.isSelected(which); + } + + public int getAction(){ + return selectionWrapper.getAction(); + } + + public Form getRootForm(){ + return selectionWrapper.getRootForm(); + } + + public String getSelectionElementFormDisId(){ + return selectionWrapper.getFormDispatchId(); + } + + } +} \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionImpl.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionImpl.java index 84a4a586a24cf1a4d2809ea5f56926ff38510c2b..5b4b1bb7613ac514db4d39f2e290bcdb933c04bc 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionImpl.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionImpl.java @@ -30,12 +30,10 @@ import java.util.List; import org.olat.core.gui.GUIInterna; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.form.flexible.FormLayouter; import org.olat.core.gui.components.form.flexible.elements.SingleSelection; import org.olat.core.gui.components.form.flexible.impl.FormItemImpl; -import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; +import org.olat.core.gui.components.form.flexible.impl.elements.SingleSelectionComponent.RadioElementComponent; import org.olat.core.logging.AssertException; -import org.olat.core.util.Util; import org.olat.core.util.ValidationStatus; import org.olat.core.util.ValidationStatusImpl; @@ -49,56 +47,54 @@ import org.olat.core.util.ValidationStatusImpl; */ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection { - private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(SingleSelectionImpl.class); - - private final static String HORIZONTAL_DEFAULT_RADIO = VELOCITY_ROOT + "/sel_elems_horizontal.html"; - private final static String VERTICAL_RADIO = VELOCITY_ROOT + "/sel_elems_vertical.html"; - private final static String SELECTBOX = VELOCITY_ROOT + "/sel_elems_selbox.html"; - - protected String[] values; - protected String[] keys; - protected String[] cssClasses; + private String[] values; + private String[] keys; + private String[] cssClasses; private String original = null; private boolean originalSelect = false; private int selectedIndex = -1; - private FormLayouter formLayoutContainer; + private final Layout layout; + private Component component; /** * @param name */ public SingleSelectionImpl(String name) { - this(null, name, createHorizontalLayout(null, name)); + this(null, name, Layout.horizontal); } - /** * set your layout * @param id A fix identifier for state-less behavior, must be unique or null * @param name * @param presentation */ - public SingleSelectionImpl(String id, String name, FormLayouter formLayout) { + public SingleSelectionImpl(String id, String name, Layout layout) { super(id, name, false); - formLayoutContainer = formLayout; + this.layout = layout; } /** * @see org.olat.core.gui.components.form.flexible.elements.SingleSelectionContainer#getSelected() */ + @Override public int getSelected() { return selectedIndex; } + + public Layout getLayout() { + return layout; + } /** * @see org.olat.core.gui.components.form.flexible.elements.SingleSelectionContainer#getSelectedKey() */ + @Override public String getSelectedKey() { if (!isOneSelected()) throw new AssertException("no key selected"); return keys[selectedIndex]; } - - @Override public String getSelectedValue() { @@ -108,7 +104,6 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection return null; } - /** * @see org.olat.core.gui.components.form.flexible.elements.SingleSelectionContainer#isOneSelected() */ @@ -181,7 +176,9 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection original = key; originalSelect = select; } - if (!found) { throw new AssertException("could not set <" + key + "> to " + select + " because key was not found!"); } + if (!found) { + throw new AssertException("could not set <" + key + "> to " + select + " because key was not found!"); + } } /** @@ -223,7 +220,6 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection }//endif }//endmethod - @Override public void validate(List<ValidationStatus> validationResults) { if ( ! isOneSelected()) { @@ -239,7 +235,6 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection select(original, originalSelect); clearError(); } - /** * @see org.olat.core.gui.components.form.flexible.FormItemImpl#setEnabled(boolean) @@ -247,33 +242,19 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection @Override public void setEnabled(boolean isEnabled) { super.setEnabled(isEnabled); - //set isEnabled for all created components - Component sssc = formLayoutContainer.getComponent(getName()+"_SELBOX"); - sssc.setEnabled(isEnabled); - for (int i = 0; i < keys.length; i++) { - Component elm = formLayoutContainer.getComponent(getName()+"_"+keys[i]); - elm.setEnabled(isEnabled); - } + component.setEnabled(isEnabled); } + @Override public void setVisible(boolean isVisible) { super.setVisible(isVisible); - //set isEnabled for all created components - Component sssc = formLayoutContainer.getComponent(getName()+"_SELBOX"); - if(sssc != null){ - sssc.setVisible(isVisible); - } - for (int i = 0; i < keys.length; i++) { - Component elm = formLayoutContainer.getComponent(getName()+"_"+keys[i]); - if(elm != null){ - elm.setVisible(isVisible); - } - } - }; + component.setVisible(isVisible); + } /** * @see org.olat.core.gui.components.form.flexible.FormBaseComponentIdProvider#getFormDispatchId() */ + @Override public String getFormDispatchId() { /** * FIXME:pb dirty hack or not to allow singleselection subcomponents being @@ -284,9 +265,9 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection * understand why this is not always the case. */ if(GUIInterna.isLoadPerformanceMode()){ - return DISPPREFIX+getRootForm().getReplayableDispatchID(formLayoutContainer.getComponent()); + return DISPPREFIX+getRootForm().getReplayableDispatchID(component); }else{ - return DISPPREFIX+formLayoutContainer.getComponent().getDispatchID(); + return DISPPREFIX + component.getDispatchID(); } } @@ -300,79 +281,24 @@ public class SingleSelectionImpl extends FormItemImpl implements SingleSelection } // keys,values initialized // create and add radio elements - String[] items = new String[keys.length]; - for (int i = 0; i < keys.length; i++) { - RadioElementComponent ssec = new RadioElementComponent(getName()+"_"+keys[i], translator, this, i); - formLayoutContainer.put(getName()+"_"+keys[i], ssec); - items[i]=getName()+"_"+keys[i]; - //formComponentsNames.add(keys[i]); - //formComponents.put(keys[i], ssec); - if (GUIInterna.isLoadPerformanceMode()) { - getRootForm().getReplayableDispatchID(ssec); + if(layout == Layout.select) { + String ssscId = getFormItemId() == null ? null : getFormItemId() + "_SELBOX"; + component = new SelectboxComponent(ssscId , getName() + "_SELBOX", translator, this, keys, values, cssClasses); + } else { + RadioElementComponent[] radios = new RadioElementComponent[keys.length]; + for (int i = 0; i < keys.length; i++) { + String radioName = getName() + "_" + keys[i]; + radios[i] = new RadioElementComponent(radioName, this, i); } + String ssscId = getFormItemId() == null ? null : getFormItemId() + "_RADIO"; + SingleSelectionComponent ssc = new SingleSelectionComponent(ssscId, this); + ssc.setRadioComponents(radios); + component = ssc; } - //create and add selectbox element - String ssscId = getFormItemId() == null ? null : getFormItemId() + "_SELBOX"; - SelectboxComponent sssc = new SelectboxComponent(ssscId , getName() + "_SELBOX", translator, this, keys, values, cssClasses); - formLayoutContainer.put(getName()+"_SELBOX", sssc); - formLayoutContainer.contextPut("selectbox", getName()+"_SELBOX"); - //formComponentsNames.add(getName()+"_SELBOX"); - //formComponents.put(getName()+"_SELBOX", sssc); - // - formLayoutContainer.contextPut("items", items); - } - - /** - * as selectbox - * @param id A fix identification for state-less behavior, must be unique - * @param name - * @return - */ - public static FormLayoutContainer createSelectboxLayouter(String id, String name) { - String contId = (id == null ? null : id + "_SELECTBOX_CONT"); - return FormLayoutContainer.createCustomFormLayout(contId, name+"SELECTBOX", null, SELECTBOX); - } - - /** - * radio buttons horizontal - * @param id A fix identification for state-less behavior, must be unique - * @param name - * @return - */ - public static FormLayoutContainer createHorizontalLayout(String id, String name) { - String contId = (id == null ? null : id + "_HORIZONTAL_DEFAULT_RADIO_CONT"); - return FormLayoutContainer.createCustomFormLayout(contId, name+"HORIZONTAL_DEFAULT_RADIO", null, HORIZONTAL_DEFAULT_RADIO); - } - - /** - * radio buttons vertical - * @param id A fix identification for state-less behavior, must be unique - * @param name - * @return - */ - public static FormLayoutContainer createVerticalLayout(String id, String name) { - String contId = (id == null ? null : id + "_VERTICAL_RADIO_CONT"); - return FormLayoutContainer.createCustomFormLayout(contId, name+"VERTICAL_RADIO", null, VERTICAL_RADIO); } + @Override protected Component getFormItemComponent() { - /** - * FIXME:pb dirty hack or not? to allow singleselection subcomponents being - * added to surrounding formlayouters -> e.g. language chooser selectbox - * we have to return the formLayoutContainer.Component if it was not a - * "custom" formlayouter. -> detection via ..endsWith() bad not beautyful - * but functional so far. - */ - String tmp = formLayoutContainer.getComponent().getComponentName(); - boolean isDefault = tmp.endsWith("VERTICAL_RADIO") || tmp.endsWith("HORIZONTAL_DEFAULT_RADIO") || tmp.endsWith("SELECTBOX"); - if(isDefault){ - return formLayoutContainer.getComponent(); - }else{ - //return a dummy, not to break rendering process with a null component. - return createSelectboxLayouter(null, "dummy").getComponent(); - } + return component; } - - - -} +} \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionRenderer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..68ad125ef3ae5bbf0d4af3c9cdb977d0df8128f2 --- /dev/null +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/SingleSelectionRenderer.java @@ -0,0 +1,109 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.gui.components.form.flexible.impl.elements; + +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.DefaultComponentRenderer; +import org.olat.core.gui.components.form.flexible.elements.SingleSelection.Layout; +import org.olat.core.gui.components.form.flexible.impl.FormJSHelper; +import org.olat.core.gui.components.form.flexible.impl.elements.SingleSelectionComponent.RadioElementComponent; +import org.olat.core.gui.render.RenderResult; +import org.olat.core.gui.render.Renderer; +import org.olat.core.gui.render.StringOutput; +import org.olat.core.gui.render.URLBuilder; +import org.olat.core.gui.translator.Translator; + +/** + * + * Initial date: 12.06.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +class SingleSelectionRenderer extends DefaultComponentRenderer { + + /** + * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer, + * org.olat.core.gui.render.StringOutput, + * org.olat.core.gui.components.Component, + * org.olat.core.gui.render.URLBuilder, + * org.olat.core.gui.translator.Translator, + * org.olat.core.gui.render.RenderResult, java.lang.String[]) + */ + @Override + public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, + RenderResult renderResult, String[] args) { + SingleSelectionComponent teC = (SingleSelectionComponent) source; + Layout layout = teC.getSingleSelectionImpl().getLayout(); + if(layout == Layout.vertical) { + renderVertical(sb, teC); + } else { + renderHorizontal(sb, teC); + } + } + + private void renderVertical(StringOutput sb, SingleSelectionComponent source) { + sb.append("<div class='o_form_selection_vertical'>"); + RadioElementComponent[] radios = source.getRadioComponents(); + for(RadioElementComponent radio:radios) { + renderRadio(sb, source, radio, "radio"); + } + sb.append("</div>"); + } + + private void renderHorizontal(StringOutput sb, SingleSelectionComponent source) { + sb.append("<div class='form-inline'>"); + RadioElementComponent[] radios = source.getRadioComponents(); + for(RadioElementComponent radio:radios) { + renderRadio(sb, source, radio, "radio-inline"); + } + sb.append("</div>"); + } + + private void renderRadio(StringOutput sb, SingleSelectionComponent source, RadioElementComponent ssec, String css) { + String subStrName = "name='" + ssec.getGroupingName() + "'"; + + String key = ssec.getKey(); + String value = ssec.getValue(); + boolean selected = ssec.isSelected(); + + // read write view + sb.append("<label class='").append(css).append("' for='").append(ssec.getFormDispatchId()).append("'>") + .append("<input id='").append(ssec.getFormDispatchId()).append("' ") + .append("type='radio' ").append(subStrName) + .append(" value='").append(key).append("' ") + .append(" checked='checked' ", selected); + + if(source.isEnabled()){ + // use the selection elements formDispId instead of the one of this element. + sb.append(FormJSHelper.getRawJSFor(ssec.getRootForm(), ssec.getSelectionElementFormDisId(), ssec.getAction())); + } else { + //mark as disabled and do not add javascript + sb.append(" disabled='disabled' "); + } + sb.append(" />").append(value).append("</label> "); + + if(source.isEnabled()){ + //add set dirty form only if enabled + sb.append(FormJSHelper.getJSStartWithVarDeclaration(ssec.getFormDispatchId())); + sb.append(FormJSHelper.getSetFlexiFormDirtyForCheckbox(ssec.getRootForm(), ssec.getFormDispatchId())); + sb.append(FormJSHelper.getJSEnd()); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/TextElementImpl.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/TextElementImpl.java index 82700a90b79741f93c73a84f38af2b56cd86e47f..bd28b69b4dcf3ac7209447ec96506a5ed253cd0b 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/TextElementImpl.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/TextElementImpl.java @@ -68,7 +68,7 @@ public class TextElementImpl extends AbstractTextElement implements InlineTextEl //inline stuff protected String transientValue;//last submitted value, which may be good or wrong - OLog log = Tracing.createLoggerFor(this.getClass()); + private static final OLog log = Tracing.createLoggerFor(TextElementImpl.class); /** * @param id A fix identifier for state-less behavior, must be unique or null diff --git a/src/main/java/org/olat/course/condition/ConditionConfigEasyController.java b/src/main/java/org/olat/course/condition/ConditionConfigEasyController.java index ea489f9b5f667e53212370ff4fd58df49797b551..adfebf71774b3fe060a33895abb40eb52247a0e9 100644 --- a/src/main/java/org/olat/course/condition/ConditionConfigEasyController.java +++ b/src/main/java/org/olat/course/condition/ConditionConfigEasyController.java @@ -49,7 +49,6 @@ import org.olat.core.gui.components.form.flexible.impl.FormEvent; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; import org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl; import org.olat.core.gui.components.form.flexible.impl.elements.JSDateChooser; -import org.olat.core.gui.components.form.flexible.impl.elements.SingleSelectionImpl; import org.olat.core.gui.components.form.flexible.impl.rules.RulesFactory; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; @@ -98,7 +97,6 @@ public class ConditionConfigEasyController extends FormBasicController implement private JSDateChooser toDate; private FormItemContainer dateSubContainer, groupSubContainer, assessSubContainer; private FormLayoutContainer areaChooseSubContainer, groupChooseSubContainer; - private FormLayoutContainer assessNodesListContainer; private MultipleSelectionElement dateSwitch; private StaticTextElement easyGroupList; private FormLink chooseGroupsLink; @@ -540,14 +538,14 @@ public class ConditionConfigEasyController extends FormBasicController implement // foop d fbg,dfbg,f ,gfbirst check two error cases of a selection // no node selected or a deleted node selected if (nodePassed.getSelectedKey().equals(NO_NODE_SELECTED_IDENTIFYER)) { - assessNodesListContainer.setErrorKey("form.easy.error.nodePassed", null); + nodePassed.setErrorKey("form.easy.error.nodePassed", null); retVal = false; } else if (nodePassed.getSelectedKey().equals(DELETED_NODE_IDENTIFYER)) { - assessNodesListContainer.setErrorKey("form.easy.error.nodeDeleted", null); + nodePassed.setErrorKey("form.easy.error.nodeDeleted", null); retVal = false; } else { //clear nodepassed error - assessNodesListContainer.clearError(); + nodePassed.clearError(); //retVal stays } } @@ -1247,17 +1245,7 @@ public class ConditionConfigEasyController extends FormBasicController implement final String[] nodePassedValues = new String[valuesList.size()]; valuesList.toArray(nodePassedValues); - // list of assessable nodes is wrapped in a layout container for proper rendering - assessNodesListContainer = (FormLayoutContainer)FormLayoutContainer.createSelbox("assNodesListContainer", getTranslator()); - assessNodesListContainer.setLabel("form.easy.nodePassed", null); - assessSubContainer.add(assessNodesListContainer); - nodePassed = new SingleSelectionImpl(null, "nodePassed", assessNodesListContainer) { - { - keys = nodePassedKeys; - values = nodePassedValues; - } - }; - + nodePassed = uifactory.addDropdownSingleselect("nodePassed", "form.easy.nodePassed", assessSubContainer, nodePassedKeys, nodePassedValues, null); if (nodePassedInitVal != null) { if (selectedNodeIsInList) { nodePassed.select(nodePassedInitVal, true); @@ -1267,14 +1255,9 @@ public class ConditionConfigEasyController extends FormBasicController implement } else { nodePassed.select(NO_NODE_SELECTED_IDENTIFYER, true); } - assessNodesListContainer.add(nodePassed); - assessmentTypeSwitch = new SingleSelectionImpl(null, "assessmentTypeSwitch", SingleSelectionImpl.createVerticalLayout(null, "yingyang")) { - { - keys = assessmentSwitchKeys; - values = assessmentSwitchValues; - } - }; + assessmentTypeSwitch = uifactory.addRadiosVertical("assessmentTypeSwitch", null, assessSubContainer, + assessmentSwitchKeys, assessmentSwitchValues); assessmentTypeSwitch.setLabel("form.easy.assessmentSwitch.type", null); assessmentTypeSwitch.addActionListener(FormEvent.ONCLICK); @@ -1294,7 +1277,6 @@ public class ConditionConfigEasyController extends FormBasicController implement assessmentTypeSwitch.setVisible(false); assessmentTypeSwitch.select(NODEPASSED_VAL_PASSED, true); } - assessSubContainer.add(assessmentTypeSwitch); cutValue = uifactory.addIntegerElement("cutval", "form.easy.cutValue", cutInitValue, assessSubContainer); cutValue.setDisplaySize(3);