Replaced all instances of new FieldSet() with new FieldList()

Replaced the complex table field used for editing the email recipients with GridField

Replaced instances of SAPPHIRE_DIR with FRAMEWORK_DIR

Replaced instances of sapphire/ in css and templates with framework/

Re-organized tabs on user defined form so they are top level

Replaced calls to toDropdownMap() with map()

Renamed getCMSFields_forPopup() top getCMSFields()
This commit is contained in:
edchipman@gmail.com 2012-04-22 16:17:42 -03:00 committed by Stig Lindqvist
parent 584219b0b5
commit 5de26cd897
15 changed files with 54 additions and 59 deletions

View File

@ -95,7 +95,7 @@ class FieldEditor extends FormField {
if($fields) { if($fields) {
array_shift($fields); // get rid of subclass 0 array_shift($fields); // get rid of subclass 0
asort($fields); // get in order asort($fields); // get in order
$output = new DataObjectSet(); $output = new ArrayList();
foreach($fields as $field => $title) { foreach($fields as $field => $title) {
// get the nice title and strip out field // get the nice title and strip out field
$niceTitle = trim(eval("return $title::\$singular_name;")); $niceTitle = trim(eval("return $title::\$singular_name;"));

View File

@ -8,7 +8,7 @@
class SubmittedFormReportField extends FormField { class SubmittedFormReportField extends FormField {
function Field() { function Field() {
Requirements::css(SAPPHIRE_DIR . "/css/SubmittedFormReportField.css"); Requirements::css(FRAMEWORK_DIR . "/css/SubmittedFormReportField.css");
Requirements::javascript("userforms/javascript/UserForm.js"); Requirements::javascript("userforms/javascript/UserForm.js");
return $this->renderWith("SubmittedFormReportField"); return $this->renderWith("SubmittedFormReportField");
} }
@ -22,12 +22,12 @@ class SubmittedFormReportField extends FormField {
$pageStart = isset($_REQUEST['start']) && is_numeric($_REQUEST['start']) ? $_REQUEST['start'] : 0; $pageStart = isset($_REQUEST['start']) && is_numeric($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$pageLength = 10; $pageLength = 10;
$items = $this->form->getRecord()->getComponents('Submissions', null, "\"Created\" DESC", null, "$pageStart,$pageLength"); $items = $this->form->getRecord()->getComponents('Submissions', null, "\"Created\" DESC")->limit($pageStart,$pageLength);
$formId = $this->form->getRecord()->ID; $formId = $this->form->getRecord()->ID;
foreach(DB::query("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = $formId") as $r) $totalCount = $r['CountRows']; foreach(DB::query("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = $formId") as $r) $totalCount = $r['CountRows'];
$items->setPageLimits($pageStart, $pageLength, $totalCount); //$items->setPageLimits($pageStart, $pageLength, $totalCount);
$items->NextStart = $pageStart + $pageLength; $items->NextStart = $pageStart + $pageLength;
$items->PrevStart = $pageStart - $pageLength; $items->PrevStart = $pageStart - $pageLength;
$items->Start = $pageStart; $items->Start = $pageStart;

View File

@ -57,43 +57,38 @@ class UserDefinedForm extends Page {
$fields = parent::getCMSFields(); $fields = parent::getCMSFields();
// define tabs // define tabs
$fields->findOrMakeTab('Root.Content.Form', _t('UserDefinedForm.FORM', 'Form')); $fields->findOrMakeTab('Root.Form', _t('UserDefinedForm.FORM', 'Form'));
$fields->findOrMakeTab('Root.Content.Options', _t('UserDefinedForm.OPTIONS', 'Options')); $fields->findOrMakeTab('Root.Options', _t('UserDefinedForm.OPTIONS', 'Options'));
$fields->findOrMakeTab('Root.Content.EmailRecipients', _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients')); $fields->findOrMakeTab('Root.EmailRecipients', _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'));
$fields->findOrMakeTab('Root.Content.OnComplete', _t('UserDefinedForm.ONCOMPLETE', 'On Complete')); $fields->findOrMakeTab('Root.OnComplete', _t('UserDefinedForm.ONCOMPLETE', 'On Complete'));
$fields->findOrMakeTab('Root.Content.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions')); $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
// field editor // field editor
$fields->addFieldToTab("Root.Content.Form", new FieldEditor("Fields", 'Fields', "", $this )); $fields->addFieldToTab("Root.Form", new FieldEditor("Fields", 'Fields', "", $this ));
// view the submissions // view the submissions
$fields->addFieldToTab("Root.Content.Submissions", new CheckboxField('DisableSaveSubmissions',_t('UserDefinedForm.SAVESUBMISSIONS',"Disable Saving Submissions to Server"))); $fields->addFieldToTab("Root.Submissions", new CheckboxField('DisableSaveSubmissions',_t('UserDefinedForm.SAVESUBMISSIONS',"Disable Saving Submissions to Server")));
$fields->addFieldToTab("Root.Content.Submissions", new SubmittedFormReportField( "Reports", _t('UserDefinedForm.RECEIVED', 'Received Submissions'), "", $this ) ); $fields->addFieldToTab("Root.Submissions", new SubmittedFormReportField( "Reports", _t('UserDefinedForm.RECEIVED', 'Received Submissions'), "", $this ) );
UserDefinedForm_EmailRecipient::$summary_fields=array(
'EmailAddress' => _t('UserDefinedForm.EMAILADDRESS', 'Email'),
'EmailSubject' => _t('UserDefinedForm.EMAILSUBJECT', 'Subject'),
'EmailFrom' => _t('UserDefinedForm.EMAILFROM', 'From')
);
// who do we email on submission // who do we email on submission
$emailRecipients = new ComplexTableField( $emailRecipients = new GridField("EmailRecipients", "EmailRecipients", $this->EmailRecipients(), GridFieldConfig_RecordEditor::create(10));
$this,
'EmailRecipients',
'UserDefinedForm_EmailRecipient',
array(
'EmailAddress' => _t('UserDefinedForm.EMAILADDRESS', 'Email'),
'EmailSubject' => _t('UserDefinedForm.EMAILSUBJECT', 'Subject'),
'EmailFrom' => _t('UserDefinedForm.EMAILFROM', 'From')
),
'getCMSFields_forPopup',
"\"FormID\" = '$this->ID'"
);
$emailRecipients->setAddTitle(_t('UserDefinedForm.AEMAILRECIPIENT', 'A Email Recipient'));
$fields->addFieldToTab("Root.Content.EmailRecipients", $emailRecipients); $fields->addFieldToTab("Root.EmailRecipients", $emailRecipients);
// text to show on complete // text to show on complete
$onCompleteFieldSet = new FieldSet( $onCompleteFieldSet = new FieldList(
new HtmlEditorField( "OnCompleteMessage", _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion'),3,"",_t('UserDefinedForm.ONCOMPLETEMESSAGE', $this->OnCompleteMessage), $this ) $editor=new HtmlEditorField( "OnCompleteMessage", _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion'), _t('UserDefinedForm.ONCOMPLETEMESSAGE', $this->OnCompleteMessage))
); );
$editor->setRows(3);
$fields->addFieldsToTab("Root.Content.OnComplete", $onCompleteFieldSet); $fields->addFieldsToTab("Root.OnComplete", $onCompleteFieldSet);
$fields->addFieldsToTab("Root.Content.Options", $this->getFormOptions()); $fields->addFieldsToTab("Root.Options", $this->getFormOptions());
return $fields; return $fields;
} }
@ -259,7 +254,7 @@ class UserDefinedForm extends Page {
public function getFormOptions() { public function getFormOptions() {
$submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit'); $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
$options = new FieldSet( $options = new FieldList(
new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit), new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton) new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton)
); );
@ -302,7 +297,7 @@ class UserDefinedForm_Controller extends Page_Controller {
Validator::set_javascript_validation_handler('none'); Validator::set_javascript_validation_handler('none');
// load the jquery // load the jquery
Requirements::javascript(SAPPHIRE_DIR .'/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
Requirements::javascript('userforms/thirdparty/jquery-validate/jquery.validate.min.js'); Requirements::javascript('userforms/thirdparty/jquery-validate/jquery.validate.min.js');
} }
@ -368,7 +363,7 @@ class UserDefinedForm_Controller extends Page_Controller {
* @return FieldSet * @return FieldSet
*/ */
function getFormFields() { function getFormFields() {
$fields = new FieldSet(); $fields = new FieldList();
if($this->Fields()) { if($this->Fields()) {
foreach($this->Fields() as $editableField) { foreach($this->Fields() as $editableField) {
@ -428,7 +423,7 @@ class UserDefinedForm_Controller extends Page_Controller {
function getFormActions() { function getFormActions() {
$submitText = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit'); $submitText = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
$actions = new FieldSet( $actions = new FieldList(
new FormAction("process", $submitText) new FormAction("process", $submitText)
); );
@ -843,9 +838,9 @@ class UserDefinedForm_EmailRecipient extends DataObject {
* Return the fields to edit this email. * Return the fields to edit this email.
* @return FieldSet * @return FieldSet
*/ */
public function getCMSFields_forPopup() { public function getCMSFields() {
$fields = new FieldSet( $fields = new FieldList(
new TextField('EmailSubject', _t('UserDefinedForm.EMAILSUBJECT', 'Email Subject')), new TextField('EmailSubject', _t('UserDefinedForm.EMAILSUBJECT', 'Email Subject')),
new TextField('EmailFrom', _t('UserDefinedForm.FROMADDRESS','Send Email From')), new TextField('EmailFrom', _t('UserDefinedForm.FROMADDRESS','Send Email From')),
new TextField('EmailAddress', _t('UserDefinedForm.SENDEMAILTO','Send Email To')), new TextField('EmailAddress', _t('UserDefinedForm.SENDEMAILTO','Send Email To')),
@ -860,21 +855,22 @@ class UserDefinedForm_EmailRecipient extends DataObject {
// if they have email fields then we could send from it // if they have email fields then we could send from it
if($validEmailFields) { if($validEmailFields) {
$fields->insertAfter(new DropdownField('SendEmailFromFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or Select a Form Field to use as the From Address'), $validEmailFields->toDropdownMap('ID', 'Title'), '', null,""), 'EmailFrom'); $fields->insertAfter(new DropdownField('SendEmailFromFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or Select a Form Field to use as the From Address'), $validEmailFields->map('ID', 'Title'), '', null,""), 'EmailFrom');
} }
// if they have multiple options // if they have multiple options
if($multiOptionFields || $validEmailFields) { if($multiOptionFields || $validEmailFields) {
if($multiOptionFields && $validEmailFields) { if($multiOptionFields && $validEmailFields) {
$multiOptionFields->merge($validEmailFields); $multiOptionFields=$multiOptionFields->toArray();
$multiOptionFields=array_merge($multiOptionFields, $validEmailFields->toArray());
$multiOptionFields=ArrayList::create($multiOptionFields);
} }
elseif(!$multiOptionFields) { elseif(!$multiOptionFields) {
$multiOptionFields = $validEmailFields; $multiOptionFields = $validEmailFields;
} }
$multiOptionFields = $multiOptionFields->toDropdownMap('ID', 'Title'); $multiOptionFields = $multiOptionFields->map('ID', 'Title');
$fields->insertAfter(new DropdownField('SendEmailToFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or Select a Field to use as the To Address'), $multiOptionFields, '', null, ""), 'EmailAddress'); $fields->insertAfter(new DropdownField('SendEmailToFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or Select a Field to use as the To Address'), $multiOptionFields, '', null, ""), 'EmailAddress');
} }
} }

View File

@ -17,7 +17,7 @@ class EditableDateField extends EditableFormField {
$default = ($this->getSetting('DefaultToToday')) ? $this->getSetting('DefaultToToday') : false; $default = ($this->getSetting('DefaultToToday')) ? $this->getSetting('DefaultToToday') : false;
$label = _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?'); $label = _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?');
return new FieldSet( return new FieldList(
new CheckboxField($this->getSettingName("DefaultToToday"), $label, $default) new CheckboxField($this->getSettingName("DefaultToToday"), $label, $default)
); );
} }

View File

@ -391,7 +391,7 @@ class EditableFormField extends DataObject {
$this->getSetting('RightTitle') $this->getSetting('RightTitle')
); );
return new FieldSet( return new FieldList(
$ec, $ec,
$right $right
); );
@ -404,7 +404,7 @@ class EditableFormField extends DataObject {
* @return FieldSet * @return FieldSet
*/ */
public function getFieldValidationOptions() { public function getFieldValidationOptions() {
$fields = new FieldSet( $fields = new FieldList(
new CheckboxField($this->getFieldName('Required'), _t('EditableFormField.REQUIRED', 'Is this field Required?'), $this->Required), new CheckboxField($this->getFieldName('Required'), _t('EditableFormField.REQUIRED', 'Is this field Required?'), $this->Required),
new TextField($this->getFieldName('CustomErrorMessage'), _t('EditableFormField.CUSTOMERROR','Custom Error Message'), $this->CustomErrorMessage) new TextField($this->getFieldName('CustomErrorMessage'), _t('EditableFormField.CUSTOMERROR','Custom Error Message'), $this->CustomErrorMessage)
); );

View File

@ -14,7 +14,7 @@ class EditableLiteralField extends EditableFormField {
static $plural_name = 'HTML Blocks'; static $plural_name = 'HTML Blocks';
function getFieldConfiguration() { function getFieldConfiguration() {
return new FieldSet( return new FieldList(
new TextareaField( new TextareaField(
$this->getSettingName('Content'), $this->getSettingName('Content'),
"HTML", 4, 20, $this->getSetting('Content') "HTML", 4, 20, $this->getSetting('Content')

View File

@ -17,7 +17,7 @@ class EditableMemberListField extends EditableFormField {
if($groups) $groups = $groups->toDropdownMap('ID', 'Title'); if($groups) $groups = $groups->toDropdownMap('ID', 'Title');
$fields = new FieldSet( $fields = new FieldList(
new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID) new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID)
); );

View File

@ -21,7 +21,7 @@ class EditableTextField extends EditableFormField {
$rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1'; $rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
$extraFields = new FieldSet( $extraFields = new FieldList(
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'), new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
new TextField($this->getSettingName('MinLength'), "", $min), new TextField($this->getSettingName('MinLength'), "", $min),
new TextField($this->getSettingName('MaxLength'), " - ", $max) new TextField($this->getSettingName('MaxLength'), " - ", $max)

View File

@ -2,9 +2,9 @@
<li class="$ClassName EditableFormField" id="$Name.ATT EditableItem_$Pos $Name"> <li class="$ClassName EditableFormField" id="$Name.ATT EditableItem_$Pos $Name">
<div class="fieldInfo"> <div class="fieldInfo">
<% if canEdit %> <% if canEdit %>
<img class="fieldHandler" src="sapphire/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of fields') %>" /> <img class="fieldHandler" src="framework/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of fields') %>" />
<% else %> <% else %>
<img class="fieldHandler" src="sapphire/images/drag_readonly.gif" alt="<% _t('LOCKED', 'These fields cannot be modified') %>" /> <img class="fieldHandler" src="framework/images/drag_readonly.gif" alt="<% _t('LOCKED', 'These fields cannot be modified') %>" />
<% end_if %> <% end_if %>
<img class="icon" src="$Icon" alt="$ClassName" title="$singular_name" /> <img class="icon" src="$Icon" alt="$ClassName" title="$singular_name" />

View File

@ -1,5 +1,5 @@
<li> <li>
<img class="handle" src="sapphire/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of options') %>" /> <img class="handle" src="framework/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of options') %>" />
<input type="text" name="{$FieldName}[Title]" value="$Title" /> <input type="text" name="{$FieldName}[Title]" value="$Title" />
<input type="hidden" class="sortOptionHidden hidden" name="{$FieldName}[Sort]" value="$Sort" /> <input type="hidden" class="sortOptionHidden hidden" name="{$FieldName}[Sort]" value="$Sort" />

View File

@ -1,6 +1,5 @@
<% require css(userforms/css/FieldEditor.css) %> <% require css(userforms/css/FieldEditor.css) %>
<% require javascript(sapphire/thirdparty/jquery-ui/jquery-ui.custom.js) %> <% require javascript(framework/thirdparty/jquery-ui/jquery-ui.js) %>
<% require javascript(sapphire/thirdparty/jquery-ui/jquery-ui-1.8rc3.custom.js) %>
<% require javascript(userforms/javascript/UserForm.js) %> <% require javascript(userforms/javascript/UserForm.js) %>
<div class="FieldEditor <% if canEdit %><% else %>readonly<% end_if %>" id="Fields"> <div class="FieldEditor <% if canEdit %><% else %>readonly<% end_if %>" id="Fields">

View File

@ -41,6 +41,6 @@ class FieldEditorTest extends FunctionalTest {
class FieldEditorTest_Controller extends Controller { class FieldEditorTest_Controller extends Controller {
function Form() { function Form() {
return new Form($this, 'Form', new FieldSet(new FieldEditor('Fields')), new FieldSet()); return new Form($this, 'Form', new FieldList(new FieldEditor('Fields')), new FieldList());
} }
} }

View File

@ -144,7 +144,7 @@ class SubmittedFormTest extends FunctionalTest {
class SubmittedFormTest_Controller extends ContentController { class SubmittedFormTest_Controller extends ContentController {
function Form() { function Form() {
$form = new Form($this, 'Form', new FieldSet(new SubmittedFormReportField('Report')), new FieldSet(new FormAction('Submit'))); $form = new Form($this, 'Form', new FieldList(new SubmittedFormReportField('Report')), new FieldList(new FormAction('Submit')));
$form->loadDataFrom($this->data()); $form->loadDataFrom($this->data());

View File

@ -129,7 +129,7 @@ class UserDefinedFormControllerTest extends FunctionalTest {
$actions = $controller->getFormActions(); $actions = $controller->getFormActions();
// by default will have 1 submit button which links to process // by default will have 1 submit button which links to process
$expected = new FieldSet(new FormAction('process', 'Submit')); $expected = new FieldList(new FormAction('process', 'Submit'));
$this->assertEquals($actions, $expected); $this->assertEquals($actions, $expected);
@ -139,7 +139,7 @@ class UserDefinedFormControllerTest extends FunctionalTest {
$actions = $controller->getFormActions(); $actions = $controller->getFormActions();
$expected = new FieldSet(new FormAction('process', 'Custom Button')); $expected = new FieldList(new FormAction('process', 'Custom Button'));
$expected->push(new ResetFormAction("clearForm")); $expected->push(new ResetFormAction("clearForm"));
$this->assertEquals($actions, $expected); $this->assertEquals($actions, $expected);

View File

@ -56,7 +56,7 @@ class UserDefinedFormTest extends FunctionalTest {
$popup = new UserDefinedForm_EmailRecipient(); $popup = new UserDefinedForm_EmailRecipient();
$fields = $popup->getCMSFields_forPopup(); $fields = $popup->getCMSFields();
$this->assertTrue($fields->dataFieldByName('EmailSubject') !== null); $this->assertTrue($fields->dataFieldByName('EmailSubject') !== null);
$this->assertTrue($fields->dataFieldByName('EmailFrom') !== null); $this->assertTrue($fields->dataFieldByName('EmailFrom') !== null);
@ -72,14 +72,14 @@ class UserDefinedFormTest extends FunctionalTest {
$popup->FormID = $form->ID; $popup->FormID = $form->ID;
$popup->write(); $popup->write();
$fields = $popup->getCMSFields_forPopup(); $fields = $popup->getCMSFields();
$this->assertThat($fields->fieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField')); $this->assertThat($fields->fieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField'));
// if the front end has checkboxs or dropdown they can select from that can also be used to send things // if the front end has checkboxs or dropdown they can select from that can also be used to send things
$dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown'); $dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
$form->Fields()->add($dropdown); $form->Fields()->add($dropdown);
$fields = $popup->getCMSFields_forPopup(); $fields = $popup->getCMSFields();
$this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null); $this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null);
$popup->delete(); $popup->delete();