FEATURE: added ability to have a clear form button. MINOR: setting up functions for deleting submissions

This commit is contained in:
Will Rossiter 2009-04-14 22:59:46 +00:00
parent d3a3122b84
commit 74442bfd89
5 changed files with 115 additions and 30 deletions

View File

@ -41,6 +41,7 @@ class UserDefinedForm extends Page {
"EmailOnSubmitSubject" => "Varchar(200)", "EmailOnSubmitSubject" => "Varchar(200)",
"SubmitButtonText" => "Varchar", "SubmitButtonText" => "Varchar",
"OnCompleteMessage" => "HTMLText", "OnCompleteMessage" => "HTMLText",
"ShowClearButton" => "Boolean"
); );
/** /**
@ -63,8 +64,6 @@ class UserDefinedForm extends Page {
"EmailRecipients" => "UserDefinedForm_EmailRecipient" "EmailRecipients" => "UserDefinedForm_EmailRecipient"
); );
protected $fields;
/** /**
* Setup the CMS Fields for the User Defined Form * Setup the CMS Fields for the User Defined Form
* *
@ -74,11 +73,36 @@ class UserDefinedForm extends Page {
$fields = parent::getCMSFields(); $fields = parent::getCMSFields();
// field editor // field editor
$fields->addFieldToTab("Root."._t('UserDefinedForm.FORM', 'Form'), new FieldEditor("Fields", 'Fields', "", $this )); $fields->addFieldToTab("Root.Content."._t('UserDefinedForm.FORM', 'Form'), new FieldEditor("Fields", 'Fields', "", $this ));
// view the submissions // view the submissions
$fields->addFieldToTab("Root."._t('UserDefinedForm.SUBMISSIONS','Submissions'), new SubmittedFormReportField( "Reports", _t('UserDefinedForm.RECEIVED', 'Received Submissions'), "", $this ) ); $fields->addFieldToTab("Root.Content."._t('UserDefinedForm.SUBMISSIONS','Submissions'), new SubmittedFormReportField( "Reports", _t('UserDefinedForm.RECEIVED', 'Received Submissions'), "", $this ) );
/*
Trying to get submissions working as a tablelistfield. close, but not close enough
$query = new SQLQuery();
$query->from("SubmittedForm");
$query->where("SubmittedForm.ParentID = '$this->ID'");
$query->orderby("SubmittedForm.Created");
$query->limit("20");
$query->leftJoin("SubmittedFormField", "SubmittedFormField.ParentID = SubmittedForm.ID");
$myTableListField = new TableListField(
'Submissions',
'SubmittedForm'
);
$myTableListField->setCustomQuery($query);
$fieldValues = array(
"Title" => "Title",
"Value" => "$Value",
"Name" => "$Name",
"ID" => "$ID",
"ParentID" => "$ParentID"
);
$myTableListField->setFieldList($fieldValues);
$fields->addFieldToTab("Root.Test", $myTableListField);
*/
// who do we email on submission // who do we email on submission
$emailRecipients = new HasManyComplexTableField($this, $emailRecipients = new HasManyComplexTableField($this,
'EmailRecipients', 'EmailRecipients',
@ -91,7 +115,7 @@ class UserDefinedForm extends Page {
'getCMSFields_forPopup' 'getCMSFields_forPopup'
); );
$emailRecipients->setAddTitle(_t('UserDefinedForm.AEMAILRECIPIENT', 'A Email Recipient')); $emailRecipients->setAddTitle(_t('UserDefinedForm.AEMAILRECIPIENT', 'A Email Recipient'));
$fields->addFieldToTab("Root."._t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $emailRecipients); $fields->addFieldToTab("Root.Content."._t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $emailRecipients);
// text to show on complete // text to show on complete
$onCompleteFieldSet = new FieldSet( $onCompleteFieldSet = new FieldSet(
@ -186,22 +210,35 @@ class UserDefinedForm extends Page {
function ReportFilterForm() { function ReportFilterForm() {
return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' ); return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' );
} }
function delete() { /**
// remove all the fields associated with this page * Called on before delete remove all the fields from the database
foreach( $this->Fields() as $field ) */
$field->delete(); public function delete() {
foreach($this->Fields() as $field) {
parent::delete(); $field->delete();
} }
parent::delete();
}
public function customFormActions( $isReadonly = false ) { /**
return new FieldSet( new TextField( "SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $this->SubmitButtonText ) ); * Custom Form Actions for the form
*
* @param bool Is the Form readonly
* @return FieldSet
*/
public function customFormActions($isReadonly = false) {
return new FieldSet(
new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $this->SubmitButtonText),
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton)
);
} }
/** /**
* Duplicate this UserDefinedForm page, and its form fields. * Duplicate this UserDefinedForm page, and its form fields.
* Submissions, on the other hand, won't be duplicated. * Submissions, on the other hand, won't be duplicated.
*
* @return Page
*/ */
public function duplicate() { public function duplicate() {
$page = parent::duplicate(); $page = parent::duplicate();
@ -224,9 +261,8 @@ class UserDefinedForm extends Page {
class UserDefinedForm_Controller extends Page_Controller { class UserDefinedForm_Controller extends Page_Controller {
function init() { function init() {
Requirements::javascript(THIRDPARTY_DIR . 'jsparty/prototype-safe.js'); Requirements::javascript(THIRDPARTY_DIR . '/prototype.js');
Requirements::javascript(THIRDPARTY_DIR . 'jsparty/behaviour.js'); Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js');
parent::init(); parent::init();
} }
@ -323,6 +359,10 @@ class UserDefinedForm_Controller extends Page_Controller {
} }
} }
function ReportFilterForm() {
return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' );
}
/** /**
* User Defined Form. Feature of the user defined form is if you want the * User Defined Form. Feature of the user defined form is if you want the
* form to appear in a custom location on the page you can use $UserDefinedForm * form to appear in a custom location on the page you can use $UserDefinedForm
@ -353,19 +393,30 @@ class UserDefinedForm_Controller extends Page_Controller {
$fields->push( new HiddenField( "Referrer", "", $referer ) ); $fields->push( new HiddenField( "Referrer", "", $referer ) );
// Build actions // Build actions
$actions = new FieldSet( $actions = new FieldSet(
new FormAction( "process", $this->SubmitButtonText ) new FormAction("process", $this->SubmitButtonText)
); );
// set the name of the form // Do we want to add a clear form. Should do this via js
$form = new Form( $this, "Form", $fields, $actions, new RequiredFields( $required ) ); if($this->ShowClearButton) {
$actions->push(new ResetFormAction("clearForm"));
}
$form = new Form( $this, "Form", $fields, $actions, new RequiredFields($required));
$form->loadDataFrom($this->failover); $form->loadDataFrom($this->failover);
return $form; return $form;
} }
/**
function ReportFilterForm() { * Clear a form action. This is the fall back to if it doesn't work
return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' ); * with the javascript
*
* @param Array data
* @param Form The form to clear
*/
public function clearForm($data, $form) {
Session::clear('FormInfo.Form');
return Director::redirectBack();
} }
/** /**
@ -521,6 +572,11 @@ class UserDefinedForm_Controller extends Page_Controller {
return $templateData; return $templateData;
} }
function deletesubmissions() {
// delete all the submissions
return true;
}
} }
/** /**

View File

@ -83,9 +83,11 @@ class FieldEditor extends FormField {
$name = $this->name; $name = $this->name;
$fieldSet = $record->$name(); $fieldSet = $record->$name();
// @todo shouldn't we deal with customFormActions on that object?
$record->EmailTo = $_REQUEST[$name]['EmailTo']; $record->EmailTo = $_REQUEST[$name]['EmailTo'];
$record->EmailOnSubmit = isset( $_REQUEST[$name]['EmailOnSubmit'] ) ? "1" : "0"; $record->EmailOnSubmit = isset( $_REQUEST[$name]['EmailOnSubmit'] ) ? "1" : "0";
$record->SubmitButtonText = $_REQUEST[$name]['SubmitButtonText']; $record->SubmitButtonText = $_REQUEST[$name]['SubmitButtonText'];
$record->ShowClearButton = isset($_REQUEST[$name]['ShowClearButton']) ? "1" : "0";
// store the field IDs and delete the missing fields // store the field IDs and delete the missing fields
// alternatively, we could delete all the fields and re add them // alternatively, we could delete all the fields and re add them

View File

@ -9,13 +9,18 @@ class SubmittedForm extends DataObject {
"Parent" => "UserDefinedForm", "Parent" => "UserDefinedForm",
); );
static $db = array(
"Recipient" => "Varchar(255)"
);
static $has_many = array( static $has_many = array(
"FieldValues" => "SubmittedFormField" "FieldValues" => "SubmittedFormField"
); );
/**
* Return the Link to DeleteLink
*
* @return String
*/
public function DeleteLink() {
return $this->Parent()->Link().'deletesubmission/'.$this->ID;
}
function SubmitTime() { function SubmitTime() {
return $this->Created; return $this->Created;

View File

@ -14,5 +14,6 @@ class SubmittedFormField extends DataObject {
static $has_one = array( static $has_one = array(
"Parent" => "SubmittedForm" "Parent" => "SubmittedForm"
); );
} }
?> ?>

View File

@ -1,7 +1,8 @@
<?php <?php
/** /**
* Displays a summary of instances of a form submitted to the website * Displays a summary of instances of a form submitted to the website
* @package cms *
* @package userforms
*/ */
class SubmittedFormReportField extends FormField { class SubmittedFormReportField extends FormField {
@ -11,15 +12,35 @@ class SubmittedFormReportField extends FormField {
return $this->renderWith("SubmittedFormReportField"); return $this->renderWith("SubmittedFormReportField");
} }
/**
* Return the submissions from the site
*
* @return ComponentSet
*/
function Submissions() { function Submissions() {
return $this->form->getRecord()->Submissions(); return $this->form->getRecord()->Submissions();
} }
/**
* Link to the export function of the controller
*
* @return String
*/
function ExportLink() { function ExportLink() {
if($this->Submissions() && $this->Submissions()->Count() > 0) { if($this->Submissions() && $this->Submissions()->Count() > 0) {
return $this->form->getRecord()->Link() . 'export/' . $this->form->getRecord()->ID; return $this->form->getRecord()->Link() . 'export/' . $this->form->getRecord()->ID;
} }
} }
/**
* Link to the delete the submission
*
* @return String
*/
function DeleteLink() {
if($this->Submissions() && $this->Submissions()->Count() > 0) {
return $this->form->getRecord()->Link() . 'deletesubmissions/' . $this->form->getRecord()->ID;
}
}
} }
?> ?>