* Konfiguration um einen Punkt erweiteret, der es erlaubt, die Anzeige der Ergebnisse wärend der aktiven Umfragezeit ein- oder auszublenden.
 * Bearbeitungspunkt zum Hinzufügen von zusätzlichen ProcessListenern eingebaut. Jetzt können Surveys Bestätigungs-Emails versenden, so wie ein URL-Redirect nach dem Ausfüllen der Umfrage ausführen.
 * Survey verwendet nun seine eigene Konfiguration an Widgets und ProcessListenern für die Erstellung des Formulars. Diese Konfiguration findet zur Zeit im Initializer statt.
 * Darstellung des CTs korrigiert. Zeigt jetzt während der aktiven Umfragezeit und in der Vorschau das Formular an. Ansonsten wird das Formular nicht angezeigt, aber der Titel und die Beschreibung sind trotzdem zu sehen. Außerdem ist die Logik für die Anzeige der Ergebnisse vorhanden und korrekt, auch wenn ich noch nicht weiß, wie ich die Ergebnisseite einbauen kann. Zur Zeit wird stattdessen ein XML-Tag als Platzhalter dargestellt.

git-svn-id: https://svn.libreccm.org/ccm/trunk@366 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-03-24 18:21:21 +00:00
parent 6dbd19f0be
commit 799d07d032
14 changed files with 415 additions and 146 deletions

View File

@ -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

View File

@ -28,6 +28,12 @@
descriptionBundle="com.arsdigita.cms.formbuilder.FormItemResources"
component="com.arsdigita.cms.contenttypes.ui.SurveyControls"/>
<ctd:authoring-step
labelKey="form_item.authoring.actions.title"
labelBundle="com.arsdigita.cms.formbuilder.FormItemResources"
descriptionKey="form_item.authoring.actions.description"
descriptionBundle="com.arsdigita.cms.formbuilder.FormItemResources"
component="com.arsdigita.cms.contenttypes.ui.SurveyActions"/>
<ctd:include href="/WEB-INF/content-types/shared.xml"/>
</ctd:authoring-kit>

View File

@ -5,7 +5,7 @@
xsi:schemaLocation="http://rhea.redhat.com/schemas/waf/xml-renderer-rules xml-renderer-rules.xsd">
<xrd:context name="com.arsdigita.cms.dispatcher.SimpleXMLGenerator">
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Survey" extends="com.arsdigita.cms.ContentPage">
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Survey" extends="com.arsdigita.cms.ContentPage" traversalClass="com.arsdigita.cms.contenttypes.SurveyTraversalAdapter">
<xrd:attributes rule="exclude">
<xrd:property name="/object/form/id"/>
<xrd:property name="/object/form/defaultDomainClass"/>

View File

@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<!-- nothing yet -->
<!--
<config class="com.arsdigita.cms.contenttypes.SurveyConfig" storage="ccm-cms-types-survey/survey.properties"/>
-->
</registry>

View File

@ -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);
}
/*

View File

@ -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();
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}
}

View File

@ -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));
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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) {