diff --git a/ccm-cms-types-survey/pdl/com/arsdigita/content-types/Survey.pdl b/ccm-cms-types-survey/pdl/com/arsdigita/content-types/Survey.pdl
index f000ac3ee..4cd3996c1 100755
--- a/ccm-cms-types-survey/pdl/com/arsdigita/content-types/Survey.pdl
+++ b/ccm-cms-types-survey/pdl/com/arsdigita/content-types/Survey.pdl
@@ -9,6 +9,7 @@ object type Survey extends ContentPage {
Date[0..1] endDate = ct_surveys.end_date DATE;
Boolean[0..1] responsesPublic = ct_surveys.responses_public;
Boolean[0..1] responsesAnonym = ct_surveys.responses_anonym;
+ Boolean[0..1] showResultsDuringSurvey = ct_surveys.results_during_survey;
component FormSection[1..1] form = join ct_surveys.form_id
to bebop_form_sections.form_section_id;
component SurveyResponse[0..n] responses = join ct_surveys.survey_id
diff --git a/ccm-cms-types-survey/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Survey.xml b/ccm-cms-types-survey/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Survey.xml
index b9f9610b9..1ee1901d4 100644
--- a/ccm-cms-types-survey/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Survey.xml
+++ b/ccm-cms-types-survey/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Survey.xml
@@ -28,6 +28,12 @@
descriptionBundle="com.arsdigita.cms.formbuilder.FormItemResources"
component="com.arsdigita.cms.contenttypes.ui.SurveyControls"/>
+
diff --git a/ccm-cms-types-survey/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Survey.xml b/ccm-cms-types-survey/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Survey.xml
index 165b0623c..60b02525e 100644
--- a/ccm-cms-types-survey/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Survey.xml
+++ b/ccm-cms-types-survey/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Survey.xml
@@ -5,7 +5,7 @@
xsi:schemaLocation="http://rhea.redhat.com/schemas/waf/xml-renderer-rules xml-renderer-rules.xsd">
-
+
diff --git a/ccm-cms-types-survey/src/ccm-cms-types-survey.config b/ccm-cms-types-survey/src/ccm-cms-types-survey.config
index 369521b94..871def5a1 100755
--- a/ccm-cms-types-survey/src/ccm-cms-types-survey.config
+++ b/ccm-cms-types-survey/src/ccm-cms-types-survey.config
@@ -1,7 +1,4 @@
-
-
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/Survey.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/Survey.java
index f414eb654..17533da1d 100755
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/Survey.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/Survey.java
@@ -1,23 +1,11 @@
package com.arsdigita.cms.contenttypes;
-import com.arsdigita.bebop.Component;
-import com.arsdigita.bebop.Form;
-import com.arsdigita.bebop.Label;
-import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.bebop.form.Widget;
-import com.arsdigita.bebop.parameters.BigDecimalParameter;
-import com.arsdigita.bebop.util.Traversal;
-import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.CustomCopy;
import com.arsdigita.cms.ItemCopier;
-import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener;
-import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener;
-import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.cms.dispatcher.XMLGenerator;
-import com.arsdigita.cms.formbuilder.FormUnavailableException;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
@@ -28,20 +16,11 @@ import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentHidden;
import com.arsdigita.formbuilder.PersistentSubmit;
-import com.arsdigita.formbuilder.ui.BaseAddObserver;
-import com.arsdigita.formbuilder.ui.PlaceholdersInitListener;
import com.arsdigita.kernel.User;
import com.arsdigita.persistence.metadata.Property;
-import com.arsdigita.util.UncheckedWrapperException;
-import com.arsdigita.web.URL;
-import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import java.util.Date;
-import com.arsdigita.formbuilder.actions.ConfirmEmailListener;
-import com.arsdigita.formbuilder.ui.FormBuilderXMLRenderer;
-import com.arsdigita.formbuilder.util.FormBuilderUtil;
-
/**
* A survey content type that represents a survey. This is partially based on
* the simplesurvey application and CT FormItem.
@@ -65,9 +44,10 @@ public class Survey extends ContentPage implements XMLGenerator {
public static final String RESPONSES_PUBLIC = "responsesPublic";
/** PDL property name for responsesAnonym */
public static final String RESPONSES_ANONYM = "responsesAnonym";
+ /** PDL property name for responsesDuringSurvey */
+ public static final String RESULTS_DURING_SURVEY = "showResultsDuringSurvey";
/** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Survey";
-
/* Config */
private static final SurveyConfig s_config = new SurveyConfig();
@@ -156,6 +136,10 @@ public class Survey extends ContentPage implements XMLGenerator {
if (getResponsesAnonym() == null) {
setResponsesAnonym(getConfig().getAnonymSurvey());
}
+ // Preset the resultsDuringSurvey
+ if (getResultsDuringSurvey() == null) {
+ setResultsDuringSurvey(getConfig().getShowResultsDuringSurvey());
+ }
}
super.beforeSave();
@@ -163,11 +147,9 @@ public class Survey extends ContentPage implements XMLGenerator {
// This will be called during publish
@Override
- public boolean copyProperty(CustomCopy src,
- Property property,
- ItemCopier copier) {
+ public boolean copyProperty(CustomCopy src, Property property, ItemCopier copier) {
+
if (property.getName().equals(FORM)) {
-// PersistentForm pForm = ((Survey) src).getForm();
PersistentForm pForm = (new FormCopier()).copyForm(((Survey) src).getForm());
// Add hidden field with survey id
@@ -226,6 +208,14 @@ public class Survey extends ContentPage implements XMLGenerator {
set(RESPONSES_ANONYM, responsesAnonym);
}
+ public Boolean getResultsDuringSurvey() {
+ return (Boolean) get(RESULTS_DURING_SURVEY);
+ }
+
+ public void setResultsDuringSurvey(Boolean resultsDuringSurvey) {
+ set(RESULTS_DURING_SURVEY, resultsDuringSurvey);
+ }
+
public SurveyResponse addResponse(User user) {
SurveyResponse surveyResponse = new SurveyResponse(getSurveyID(), user);
addResponse(surveyResponse);
@@ -253,123 +243,36 @@ public class Survey extends ContentPage implements XMLGenerator {
return !this.getResponses(user).isEmpty();
}
- public boolean isActive() {
+ public boolean hasStarted() {
Date currentDate = new Date();
- return currentDate.compareTo(getStartDate()) > 0 && currentDate.compareTo(getEndDate()) < 0;
+ Date startDate = this.getStartDate();
+ boolean status = true;
+
+ if (startDate != null) {
+ status = currentDate.after(startDate);
+ }
+
+ return status;
+ }
+
+ public boolean hasEnded() {
+ Date currentDate = new Date();
+ Date endDate = this.getEndDate();
+ boolean status = false;
+
+ if (endDate != null) {
+ status = currentDate.after(endDate);
+ }
+
+ return status;
+ }
+
+ public boolean isActive() {
+ return hasStarted() && !hasEnded();
}
public void generateXML(PageState state, Element parent, String useContext) {
-
- PersistentForm pForm = getForm();
- Component c = instantiateForm(pForm, "itemAdminSummary".equals(useContext));
-
- // Fake the page context for the item, since we
- // have no access to the real page context.
- Page p = new Page("dummy");
- p.add(c);
- p.lock();
-
- PageState fake;
- try {
-// if ("itemAdminSummary".equals(useContext)) {
- // Chop off all the parameters to stop bebop stategetting confused
-// fake = p.process(new NoParametersHttpServletRequest(
-// state.getRequest()), state.getResponse());
-// } else {
- // Really serving the user page, so need the params when
- // processing the pForm
- fake = p.process(state.getRequest(), state.getResponse());
-// }
- } catch (Exception e) {
- throw new UncheckedWrapperException(e);
- }
-
-// Traversal t = new VisibleTraverse(fake);
-// t.preorder(c);
-
-
- // Simply embed the bebop xml as a child of the cms:item tag
- Element element = parent.newChildElement("cms:item", CMS.CMS_XML_NS);
-// generateXMLBody(fake, element, pForm);
- String action = pForm.getAction();
- if (action == null) {
- final URL requestURL = Web.getContext().getRequestURL();
-
- if (requestURL == null) {
- action = state.getRequest().getRequestURI();
- } else {
- action = requestURL.getRequestURI();
- }
- }
-
- element.addAttribute(FormBuilderUtil.FORM_ACTION, action);
-
- FormBuilderXMLRenderer renderer =
- new FormBuilderXMLRenderer(element);
- renderer.setWrapAttributes(true);
- renderer.setWrapRoot(false);
- renderer.setRevisitFullObject(true);
- renderer.setWrapObjects(false);
-
- renderer.walk(this, SimpleXMLGenerator.ADAPTER_CONTEXT);
-
- // then, if the component is actually a pForm, we need
- // to print out any possible errors
- // Ideally we could do this as part of the "walk" but for now
- // that does not work because we don't pass in the page state
- // although that can always we updated.
-// if (c instanceof Form) {
-// Element infoElement =
-// element.newChildElement(FormBuilderUtil.FORMBUILDER_FORM_INFO,
-// FormBuilderUtil.FORMBUILDER_XML_NS);
-// Form f = (Form) c;
-
-// Traversal infoTraversal =
-// new ComponentTraverse(state, ((Form) c).getFormData(state),
-// infoElement);
-// infoTraversal.preorder(f);
-// }
-
- // we need to generate the state so that it can be part of the pForm
- // and correctly included when the pForm is submitted. We could
- // do this by iterating through the pForm data but it does not
- // seem like a good idea to just cut and paste the code out
- // of the PageState class
- fake.setControlEvent(c);
- fake.generateXML(element.newChildElement(FormBuilderUtil.FORMBUILDER_PAGE_STATE,
- FormBuilderUtil.FORMBUILDER_XML_NS));
- }
-
- protected Component instantiateForm(PersistentForm persistentForm, boolean readOnly) {
-
- try {
-
- persistentForm.setComponentAddObserver(new BaseAddObserver());
- Form form = (Form) persistentForm.createComponent();
- form.addInitListener(new PlaceholdersInitListener());
- form.addProcessListener(new SurveyProcessListener());
- form.setMethod(Form.GET);
-
- if (readOnly) {
- Traversal t = new Traversal() {
-
- public void act(Component c) {
- try {
- Widget widget = (Widget) c;
- widget.setDisabled();
- widget.setReadOnly();
- } catch (ClassCastException ex) {
- // Nada
- }
- }
- };
- t.preorder(form);
- }
-
- return form;
- } catch (FormUnavailableException ex) {
- return new Label("This form is temporarily unavailable");
- }
+ new SurveyXMLGenerator().generateXML(state, parent, useContext);
}
/*
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig.java
index 286296ecd..e503dba60 100644
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig.java
@@ -25,6 +25,7 @@ import com.arsdigita.util.parameter.BooleanParameter;
public class SurveyConfig extends AbstractConfig {
private final Parameter m_showResultsPublic;
+ private final Parameter m_showResultsDuringSurvey;
private final Parameter m_anonymSurvey;
public SurveyConfig() {
@@ -32,7 +33,12 @@ public class SurveyConfig extends AbstractConfig {
"com.arsdigita.cms.contenttypes.survey.show_results_public",
Parameter.REQUIRED,
new Boolean(true));
-
+
+ m_showResultsDuringSurvey = new BooleanParameter(
+ "com.arsdigita.cms.contenttypes.survey.show_results_during_survey",
+ Parameter.REQUIRED,
+ new Boolean(true));
+
m_anonymSurvey = new BooleanParameter(
"com.arsdigita.cms.contenttypes.survey.anonym_survey",
Parameter.REQUIRED,
@@ -40,6 +46,7 @@ public class SurveyConfig extends AbstractConfig {
register(m_showResultsPublic);
+ register(m_showResultsDuringSurvey);
register(m_anonymSurvey);
loadInfo();
@@ -48,6 +55,11 @@ public class SurveyConfig extends AbstractConfig {
public final boolean getShowResultsPublic() {
return ((Boolean) get(m_showResultsPublic)).booleanValue();
}
+
+ public final boolean getShowResultsDuringSurvey() {
+ return ((Boolean) get(m_showResultsDuringSurvey)).booleanValue();
+ }
+
public final boolean getAnonymSurvey() {
return ((Boolean) get(m_anonymSurvey)).booleanValue();
}
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig_parameter.properties b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig_parameter.properties
index e20137e79..fc24682e2 100644
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig_parameter.properties
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyConfig_parameter.properties
@@ -3,6 +3,11 @@ com.arsdigita.cms.contenttypes.survey.show_results_public.purpose=Default settin
com.arsdigita.cms.contenttypes.survey.show_results_public.example=false
com.arsdigita.cms.contenttypes.survey.show_results_public.format=[boolean]
+com.arsdigita.cms.contenttypes.survey.show_results_during_survey.title=Show results during survey
+com.arsdigita.cms.contenttypes.survey.show_results_during_survey.purpose=Default setting for public results during survey
+com.arsdigita.cms.contenttypes.survey.show_results_during_survey.example=false
+com.arsdigita.cms.contenttypes.survey.show_results_during_survey.format=[boolean]
+
com.arsdigita.cms.contenttypes.survey.anonym_survey.title=Anonymous survey
com.arsdigita.cms.contenttypes.survey.anonym_survey.purpose=Default setting for anonymous survey
com.arsdigita.cms.contenttypes.survey.anonym_survey.example=false
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyInitializer.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyInitializer.java
index c834e88d0..f0d167354 100755
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyInitializer.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyInitializer.java
@@ -1,5 +1,8 @@
package com.arsdigita.cms.contenttypes;
+import com.arsdigita.runtime.DomainInitEvent;
+import java.util.Arrays;
+import java.util.List;
import org.apache.log4j.Logger;
/**
@@ -19,13 +22,75 @@ public class SurveyInitializer extends ContentTypeInitializer {
Survey.BASE_DATA_OBJECT_TYPE);
}
+ @Override
public String[] getStylesheets() {
return new String[]{
"/static/content-types/com/arsdigita/cms/contenttypes/Survey.xsl"
};
}
+ @Override
public String getTraversalXML() {
return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Survey.xml";
}
+
+ @Override
+ public void init(DomainInitEvent evt) {
+
+ List widgets = Arrays.asList(
+ Arrays.asList("ct_survey", "Checkbox group", "Checkbox groups",
+ "com.arsdigita.formbuilder.PersistentCheckboxGroup",
+ "com.arsdigita.formbuilder.ui.editors.CheckboxGroupEditor"),
+ Arrays.asList("ct_survey", "Date field", "Date fields",
+ "com.arsdigita.formbuilder.PersistentDate",
+ "com.arsdigita.formbuilder.ui.editors.DateForm"),
+ Arrays.asList("ct_survey", "Hidden field", "Hidden fields",
+ "com.arsdigita.formbuilder.PersistentHidden",
+ "com.arsdigita.formbuilder.ui.editors.HiddenForm"),
+ Arrays.asList("ct_survey", "Multiple select box", "Multiple select boxes",
+ "com.arsdigita.formbuilder.PersistentMultipleSelect",
+ "com.arsdigita.formbuilder.ui.editors.MultipleSelectEditor"),
+ Arrays.asList("ct_survey", "Radio group", "Radio groups",
+ "com.arsdigita.formbuilder.PersistentRadioGroup",
+ "com.arsdigita.formbuilder.ui.editors.RadioGroupEditor"),
+ Arrays.asList("ct_survey", "Single select box", "Single select boxes",
+ "com.arsdigita.formbuilder.PersistentSingleSelect",
+ "com.arsdigita.formbuilder.ui.editors.SingleSelectEditor"),
+ Arrays.asList("ct_survey", "Text area", "Text areas",
+ "com.arsdigita.formbuilder.PersistentTextArea",
+ "com.arsdigita.formbuilder.ui.editors.TextAreaForm"),
+ Arrays.asList("ct_survey", "Text field", "Text fields",
+ "com.arsdigita.formbuilder.PersistentTextField",
+ "com.arsdigita.formbuilder.ui.editors.TextFieldForm"),
+ Arrays.asList("ct_survey", "Text Description", "Text Descriptions",
+ "com.arsdigita.formbuilder.PersistentText",
+ "com.arsdigita.formbuilder.ui.editors.TextForm"),
+ Arrays.asList("ct_survey", "Text Heading", "Text Headings",
+ "com.arsdigita.formbuilder.PersistentHeading",
+ "com.arsdigita.formbuilder.ui.editors.HeadingForm"),
+ Arrays.asList("ct_survey", "Section Break", "Section Break",
+ "com.arsdigita.formbuilder.PersistentHorizontalRule",
+ "com.arsdigita.formbuilder.ui.editors.HorizontalRuleForm"),
+ Arrays.asList("ct_survey", "User Email Field", "User Email Fields",
+ "com.arsdigita.formbuilder.PersistentEmailField",
+ "com.arsdigita.formbuilder.ui.editors.EmailFieldForm"));
+
+ List processListeners = Arrays.asList(
+ Arrays.asList("ct_survey", "Confirmation email", "Confirmation emails",
+ "com.arsdigita.formbuilder.actions.ConfirmEmailListener",
+ "com.arsdigita.formbuilder.ui.editors.ConfirmEmailForm"),
+ Arrays.asList("ct_survey", "URL redirect", "URL redirects",
+ "com.arsdigita.formbuilder.actions.ConfirmRedirectListener",
+ "com.arsdigita.formbuilder.ui.editors.ConfirmRedirectForm"),
+ Arrays.asList("ct_survey", "Simple email", "Simple emails",
+ "com.arsdigita.formbuilder.actions.SimpleEmailListener",
+ "com.arsdigita.formbuilder.ui.editors.SimpleEmailForm"),
+ Arrays.asList("ct_survey", "Templated email", "Templated emails",
+ "com.arsdigita.formbuilder.actions.TemplateEmailListener",
+ "com.arsdigita.formbuilder.ui.editors.TemplateEmailForm"));
+
+ List dataQueries = Arrays.asList();
+
+ new com.arsdigita.formbuilder.installer.Initializer(widgets, processListeners, dataQueries);
+ }
}
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyTraversalAdapter.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyTraversalAdapter.java
new file mode 100644
index 000000000..c5eeb8c12
--- /dev/null
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyTraversalAdapter.java
@@ -0,0 +1,53 @@
+package com.arsdigita.cms.contenttypes;
+
+import org.apache.log4j.Logger;
+import com.arsdigita.persistence.metadata.Property;
+import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
+import com.arsdigita.domain.DomainObject;
+
+/**
+ * An adapter for Survey allowing pluggable
+ * assets to extend the traversal.
+ *
+ * This is a modified copy of ContentItemTraversalAdapter to allow the
+ * Survey objects to show the survey form only during active survey time
+ */
+public class SurveyTraversalAdapter extends ContentItemTraversalAdapter {
+
+ private static final Logger s_log =
+ Logger.getLogger(SurveyTraversalAdapter.class);
+
+ public SurveyTraversalAdapter() {
+ super();
+ }
+
+ public SurveyTraversalAdapter(SimpleDomainObjectTraversalAdapter adapter) {
+ super(adapter);
+ }
+
+ /**
+ * If the path references an asset, then delegates
+ * to the asset's adapter, otherwise delegates to
+ * the content item's primary adapter
+ */
+ @Override
+ public boolean processProperty(DomainObject obj, String path, Property prop, String context) {
+
+ if (obj instanceof Survey) {
+
+ if (s_log.isDebugEnabled()) {
+ s_log.debug("Found a Survey CT. Using own SurveyTraversalAdapter.");
+ }
+
+ // Test if we are processing a form property
+ if (prop.getName().equals(Survey.FORM)) {
+
+ // If the Survey is active or not live (preview), show the form. Otherwise dismiss it.
+ return ((Survey) obj).isActive() || !((Survey) obj).isLiveVersion();
+ }
+ }
+
+ // In all other cases delegate to parent class
+ return super.processProperty(obj, path, prop, context);
+ }
+}
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyXMLGenerator.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyXMLGenerator.java
new file mode 100644
index 000000000..b0567f107
--- /dev/null
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/SurveyXMLGenerator.java
@@ -0,0 +1,158 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.arsdigita.cms.contenttypes;
+
+import com.arsdigita.cms.dispatcher.*;
+import com.arsdigita.bebop.Component;
+import com.arsdigita.bebop.Form;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.Page;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.form.Widget;
+import com.arsdigita.bebop.util.Traversal;
+import com.arsdigita.cms.CMS;
+import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener;
+import com.arsdigita.cms.formbuilder.FormUnavailableException;
+import com.arsdigita.cms.formbuilder.NoParametersHttpServletRequest;
+import com.arsdigita.formbuilder.PersistentForm;
+import com.arsdigita.formbuilder.ui.BaseAddObserver;
+import com.arsdigita.formbuilder.ui.FormBuilderXMLRenderer;
+import com.arsdigita.formbuilder.ui.PlaceholdersInitListener;
+import com.arsdigita.formbuilder.util.FormBuilderUtil;
+
+import com.arsdigita.util.UncheckedWrapperException;
+import com.arsdigita.web.URL;
+import com.arsdigita.web.Web;
+import com.arsdigita.xml.Element;
+
+/**
+ *
+ * @author quasi
+ */
+public class SurveyXMLGenerator extends SimpleXMLGenerator {
+
+ @Override
+ public void generateXML(PageState state, Element parent, String useContext) {
+
+ Survey survey = (Survey) getContentItem(state);
+ PersistentForm pForm = survey.getForm();
+ Component c = instantiateForm(pForm, "itemAdminSummary".equals(useContext));
+// String url = DispatcherHelper.getRequestContext().getRemainingURLPart();
+
+ // Fake the page context for the item, since we
+ // have no access to the real page context.
+ Page p = new Page("dummy");
+ p.add(c);
+ p.lock();
+
+ PageState fake;
+ try {
+ if ("itemAdminSummary".equals(useContext)) {
+ // Chop off all the parameters to stop bebop stategetting confused
+ fake = p.process(new NoParametersHttpServletRequest(
+ state.getRequest()), state.getResponse());
+ } else {
+ // Really serving the user page, so need the params when
+ // processing the pForm
+ fake = p.process(state.getRequest(), state.getResponse());
+ }
+ } catch (Exception e) {
+ throw new UncheckedWrapperException(e);
+ }
+
+// Traversal t = new VisibleTraverse(fake);
+// t.preorder(c);
+
+ // Simply embed the bebop xml as a child of the cms:item tag
+ Element element = parent.newChildElement("cms:item", CMS.CMS_XML_NS);
+
+ String action = pForm.getAction();
+ if (action == null) {
+ final URL requestURL = Web.getContext().getRequestURL();
+
+ if (requestURL == null) {
+ action = state.getRequest().getRequestURI();
+ } else {
+ action = requestURL.getRequestURI();
+ }
+ }
+
+ element.addAttribute(FormBuilderUtil.FORM_ACTION, action);
+
+ if (!survey.hasStarted()) {
+ // This survey has not started yet, so show info text instead of survey form
+ element.newChildElement(new Element("info").setText("not started yet"));
+ } else if (survey.getResponsesPublic().booleanValue() && survey.hasResponses() &&
+ (survey.getResultsDuringSurvey() || survey.hasEnded())) {
+ element.newChildElement(new Element("results").setText("go to results"));
+ }
+
+ FormBuilderXMLRenderer renderer = new FormBuilderXMLRenderer(element);
+ renderer.setWrapAttributes(true);
+ renderer.setWrapRoot(false);
+ renderer.setRevisitFullObject(true);
+ renderer.setWrapObjects(false);
+
+ renderer.walk(survey, SurveyXMLGenerator.ADAPTER_CONTEXT);
+
+ // then, if the component is actually a pForm, we need
+ // to print out any possible errors
+ // Ideally we could do this as part of the "walk" but for now
+ // that does not work because we don't pass in the page state
+ // although that can always we updated.
+ // if (c instanceof Form) {
+ // Element infoElement =
+ // element.newChildElement(FormBuilderUtil.FORMBUILDER_FORM_INFO,
+ // FormBuilderUtil.FORMBUILDER_XML_NS);
+ // Form f = (Form) c;
+
+ // Traversal infoTraversal =
+ // new ComponentTraverse(state, ((Form) c).getFormData(state),
+ // infoElement);
+ // infoTraversal.preorder(f);
+ // }
+
+ // we need to generate the state so that it can be part of the pForm
+ // and correctly included when the pForm is submitted. We could
+ // do this by iterating through the pForm data but it does not
+ // seem like a good idea to just cut and paste the code out
+ // of the PageState class
+ fake.setControlEvent(c);
+
+ // Generate the hidden PageState info for this page
+ fake.generateXML(element.newChildElement(FormBuilderUtil.FORMBUILDER_PAGE_STATE, FormBuilderUtil.FORMBUILDER_XML_NS));
+ }
+
+ protected Component instantiateForm(PersistentForm persistentForm, boolean readOnly) {
+
+ try {
+
+ persistentForm.setComponentAddObserver(new BaseAddObserver());
+ Form form = (Form) persistentForm.createComponent();
+ form.addInitListener(new PlaceholdersInitListener());
+ form.addProcessListener(new SurveyProcessListener());
+
+ if (readOnly) {
+ Traversal t = new Traversal() {
+
+ public void act(Component c) {
+ try {
+ Widget widget = (Widget) c;
+ widget.setDisabled();
+ widget.setReadOnly();
+ } catch (ClassCastException ex) {
+ // Nada
+ }
+ }
+ };
+ t.preorder(form);
+ }
+
+ return form;
+ } catch (FormUnavailableException ex) {
+ return new Label("This form is temporarily unavailable");
+ }
+ }
+}
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyActions.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyActions.java
new file mode 100644
index 000000000..b762c1236
--- /dev/null
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyActions.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.cms.contenttypes.ui;
+
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
+import com.arsdigita.formbuilder.ui.ProcessListenerEditor;
+import org.apache.log4j.Logger;
+
+public class SurveyActions extends ProcessListenerEditor {
+
+ private static final Logger s_log =
+ Logger.getLogger(SurveyActions.class);
+
+ public SurveyActions(ItemSelectionModel model, AuthoringKitWizard parent) {
+ super("ct_survey", new SurveySingleSelectionModel(model));
+ }
+}
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyControls.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyControls.java
index 0148481a6..333b6cd15 100644
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyControls.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyControls.java
@@ -26,7 +26,7 @@ public class SurveyControls extends ControlEditor {
private ItemSelectionModel m_itemModel;
public SurveyControls(ItemSelectionModel item, AuthoringKitWizard parent) {
- super("forms-cms", new SurveySingleSelectionModel(item), true);
+ super("ct_survey", new SurveySingleSelectionModel(item), true);
m_itemModel = item;
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesForm.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesForm.java
index d55c61b78..389a660b4 100755
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesForm.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesForm.java
@@ -52,6 +52,7 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
public static final String END_DATE = Survey.END_DATE;
public static final String RESPONSES_PUBLIC = Survey.RESPONSES_PUBLIC;
public static final String RESPONSES_ANONYM = Survey.RESPONSES_ANONYM;
+ public static final String RESULTS_DURING_SURVEY = Survey.RESULTS_DURING_SURVEY;
/**
* ID of the form
*/
@@ -108,6 +109,16 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
responsesPublic.addOption(rp2);
add(responsesPublic);
+ add(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.show_results_during_survey").localize()));
+ ParameterModel resultsDuringSurveyParam = new BooleanParameter(RESULTS_DURING_SURVEY);
+ resultsDuringSurveyParam.addParameterListener(new NotNullValidationListener());
+ RadioGroup resultsDuringSurvey = new RadioGroup("resultsDuringSurvey");
+ Option rds1 = new Option("true", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.Yes").localize()));
+ Option rds2 = new Option("false", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.No").localize()));
+ resultsDuringSurvey.addOption(rp1);
+ resultsDuringSurvey.addOption(rp2);
+ add(resultsDuringSurvey);
+
add(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.should_quiz_responses_be_anonym").localize()));
ParameterModel responsesAnonymParam = new BooleanParameter(RESPONSES_ANONYM);
responsesAnonymParam.addParameterListener(new NotNullValidationListener());
@@ -131,6 +142,12 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
if (survey.getResponsesPublic() != null) {
data.put(RESPONSES_PUBLIC, survey.getResponsesPublic().booleanValue());
}
+ if (survey.getResultsDuringSurvey() != null) {
+ data.put(RESULTS_DURING_SURVEY, survey.getResultsDuringSurvey().booleanValue());
+ }
+ if (survey.getResponsesAnonym() != null) {
+ data.put(RESPONSES_ANONYM, survey.getResponsesAnonym().booleanValue());
+ }
}
@Override
@@ -144,6 +161,7 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
survey.setStartDate((java.util.Date) data.get(START_DATE));
survey.setEndDate((java.util.Date) data.get(END_DATE));
survey.setResponsesPublic(new Boolean((String) data.get(RESPONSES_PUBLIC)));
+ survey.setResultsDuringSurvey(new Boolean((String) data.get(RESULTS_DURING_SURVEY)));
survey.setResponsesAnonym(new Boolean((String) data.get(RESPONSES_ANONYM)));
survey.save();
diff --git a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesStep.java b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesStep.java
index 4398b9978..ed2552da4 100644
--- a/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesStep.java
+++ b/ccm-cms-types-survey/src/com/arsdigita/cms/contenttypes/ui/SurveyPropertiesStep.java
@@ -103,7 +103,24 @@ public class SurveyPropertiesStep extends SimpleEditStep {
}
});
- /* Display the Status of ResponsesPublic in localized form */
+ /* Display the Status of ResultsDuringSurvey in localized form */
+ sheet.add(SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.show_results_during_survey"), Survey.RESULTS_DURING_SURVEY, new DomainObjectPropertySheet.AttributeFormatter() {
+
+ public String format(DomainObject obj, String attribute, PageState state) {
+ Survey survey = (Survey) obj;
+ if (survey.getResultsDuringSurvey() != null) {
+ if (survey.getResultsDuringSurvey().booleanValue() == true) {
+ return (String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.Yes").localize();
+ } else {
+ return (String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.No").localize();
+ }
+ } else {
+ return (String) GlobalizationUtil.globalize("cms.ui.unknown").localize();
+ }
+ }
+ });
+
+ /* Display the Status of ResponsesAnonym in localized form */
sheet.add(SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.should_quiz_responses_be_anonym"), Survey.RESPONSES_ANONYM, new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject obj, String attribute, PageState state) {