This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git
commit 5ff658a7083ce1ce312d6ad48c9d99c20ad6420f Author: Andi Huber <[email protected]> AuthorDate: Fri Nov 11 12:56:37 2022 +0100 ISIS-3071: fixes recursive file-upload nesting - using a client side script for DOM cleanup (this is a workaround) (force-pushing to correct commit mesg) --- .../scalars/ScalarPanelTextFieldAbstract.java | 1 - .../fileinput/FileUploadFieldWithNestingFix.java | 74 ++++++++++++++++++++++ .../fileinput/FileUploadNestingFixJsReference.java | 50 +++++++++++++++ .../widgets/fileinput/file-upload-nesting-fix.js | 39 ++++++++++++ .../apache/causeway/viewer/wicket/ui/util/Wkt.java | 46 ++++---------- 5 files changed, 174 insertions(+), 36 deletions(-) diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/ScalarPanelTextFieldAbstract.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/ScalarPanelTextFieldAbstract.java index 9f3f92cc2f..b2daeedc17 100644 --- a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/ScalarPanelTextFieldAbstract.java +++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/scalars/ScalarPanelTextFieldAbstract.java @@ -31,7 +31,6 @@ import org.apache.causeway.core.metamodel.spec.feature.ObjectFeature; import org.apache.causeway.viewer.commons.model.components.UiString; import org.apache.causeway.viewer.wicket.model.models.ScalarModel; import org.apache.causeway.viewer.wicket.ui.components.scalars.ScalarFragmentFactory.InputFragment; -import org.apache.causeway.viewer.wicket.ui.components.scalars.ScalarPanelAbstract.FormatModifier; import org.apache.causeway.viewer.wicket.ui.panels.PanelAbstract; import org.apache.causeway.viewer.wicket.ui.util.Wkt; diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadFieldWithNestingFix.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadFieldWithNestingFix.java new file mode 100644 index 0000000000..fef365ddba --- /dev/null +++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadFieldWithNestingFix.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.causeway.viewer.wicket.ui.components.widgets.fileinput; + +import java.util.List; + +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.html.form.upload.FileUpload; +import org.apache.wicket.model.IModel; + +import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInputField; +import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig; +import lombok.SneakyThrows; + +public class FileUploadFieldWithNestingFix extends BootstrapFileInputField { + + private static final long serialVersionUID = 1L; + + public FileUploadFieldWithNestingFix(final String id, final IModel<List<FileUpload>> model, final FileInputConfig config) { + super(id, model, config); + } + + + @Override @SneakyThrows + public void renderHead(final IHeaderResponse response) { + super.renderHead(response); + FileUploadNestingFixJsReference.INSTANCE.renderHead(response); + + +// val cleanupScript = _Resources.loadAsString(Wkt.class, "file-input-cleanup.js", StandardCharsets.UTF_8); +// response.render(OnDomReadyHeaderItem.forScript(cleanupScript)); + } +// @Override +// public void convertInput() { +// super.convertInput(); // keep side-effects +// if(!isRequired()) {return;} +// /*[ISIS-3203]: in the context of mandatory property or action parameter negotiation, +// * we need to set the converted input to something other than null, even an empty list will do +// */ +// if(isConvertedInputNull() +// && !isModelEmpty()) { +// super.setConvertedInput(Collections.emptyList()); // always pass +// } +// } +// @Override +// public boolean checkRequired() { +// super.checkRequired(); // keep side-effects +// return true; // always pass otherwise workaround won't work +// } +// private boolean isModelEmpty() { return getModel().getObject()==null; } +// private boolean isConvertedInputNull() { return getConvertedInput()==null; } + @Override + public boolean isRequired() { + //FIXME[ISIS-3203] + return false; // nothing else worked yet + } + +} diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadNestingFixJsReference.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadNestingFixJsReference.java new file mode 100644 index 0000000000..d84391409d --- /dev/null +++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/FileUploadNestingFixJsReference.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.causeway.viewer.wicket.ui.components.widgets.fileinput; + +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.OnDomReadyHeaderItem; +import org.apache.wicket.markup.html.IHeaderContributor; + +import org.apache.causeway.commons.internal.base._Text; + +import lombok.SneakyThrows; + +final class FileUploadNestingFixJsReference implements IHeaderContributor { + private static final long serialVersionUID = 1L; + public static final FileUploadNestingFixJsReference INSTANCE = new FileUploadNestingFixJsReference(); + private String jsScriptSource; + + @SneakyThrows + private FileUploadNestingFixJsReference() { + this.jsScriptSource = _Text.readLinesFromResource( + FileUploadNestingFixJsReference.class, "file-upload-nesting-fix.js", StandardCharsets.UTF_8) + .stream() + .skip(18) // skip license header + .collect(Collectors.joining("\n")); + } + + @Override + public void renderHead(final IHeaderResponse response) { + response.render(OnDomReadyHeaderItem.forScript(jsScriptSource)); + } +} diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/file-upload-nesting-fix.js b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/file-upload-nesting-fix.js new file mode 100644 index 0000000000..417ccf947e --- /dev/null +++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/fileinput/file-upload-nesting-fix.js @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*ISIS-3071 file-input nesting issue*/ +let scalarFrames = document + .querySelectorAll("span.uploadFile"); +scalarFrames.forEach((scalarFrame) => { + window.console.log("found outer frame" + scalarFrame); + + let fileInputFrames = scalarFrame + .querySelectorAll("div.file-input-ajax-new"); + + let isNested = fileInputFrames.length>1; + + /* replace the outermost with the innermost*/ + if(isNested) { + let outermost = fileInputFrames[0]; + let innermost = fileInputFrames[fileInputFrames.length-1]; + outermost.parentNode.replaceChild(innermost, outermost); + } +}); + + + diff --git a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java index d34279803e..138b706df6 100644 --- a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java +++ b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/util/Wkt.java @@ -93,6 +93,7 @@ import org.apache.causeway.viewer.commons.model.components.UiString; import org.apache.causeway.viewer.wicket.model.hints.CausewayActionCompletedEvent; import org.apache.causeway.viewer.wicket.model.hints.CausewayEnvelopeEvent; import org.apache.causeway.viewer.wicket.ui.components.scalars.markup.MarkupComponent; +import org.apache.causeway.viewer.wicket.ui.components.widgets.fileinput.FileUploadFieldWithNestingFix; import org.apache.causeway.viewer.wicket.ui.components.widgets.links.AjaxLinkNoPropagate; import org.apache.causeway.viewer.wicket.ui.panels.PanelUtil; @@ -103,7 +104,7 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.Confi import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkboxx.CheckBoxX; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkboxx.CheckBoxXConfig; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkboxx.CheckBoxXConfig.Sizes; -import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.BootstrapFileInputField; +import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.fileinput.FileInputConfig; import de.agilecoders.wicket.jquery.Key; import lombok.NonNull; import lombok.val; @@ -570,40 +571,15 @@ public class Wkt { final String id, final String initialCaption, final IModel<List<FileUpload>> model) { - val fileUploadField = new BootstrapFileInputField(id, model) { - private static final long serialVersionUID = 1L; -// @Override -// public void convertInput() { -// super.convertInput(); // keep side-effects -// if(!isRequired()) {return;} -// /*[CAUSEWAY-3203]: in the context of mandatory property or action parameter negotiation, -// * we need to set the converted input to something other than null, even an empty list will do -// */ -// if(isConvertedInputNull() -// && !isModelEmpty()) { -// super.setConvertedInput(Collections.emptyList()); // always pass -// } -// } -// @Override -// public boolean checkRequired() { -// super.checkRequired(); // keep side-effects -// return true; // always pass otherwise workaround won't work -// } -// private boolean isModelEmpty() { return getModel().getObject()==null; } -// private boolean isConvertedInputNull() { return getConvertedInput()==null; } - @Override - public boolean isRequired() { - //FIXME[CAUSEWAY-3203] - return false; // nothing else worked yet - } - }; - fileUploadField.getConfig() - .maxFileCount(1) - .mainClass("input-group-sm") - .initialCaption(initialCaption) - .captionClass("form-control-sm") - .showUpload(false) - ; + val fileUploadField = new FileUploadFieldWithNestingFix( + id, + model, + new FileInputConfig() + .maxFileCount(1) + .mainClass("input-group-sm") + .initialCaption(initialCaption) + .captionClass("form-control-sm") + .showUpload(false)); return fileUploadField; }
