Behoben: #1692 Image hochladen

JavaScript und ImageSelectResultComponent angepaßt, so daß das Hochladen eines Bildes nun wie erwartet das Bild automatisch auswählt und einfügt.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2337 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2013-10-04 16:45:10 +00:00
parent 1849ade7b9
commit 356f805ec6
4 changed files with 40 additions and 15 deletions

View File

@ -46,7 +46,7 @@ public class ImageComponentSelectListener extends ImageComponentAbstractListener
PageState ps, PageState ps,
ImageComponent component, ImageComponent component,
ReusableImageAsset image) { ReusableImageAsset image) {
m_resultPane.setResult(image, (String) m_imageComponent.getSelectedKey(ps));
m_imageComponent.setSelectedKey(ps, ImageSelectPage.RESULT); m_imageComponent.setSelectedKey(ps, ImageSelectPage.RESULT);
m_resultPane.reset(ps);
} }
} }

View File

@ -75,7 +75,7 @@ public class ImageLibraryComponent extends SimpleContainer
try { try {
final ReusableImageAsset image = new ReusableImageAsset(imageID); final ReusableImageAsset image = new ReusableImageAsset(imageID);
if(m_mode == ImageComponent.SELECT_IMAGE) { if(m_mode == ImageComponent.SELECT_IMAGE) {
parent.getResultComponent().setResult(image); parent.getResultComponent().setResult(image, ImageComponent.LIBRARY);
} }
m_imageModel.setSelectedObject(state, image); m_imageModel.setSelectedObject(state, image);
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {

View File

@ -13,16 +13,17 @@ import com.arsdigita.web.URL;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
/** /**
* A component which will insert a javascript to the xml output with the * A component which will insert a javascript to the xml output with the image
* image information for the OpenCCM plugin for Xinha editor. * information for the OpenCCM plugin for Xinha editor.
* *
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de> * @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/ */
public class ImageSelectResultComponent extends SimpleContainer public class ImageSelectResultComponent extends SimpleContainer
implements Resettable { implements Resettable {
boolean m_valid = false; boolean m_valid = false;
ImageAsset m_image; ImageAsset m_image;
String m_lastImageComponent;
public ImageSelectResultComponent() { public ImageSelectResultComponent() {
super(); super();
@ -31,13 +32,11 @@ public class ImageSelectResultComponent extends SimpleContainer
/** /**
* Save image imformation * Save image imformation
* *
* @param iamge an {@link ImageAsset} * @param image an {@link ImageAsset}
*/ */
public void setResult(final ImageAsset image/*, final String name, public void setResult(final ImageAsset image, final String lastComponent) {
* final BigDecimal id,
* final BigDecimal width,
* final BigDecimal height*/) {
m_image = image; m_image = image;
m_lastImageComponent = lastComponent;
m_valid = (m_image != null); m_valid = (m_image != null);
} }
@ -49,11 +48,18 @@ public class ImageSelectResultComponent extends SimpleContainer
StringBuilder script = new StringBuilder(1000); StringBuilder script = new StringBuilder(1000);
// Create funtion
script.append("function selectImage(button) {"); script.append("function selectImage(button) {");
// If there is a valid image
if (m_valid) { if (m_valid) {
script.append("if(button.id == \"save\" ) {"); // If in library mode, only listen to save button
if (m_lastImageComponent.equals(ImageComponent.LIBRARY)) {
script.append("if(button.id != \"save\" ) { return false; } ");
}
// Send image parameters to xinha plugin
script.append("window.opener.openCCM.imageSet({"); script.append("window.opener.openCCM.imageSet({");
script.append(" src : \""); script.append(" src : \"");
script.append(URL.getDispatcherPath()); script.append(URL.getDispatcherPath());
@ -69,14 +75,24 @@ public class ImageSelectResultComponent extends SimpleContainer
script.append(m_image.getHeight()); script.append(m_image.getHeight());
script.append("\""); script.append("\"");
script.append("});"); script.append("});");
script.append("}");
// Close window
script.append("self.close();"); script.append("self.close();");
} }
script.append("return false;"); script.append("return false;");
script.append("}"); script.append("}");
// If in upload mode and if there is a valid image, execute the
// javascript function
if (m_valid && ImageComponent.UPLOAD.equals(m_lastImageComponent)) {
script.append("selectImage();");
}
scriptElem.setText(script.toString()); scriptElem.setText(script.toString());
// Reset ImageSelectResultComponent
reset(state);
} }
/** /**
@ -85,6 +101,6 @@ public class ImageSelectResultComponent extends SimpleContainer
* @param state Page state * @param state Page state
*/ */
public void reset(PageState state) { public void reset(PageState state) {
setResult(null); setResult(null, null);
} }
} }

View File

@ -21,7 +21,6 @@ package com.arsdigita.bebop;
import java.util.Map; import java.util.Map;
import com.arsdigita.bebop.event.ChangeListener; import com.arsdigita.bebop.event.ChangeListener;
import com.arsdigita.util.Assert;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.Lockable; import com.arsdigita.util.Lockable;
@ -98,6 +97,7 @@ public class MapComponentSelectionModel
* @param state the state of the current request * @param state the state of the current request
* @return the component used to output the selected element. * @return the component used to output the selected element.
*/ */
@Override
public Component getComponent(PageState state) { public Component getComponent(PageState state) {
if(!isSelected(state)) { if(!isSelected(state)) {
return null; return null;
@ -126,6 +126,7 @@ public class MapComponentSelectionModel
* @return <code>true</code> if there is a selected component * @return <code>true</code> if there is a selected component
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
@Override
public boolean isSelected(PageState state) { public boolean isSelected(PageState state) {
return m_selModel.isSelected(state); return m_selModel.isSelected(state);
} }
@ -136,6 +137,7 @@ public class MapComponentSelectionModel
* @param state a <code>PageState</code> value * @param state a <code>PageState</code> value
* @return a <code>String</code> value. * @return a <code>String</code> value.
*/ */
@Override
public Object getSelectedKey(PageState state) { public Object getSelectedKey(PageState state) {
return m_selModel.getSelectedKey(state); return m_selModel.getSelectedKey(state);
} }
@ -149,6 +151,7 @@ public class MapComponentSelectionModel
* @throws IllegalArgumentException if the supplied <code>key</code> cannot * @throws IllegalArgumentException if the supplied <code>key</code> cannot
* be selected in the context of the current request. * be selected in the context of the current request.
*/ */
@Override
public void setSelectedKey(PageState state, Object key) { public void setSelectedKey(PageState state, Object key) {
m_selModel.setSelectedKey(state, key); m_selModel.setSelectedKey(state, key);
} }
@ -159,6 +162,7 @@ public class MapComponentSelectionModel
* @param state the state of the current request * @param state the state of the current request
* @post ! isSelected(state) * @post ! isSelected(state)
*/ */
@Override
public void clearSelection(PageState state) { public void clearSelection(PageState state) {
m_selModel.clearSelection(state); m_selModel.clearSelection(state);
} }
@ -169,6 +173,7 @@ public class MapComponentSelectionModel
* *
* @param l a listener to notify when the selected key changes * @param l a listener to notify when the selected key changes
*/ */
@Override
public void addChangeListener(ChangeListener l) { public void addChangeListener(ChangeListener l) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
m_selModel.addChangeListener(l); m_selModel.addChangeListener(l);
@ -179,6 +184,7 @@ public class MapComponentSelectionModel
* *
* @param l the listener to remove * @param l the listener to remove
*/ */
@Override
public void removeChangeListener(ChangeListener l) { public void removeChangeListener(ChangeListener l) {
Assert.isUnlocked(this); Assert.isUnlocked(this);
m_selModel.removeChangeListener(l); m_selModel.removeChangeListener(l);
@ -195,15 +201,18 @@ public class MapComponentSelectionModel
* @return the state parameter to use to keep * @return the state parameter to use to keep
* track of the currently selected component. * track of the currently selected component.
*/ */
@Override
public ParameterModel getStateParameter() { public ParameterModel getStateParameter() {
return m_selModel.getStateParameter(); return m_selModel.getStateParameter();
} }
// implement Lockable // implement Lockable
@Override
public final void lock() { public final void lock() {
m_locked = true; m_locked = true;
} }
@Override
public final boolean isLocked() { public final boolean isLocked() {
return m_locked; return m_locked;
} }