From 84a1baa2f1a2899ff4dfb3756cf56ba6d07f114d Mon Sep 17 00:00:00 2001 From: midori Date: Thu, 30 Jan 2014 00:52:37 +0200 Subject: [PATCH 1/3] Ticket #6329 Update send email screen --- Admin/EmailSendAdmin.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Admin/EmailSendAdmin.php b/Admin/EmailSendAdmin.php index 52efe6d..3fa3eb5 100644 --- a/Admin/EmailSendAdmin.php +++ b/Admin/EmailSendAdmin.php @@ -32,6 +32,17 @@ public function getManager() return $this->manager; } + /** + * {@inheritdoc} + */ + public function getNewInstance() + { + $email = parent::getNewInstance(); + // show current date based on user timezone + $email->setSendDate(new \DateTime()); + return $email; + } + /** * {@inheritdoc} */ @@ -58,9 +69,6 @@ protected function configureFormFields(FormMapper $formMapper) 'expanded' => false, 'required' => false, )) - ->add('isHtmlContent', 'checkbox', array( - 'required' => false - )) ->add('sendDate', 'datetime', array( 'required' => false, 'date_widget' => 'single_text', @@ -92,7 +100,6 @@ protected function configureShowField(ShowMapper $showMapper) ->add('title') ->add('sender') ->add('userLists') - ->add('isHtmlContent') ->add('sendDate') ->add('created') ->add('attempted') @@ -133,7 +140,6 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper) $datagridMapper ->add('title') - ->add('isHtmlContent') ->add('created', $dateType, array(), null, array( 'label' => 'Created after' )) @@ -148,7 +154,6 @@ protected function configureListFields(ListMapper $listMapper) ->add('title') ->add('sender') ->add('userLists') - ->add('isHtmlContent') ->add('sendDate') ->add('created') ->add('attempted') From 1e00935adcaa5d00f7cb160db87f5abb7dc20ae2 Mon Sep 17 00:00:00 2001 From: midori Date: Thu, 30 Jan 2014 00:59:57 +0200 Subject: [PATCH 2/3] codestyle fixes --- Admin/EmailSendAdmin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Admin/EmailSendAdmin.php b/Admin/EmailSendAdmin.php index 3fa3eb5..92149d3 100644 --- a/Admin/EmailSendAdmin.php +++ b/Admin/EmailSendAdmin.php @@ -38,8 +38,8 @@ public function getManager() public function getNewInstance() { $email = parent::getNewInstance(); - // show current date based on user timezone $email->setSendDate(new \DateTime()); + return $email; } From c1351f1e85b16583a9b5df60201e6e05db15324c Mon Sep 17 00:00:00 2001 From: midori Date: Tue, 11 Feb 2014 16:26:54 +0200 Subject: [PATCH 3/3] added validation for send date not to be in the past and send now checkbox --- Admin/EmailSendAdmin.php | 17 ++-- Form/Type/EmailSendChoiceType.php | 39 ++++++++ Form/Type/EmailSendType.php | 3 - .../views/Admin/CRUD/email_send.html.twig | 92 +++++++++++-------- Validator/Constraints/EmailSendConstraint.php | 2 + .../EmailSendConstraintValidator.php | 11 +++ 6 files changed, 110 insertions(+), 54 deletions(-) create mode 100644 Form/Type/EmailSendChoiceType.php diff --git a/Admin/EmailSendAdmin.php b/Admin/EmailSendAdmin.php index 92149d3..ba151a4 100644 --- a/Admin/EmailSendAdmin.php +++ b/Admin/EmailSendAdmin.php @@ -32,17 +32,6 @@ public function getManager() return $this->manager; } - /** - * {@inheritdoc} - */ - public function getNewInstance() - { - $email = parent::getNewInstance(); - $email->setSendDate(new \DateTime()); - - return $email; - } - /** * {@inheritdoc} */ @@ -69,6 +58,12 @@ protected function configureFormFields(FormMapper $formMapper) 'expanded' => false, 'required' => false, )) + ->add('sendImmediately', 'checkbox', array( + 'mapped' => false, + 'label' => 'Send immediately?', + 'required' => false, + 'attr' => array('class' => 'send_immediately'), + )) ->add('sendDate', 'datetime', array( 'required' => false, 'date_widget' => 'single_text', diff --git a/Form/Type/EmailSendChoiceType.php b/Form/Type/EmailSendChoiceType.php new file mode 100644 index 0000000..dbd74f3 --- /dev/null +++ b/Form/Type/EmailSendChoiceType.php @@ -0,0 +1,39 @@ +add('sender') + ->add('userLists') + ->add('sendImmediately', 'checkbox', array( + 'mapped' => false, + 'label' => 'Send immediately?', + 'required' => false, + )) + ->add('sendDate', 'datetime', array( + 'required' => false, + 'date_widget' => 'single_text', + 'time_widget' => 'choice', + )) + ->add('testEmails', 'san_emails') + ; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'emailSendChoice'; + } +} \ No newline at end of file diff --git a/Form/Type/EmailSendType.php b/Form/Type/EmailSendType.php index 7b2646b..f933d0f 100644 --- a/Form/Type/EmailSendType.php +++ b/Form/Type/EmailSendType.php @@ -16,9 +16,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('sender') ->add('userLists') - ->add('isHtmlContent', 'checkbox', array( - 'required' => false - )) ->add('sendDate', 'datetime', array( 'required' => false, 'date_widget' => 'single_text', diff --git a/Resources/views/Admin/CRUD/email_send.html.twig b/Resources/views/Admin/CRUD/email_send.html.twig index d990817..5fb4e0e 100644 --- a/Resources/views/Admin/CRUD/email_send.html.twig +++ b/Resources/views/Admin/CRUD/email_send.html.twig @@ -1,18 +1,18 @@ {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %} {% block form %} -
- {% if form.vars.errors|length > 0 %} -
- {{ form_errors(form) }} -
- {% endif %} + + {% if form.vars.errors|length > 0 %} +
+ {{ form_errors(form) }} +
+ {% endif %} - {% block sonata_pre_fieldsets %} + {% block sonata_pre_fieldsets %}
- {% endblock %} - -
- {% for name, form_group in admin.formgroups %} -
-
-
- {% if form_group.description != false %} -

