Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket #6329 Update send email screen #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Admin/EmailSendAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ protected function configureFormFields(FormMapper $formMapper)
'expanded' => false,
'required' => false,
))
->add('isHtmlContent', 'checkbox', array(
'required' => false
->add('sendImmediately', 'checkbox', array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe all emails by default will be sent immediately, except when you set schedule date

'mapped' => false,
'label' => 'Send immediately?',
'required' => false,
'attr' => array('class' => 'send_immediately'),
))
->add('sendDate', 'datetime', array(
'required' => false,
Expand Down Expand Up @@ -92,7 +95,6 @@ protected function configureShowField(ShowMapper $showMapper)
->add('title')
->add('sender')
->add('userLists')
->add('isHtmlContent')
->add('sendDate')
->add('created')
->add('attempted')
Expand Down Expand Up @@ -135,7 +137,6 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper)

$datagridMapper
->add('title')
->add('isHtmlContent')
->add('created', $dateType, array(), null, array(
'label' => 'Created after'
))
Expand All @@ -150,7 +151,6 @@ protected function configureListFields(ListMapper $listMapper)
->add('title')
->add('sender')
->add('userLists')
->add('isHtmlContent')
->add('sendDate')
->add('created')
->add('attempted')
Expand Down
39 changes: 39 additions & 0 deletions Form/Type/EmailSendChoiceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace San\EmailBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class EmailSendChoiceType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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';
}
}
3 changes: 0 additions & 3 deletions Form/Type/EmailSendType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
94 changes: 53 additions & 41 deletions Resources/views/Admin/CRUD/email_send.html.twig
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}

{% block form %}
<form class="form-horizontal"
action="{{ admin.generateUrl('createSend', {'id': emailId, 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}" {{ form_enctype(form) }}
method="POST"
{% if not admin_pool.getOption('html5_validate') %}novalidate="novalidate"{% endif %}
>
{% if form.vars.errors|length > 0 %}
<div class="sonata-ba-form-error">
{{ form_errors(form) }}
</div>
{% endif %}

{% block sonata_pre_fieldsets %}
<form class="form-horizontal"
action="{{ admin.generateUrl('create', {'id': emailId, 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}" {{ form_enctype(form) }}
method="POST"
{% if not admin_pool.getOption('html5_validate') %}novalidate="novalidate"{% endif %}
>
{% if form.vars.errors|length > 0 %}
<div class="sonata-ba-form-error">
{{ form_errors(form) }}
</div>
{% endif %}
{% block sonata_pre_fieldsets %}
<div class="tabbable">
<ul class="nav nav-tabs">
{% for name, form_group in admin.formgroups %}
Expand All @@ -24,44 +24,56 @@
</li>
{% endfor %}
</ul>
{% endblock %}

<div class="tab-content">
{% for name, form_group in admin.formgroups %}
<div class="tab-pane {% if loop.first %} active{% endif %}" id="{{ admin.uniqid }}_{{ loop.index }}">
<fieldset>
<div class="sonata-ba-collapsed-fields">
{% if form_group.description != false %}
<p>{{ form_group.description|raw }}</p>
{% endif %}
{% endblock %}

{% for field_name in form_group.fields %}
{% if admin.formfielddescriptions[field_name] is defined %}
{{ form_row(form[field_name])}}
<div class="tab-content">
{% for name, form_group in admin.formgroups %}
<div class="tab-pane {% if loop.first %} active{% endif %}" id="{{ admin.uniqid }}_{{ loop.index }}">
<fieldset>
<div class="sonata-ba-collapsed-fields">
{% if form_group.description != false %}
<p>{{ form_group.description|raw }}</p>
{% endif %}
{% endfor %}
</div>
</fieldset>
</div>
{% endfor %}
</div>

{% 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 %}
</div>
</fieldset>
</div>
{% endfor %}
</div>

{% block sonata_post_fieldsets %}
</div>
{% endblock %}
{% endblock %}

{{ form_rest(form) }}
{{ form_rest(form) }}

{% block formactions %}
<div class="well well-small form-actions">
<input type="submit" class="btn btn-primary" name="btn_create_and_list" value="Send"/>
<input type="submit" class="btn" name="btn_test" value="Send a test"/>
</div>
{% endblock formactions %}
</form>
{% block formactions %}
<div class="well well-small form-actions">
<input type="submit" class="btn btn-primary" name="btn_create_and_list" value="Send"/>
<input type="submit" class="btn" name="btn_test" value="Send a test"/>
</div>
{% endblock formactions %}
</form>
{% endblock %}

{% block footer %}
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.send_immediately').on('change', function () {
if($('.send_immediately').is(':checked')){
$('.hasDatepicker, span.time select').attr('disabled', 'disabled');
} else{
$('.hasDatepicker, span.time select').removeAttr('disabled', 'disabled');
}
})
});
</script>
{{ parent() }}
{% include 'SanEmailBundle:Admin/CRUD:preview_modal.html.twig' %}

{% endblock %}
2 changes: 2 additions & 0 deletions Validator/Constraints/EmailSendConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions Validator/Constraints/EmailSendConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public function validate($object, Constraint $constraint)

return;
}
if (!$object->getIsTest()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check it, at this point $object->getIsTest() == false

if ($object->getSendDate() == null) {
return;
}
if ($object->getSendDate() < new \DateTime()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of this if..else, it will never reach line 39

return $this->context->addViolationAt('emailSend', $constraint->invalidSendDate);
} else {
return;
}
}

if ($object->getUserLists()->count() == 0) {
return $this->context->addViolationAt('userLists', $constraint->invalidUserLists);
Expand Down