* Konfiguration hinzugefügt
 * Fehlerbereinigung für Submit-Button und Hidden Survey-ID

git-svn-id: https://svn.libreccm.org/ccm/trunk@361 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-03-02 06:43:18 +00:00
parent 06392e0bfa
commit f73c6e8984
3 changed files with 88 additions and 24 deletions

View File

@ -12,8 +12,7 @@ import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.CustomCopy; import com.arsdigita.cms.CustomCopy;
import com.arsdigita.cms.ItemCopier; import com.arsdigita.cms.ItemCopier;
import com.arsdigita.cms.contenttypes.ui.SurveyPersistentProcessListener;
import com.arsdigita.cms.contenttypes.ui.SurveyPersistentProcessListener;
import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener; import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener;
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.SimpleXMLGenerator;
@ -68,18 +67,18 @@ public class Survey extends ContentPage implements XMLGenerator {
public static final String RESPONSES_ANONYM = "responsesAnonym"; public static final String RESPONSES_ANONYM = "responsesAnonym";
/** Data object type for this domain object */ /** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Survey"; public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Survey";
/* /* Config */
private static final SurveyConfig s_config = new SurveyConfig(); private static final SurveyConfig s_config = new SurveyConfig();
static { static {
s_config.load(); s_config.load();
} }
public static final SurveyConfig getConfig() public static final SurveyConfig getConfig() {
{ return s_config;
return s_config;
} }
*/
/** /**
* Default constructor. This creates a new (empty) Survey. * Default constructor. This creates a new (empty) Survey.
**/ **/
@ -136,7 +135,7 @@ public class Survey extends ContentPage implements XMLGenerator {
/** /**
* This will handle the mandatory FormSection. If there is no * This will handle the mandatory FormSection. If there is no
* FormSection set it will create an empty new form and assign it * FormSection set it will create an empty new pForm and assign it
* to keep the db happy. * to keep the db happy.
*/ */
@Override @Override
@ -151,11 +150,11 @@ public class Survey extends ContentPage implements XMLGenerator {
// Preset the responsesPublic // Preset the responsesPublic
if (getResponsesPublic() == null) { if (getResponsesPublic() == null) {
setResponsesPublic(false); setResponsesPublic(getConfig().getShowResultsPublic());
} }
// Preset the responsesAnonym // Preset the responsesAnonym
if (getResponsesAnonym() == null) { if (getResponsesAnonym() == null) {
setResponsesAnonym(false); setResponsesAnonym(getConfig().getAnonymSurvey());
} }
} }
@ -168,9 +167,10 @@ public class Survey extends ContentPage implements XMLGenerator {
Property property, Property property,
ItemCopier copier) { ItemCopier copier) {
if (property.getName().equals(FORM)) { if (property.getName().equals(FORM)) {
PersistentForm pForm = ((Survey) src).getForm(); // PersistentForm pForm = ((Survey) src).getForm();
PersistentForm pForm = (new FormCopier()).copyForm(((Survey) src).getForm());
// Add hideden field with survey id // Add hidden field with survey id
PersistentHidden survey_id = PersistentHidden.create(SURVEY_ID); PersistentHidden survey_id = PersistentHidden.create(SURVEY_ID);
survey_id.setDefaultValue(((Survey) src).getSurveyID().toString()); survey_id.setDefaultValue(((Survey) src).getSurveyID().toString());
pForm.addComponent(survey_id); pForm.addComponent(survey_id);
@ -178,7 +178,7 @@ public class Survey extends ContentPage implements XMLGenerator {
// Add a submit button // Add a submit button
PersistentSubmit submit = PersistentSubmit.create("submit"); PersistentSubmit submit = PersistentSubmit.create("submit");
pForm.addComponent(submit); pForm.addComponent(submit);
setAssociation(FORM, (new FormCopier()).copyForm(pForm)); setAssociation(FORM, pForm);
return true; return true;
} }
@ -260,8 +260,8 @@ public class Survey extends ContentPage implements XMLGenerator {
public void generateXML(PageState state, Element parent, String useContext) { public void generateXML(PageState state, Element parent, String useContext) {
PersistentForm form = getForm(); PersistentForm pForm = getForm();
Component c = instantiateForm(form, "itemAdminSummary".equals(useContext)); Component c = instantiateForm(pForm, "itemAdminSummary".equals(useContext));
// Fake the page context for the item, since we // Fake the page context for the item, since we
// have no access to the real page context. // have no access to the real page context.
@ -277,7 +277,7 @@ public class Survey extends ContentPage implements XMLGenerator {
// state.getRequest()), state.getResponse()); // state.getRequest()), state.getResponse());
// } else { // } else {
// Really serving the user page, so need the params when // Really serving the user page, so need the params when
// processing the form // processing the pForm
fake = p.process(state.getRequest(), state.getResponse()); fake = p.process(state.getRequest(), state.getResponse());
// } // }
} catch (Exception e) { } catch (Exception e) {
@ -290,8 +290,8 @@ public class Survey extends ContentPage implements XMLGenerator {
// Simply embed the bebop xml as a child of the cms:item tag // Simply embed the bebop xml as a child of the cms:item tag
Element element = parent.newChildElement("cms:item", CMS.CMS_XML_NS); Element element = parent.newChildElement("cms:item", CMS.CMS_XML_NS);
// generateXMLBody(fake, element, form); // generateXMLBody(fake, element, pForm);
String action = form.getAction(); String action = pForm.getAction();
if (action == null) { if (action == null) {
final URL requestURL = Web.getContext().getRequestURL(); final URL requestURL = Web.getContext().getRequestURL();
@ -313,7 +313,7 @@ public class Survey extends ContentPage implements XMLGenerator {
renderer.walk(this, SimpleXMLGenerator.ADAPTER_CONTEXT); renderer.walk(this, SimpleXMLGenerator.ADAPTER_CONTEXT);
// then, if the component is actually a form, we need // then, if the component is actually a pForm, we need
// to print out any possible errors // to print out any possible errors
// Ideally we could do this as part of the "walk" but for now // 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 // that does not work because we don't pass in the page state
@ -330,9 +330,9 @@ public class Survey extends ContentPage implements XMLGenerator {
// infoTraversal.preorder(f); // infoTraversal.preorder(f);
// } // }
// we need to generate the state so that it can be part of the form // we need to generate the state so that it can be part of the pForm
// and correctly included when the form is submitted. We could // and correctly included when the pForm is submitted. We could
// do this by iterating through the form data but it does not // 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 // seem like a good idea to just cut and paste the code out
// of the PageState class // of the PageState class
fake.setControlEvent(c); fake.setControlEvent(c);

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 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;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.BooleanParameter;
public class SurveyConfig extends AbstractConfig {
private final Parameter m_showResultsPublic;
private final Parameter m_anonymSurvey;
public SurveyConfig() {
m_showResultsPublic = new BooleanParameter(
"com.arsdigita.cms.contenttypes.survey.show_results_public",
Parameter.REQUIRED,
new Boolean(true));
m_anonymSurvey = new BooleanParameter(
"com.arsdigita.cms.contenttypes.survey.anonym_survey",
Parameter.REQUIRED,
new Boolean(true));
register(m_showResultsPublic);
register(m_anonymSurvey);
loadInfo();
}
public final boolean getShowResultsPublic() {
return ((Boolean) get(m_showResultsPublic)).booleanValue();
}
public final boolean getAnonymSurvey() {
return ((Boolean) get(m_anonymSurvey)).booleanValue();
}
}

View File

@ -0,0 +1,9 @@
com.arsdigita.cms.contenttypes.survey.show_results_public.title=Show results public
com.arsdigita.cms.contenttypes.survey.show_results_public.purpose=Default setting for public results
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.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
com.arsdigita.cms.contenttypes.survey.anonym_survey.format=[boolean]