-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathfields.html.twig
More file actions
238 lines (209 loc) · 9.92 KB
/
fields.html.twig
File metadata and controls
238 lines (209 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
{#
# -------------------------------------------------------------------------
# Fields plugin for GLPI
# -------------------------------------------------------------------------
#
# LICENSE
#
# This file is part of Fields.
#
# Fields is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Fields is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Fields. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
# @copyright Copyright (C) 2013-2023 by Fields plugin team.
# @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
# @link https://github.com/pluginsGLPI/fields
# -------------------------------------------------------------------------
#}
{% import 'components/form/fields_macros.html.twig' as macros %}
{% set in_itilobject = item is instanceof('CommonITILObject') and container.fields['type'] == 'dom' %}
{% set in_form_builder = item is instanceof('Glpi\\Form\\Form') %}
{% set already_wrapped = in_itilobject or in_form_builder %}
{% set dropdown_item = item is instanceof('CommonDropdown') and container.fields['type'] == 'dom' %}
{% set textarea_display_options = {
'in_itilobject': {
'field_class': 'col-12',
'label_class': 'col-2',
'input_class': 'col-10',
'is_horizontal': true,
'align_label_right': true,
},
'in_form_builder': {
'field_class': 'col-12',
'label_class': 'form-label',
'input_class': 'w-100',
'is_horizontal': false,
'align_label_right': false,
},
'default': {
'field_class': 'col-12',
'label_class': 'col-xxl-2',
'input_class': 'col-xxl-10',
'is_horizontal': true,
'align_label_right': true,
},
} %}
{% if in_itilobject %}
{% set current_textarea_options = textarea_display_options.in_itilobject %}
{% elseif in_form_builder %}
{% set current_textarea_options = textarea_display_options.in_form_builder %}
{% else %}
{% set current_textarea_options = textarea_display_options.default %}
{% endif %}
{% if not already_wrapped and not dropdown_item%}
{% set class = item.isNewItem() or item is instanceof('User') or container.fields['type'] == 'dom' ? 'col-xxl-12' : 'col-xxl-9' %}
<div class="col-12 {{ class }} flex-column">
<div class="d-flex flex-row flex-wrap flex-xl-nowrap">
<div class="row flex-row align-items-start flex-grow-1">
<div class="row flex-row">
{% if item.isNewItem() and item is instanceof('User') %}
<div>
{% endif %}
{% endif %}
{% for field in fields %}
{% set type = field['type'] %}
{% set name = field['name'] %}
{% set label = field['label'] %}
{% set value = item.input[name]|default(field['value']) %}
{% set readonly = field['is_readonly'] %}
{% set rand = random() %}
{% set field_options = field_options|merge({
'readonly': readonly or not canedit,
'required': field['mandatory'],
'full_width': field_options.full_width ?? already_wrapped,
}) %}
{% set input_name = field_options.input_name ?? name %}
{% if type == 'header' %}
{{ macros.largeTitle(label) }}
{% elseif type == 'text' %}
{{ macros.textField(input_name, value, label, field_options) }}
{% elseif type == 'number' %}
{{ macros.numberField(input_name, value, label, field_options|merge({step: 'any', min: ''})) }}
{% elseif type == 'url' %}
{% set ext_link %}
{% if value|length %}
<a target="_blank" href="{{ value }}">
<i class="ti ti-external-link"></i>
{{ __('show', 'fields') }}
</a>
{% endif %}
{% endset %}
{{ macros.textField(input_name, value, label, field_options|merge({
'type': 'url',
'add_field_html': ext_link
})) }}
{% elseif type == 'textarea' %}
{{ macros.textareaField(input_name, value, label, field_options|merge(current_textarea_options)) }}
{% elseif type == 'richtext' %}
{{ macros.textareaField(input_name, value, label, field_options|merge(current_textarea_options)|merge({
'enable_richtext': true,
})) }}
{% elseif type == 'yesno' %}
{{ macros.dropdownYesNo(input_name, value, label, field_options) }}
{% elseif type == 'date' %}
{{ macros.dateField(input_name, value, label, field_options) }}
{% elseif type == 'datetime' %}
{{ macros.datetimeField(input_name, value, label, field_options) }}
{% elseif type == 'dropdown' %}
{% set dropdown_options = {'entity': item.getEntityID()} %}
{% if field['multiple'] %}
{% set dropdown_options = dropdown_options|merge({'multiple': true}) %}
{% endif %}
{% if item.isRecursive() %}
{% set dropdown_options = dropdown_options|merge({'entity_sons': true}) %}
{% endif %}
{% if "dropdowns_id" in name %}
{% set dropdown_itemtype = call("getItemtypeForForeignKeyField", [name]) %}
{% else %}
{% set dropdown_itemtype = call("PluginFieldsDropdown::getClassname", [name]) %}
{% endif %}
{% if input_name == name %}
{% set name_fk = call("getForeignKeyFieldForItemType", [dropdown_itemtype]) %}
{% endif %}
{{ macros.dropdownField(dropdown_itemtype, name_fk ?? input_name, value, label, field_options|merge(dropdown_options|default({}))) }}
{% elseif type matches '/^dropdown-.+/i' %}
{% set dropdown_options = {'entity': item.getEntityID()} %}
{% if field['dropdown_condition'] is defined and field['dropdown_condition']|length %}
{% set dropdown_options = dropdown_options|merge({'condition': field['dropdown_condition']}) %}
{% endif %}
{% if field['dropdown_class'] == 'User' %}
{% set dropdown_options = dropdown_options|merge({'entity': -1, 'right': 'all'}) %}
{% elseif field['dropdown_class'] == 'Entity' or item.isRecursive() %}
{% set dropdown_options = dropdown_options|merge({'entity_sons': true}) %}
{% endif %}
{% if field['multiple'] %}
{% set dropdown_options = dropdown_options|merge({'multiple': true}) %}
{% endif %}
{{ macros.dropdownField(field['dropdown_class'], input_name, value, label, field_options|merge(dropdown_options|default({}))) }}
{% elseif type == 'glpi_item' %}
{% if not massiveaction %}
{% if item is instanceof('Glpi\\Form\\Form') %}
{% set itemtype_input_name = input_name ~ '[itemtype]' %}
{% set items_id_input_name = input_name ~ '[items_id]' %}
{% else %}
{% set itemtype_input_name = 'itemtype_' ~ name %}
{% set items_id_input_name = 'items_id_' ~ name %}
{% endif %}
{% if container.fields['type'] == 'tab' %}
{# start new row for glpi object #}
<div class="w-100"></div>
{% endif %}
{% set items_id_dropdown %}
{% do call('Ajax::updateItemOnSelectEvent',
[
'dropdown_' ~ itemtype_input_name ~ rand,
'results_items_id' ~ (rand),
config('root_doc') ~ '/ajax/dropdownAllItems.php',
{
'idtable' : '__VALUE__',
'name' : items_id_input_name,
'entity_restrict' : item.getEntityID(),
'dom_name' : items_id_input_name,
'display_emptychoice' : false,
'action' : 'get_items_from_itemtype',
'dom_rand' : rand,
'width' : '100%',
}
]) %}
<span id='results_items_id{{ rand }}' class='col-lg-14'>
{% if value.itemtype|default('') != '' %}
{{ macros.dropdownField(value.itemtype, items_id_input_name, value.items_id|default(''), ' ', field_options|merge({
'entity': value.itemtype|default('') == 'User' ? -1 : item.getEntityID(),
'rand': rand,
'right': 'all',
'displaywith': ['otherserial', 'serial'],
'display_emptychoice' : false,
'no_label': true,
'full_width': true,
})) }}
{% endif %}
</span>
{% endset %}
{{ macros.dropdownArrayField(itemtype_input_name, value.itemtype|default(''), field['allowed_values'], label, field_options|merge({
'rand' : rand,
'display_emptychoice': true,
'add_field_class' : field_options.add_field_class|default('') ~ ' glpi-fields-plugin-glpi-item-field',
'add_field_html' : items_id_dropdown
})) }}
{% endif %}
{% endif %}
{% endfor %}
{% if not already_wrapped and not dropdown_item%}
{% if item.isNewItem() and item is instanceof('User') %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}