make partials source-agnostic

they're currently expecting a RecipientsCSV object - but we won't
always have that available if we're handling a single notification.

So make the partials take generic variables, and then use a jinja with
block to pass in the correct values from either the check csv page or
the check notification page.

Additionally set the notification check page to show errors nicely -
hide the send button if there were problems, and replace the header
This commit is contained in:
Leo Hemsted
2017-06-29 15:33:31 +01:00
parent 70914bfe8a
commit 42e33ce9e6
4 changed files with 42 additions and 17 deletions

View File

@@ -4,7 +4,8 @@
Message too long
</h1>
<p>
Text messages cant be longer than {{ template|string|length }} characters. Your message is {{message_length}} characters.
Text messages cant be longer than {{ SMS_CHAR_COUNT_LIMIT }} characters.
Your message is {{ template.content_count }} characters.
</p>
{% endcall %}
</div>

View File

@@ -1,11 +1,19 @@
{% from "components/banner.html" import banner_wrapper %}
{% macro skip_to_file_contents() %}
<p class="visually-hidden">
<a href="#{{ file_contents_header_id }}">Skip to file contents</a>
</p>
{% endmacro %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
<h1 class='banner-title'>
You cant send to
{{ 'this' if count_of_recipients == 1 else 'these' }}
{{ recipients.recipient_column_headers[0] }}
{{ template_type_label }}
{%- if count_of_recipients != 1 -%}
{{ 'es' if 'email address' == recipients.recipient_column_headers[0] else 's' }}
{{ 'es' if 'email address' == template_type_label else 's' }}
{%- endif %}
</h1>
<p>

View File

@@ -120,7 +120,12 @@
</div>
{% elif not recipients.allowed_to_send_to %}
{% include "partials/check/not-allowed-to-send-to.html" %}
{% with
count_of_recipients=count_of_recipients,
template_type_label=recipients.recipient_column_headers[0]
%}
{% include "partials/check/not-allowed-to-send-to.html" %}
{% endwith %}
{% elif recipients.more_rows_than_can_send %}
{% include "partials/check/too-many-messages.html" %}
{% else %}

View File

@@ -1,20 +1,29 @@
{% extends "withnav_template.html" %}
<!-- {% from "components/banner.html" import banner_wrapper %} -->
<!-- {% from "components/table.html" import list_table, field, text_field, index_field, hidden_field_heading %} -->
<!-- {% from "components/file-upload.html" import file_upload %} -->
<!-- {% from "components/page-footer.html" import page_footer %} -->
{% from "components/radios.html" import radio_select %}
{% from "components/message-count-label.html" import message_count_label %}
{% block service_page_title %}
{{ "Error" if errors else "Preview" }}
{{ "Error" if error else "Preview" }}
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
Preview of {{ template.name }}
</h1>
{% if error == 'not-allowed-to-send-to' %}
{% with
count_of_recipients=1,
template_type_label='phone number'
%}
{% include "partials/check/not-allowed-to-send-to.html" %}
{% endwith %}
{% elif error == 'more_rows_than_can_send' %}
{% include "partials/check/too-many-messages.html" %}
{% elif error == 'row_errors' %}
{# the only row_errors we can get when sending one off messages is that the message is too long #}
{% include "partials/check/message-too-long.html" %}
{% else %}
<h1 class="heading-large">
Preview of {{ template.name }}
</h1>
{% endif %}
{{ template|string }}
@@ -22,10 +31,12 @@
<form method="post" enctype="multipart/form-data" action="{{url_for('main.send_notification', service_id=current_service.id, template_id=template.id)}}" class='page-footer'>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="help" value="{{ '3' if help else 0 }}" />
{% if template.template_type != 'letter' or not request.args.from_test %}
<input type="submit" class="button" value="Send 1 {{ message_count_label(1, template.template_type, suffix='') }}" />
{% else %}
<a href="{{ url_for('main.check_messages_preview', service_id=current_service.id, template_type=template.template_type, upload_id=upload_id, filetype='pdf') }}" download="download" class="button">Download as a printable PDF</a>
{% if not error %}
{% if template.template_type != 'letter' or not request.args.from_test %}
<input type="submit" class="button" value="Send 1 {{ message_count_label(1, template.template_type, suffix='') }}" />
{% else %}
<a href="{{ url_for('main.check_messages_preview', service_id=current_service.id, template_type=template.template_type, upload_id=upload_id, filetype='pdf') }}" download="download" class="button">Download as a printable PDF</a>
{% endif %}
{% endif %}
<a href="{{ back_link }}" class="page-footer-back-link">Back</a>
</form>