{{ form_group.description|raw }}

- {% endif %} + {% endblock %} - {% for field_name in form_group.fields %} - {% if admin.formfielddescriptions[field_name] is defined %} - {{ form_row(form[field_name])}} +
+ {% for name, form_group in admin.formgroups %} +
+
+
+ {% if form_group.description != false %} +

{{ form_group.description|raw }}

{% endif %} - {% endfor %} -
-
-
- {% endfor %} -
- {% block sonata_post_fieldsets %} + {% for field_name in form_group.fields %} + {% if admin.formfielddescriptions[field_name] is defined %} + {{ form_row(form[field_name])}} + {% endif %} + {% endfor %} +
+
+
+ {% endfor %} +
+ + {% block sonata_post_fieldsets %}
- {% endblock %} + {% endblock %} - {{ form_rest(form) }} + {{ form_rest(form) }} - {% block formactions %} -
- - -
- {% endblock formactions %} -
+ {% block formactions %} +
+ + +
+ {% endblock formactions %} + {% endblock %} {% block footer %} + {{ parent() }} {% include 'SanEmailBundle:Admin/CRUD:preview_modal.html.twig' %} + {% endblock %} diff --git a/Validator/Constraints/EmailSendConstraint.php b/Validator/Constraints/EmailSendConstraint.php index c489a3d..87d0789 100644 --- a/Validator/Constraints/EmailSendConstraint.php +++ b/Validator/Constraints/EmailSendConstraint.php @@ -12,6 +12,8 @@ class EmailSendConstraint extends Constraint public $invalidUserLists = 'Please pick up at least one user list'; + public $invalidSendDate = 'Please set a send date in future'; + public function getTargets() { return self::CLASS_CONSTRAINT; diff --git a/Validator/Constraints/EmailSendConstraintValidator.php b/Validator/Constraints/EmailSendConstraintValidator.php index da13cef..9f65cd3 100644 --- a/Validator/Constraints/EmailSendConstraintValidator.php +++ b/Validator/Constraints/EmailSendConstraintValidator.php @@ -17,6 +17,17 @@ public function validate($object, Constraint $constraint) } } + if (!$object->getIsTest()) { + if ($object->getSendDate() == null) { + return; + } + if ($object->getSendDate() < new \DateTime()) { + return $this->context->addViolationAt('emailSend', $constraint->invalidSendDate); + } else { + return; + } + } + if (!$object->getTestEmails()) { return $this->context->addViolationAt('testEmails', $constraint->invalidTestSend); }