{# # ------------------------------------------------------------------------- # 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 . # ------------------------------------------------------------------------- # @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 %}
{% 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 %} {{ __('show', 'fields') }} {% 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 "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' %} {% 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 #}
{% endif %} {{ macros.dropdownArrayField(itemtype_prefix ~ name, value.itemtype, field['allowed_values'], label, field_options|merge({ 'rand': rand, 'display_emptychoice': true, })) }}
{% 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 #}
{% 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 %}
{% endif %} {% endif %} {% endfor %} {% if not already_wrapped %}
{% endif %}