missing 'not', add alert-warning for unsaved form

This commit is contained in:
Andrew Aitken-Fincham 2018-02-20 14:32:14 +00:00
parent bc5c6221f0
commit e2066a55b3
3 changed files with 30 additions and 6 deletions

View File

@ -31,11 +31,13 @@ use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\Member;
use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField; use SilverStripe\UserForms\Model\EditableFormField\EditableEmailField;
use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField; use SilverStripe\UserForms\Model\EditableFormField\EditableMultipleOptionField;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField; use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\UserDefinedForm; use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\UserForm;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton; use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns; use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
@ -126,7 +128,7 @@ class EmailRecipient extends DataObject
/** /**
* Get instance of UserForm when editing in getCMSFields * Get instance of UserForm when editing in getCMSFields
* *
* @return UserDefinedForm * @return UserDefinedForm|UserForm
*/ */
protected function getFormParent() protected function getFormParent()
{ {
@ -197,6 +199,10 @@ class EmailRecipient extends DataObject
// Build fieldlist // Build fieldlist
$fields = FieldList::create(Tabset::create('Root')->addExtraClass('EmailRecipientForm')); $fields = FieldList::create(Tabset::create('Root')->addExtraClass('EmailRecipientForm'));
if (!$this->getFormParent()) {
$fields->addFieldToTab('Root.EmailDetails', $this->getUnsavedFormLiteralField());
}
// Configuration fields // Configuration fields
$fields->addFieldsToTab('Root.EmailDetails', [ $fields->addFieldsToTab('Root.EmailDetails', [
$this->getSubjectCMSFields(), $this->getSubjectCMSFields(),
@ -204,6 +210,7 @@ class EmailRecipient extends DataObject
$this->getEmailFromCMSFields(), $this->getEmailFromCMSFields(),
$this->getEmailReplyToCMSFields(), $this->getEmailReplyToCMSFields(),
]); ]);
$fields->fieldByName('Root.EmailDetails')->setTitle(_t(__CLASS__ . '.EMAILDETAILSTAB', 'Email Details')); $fields->fieldByName('Root.EmailDetails')->setTitle(_t(__CLASS__ . '.EMAILDETAILSTAB', 'Email Details'));
// Only show the preview link if the recipient has been saved. // Only show the preview link if the recipient has been saved.
@ -227,7 +234,7 @@ class EmailRecipient extends DataObject
); );
} else { } else {
$preview = sprintf( $preview = sprintf(
'<em>%s</em>', '<p class="alert alert-warning">%s</p>',
_t( _t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE', 'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE',
'You can preview this email once you have saved the Recipient.' 'You can preview this email once you have saved the Recipient.'
@ -285,8 +292,10 @@ class EmailRecipient extends DataObject
); );
$grid->setDescription(_t( $grid->setDescription(_t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.RulesDescription', 'SilverStripe\\UserForms\\Model\\UserDefinedForm.RulesDescription',
'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.' 'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, '
. 'this recipient will receive notifications for every submission.'
)); ));
$fields->addFieldsToTab('Root.CustomRules', [ $fields->addFieldsToTab('Root.CustomRules', [
DropdownField::create( DropdownField::create(
'CustomRulesCondition', 'CustomRulesCondition',
@ -688,7 +697,7 @@ class EmailRecipient extends DataObject
*/ */
protected function getValidEmailToFields() protected function getValidEmailToFields()
{ {
if ($this->getFormParent()) { if (!$this->getFormParent()) {
return null; return null;
} }
@ -703,4 +712,18 @@ class EmailRecipient extends DataObject
return $this->getMultiOptionFields(); return $this->getMultiOptionFields();
} }
} }
protected function getUnsavedFormLiteralField()
{
return LiteralField::create(
'UnsavedFormMessage',
sprintf(
'<p class="alert alert-warning">%s</p>',
_t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAIL_RECIPIENT_UNSAVED_FORM',
'You will be able to select from valid form fields after saving this record.'
)
)
);
}
} }

View File

@ -221,6 +221,7 @@ en:
EMAILBODYHTML: Body EMAILBODYHTML: Body
EMAILFROM: From EMAILFROM: From
EMAILRECIPIENTS: 'Email Recipients' EMAILRECIPIENTS: 'Email Recipients'
EMAIL_RECIPIENT_UNSAVED_FORM: 'You will be able to select from valid form fields after saving this record.'
EMAILSUBJECT: 'Email subject' EMAILSUBJECT: 'Email subject'
EMAILTEMPLATE: 'Email template' EMAILTEMPLATE: 'Email template'
ENABLELIVEVALIDATION: 'Enable live validation' ENABLELIVEVALIDATION: 'Enable live validation'

View File

@ -130,7 +130,7 @@ class UserDefinedFormTest extends FunctionalTest
$fields = $popup->getCMSFields(); $fields = $popup->getCMSFields();
$this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf(DropdownField::class)); $this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf(DropdownField::class));
// 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 checkboxes or dropdown they can select from that can also be used to send things
$dropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown'); $dropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown');
$form->Fields()->add($dropdown); $form->Fields()->add($dropdown);