-
Notifications
You must be signed in to change notification settings - Fork 69
/
fields.html.twig
192 lines (169 loc) · 8.02 KB
/
fields.html.twig
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
{#
# -------------------------------------------------------------------------
# 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 already_wrapped = item is instanceof('CommonITILObject') and container.fields['type'] == 'dom' %}
{% if not already_wrapped %}
<div class="card-body d-flex flex-wrap">
<div class="col-12 col-xxl-12 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">
{% endif %}
{% for field in fields %}
{% set type = field['type'] %}
{% set name = field['name'] %}
{% set label = field['label'] %}
{% set value = item.input[name] ?: 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': already_wrapped
}) %}
{% if type == 'header' %}
{{ macros.largeTitle(label) }}
{% elseif type == 'text' %}
{{ macros.textField(name, value, label, field_options) }}
{% elseif type == 'number' %}
{{ macros.numberField(name, value, label, field_options|merge({step: 'any', min: ''})) }}
{% elseif type == 'url' %}
{% set ext_link %}
{% if value|length %}
<a target="_blank" href="{{ value|verbatim_value }}">
<i class="ti ti-external-link"></i>
{{ __('show', 'fields') }}
</a>
{% endif %}
{% endset %}
{{ macros.textField(name, value, label, field_options|merge({
'type': 'url',
'add_field_html': ext_link
})) }}
{% elseif type == 'textarea' %}
{{ macros.textareaField(name, value, label, field_options) }}
{% elseif type == 'richtext' %}
{{ macros.textareaField(name, value, label, field_options|merge({
'enable_richtext': true,
'field_class': 'col-12',
'label_class': '',
'input_class': '',
'align_label_right': false,
'mb': 'm-2'
})) }}
{% elseif type == 'yesno' %}
{{ macros.dropdownYesNo(name, value, label, field_options) }}
{% elseif type == 'date' %}
{{ macros.dateField(name, value, label, field_options) }}
{% elseif type == 'datetime' %}
{{ macros.datetimeField(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 %}
{% set name_fk = call("getForeignKeyFieldForItemType", [dropdown_itemtype]) %}
{{ macros.dropdownField(dropdown_itemtype, name_fk, value, label, field_options|merge(dropdown_options)) }}
{% elseif type matches '/^dropdown-.+/i' %}
{% if not massiveaction %}
{% set dropdown_options = {'condition': field['dropdown_condition'], 'entity': item.getEntityID()} %}
{% 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'], name, value, label, field_options|merge(dropdown_options)) }}
{% endif %}
{% elseif type == 'glpi_item' %}
{% if not massiveaction %}
{% set itemtype_prefix = 'itemtype_' %}
{% set items_id_prefix = 'items_id_' %}
{% if container.fields['type'] == 'tab' %}
{# start new row for glpi object #}
<div class="w-100"></div>
{% endif %}
{{ macros.dropdownArrayField(itemtype_prefix ~ name, value.itemtype, field['allowed_values'], label, field_options|merge({
'rand': rand,
'display_emptychoice': true,
})) }}
<div class='form-field row col-12 {{ container.fields['type'] == 'tab' ? 'col-sm-6' : '' }} mb-2'>
{% do call('Ajax::updateItemOnSelectEvent',
[
'dropdown_' ~ itemtype_prefix ~ name ~ rand,
'results_items_id' ~ (rand),
config('root_doc') ~ '/ajax/dropdownAllItems.php',
{
'idtable' : '__VALUE__',
'name' : items_id_prefix ~ name,
'entity_restrict' : item.getEntityID(),
'dom_name' : items_id_prefix ~ name,
'display_emptychoice' : false,
'action' : 'get_items_from_itemtype',
'dom_rand' : rand,
'width' : '100%',
}
]) %}
{# fake label for DOM disposition #}
<label class="col-form-label col-xxl-4 text-xxl-end" for="dropdown_items_id_testfield{{rand}}">
</label>
<div class="col-xxl-8 field-container">
<span id='results_items_id{{rand}}' class='col-lg-14'>
{% if value.itemtype != '' %}
{{ macros.dropdownField(value.itemtype, items_id_prefix ~ name, value.items_id, ' ', field_options|merge({
'entity': value.itemtype == 'User' ? -1 : item.getEntityID(),
'rand': rand,
'right': 'all',
'displaywith': ['otherserial', 'serial'],
'display_emptychoice' : false,
'no_label': true
})) }}
{% endif %}
</span>
</div>
</div>
{% endif %}
{% endif %}
{% endfor %}
{% if not already_wrapped %}
</div>
</div>
</div>
</div>
</div>
{% endif %}