From: <mb...@re...> - 2005-02-11 16:59:04
|
Author: mbooth Date: 2005-02-11 17:58:13 +0100 (Fri, 11 Feb 2005) New Revision: 208 Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormbuilderResources.properties ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java Log: Add friendly component name substitution in Templated Email editor. Loosely based on code from InfoAxon. Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormbuilderResources.properties =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormbuilderResources.properties 2005-02-11 12:07:06 UTC (rev 207) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/FormbuilderResources.properties 2005-02-11 16:58:13 UTC (rev 208) @@ -2,6 +2,7 @@ formbuilder.ui.editors.from=From: formbuilder.ui.editors.subject=Subject: formbuilder.ui.editors.body=Body: +formbuilder.ui.editors.control_names=Controls: formbuilder.ui.editors.url=URL: formbuilder.ui.editors.query=Query: formbuilder.ui.editors.multiselect=Multi-select Modified: ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java 2005-02-11 12:07:06 UTC (rev 207) +++ ccm-core/trunk/src/com/arsdigita/formbuilder/ui/editors/TemplateEmailForm.java 2005-02-11 16:58:13 UTC (rev 208) @@ -35,6 +35,8 @@ import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.form.TextArea; import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.EmailParameter; @@ -46,9 +48,11 @@ import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.OID; import com.arsdigita.util.Assert; +import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; import java.util.Iterator; +import java.util.TooManyListenersException; import org.apache.log4j.Logger; @@ -56,7 +60,7 @@ private TextField m_to; private TextField m_subject; private TextArea m_body; - private Label m_bodyLabel; + private SingleSelect m_controls; private SingleSelectionModel m_form; @@ -89,50 +93,51 @@ section.add(m_subject); m_body = new TextArea(new StringParameter("body")); + m_body.setIdAttr("templatedEmailBody"); m_body.setCols(50); m_body.setRows(20); m_body.addValidationListener(new NotNullValidationListener()); m_body.addValidationListener(new StringInRangeValidationListener(1, 4000)); - m_bodyLabel = new Label(new PrintListener() { - public void prepare( PrintEvent ev ) { - PageState state = ev.getPageState(); - Label target = (Label) ev.getTarget(); + m_controls = new SingleSelect("controls"); + m_controls.addOption(new Option("", "Select a control")); + m_controls.setOnChange("if(this.value.length>0) document.getElementById('templatedEmailBody').value+='::form.'+this.value+'::';"); + try { + m_controls.addPrintListener(new PrintListener() { + public void prepare(PrintEvent ev) { + PageState ps = ev.getPageState(); - BigDecimal formID = (BigDecimal) m_form.getSelectedKey( state ); - Assert.exists( formID, BigDecimal.class ); + BigDecimal formID = (BigDecimal) + m_form.getSelectedKey( ps ); + Assert.exists( formID, BigDecimal.class ); - OID formOID = new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE, - formID ); + OID formOID = + new OID( PersistentFormSection.BASE_DATA_OBJECT_TYPE, + formID ); - PersistentFormSection form = (PersistentFormSection) - DomainObjectFactory.newInstance( formOID ); + PersistentFormSection form = (PersistentFormSection) + DomainObjectFactory.newInstance( formOID ); - StringBuffer buf = new StringBuffer(); - buf.append( GlobalizationUtil.globalize("formbuilder.ui.editors.body").localize( state.getRequest() ) ); - buf.append( "<ul>" ); + DataAssociationCursor components = form.getComponents(); + while( components.next() ) { + PersistentComponent c = (PersistentComponent) + DomainObjectFactory.newInstance( components.getDataObject() ); - DataAssociationCursor components = form.getComponents(); - while( components.next() ) { - PersistentComponent c = (PersistentComponent) - DomainObjectFactory.newInstance( components.getDataObject() ); + if( c instanceof PersistentWidget ) { + PersistentWidget w = (PersistentWidget) c; - if( c instanceof PersistentWidget ) { - PersistentWidget w = (PersistentWidget) c; - - buf.append( "<li>::form." ); - buf.append( w.getParameterName() ); - buf.append( "::</li>" ); + m_controls.addOption(new Option(w.getParameterName(), w.getParameterName()), ps); + } } } - buf.append( "</ul>" ); + }); + } catch (TooManyListenersException ex) { + throw new UncheckedWrapperException(ex); + } - target.setLabel( buf.toString() ); - } - }); - m_bodyLabel.setOutputEscaping( false ); - - section.add(m_bodyLabel, ColumnPanel.RIGHT); + section.add(new Label(GlobalizationUtil.globalize("formbuilder.ui.editors.control_names")), ColumnPanel.RIGHT); + section.add(m_controls); + section.add(new Label(GlobalizationUtil.globalize("formbuilder.ui.editors.body")), ColumnPanel.RIGHT); section.add(m_body); } |