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 %}
{%- endmacro %}
{% macro optional_text_field(text, default=None) -%}
{{ text_field(
text or default,
status='' if text else 'default'
) }}
{%- endmacro %}
{% macro link_field(text, link) -%}
{% call field() %}
<a href="{{ link }}">{{ text }}</a>

View File

@@ -1,7 +1,7 @@
{% extends "withnav_template.html" %}
{% from "components/banner.html" import banner_wrapper %}
{% 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 %}
Settings
@@ -90,7 +90,7 @@
{% 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)) }}
{% else %}
{{ text_field('') }}
{{ text_field('') }}
{% endif %}
{% endcall %}
@@ -110,10 +110,7 @@
{% if can_receive_inbound %}
{% call row() %}
{{ text_field('API endpoint for received text messages') }}
{{ text_field(
'None' if not inbound_api_url else inbound_api_url,
status='' if inbound_api_url else 'default'
) }}
{{ optional_text_field(inbound_api_url) }}
{{ edit_field('Change', url_for('.service_set_inbound_api', service_id=current_service.id)) }}
{% endcall %}
{% endif %}
@@ -193,9 +190,8 @@
) %}
{% call row() %}
{{ text_field('Organisation type')}}
{{ text_field(
current_service.organisation_type|title or 'Not set',
status='' if current_service.organisation_type else 'default'
{{ optional_text_field(
(current_service.organisation_type or '')|title
) }}
{{ text_field() }}
{% endcall %}