templates/bundles/SgDatatablesBundle/render/action.html.twig line 1

Open in your IDE?
  1. {# #
  2.  # This file is part of the SgDatatablesBundle package.
  3.  #
  4.  # (c) stwe <https://github.com/stwe/DatatablesBundle>
  5.  #
  6.  # For the full copyright and license information, please view the LICENSE
  7.  # file that was distributed with this source code.
  8. #}
  9. {% import _self as macros %}
  10. {% macro link_title(action) %}
  11.     {% if action.label is same as(null) and action.icon is same as(null) %}
  12.         {% if action.route is not same as(null) %}
  13.             {{ action.route }}
  14.         {% else %}
  15.             null
  16.         {% endif %}
  17.     {% else %}
  18.     <i class="{{ action.icon }} m-r-xs"></i>{{ action.label }}
  19.     {% endif %}
  20. {% endmacro %}
  21. {% macro attributes(attributes) %}
  22.     {% for key, value in attributes %}
  23.         {{ key }}="{{ value }}"
  24.     {% endfor %}
  25. {% endmacro %}
  26. {% macro confirm_dialog(action) %}
  27.     {% if action.confirm is same as(true) %}
  28.         {% if action.confirmMessage is not same as(null) %}
  29.             onclick="return confirm('{{ action.confirmMessage }}')"
  30.         {% else %}
  31.             onclick="return confirm('{{ 'sg.datatables.confirmMessage'|trans({}, 'messages') }}')"
  32.         {% endif %}
  33.     {% endif %}
  34. {% endmacro %}
  35. {% macro href(action, route_parameters) %}
  36.     {% if action.routeParameters is not same as(null) %}
  37.         {% if app.request.locale is defined and app.request.locale is not null %}
  38.             {% if '_locale' in route_parameters|keys %}
  39.                 {% set route_parameters = route_parameters|merge({ '_locale': app.request.locale }) %}
  40.             {% endif %}
  41.         {% endif %}
  42.     {% endif %}
  43.     {% if action.route is not same as(null) %}
  44.         href="{{ path(action.route, route_parameters) }}"
  45.     {% else %}
  46.         href="javascript:void(0);"
  47.     {% endif %}
  48. {% endmacro %}
  49. {% macro value(value) %}
  50.     {% if value is not null %}
  51.         value="{{ value }}"
  52.     {% endif %}
  53. {% endmacro %}
  54. {{ start_html_container|raw }}
  55. {% if actions|length > 1 %}
  56.     <div class="d-flex">
  57.         <div class="btn-group">
  58.             {% if actions[0] %}
  59.                 <a type="button" {{ macros.href(actions[0], route_parameters[0]) }}
  60.                    class="btn btn-outline btn-primary btn-sm">{{ macros.link_title(actions[0]) }}
  61.                 </a>
  62.             {% endif %}
  63.             <button type="button" class="btn btn-outline btn-primary btn-sm dropdown-toggle dropdown-toggle-split"
  64.                     data-toggle="dropdown" aria-expanded="false" data-reference="parent">
  65.                 <span class="sr-only">Toggle Dropdown</span>
  66.             </button>
  67.             <div class="dropdown-menu" x-placement="bottom-start">
  68.                 {% for actionKey, action in actions %}
  69.                     {% if not loop.first and render_if_actions[actionKey] is same as(true) %}
  70.                         {{ action.startHtml|raw }}
  71.                         <a class="dropdown-item" {{ macros.href(action, route_parameters[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}>
  72.                             {{ macros.link_title(action) }}
  73.                         </a>
  74.                         {{ action.endHtml|raw }}
  75.                     {% endif %}
  76.                 {% endfor %}
  77.             </div>
  78.         </div>
  79.     </div>
  80. {% else %}
  81.     {% for actionKey, action in actions %}
  82.         {% if render_if_actions[actionKey] is same as(true) %}
  83.             {{ action.startHtml|raw }}
  84.             <a type="button" {{ macros.href(action, route_parameters[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}
  85.                class="btn btn-outline btn-primary btn-sm">{{ macros.link_title(action) }}
  86.             </a>
  87.             {{ action.endHtml|raw }}
  88.         {% endif %}
  89.     {% endfor %}
  90. {% endif %}
  91. {# {% for actionKey, action in actions %} #}
  92. {#    {% if render_if_actions[actionKey] is same as(true) %} #}
  93. {#        {% if action.button is same as(false) %} #}
  94. {#            {{ action.startHtml|raw }} #}
  95. {#            <a {{ macros.href(action, route_parameters[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}> #}
  96. {#                {{ macros.link_title(action) }} #}
  97. {#            </a> #}
  98. {#            {{ action.endHtml|raw }} #}
  99. {#        {% else %} #}
  100. {#            {{ action.startHtml|raw }} #}
  101. {#            <button #}
  102. {#                type="button" {{ macros.value(values[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}> #}
  103. {#                {{ macros.link_title(action) }} #}
  104. {#            </button> #}
  105. {#            {{ action.endHtml|raw }} #}
  106. {#        {% endif %} #}
  107. {#    {% endif %} #}
  108. {# {% endfor %} #}
  109. {{ end_html_container|raw }}