list.html.twig 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. {% extends "forms/field.html.twig" %}
  2. {% set value = (value is null ? field.default : value) %}
  3. {% set name = field.name %}
  4. {% set btnLabel = field.btnLabel is defined ? field.btnLabel : "PLUGIN_ADMIN.ADD_ITEM" %}
  5. {% set btnSortLabel = field.btnSortLabel is defined ? field.btnSortLabel : "PLUGIN_ADMIN.SORT_BY" %}
  6. {% set fieldControls = field.controls|default('bottom') %}
  7. {% block contents %}
  8. <div class="form-label{% if not vertical %} block size-1-3 pure-u-1-3{% endif %}">
  9. {% if field.toggleable %}
  10. <span class="checkboxes toggleable" data-grav-field="toggleable" data-grav-field-name="{{ (scope ~ field.name)|fieldName }}">
  11. <input type="checkbox"
  12. id="toggleable_{{ field.name }}"
  13. {% if toggleableChecked %}value="1"{% endif %}
  14. name="toggleable_{{ (scope ~ field.name)|fieldName }}"
  15. {% if toggleableChecked %}checked="checked"{% endif %}
  16. >
  17. <label for="toggleable_{{ field.name }}"></label>
  18. </span>
  19. {% endif %}
  20. <label{{ (field.toggleable ? ' class="toggleable" for="toggleable_' ~ field.name ~ '"')|raw }}>
  21. {% if field.help %}
  22. <span class="hint--bottom" data-hint="{{ field.help|e|tu }}">{{ field.label|tu }}</span>
  23. {% else %}
  24. {{ field.label|tu }}
  25. {% endif %}
  26. {{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
  27. </label>
  28. </div>
  29. <div class="form-data{% if not vertical %} block size-2-3 pure-u-2-3{% endif %}"
  30. {% block global_attributes %}
  31. data-grav-field="{{ field.type }}"
  32. data-grav-disabled="{{ toggleableChecked }}"
  33. data-grav-default="{{ field.default|json_encode|e('html_attr') }}"
  34. {% endblock %}
  35. >
  36. <div class="form-list-wrapper {{ field.size }}" data-type="collection"
  37. {% if field.selectunique %}
  38. data-select-unique="{{ field.selectunique|json_encode|e('html_attr') }}"
  39. data-max="{{ field.selectunique|length }}"
  40. {% endif %}
  41. {% if field.min is defined %}data-min="{{ field.min }}"{% endif %}
  42. {% if field.max is defined and not field.selectunique %}data-max="{{ field.max }}"{% endif %}
  43. >
  44. {% if fieldControls in ['top', 'both'] %}
  45. <div class="collection-actions{{ not value|length ? ' hidden' : '' }}">
  46. <button class="button" type="button" data-action="expand_all"
  47. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-chevron-circle-down"></i> {{ "PLUGIN_ADMIN.EXPAND_ALL"|e|tu }}</button>
  48. <button class="button" type="button" data-action="collapse_all"
  49. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-chevron-circle-right"></i> {{ "PLUGIN_ADMIN.COLLAPSE_ALL"|e|tu }}</button>
  50. {% if field.sortby %}
  51. <button class="button{{ not value|length ? ' hidden' : '' }}" type="button" data-action="sort" data-action-sort="{{ field.sortby }}" data-action-sort-dir="{{ field.sortby_dir|default('asc') }}"
  52. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-sort-amount-{{ field.sortby_dir|default('asc') }}"></i> {{ btnSortLabel|e|tu }} '{{ field.sortby }}'</button>
  53. {% endif %}
  54. <button class="button" type="button" data-action="add" data-action-add="top"
  55. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-plus"></i> {{ btnLabel|e|tu }}</button>
  56. </div>
  57. {% endif %}
  58. <ul {% if field.classes is defined %}class="{{ field.classes }}"{% endif %} data-collection-holder="{{ name }}"
  59. {% if field.sort is same as(false) %}
  60. data-collection-nosort
  61. {% endif %}>
  62. {% if field.fields %}
  63. {% set collapsible = field.fields|length > 1 and (field.collapsible is not defined or field.collapsible) %}
  64. {% for key, val in value %}
  65. {% set itemName = name ? name ~ '.' ~ key : key %}
  66. <li data-collection-item="{{ itemName }}" data-collection-key="{{ key }}" class="{{ collapsible and field.collapsed ? 'collection-collapsed' : '' }}">
  67. <div class="collection-sort"><i class="fa fa-fw fa-bars"></i></div>
  68. {% for childName, child in field.fields %}
  69. {%- if childName == 'value' -%}
  70. {% set childKey = '' %}
  71. {% set childValue = val %}
  72. {% set childName = itemName -%}
  73. {%- elseif childName starts with '.' -%}
  74. {% set childKey = childName|trim('.') %}
  75. {% set childValue = val[childName[1:]] %}
  76. {% set childName = itemName ~ childName %}
  77. {% else %}
  78. {% set childKey = childName %}
  79. {% set childValue = data.value(scope ~ childName) %}
  80. {% set childName = childName|replace({'*': key}) %}
  81. {% endif %}
  82. {% set child = child|merge({ name: childName }) %}
  83. {% if child.type == 'key' %}
  84. {%
  85. include 'forms/fields/key/key.html.twig'
  86. with { field: child, value: key }
  87. %}
  88. {% elseif child.key == true %}
  89. {% include [
  90. "forms/fields/#{child.type}/#{child.type}.html.twig",
  91. 'forms/fields/key/key.html.twig'
  92. ] with { field: child, value: key }
  93. %}
  94. {% elseif child.type %}
  95. {% set originalValue = childValue %}
  96. {%
  97. include [
  98. "forms/fields/#{child.type}/#{child.type}.html.twig",
  99. 'forms/fields/text/text.html.twig'
  100. ] with { field: child, value: childValue }
  101. %}
  102. {% endif %}
  103. {% endfor %}
  104. <div class="item-actions">
  105. {% if collapsible %}
  106. <i class="fa fa-chevron-circle-{{ field.collapsed ? 'right' : 'down' }}" data-action="{{ field.collapsed ? 'expand' : 'collapse' }}"></i>
  107. <br />
  108. {% endif %}
  109. <i class="fa fa-trash-o" data-action="delete"></i>
  110. </div>
  111. </li>
  112. {% endfor %}
  113. {% endif %}
  114. </ul>
  115. {% if fieldControls in ['bottom', 'both'] %}
  116. <div class="collection-actions">
  117. {% if collapsible %}
  118. <button class="button" type="button" data-action="expand_all"
  119. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-chevron-circle-down"></i> {{ "PLUGIN_ADMIN.EXPAND_ALL"|e|tu }}</button>
  120. <button class="button" type="button" data-action="collapse_all"
  121. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-chevron-circle-right"></i> {{ "PLUGIN_ADMIN.COLLAPSE_ALL"|e|tu }}</button>
  122. {% endif %}
  123. {% if field.sortby %}
  124. <button class="button{{ not value|length ? ' hidden' : '' }}" type="button" data-action="sort" data-action-sort="{{ field.sortby }}" data-action-sort-dir="{{ field.sortby_dir|default('asc') }}"
  125. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-sort-amount-{{ field.sortby_dir|default('asc') }}"></i> {{ btnSortLabel|e|tu }} '{{ field.sortby }}'</button>
  126. {% endif %}
  127. <button class="button" type="button" data-action="add" data-action-add="bottom"
  128. {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}><i class="fa fa-plus"></i> {{ btnLabel|e|tu }}</button>
  129. </div>
  130. {% endif %}
  131. {%- set itemName = name ? name ~ '.*' : '*' -%}
  132. <div style="display: none;" data-collection-template="new" data-collection-template-html="{%- filter replace({' ': ' ', '\n': ' '})|e('html_attr') -%}
  133. <li data-collection-item="{{ itemName }}">
  134. {% if field.sort is not same as(false) %}
  135. <div class="collection-sort"><i class="fa fa-fw fa-bars"></i></div>
  136. {% endif %}
  137. {%- if field.fields -%}
  138. {%- for childName, child in field.fields -%}
  139. {%- if childName == 'value' -%}
  140. {%- set childKey = '' -%}
  141. {%- set childName = itemName -%}
  142. {%- elseif childName starts with '.' -%}
  143. {%- set childKey = childName|trim('.') -%}
  144. {%- set childName = itemName ~ childName -%}
  145. {%- else %}
  146. {%- set childKey = childName -%}
  147. {%- set childName = childName|replace({'*': key}) -%}
  148. {%- endif %}
  149. {%- set child = child|merge({ name: childName }) -%}
  150. {%- if child.type == 'key' -%}
  151. {%-
  152. include 'forms/fields/key/key.html.twig'
  153. with { field: child, value: null }
  154. -%}
  155. {%- elseif child.key == true -%}
  156. {%-
  157. include [
  158. "forms/fields/#{child.type}/#{child.type}.html.twig",
  159. 'forms/fields/key/key.html.twig'
  160. ] with { field: child, value: null }
  161. -%}
  162. {%- elseif child.type -%}
  163. {%-
  164. include [
  165. "forms/fields/#{child.type}/#{child.type}.html.twig",
  166. 'forms/fields/text/text.html.twig'
  167. ] with { field: child, value: null }
  168. -%}
  169. {%- endif -%}
  170. {%- endfor %}
  171. <div class="item-actions">
  172. {% if collapsible %}
  173. <i class="fa fa-chevron-circle-down" data-action="collapse"></i>
  174. <br />
  175. {% endif %}
  176. <i class="fa fa-trash-o" data-action="delete"></i>
  177. </div>
  178. {%- endif -%}
  179. </li>
  180. {%- endfilter -%}"></div>
  181. <div style="display: none;" data-collection-config="{{ name }}"></div>
  182. </div>
  183. </div>
  184. {% endblock %}