Commit b6e365db authored by Mathijs den Burger's avatar Mathijs den Burger

HSTCONFIGEDIT-174: remove page thumbnail upload functionality

It did not work and was not used by anyone anyway
parent 2001c528
......@@ -108,7 +108,7 @@ public class ContainerItemComponentEditorPlugin extends BasicEditorPlugin<Contai
xTypesDropDown.setEnabled(!getLockInfo().isLocked());
form.add(xTypesDropDown);
form.add(new DescriptionPanel("componentDescription", form.getInnermostModel(), context, config)
form.add(new DescriptionPanel("componentDescription", form.getInnermostModel())
.setEnabled(!getLockInfo().isLocked()));
IModel<Parameters> params = new AbstractReadOnlyModel<Parameters>() {
......
......@@ -89,7 +89,7 @@ public class ComponentEditorPlugin extends BasicEditorPlugin<Component> {
}
});
form.add(new DescriptionPanel("componentDescription", form.getInnermostModel(), context, config).setEnabled(!getLockInfo().isLocked()));
form.add(new DescriptionPanel("componentDescription", form.getInnermostModel()).setEnabled(!getLockInfo().isLocked()));
form.add(new AjaxCheckBox("reference") {
......
<!--
* Copyright 2008-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,21 +22,6 @@
<label for="description"><wicket:message key="component.description">Description</wicket:message></label>
<div wicket:id="description">[ Description ]</div>
</div>
<div wicket:id="icon">[ Icon widget ]</div>
</fieldset>
<wicket:fragment wicket:id="noIconSelected">
<div>
<label for="icon"><wicket:message key="component.icon">Thumbnail</wicket:message></label>
<a wicket:id="iconSelector"><wicket:message key="icon.select">Select thumbnail</wicket:message></a>
</div>
</wicket:fragment>
<wicket:fragment wicket:id="iconSelected">
<label><wicket:message key="icon.selected">Selected icon</wicket:message></label>
<img wicket:id="image"/>
</wicket:fragment>
</wicket:panel>
</html>
......@@ -16,161 +16,19 @@
package org.hippoecm.hst.plugins.frontend.editor.description;
import java.io.IOException;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.image.NonCachingImage;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.string.StringValueConversionException;
import org.apache.wicket.util.value.IValueMap;
import org.hippoecm.frontend.dialog.AbstractDialog;
import org.hippoecm.frontend.dialog.DialogConstants;
import org.hippoecm.frontend.dialog.IDialogService;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.plugins.gallery.model.DefaultGalleryProcessor;
import org.hippoecm.frontend.plugins.gallery.model.GalleryException;
import org.hippoecm.frontend.widgets.TextAreaWidget;
import org.hippoecm.hst.plugins.frontend.editor.domain.Descriptive;
import org.hippoecm.hst.plugins.frontend.util.IOUtil;
public class DescriptionPanel extends Panel {
IPluginContext context;
IPluginConfig config;
public DescriptionPanel(String id, IModel model, IPluginContext context, IPluginConfig config) {
public DescriptionPanel(String id, IModel model) {
super(id, model);
this.context = context;
this.config = config;
TextAreaWidget descWidget = new TextAreaWidget("description", new PropertyModel<>(model, "description"));
descWidget.setRenderBodyOnly(true);
add(descWidget);
}
@Override
protected void onBeforeRender() {
super.onBeforeRender();
renderIconFragment();
}
private void renderIconFragment() {
Descriptive desc = (Descriptive) getDefaultModelObject();
if (desc.getIconResource() == null) {
addOrReplace(new NoIconSelected("icon", "noIconSelected", this));
} else {
addOrReplace(new IconSelected("icon", "iconSelected", this));
}
}
class NoIconSelected extends Fragment {
public NoIconSelected(String id, String markupId, MarkupContainer markupProvider) {
super(id, markupId, markupProvider);
setOutputMarkupId(true);
add(new AjaxLink("iconSelector") {
@Override
public void onClick(AjaxRequestTarget target) {
IDialogService dialogService = context.getService(IDialogService.class.getName(),
IDialogService.class);
UploadDialog dialog = new UploadDialog();
dialogService.show(dialog);
}
});
}
class UploadDialog extends AbstractDialog {
public UploadDialog() {
setNonAjaxSubmit();
add(new UploadForm());
}
@Override
public IValueMap getProperties() {
return DialogConstants.SMALL;
}
@Override
public IModel<String> getTitle() {
return Model.of(getString("dialog.upload.thumbnail"));
}
}
class UploadForm extends Form {
private final FileUploadField uploadField;
public UploadForm() {
super("form");
setMultiPart(true);
setMaxSize(Bytes.megabytes(5));
add(uploadField = new FileUploadField("input"));
}
@Override
protected void onSubmit() {
final FileUpload upload = uploadField.getFileUpload();
if (upload != null) {
try {
Descriptive desc = (Descriptive) DescriptionPanel.this.getDefaultModelObject();
desc.setIconResource(IOUtil.obtainResource(new DefaultGalleryProcessor().createThumbnail(upload.getInputStream(),
100, upload.getContentType())));
} catch (IOException | GalleryException e) {
error(e);
}
renderIconFragment();
} else {
error("Something went wrong during upload.");
}
}
}
}
class IconSelected extends Fragment {
public IconSelected(String id, String markupId, MarkupContainer markupProvider) {
super(id, markupId, markupProvider);
setOutputMarkupId(true);
Descriptive desc = (Descriptive) DescriptionPanel.this.getDefaultModelObject();
NonCachingImage img = new NonCachingImage("image", new ResourceStreamResource(desc.getIconResource())) {
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
int width;
try {
width = config.getInt("icon.size");
} catch (StringValueConversionException e) {
width = 0;
}
if (width > 0) {
tag.put("width", width);
}
}
};
add(img);
}
}
}
component.legend.description: Annotation
component.description: Description
component.icon: Thumbnail
icon.select: Select thumbnail
icon.selected: Selected thumbnail
component.description: Description
\ No newline at end of file
component.legend.description: Anmerkung
component.description: Beschreibung
component.icon: Thumbnail
icon.select: W\u00E4hle Thumbnail aus
icon.selected: Ausgew\u00E4hltes Thumbnail
component.legend.description: Annotation
component.description: Description
component.icon: Miniature
icon.select: S\u00E9lectionnez une miniature
icon.selected: Miniature s\u00E9lectionn\u00E9e
component.legend.description: Beschrijving
component.description: Beschrijving
component.icon: Thumbnail
icon.select: Voeg een thumbnail toe
icon.selected:
/*
* Copyright 2008-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -155,7 +155,7 @@ public abstract class NewPageWizard extends AjaxWizard {
public PageDescriptionStep(IDynamicWizardStep previousStep) {
super(previousStep);
add(new DescriptionPanel("desc", new Model(newPage), context, config));
add(new DescriptionPanel("desc", new Model(newPage)));
}
public boolean isLastStep() {
......
......@@ -45,7 +45,7 @@ public class TemplateEditorPlugin extends BasicEditorPlugin<Template> {
public TemplateEditorPlugin(IPluginContext context, IPluginConfig config) {
super(context, config);
final DescriptionPanel description = new DescriptionPanel("description", form.getInnermostModel(), context, config);
final DescriptionPanel description = new DescriptionPanel("description", form.getInnermostModel());
description.setEnabled(!getLockInfo().isLocked());
description.setRenderBodyOnly(true);
form.add(description);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment