From: <pb...@fe...> - 2012-12-16 18:17:16
|
Author: pboy Date: 2012-12-16 18:17:07 +0000 (Sun, 16 Dec 2012) New Revision: 2381 Modified: trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectPage.java trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultPane.java trunk/ccm-cms/web/assets/xinha/plugins/OpenCCM/images/images.js Log: Enhanced ItemSelectPage: component communication established. (on behalf of quasimodo) Modified: trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java 2012-12-16 18:13:14 UTC (rev 2380) +++ trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageComponentSelectListener.java 2012-12-16 18:17:07 UTC (rev 2381) @@ -4,11 +4,11 @@ */ package com.arsdigita.cms.ui; +import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.MapComponentSelectionModel; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.cms.ReusableImageAsset; -import java.math.BigDecimal; import org.apache.log4j.Logger; /** @@ -25,9 +25,14 @@ m_resultPane = resultPane; } + @Override + protected void cancelled(PageState ps) { + super.cancelled(ps); + m_resultPane.reset(ps); + } + protected void processImage(FormSectionEvent event, PageState ps, ImageComponent component, ReusableImageAsset image) { - m_resultPane.setResult(image.getDisplayName(), image.getID(), image.getWidth(), image.getHeight()); - m_imageComponent.setSelectedKey(ps, ImageSelectPage.RESULT); + m_resultPane.reset(ps); } } Modified: trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java 2012-12-16 18:13:14 UTC (rev 2380) +++ trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageLibraryComponent.java 2012-12-16 18:17:07 UTC (rev 2381) @@ -42,10 +42,14 @@ private int m_mode; public ImageLibraryComponent() { - this(ImageComponent.ATTACH_IMAGE); + this(ImageComponent.ATTACH_IMAGE, null); } public ImageLibraryComponent(final int mode) { + this(mode, null); + } + + public ImageLibraryComponent(final int mode, final ImageSelectPage parent) { m_mode = mode; m_imageID = new BigDecimalParameter("imageID"); m_imageModel = new ItemSelectionModel(m_imageID); @@ -62,6 +66,9 @@ ImagesPane.S_LOG.debug("Clicked select"); try { final ReusableImageAsset image = new ReusableImageAsset(imageID); + if(m_mode == ImageComponent.SELECT_IMAGE) { + parent.getResultPane().setResult(image.getDisplayName(), image.getID(), image.getWidth(), image.getHeight()); + } m_imageModel.setSelectedObject(state, image); } catch (DataObjectNotFoundException ex) { ImagesPane.S_LOG.error("Selected non-existant image: " + imageID, ex); @@ -105,8 +112,14 @@ m_form.add(m_useContext); } +// if (m_mode == ImageComponent.SELECT_IMAGE) { +// m_form.setOnSubmit("selectImage();"); +// } + // save and cancel buttons m_saveCancel = new SaveCancelSection(); + m_saveCancel.getSaveButton().setOnClick("selectImage(this)"); + m_saveCancel.getCancelButton().setOnClick("selectImage(this)"); if (m_mode == ImageComponent.SELECT_IMAGE || m_mode == ImageComponent.ATTACH_IMAGE) { m_form.add(m_saveCancel); } Modified: trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectPage.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectPage.java 2012-12-16 18:13:14 UTC (rev 2380) +++ trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectPage.java 2012-12-16 18:17:07 UTC (rev 2381) @@ -38,7 +38,6 @@ private final MapComponentSelectionModel m_imageComponent; private final ImageComponentSelectListener m_selectListener; private static final CMSConfig s_conf = CMSConfig.getInstance(); - private static final boolean LIMIT_TO_CONTENT_SECTION = false; public static final String CONTENT_SECTION = "section_id"; public static final String RESULT = "result"; @@ -85,7 +84,7 @@ protected ImageLibraryComponent getImageLibraryPane() { if (m_imageLibrary == null) { - m_imageLibrary = new ImageLibraryComponent(ImageComponent.SELECT_IMAGE); + m_imageLibrary = new ImageLibraryComponent(ImageComponent.SELECT_IMAGE, this); m_imageLibrary.getForm().addInitListener(m_selectListener); m_imageLibrary.getForm().addProcessListener(m_selectListener); m_imageComponent.getComponentsMap().put(ImageComponent.LIBRARY, m_imageLibrary); Modified: trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultPane.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultPane.java 2012-12-16 18:13:14 UTC (rev 2380) +++ trunk/ccm-cms/src/com/arsdigita/cms/ui/ImageSelectResultPane.java 2012-12-16 18:17:07 UTC (rev 2381) @@ -16,10 +16,7 @@ */ public class ImageSelectResultPane extends SimpleContainer implements Resettable { - public static final int UNSET = 0; - public static final int CANCEL = 1; - public static final int SELECT = 2; - int m_state = UNSET; + boolean m_valid = false; String m_name; BigDecimal m_id; BigDecimal m_width; @@ -34,46 +31,44 @@ m_id = id; m_width = width; m_height = height; - m_state = SELECT; + m_valid = true; } @Override public void generateXML(PageState state, Element parent) { - if (m_state != UNSET) { + Element scriptElem = parent.newChildElement("script"); + scriptElem.addAttribute("type", "text/javascript"); - Element scriptElem = parent.newChildElement("script"); - scriptElem.addAttribute("type", "text/javascript"); - scriptElem.addAttribute("eventHandler", "onload"); + StringBuilder script = new StringBuilder(1000); - StringBuilder script = new StringBuilder(1000); + script.append("function selectImage(button) {"); + if (m_valid) { - script.append("alert(\"SCRIPT\");"); + script.append("if(button.id == \"save\" ) {"); + + script.append("window.opener.openCCM.imageSet({"); + script.append(" src : \"/ccm/cms-service/stream/image/?image_id="); + script.append(m_id); + script.append("\", "); + script.append(" name : \""); + script.append(m_name); + script.append("\", "); + script.append(" width : \""); + script.append(m_width); + script.append("\", "); + script.append(" height : \""); + script.append(m_height); + script.append("\""); + script.append("});"); + script.append("}"); - if (m_state == SELECT) { -// script.append("window.opener.document.OpenCCM.imageSet("); - script.append("window.openCCM.imageSet("); - script.append("{"); - script.append(" src : \"/theme/mandalay/ccm/cms-service/stream/image/?image_id="); - script.append(m_id); - script.append("\", "); - script.append(" name : \""); - script.append(m_name); - script.append("\", "); - script.append(" width : \""); - script.append(m_width); - script.append("\", "); - script.append(" height : \""); - script.append(m_height); - script.append("\""); - script.append(" });"); - } - script.append("self.close();"); - script.append("return false;"); - scriptElem.setText(script.toString()); } + script.append("return false;"); + script.append("}"); + scriptElem.setText(script.toString()); } public void reset(PageState state) { @@ -81,6 +76,6 @@ m_id = null; m_width = null; m_height = null; - m_state = UNSET; + m_valid = false; } } Modified: trunk/ccm-cms/web/assets/xinha/plugins/OpenCCM/images/images.js =================================================================== --- trunk/ccm-cms/web/assets/xinha/plugins/OpenCCM/images/images.js 2012-12-16 18:13:14 UTC (rev 2380) +++ trunk/ccm-cms/web/assets/xinha/plugins/OpenCCM/images/images.js 2012-12-16 18:17:07 UTC (rev 2381) @@ -293,8 +293,8 @@ // var searchDialog = new Xinha.Dialog(this.editor, destURL, '');//,{width:800, height:600}, {'closable':true}); // searchDialog.show(); var selectWindow = window.open(destURL, "_blank", "scrollbars=yes,directories=no,toolbar=no,width=800,height=600,status=no,menubar=no"); - selectWindow.openCCM = this; -// return false; + window.openCCM = this; + return false; }; OpenCCM.prototype.imageSet = function(imageData) |