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,
ImageComponent component,
ReusableImageAsset image) {
m_resultPane.setResult(image, (String) m_imageComponent.getSelectedKey(ps));
m_imageComponent.setSelectedKey(ps, ImageSelectPage.RESULT);
m_resultPane.reset(ps);
}
}

View File

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

View File

@ -13,16 +13,17 @@ import com.arsdigita.web.URL;
import com.arsdigita.xml.Element;
/**
* A component which will insert a javascript to the xml output with the
* image information for the OpenCCM plugin for Xinha editor.
* A component which will insert a javascript to the xml output with the image
* information for the OpenCCM plugin for Xinha editor.
*
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/
public class ImageSelectResultComponent extends SimpleContainer
implements Resettable {
public class ImageSelectResultComponent extends SimpleContainer
implements Resettable {
boolean m_valid = false;
ImageAsset m_image;
String m_lastImageComponent;
public ImageSelectResultComponent() {
super();
@ -31,13 +32,11 @@ public class ImageSelectResultComponent extends SimpleContainer
/**
* Save image imformation
*
* @param iamge an {@link ImageAsset}
* @param image an {@link ImageAsset}
*/
public void setResult(final ImageAsset image/*, final String name,
* final BigDecimal id,
* final BigDecimal width,
* final BigDecimal height*/) {
public void setResult(final ImageAsset image, final String lastComponent) {
m_image = image;
m_lastImageComponent = lastComponent;
m_valid = (m_image != null);
}
@ -49,11 +48,18 @@ public class ImageSelectResultComponent extends SimpleContainer
StringBuilder script = new StringBuilder(1000);
// Create funtion
script.append("function selectImage(button) {");
// If there is a valid image
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(" src : \"");
script.append(URL.getDispatcherPath());
@ -69,14 +75,24 @@ public class ImageSelectResultComponent extends SimpleContainer
script.append(m_image.getHeight());
script.append("\"");
script.append("});");
script.append("}");
// Close window
script.append("self.close();");
}
script.append("return false;");
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());
// Reset ImageSelectResultComponent
reset(state);
}
/**
@ -85,6 +101,6 @@ public class ImageSelectResultComponent extends SimpleContainer
* @param state Page 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 com.arsdigita.bebop.event.ChangeListener;
import com.arsdigita.util.Assert;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.util.Assert;
import com.arsdigita.util.Lockable;
@ -98,6 +97,7 @@ public class MapComponentSelectionModel
* @param state the state of the current request
* @return the component used to output the selected element.
*/
@Override
public Component getComponent(PageState state) {
if(!isSelected(state)) {
return null;
@ -126,6 +126,7 @@ public class MapComponentSelectionModel
* @return <code>true</code> if there is a selected component
* <code>false</code> otherwise.
*/
@Override
public boolean isSelected(PageState state) {
return m_selModel.isSelected(state);
}
@ -136,6 +137,7 @@ public class MapComponentSelectionModel
* @param state a <code>PageState</code> value
* @return a <code>String</code> value.
*/
@Override
public Object getSelectedKey(PageState state) {
return m_selModel.getSelectedKey(state);
}
@ -149,6 +151,7 @@ public class MapComponentSelectionModel
* @throws IllegalArgumentException if the supplied <code>key</code> cannot
* be selected in the context of the current request.
*/
@Override
public void setSelectedKey(PageState state, Object key) {
m_selModel.setSelectedKey(state, key);
}
@ -159,6 +162,7 @@ public class MapComponentSelectionModel
* @param state the state of the current request
* @post ! isSelected(state)
*/
@Override
public void clearSelection(PageState state) {
m_selModel.clearSelection(state);
}
@ -169,6 +173,7 @@ public class MapComponentSelectionModel
*
* @param l a listener to notify when the selected key changes
*/
@Override
public void addChangeListener(ChangeListener l) {
Assert.isUnlocked(this);
m_selModel.addChangeListener(l);
@ -179,6 +184,7 @@ public class MapComponentSelectionModel
*
* @param l the listener to remove
*/
@Override
public void removeChangeListener(ChangeListener l) {
Assert.isUnlocked(this);
m_selModel.removeChangeListener(l);
@ -195,15 +201,18 @@ public class MapComponentSelectionModel
* @return the state parameter to use to keep
* track of the currently selected component.
*/
@Override
public ParameterModel getStateParameter() {
return m_selModel.getStateParameter();
}
// implement Lockable
@Override
public final void lock() {
m_locked = true;
}
@Override
public final boolean isLocked() {
return m_locked;
}