{% set headers = _args.headers %}
{% set contacts = _args.contacts %}
{% set routes_enable = _args.routes_enable %}
{% set routes_primary = _args.routes_primary %}
{% set routes_secondary = _args.routes_secondary %}
{% set routes_edit = _args.routes_edit|default(null) %}
{% set routes_add_phone = _args.routes_add_phone|default(null) %}
{% set routes_add_email = _args.routes_add_email|default(null) %}
{% set permissions = (_args.permissions is defined) ? (_args.permissions is same as(true)) : true %}
<table class="prefgrid" id="prefs">
<tbody>
<tr>
<th>Notifications</th>
{% for header in headers %}
<th>
<span class="d-flex align-items-center">
{% if header.badge|default(null) %}
<i class="{{ header.badge }}"></i>
{% endif %}
{{ header.title }}
{% if header.tooltip|default(null) %}
{% set tkn = token() %}
<div
id="tooltip-{{ tkn }}"
data-toggle="popover"
data-container="#tooltip-{{ tkn }}"
data-placement="top"
data-delay="{"show": 0, "hide": 250}"
data-trigger="hover focus"
data-html="true"
data-content="{{- header.tooltip|e('html_attr') -}}"
>
<span
class="badge badge--right badge--sphere text-extrabold"
>?</span>
</div>
{% endif %}
</span>
</th>
{% endfor %}
</tr>
{% for contact in contacts %}
<tr class="prefgrid__card{% if not contact.enabled %} prefgrid__card--disabled{% endif %}">
<td>
<span class="prefgrid__group">
<span class="custom-control custom-checkbox">
<input
type="checkbox"
class="custom-control-input"
id="enabled_{{ contact.id }}"
{% if permissions and not is_granted('app.notifications.contacts.admin') %}disabled{% endif %}
{% if contact.enabled %}checked{% endif %}
data-trigger="toggler"
data-toggler-url="{{ path(routes_enable, {
contact: contact.id,
}) }}"
/>
<label class="custom-control-label" for="enabled_{{ contact.id }}"></label>
</span>
<span class="prefgrid__control">
<i class="icon-{{ first_of({
'activity-voice': contact.isPhone,
'activity-mail': contact.isEmail,
'deviceapp': contact.isApp,
}) }}"></i>
<span>
{% set hasTooltip =
contact.recipient.discr is defined and
contact.recipient.discr == 'phone' and
contact.recipient.lookup['carrier']['name'] is defined and
contact.recipient.lookup['carrier']['name'] is not empty
%}
{% if hasTooltip %}
{% set tooltipId = token() %}
<div
id="tooltip-{{ tooltipId }}"
data-toggle="popover"
data-container="#tooltip-{{ tooltipId }}"
data-placement="top"
data-delay="{"show": 0, "hide": 250}"
data-trigger="hover focus"
data-html="true"
data-content="Carrier: {{ contact.recipient.lookup['carrier']['name']|capitalize }}"
>
<span class="weglot-skip">{{- contact.recipient|recipient_format }}</span>
</div>
{% else %}
<span class="weglot-skip">{{- contact.recipient|recipient_format }}</span>
{% endif %}
{% if routes_edit and not contact.isApp %}
<a href="{{- path(routes_edit, {
contact: contact.id,
}) -}}">(edit)</a>
{% endif %}
</span>
</span>
</span>
</td>
<td>
<span class="prefgrid__group">
<span class="prefgrid__colLab">Urgent messages</span>
{% if contact.isPhone %}
<label data-subscribe="on" class="wide__switch wide__switch-sm">
<input
type="checkbox"
class="wide__switchcheckbox"
id="urgent_{{ contact.id }}"
{% if permissions and (not contact.enabled or not is_granted('app.notifications.contacts.admin')) %}disabled{% endif %}
{% if contact.hasPrimaryPreference(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__SMS')) %}checked{% endif %}
data-trigger="toggler"
data-toggler-url="{{ path(routes_primary, {
contact: contact.id,
}) }}"
data-toggler-payload="{{- {
preference: constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__SMS'),
}|json_encode|e('html_attr') -}}"
/>
<span class="wide__switchhiglight"></span>
<span class="wide__switchtab wide__switchone">Voice</span>
<span class="wide__switchtab wide__switchtwo">Text</span>
</label>
{% else %}
<div class="custom-control custom-control--nolabel custom-switch">
<input
type="checkbox"
class="custom-control-input"
id="urgent_{{ contact.id }}"
{% if permissions and (not contact.enabled or not is_granted('app.notifications.contacts.admin')) %}disabled{% endif %}
{% if contact.hasPrimaryPreference(first_of({
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__EMAIL')): contact.isEmail,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__APP')): contact.isApp,
})) %}checked{% endif %}
data-trigger="toggler"
data-toggler-url="{{ path(routes_primary, {
contact: contact.id,
}) }}"
data-toggler-payload="{{- {
preference: first_of({
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__EMAIL')): contact.isEmail,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__APP')): contact.isApp,
}),
}|json_encode|e('html_attr') -}}"
/>
<label class="custom-control-label" for="urgent_{{ contact.id }}"></label>
</div>
{% endif %}
</span>
</td>
<td>
<span class="prefgrid__group">
<span class="prefgrid__colLab">General messages</span>
<div class="custom-control custom-control--nolabel custom-switch">
<input
type="checkbox"
class="custom-control-input"
id="general_{{ contact.id }}"
{% if permissions and (not contact.enabled or not is_granted('app.notifications.contacts.admin')) %}disabled{% endif %}
{% if contact.hasSecondaryPreference(first_of({
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__SMS')): contact.isPhone,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__EMAIL')): contact.isEmail,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCES__APP')): contact.isApp,
})) %}checked{% endif %}
data-trigger="toggler"
data-toggler-url="{{ path(routes_secondary, {
contact: contact.id,
}) }}"
data-toggler-payload="{{- {
preference: first_of({
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__SMS')): contact.isPhone,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__EMAIL')): contact.isEmail,
(constant('Products\\NotificationsBundle\\Util\\Preferences::PREFERENCE__APP')): contact.isApp,
}),
}|json_encode|e('html_attr') -}}"
/>
<label class="custom-control-label" for="general_{{ contact.id }}"></label>
</div>
</span>
</td>
</tr>
{% endfor %}
{% if routes_add_email %}
<tr class="prefgrid__card prefgrid__card--disabled">
<td colspan="4">
<span class="prefgrid__group">
<span class="custom-control custom-checkbox invisible">
<input type="checkbox" class="custom-control-input" id="prefs__add">
<label class="custom-control-label" for="prefs__add"></label>
</span>
<span class="prefgrid__control prefgrid__addphone">
<i class="icon-activity-mail"></i>
<span>
<a href="{{ path(routes_add_email) }}">+ Add additional email</a>
</span>
</span>
</span>
</td>
</tr>
{% endif %}
{% if routes_add_phone %}
<tr class="prefgrid__card prefgrid__card--disabled">
<td colspan="4">
<span class="prefgrid__group">
<span class="custom-control custom-checkbox invisible">
<input type="checkbox" class="custom-control-input" id="prefs__add">
<label class="custom-control-label" for="prefs__add"></label>
</span>
<span class="prefgrid__control prefgrid__addphone">
<i class="icon-activity-voice"></i>
<span>
<a href="{{ path(routes_add_phone) }}">+ Add additional number</a>
</span>
</span>
</span>
</td>
</tr>
{% endif %}
</tbody>
</table>
<script type="text/javascript">
(function (window, document, $, undefined) {
$(function () {
$('#prefs')
.on('always.toggler', '[id^="enabled_"]', function (e, data) {
var $target = $(e.currentTarget);
$target
.closest('tr')
.toggleClass('prefgrid__card--disabled', ( ! data.value))
.find('input')
.not($target)
.attr('disabled', ( ! data.value))
;
})
;
$('[data-toggle="popover"]').popover();
});
})(window, document, jQuery);
</script>