Add ‘optional text’ macro

This pattern of value or grey text saying `None` is common enough in our
app that we should codify it into a pattern. Which this commit does.
This commit is contained in:
Chris Hill-Scott
2017-10-05 11:21:00 +01:00
parent ff6b2b01dd
commit 521b5b6cf1
2 changed files with 12 additions and 9 deletions

View File

@@ -92,6 +92,13 @@
{% endcall %} {% endcall %}
{%- endmacro %} {%- endmacro %}
{% macro optional_text_field(text, default=None) -%}
{{ text_field(
text or default,
status='' if text else 'default'
) }}
{%- endmacro %}
{% macro link_field(text, link) -%} {% macro link_field(text, link) -%}
{% call field() %} {% call field() %}
<a href="{{ link }}">{{ text }}</a> <a href="{{ link }}">{{ text }}</a>

View File

@@ -1,7 +1,7 @@
{% extends "withnav_template.html" %} {% extends "withnav_template.html" %}
{% from "components/banner.html" import banner_wrapper %} {% from "components/banner.html" import banner_wrapper %}
{% from "components/browse-list.html" import browse_list %} {% from "components/browse-list.html" import browse_list %}
{% from "components/table.html" import mapping_table, row, text_field, edit_field, field, boolean_field %} {% from "components/table.html" import mapping_table, row, text_field, optional_text_field, edit_field, field, boolean_field %}
{% block service_page_title %} {% block service_page_title %}
Settings Settings
@@ -90,7 +90,7 @@
{% if (current_user.has_permissions([], admin_override=True) or not can_receive_inbound) and not can_receive_inbound %} {% if (current_user.has_permissions([], admin_override=True) or not can_receive_inbound) and not can_receive_inbound %}
{{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=False)) }} {{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=False)) }}
{% else %} {% else %}
{{ text_field('') }} {{ text_field('') }}
{% endif %} {% endif %}
{% endcall %} {% endcall %}
@@ -110,10 +110,7 @@
{% if can_receive_inbound %} {% if can_receive_inbound %}
{% call row() %} {% call row() %}
{{ text_field('API endpoint for received text messages') }} {{ text_field('API endpoint for received text messages') }}
{{ text_field( {{ optional_text_field(inbound_api_url) }}
'None' if not inbound_api_url else inbound_api_url,
status='' if inbound_api_url else 'default'
) }}
{{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }} {{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }}
{% endcall %} {% endcall %}
{% endif %} {% endif %}
@@ -193,9 +190,8 @@
) %} ) %}
{% call row() %} {% call row() %}
{{ text_field('Organisation type')}} {{ text_field('Organisation type')}}
{{ text_field( {{ optional_text_field(
current_service.organisation_type|title or 'Not set', (current_service.organisation_type or '')|title
status='' if current_service.organisation_type else 'default'
) }} ) }}
{{ text_field() }} {{ text_field() }}
{% endcall %} {% endcall %}