From d1d62fc670f6b4a817ad257ed76b1dfd38c5c78b Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Wed, 5 Feb 2020 11:05:17 +0100 Subject: [PATCH] OO-4504: allow integration of batch buttons in table --- .../flexible/elements/FlexiTableElement.java | 8 ++++++ .../table/AbstractFlexiTableRenderer.java | 18 ++++++++++++- .../elements/table/FlexiTableElementImpl.java | 25 +++++++++++++------ .../FIBAssessmentItemBuilder.java | 9 ++++--- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/FlexiTableElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/FlexiTableElement.java index 1ed81d99398..d244551c6d9 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/FlexiTableElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/FlexiTableElement.java @@ -472,4 +472,12 @@ public interface FlexiTableElement extends FormItem, FormItemCollection { * @return The i18n key for the message to be displayed when the table is empty or NULL when no message should be displayed. */ public String getEmtpyTableMessageKey(); + + /** + * Add a button or an other component in the "button grouped" + * panel under the table. + * + * @param item An acceptable form item + */ + public void addBatchButton(FormItem item); } \ No newline at end of file diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/AbstractFlexiTableRenderer.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/AbstractFlexiTableRenderer.java index 21b1cfad6cf..128a0f16f9e 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/AbstractFlexiTableRenderer.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/AbstractFlexiTableRenderer.java @@ -95,6 +95,7 @@ public abstract class AbstractFlexiTableRenderer extends DefaultComponentRendere sb.append("</table>"); renderFooterButtons(sb, ftC, translator); + renderFooterGroupedButtons(renderer, sb, ftC, ubu, translator, renderResult, args); //draggable if(ftE.getColumnIndexForDragAndDropLabel() > 0) { sb.append("<script>") @@ -402,7 +403,7 @@ public abstract class AbstractFlexiTableRenderer extends DefaultComponentRendere protected void renderFormItem(Renderer renderer, StringOutput sb, FormItem item, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) { - if(item != null) { + if(item != null && item.isVisible()) { Component cmp = item.getComponent(); cmp.getHTMLRendererSingleton().render(renderer, sb, cmp, ubu, translator, renderResult, args); cmp.setDirty(false); @@ -468,6 +469,21 @@ public abstract class AbstractFlexiTableRenderer extends DefaultComponentRendere } } + protected void renderFooterGroupedButtons(Renderer renderer, StringOutput sb, FlexiTableComponent ftC, + URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) { + List<FormItem> items = ftC.getFlexiTableElement().getBatchButtons(); + if(items != null) { + boolean atLeastOneVisible = items.stream().anyMatch(FormItem::isVisible); + if(atLeastOneVisible) { + sb.append("<div class='o_button_group'>"); + for(FormItem item:items) { + renderFormItem(renderer, sb, item, ubu, translator, renderResult, args); + } + sb.append("</div>"); + } + } + } + protected abstract void renderHeaders(StringOutput target, FlexiTableComponent ftC, Translator translator); protected void renderBody(Renderer renderer, StringOutput target, FlexiTableComponent ftC, diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/FlexiTableElementImpl.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/FlexiTableElementImpl.java index 6b04bcef473..93824009f2f 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/FlexiTableElementImpl.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/FlexiTableElementImpl.java @@ -114,8 +114,10 @@ public class FlexiTableElementImpl extends FormItemImpl implements FlexiTableEle private VelocityContainer rowRenderer; private VelocityContainer detailsRenderer; - private FormLink customButton, exportButton; - private FormLink searchButton, extendedSearchButton; + private FormLink customButton; + private FormLink exportButton; + private FormLink searchButton; + private FormLink extendedSearchButton; private FormLink classicTypeButton; private FormLink customTypeButton; private FormLink extendedFilterButton; @@ -147,8 +149,8 @@ public class FlexiTableElementImpl extends FormItemImpl implements FlexiTableEle private FlexiTreeTableNode rootCrumb; private List<FlexiTreeTableNode> crumbs; - private Map<String,FormItem> components = new HashMap<>(); + private List<FormItem> batchButtons = new ArrayList<>(); public FlexiTableElementImpl(WindowControl wControl, String name, Translator translator, FlexiTableDataModel<?> tableModel) { this(wControl, name, translator, tableModel, -1, true); @@ -845,6 +847,18 @@ public class FlexiTableElementImpl extends FormItemImpl implements FlexiTableEle public void addFormItem(FormItem item) { components.put(item.getName(), item); } + + public List<FormItem> getBatchButtons() { + return batchButtons; + } + + @Override + public void addBatchButton(FormItem item) { + if(item != null) { + batchButtons.add(item); + addFormItem(item); + } + } @Override public void doDispatchFormRequest(UserRequest ureq) { @@ -855,10 +869,7 @@ public class FlexiTableElementImpl extends FormItemImpl implements FlexiTableEle protected void dispatchFormRequest(UserRequest ureq) { super.dispatchFormRequest(ureq); } - - /** - * @see org.olat.core.gui.components.form.flexible.FormItemImpl#evalFormRequest(org.olat.core.gui.UserRequest) - */ + @Override public void evalFormRequest(UserRequest ureq) { Form form = getRootForm(); diff --git a/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java b/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java index 1bfa7136caa..dbd93f9d9d4 100644 --- a/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java +++ b/src/main/java/org/olat/ims/qti21/model/xml/interactions/FIBAssessmentItemBuilder.java @@ -1393,10 +1393,11 @@ public class FIBAssessmentItemBuilder extends AssessmentItemBuilder { if(match(response, solution)) { return true; } - - for(TextEntryAlternative textEntryAlternative:alternatives) { - if(match(response, textEntryAlternative.getAlternative())) { - return true; + if(alternatives != null && !alternatives.isEmpty()) { + for(TextEntryAlternative textEntryAlternative:alternatives) { + if(match(response, textEntryAlternative.getAlternative())) { + return true; + } } } return false; -- GitLab