diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java b/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java index b724fc177..06b147633 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java @@ -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); } } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java b/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java index 55604af66..53d91e2a2 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java @@ -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) { diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultComponent.java b/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultComponent.java index f88924665..3807e5ecb 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultComponent.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultComponent.java @@ -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) */ -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); } } diff --git a/ccm-core/src/com/arsdigita/bebop/MapComponentSelectionModel.java b/ccm-core/src/com/arsdigita/bebop/MapComponentSelectionModel.java index 3cd7136f5..cabbc6b6f 100755 --- a/ccm-core/src/com/arsdigita/bebop/MapComponentSelectionModel.java +++ b/ccm-core/src/com/arsdigita/bebop/MapComponentSelectionModel.java @@ -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 true if there is a selected component * false otherwise. */ + @Override public boolean isSelected(PageState state) { return m_selModel.isSelected(state); } @@ -136,6 +137,7 @@ public class MapComponentSelectionModel * @param state a PageState value * @return a String value. */ + @Override public Object getSelectedKey(PageState state) { return m_selModel.getSelectedKey(state); } @@ -149,6 +151,7 @@ public class MapComponentSelectionModel * @throws IllegalArgumentException if the supplied key 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; }