UNPKG

5.77 kBHTMLView Raw
1{%- include "formMacros.html" -%}
2
3{# Called for you by schemaFields when a group is encountered. #}
4{%- macro schemaOpenGroup(fields, group, active) -%}
5 <div class="apos-modal-tab {% if active %}apos-active{% endif %}" data-tab-id="{{ group }}">
6 <div class="apos-modal-tab-content">
7{%- endmacro -%}
8
9{# Called for you by schemaFields when a group ends. #}
10{%- macro schemaCloseGroup() -%}
11 </div>
12 </div>
13{%- endmacro -%}
14
15{# Output all the fields in a schema. Second argument is optional, contains options. #}
16
17{# NOTE: all of the options below may have surprising results if used #}
18{# in a schema with groups (aka tabs). If you are using tabs we #}
19{# suggest you specify a template name for any custom fields rather #}
20{# than attempting to template them inline with multiple calls to #}
21{# schemaFields. #}
22
23{# If "from" is set, start with that field. If "after" is set, start after it. #}
24{# If "to" is set, end with that field. If "before" is set, end just before it. #}
25{# You can use "from", "to", "after" and "before" to output a portion of the schema fields #}
26{# in order, automatically, then output one in a customized way, then resume #}
27{# outputting the rest automatically. #}
28
29{# You can also output specific fields by specifying only: [ 'field1', 'field2' ... ] #}
30{# or exclude specific fields by specifying except: [ 'field1', 'field2' ... ]. #}
31
32{# Fields are always output in the order specified at configuration time. #}
33
34{# Any field types not known to this macro are skipped, without error. #}
35
36{%- macro schemaFields(fields, options = { from: false, to: false, except: [], only: false }) -%}
37 {%- set groups = aposFilter(fields, 'type', 'group') -%}
38 {%- set firstGroupReached = false -%}
39 {%- set fromFound = false -%}
40 {%- set toFound = false -%}
41 {%- for field in fields -%}
42 {%- if (not (options.from or options.after)) or (field.name == options.from) -%}
43 {%- set fromFound = true -%}
44 {%- endif -%}
45 {%- if (field.name == options.before) -%}
46 {%- set toFound = true -%}
47 {%- endif -%}
48 {%- set found = fromFound and (not toFound) -%}
49 {%- set notExcepted = (not aposContains(options.except, field.name)) -%}
50 {%- set allowed = (not options.only) or aposContains(options.only, field.name) -%}
51 {%- set notContextual = (not field.contextual) -%}
52
53 {%- if (found and notExcepted and allowed and notContextual) -%}
54 {%- if field.group and (field.group != lastGroup) -%}
55 {%- if lastGroup -%}
56 {{ schemaCloseGroup() }}
57 {%- set activeGroup = false -%}
58 {%- else -%}
59 {%- set activeGroup = true -%}
60 {# First grouped control encountered, open the tabs div #}
61 <div class="apos-modal-tabs">
62 <div class="apos-modal-tab-control">
63 {%- for group in groups -%}
64 <div class="apos-modal-tab-title {% if loop.first -%}apos-active{%- endif %}" data-tab="{{ group.name }}"><i class="{{ group.icon }}"></i> {{ group.label }}</div>
65 {%- endfor -%}
66 </div>
67 {# Helpful when treating tabs as scrolling signposts rather than #}
68 {# showing and hiding divs. -Tom #}
69 <div class="apos-modal-tab-bodies">
70 {%- endif -%}
71 {{ schemaOpenGroup(fields, field.group, activeGroup) }}
72 {%- set lastGroup = field.group -%}
73 {%- endif -%}
74 {% set replacement = options.custom and options.custom[field.name] %}
75 {% if replacement %}
76 {# If specified, call another macro to output this field #}
77 {{ replacement(field) }}
78 {% else %}
79 {# Invokes standard templates for each type in
80 apostrophe-schemas/templates/views, or custom renderers
81 if supplied for the field's type or that individual field #}
82 {{ aposSchemaField(field) }}
83 {% endif %}
84 {%- if field.help -%}
85 <p class="apos-help">{{ field.help | e }}</p>
86 {%- endif -%}
87 {%- endif -%}
88 {%- if (field.name == options.to) -%}
89 {%- set toFound = true -%}
90 {%- endif -%}
91 {%- if (field.name == options.after) -%}
92 {%- set fromFound = true -%}
93 {%- endif -%}
94 {%- endfor -%}
95 {# Nunjucks won't let us just test lastGroup from here due to #}
96 {# scoping issues https://github.com/mozilla/nunjucks/issues/166 #}
97 {%- if aposFilterNonempty(fields, 'group').length -%}
98 {{ schemaCloseGroup() }}
99 {# apos-modal-tab-bodies #}
100 </div>
101 {# apos-modal-tabs #}
102 </div>
103 {%- endif -%}
104{%- endmacro -%}
105
106{%- macro schemaArray(name, label, schema) -%}
107 <fieldset class="apos-fieldset apos-fieldset-array apos-fieldset-{{ name | css }}" data-name="{{ name }}">
108 <div class="apos-fieldset-row">
109 {#- <label>{{ __(label) | e }}</label> -#}
110 {#- Cannot be inside the sortable div -#}
111 <span class="apos-ui-container">
112 <a href="#" class="apos-control apos-button" data-add>
113 <i class="icon-plus"></i>
114 Add {{ __(label) | e }}
115 </a>
116 </span>
117 </div>
118
119 <div data-elements>
120 <div data-element class="apos-template apos-array-item">
121 <div class="apos-ui-container right">
122 <span class="apos-ui-btn-group">
123 <span href="#" class="apos-ui apos-ui-btn apos-array-open" data-open-item><i class="icon-plus"></i></span>
124 <span class="apos-ui apos-ui-btn" data-move-item="up"><i class="icon-arrow-up"></i></span>{#
125 #}<span class="apos-ui apos-ui-btn" data-move-item="down"><i class="icon-arrow-down"></i></span>{#
126 #}<a href="#" class="apos-ui apos-ui-btn apos-array-remove" data-remove><i class="icon-remove"></i></a>
127 </span>
128 </div>
129 {{ schemaFields(schema) }}
130 </div>
131 </div>
132
133 </fieldset>
134{%- endmacro -%}