{# # --------------------------------------------------------------------- # # GLPI - Gestionnaire Libre de Parc Informatique # # http://glpi-project.org # # @copyright 2015-2024 Teclib' and contributors. # @copyright 2003-2014 by the INDEPNET Development Team. # @licence https://www.gnu.org/licenses/gpl-3.0.html # # --------------------------------------------------------------------- # # LICENSE # # This file is part of GLPI. # # This program 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 3 of the License, or # (at your option) any later version. # # This program 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 this program. If not, see . # # --------------------------------------------------------------------- #} {% macro largeTitle(label, icon = '', first = false, helper = '') %} {% set margins = 'mt-3' %} {% if first %} {% set margins = 'mt-n2' %} {% endif %}

{% if icon|length %}
{% endif %} {{ label }} {% if helper is not empty %} ? {% endif %}

{% endmacro %} {% macro smallTitle(label, icon = '', helper = '', id = '') %} {% set margins = 'mt-2 mb-2' %} {% set id = id != '' ? id : 'formsection' ~ random() %}

{% if icon|length %}
{% endif %} {{ label }} {% if helper is not empty %} ? {% endif %}

{% endmacro %} {% macro autoNameField(name, item, label = '', withtemplate, options = {}) %} {% set tpl_value = option.value|length > 0 ? option.value : item.fields[name] %} {% if item.isTemplate() %} {# TODO exluded types #} {% set options = options|merge({ tpl_mark: item.getAutofillMark(name, {'withtemplate': withtemplate}, tpl_value) }) %} {% endif %} {% if item.fields[name] is defined and item.fields[name] is not null %} {% set value = call('autoName', [item.fields[name], name, (withtemplate == 2), item.getType(), item.fields['entities_id']]) %} {% else %} {% set value = null %} {% endif %} {{ _self.textField(name, value, label, options) }} {% endmacro %} {% macro textField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%' }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.text(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro urlField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%' }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.input(name, value, options|merge({ 'type': 'url' })) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro checkboxField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%', 'center': true, }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.checkbox(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro sliderField(name, value, label = '', options = {}) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = { 'required': true }|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% set options = { 'no_value': 0, 'yes_value': 1, }|merge(options) %} {% set field %} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro numberField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%' }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.number(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro readOnlyField(name, value, label = '', options = {}) %} {% set options = options|merge({'readonly': true}) %} {% set value %} {% if value|length == 0 %}   {% else %} {{ value }} {% endif %} {% endset %} {{ _self.field(name, value, label, options) }} {% endmacro %} {% macro textareaField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'enable_richtext': false, 'enable_images': true, 'enable_fileupload': false, 'enable_mentions': false, 'entities_id': session('glpiactive_entity'), 'uploads': [], 'rows': 3, }|merge(options) %} {% if options.id is not defined %} {# `id` is mandatory at this point to correctly handle file uploads #} {% set options = {id: name ~ '_' ~ options.rand}|merge(options) %} {% endif %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.textarea(name, value, options) }} {% endset %} {% set add_html = '' %} {% if not options.readonly and options.enable_fileupload %} {% set add_html %} {% do call('Html::file', [{ 'editor_id': options.id, 'multiple': true, 'uploads': options.uploads, 'required': options.fields_template.isMandatoryField('_documents_id') }]) %} {% endset %} {% elseif not options.readonly and not options.enable_fileupload and options.enable_richtext and options.enable_images %} {% set add_html %} {% do call('Html::file', [{ 'editor_id': options.id, 'name': name, 'only_uploaded_files': true, 'uploads': options.uploads, 'required': options.fields_template.isMandatoryField('_documents_id') }]) %} {% endset %} {% endif %} {% if add_html != '' %} {% if options.add_field_html is defined %} {% set add_html = add_html ~ options.add_field_html %} {% endif %} {% set options = options|merge({'add_field_html': add_html}) %} {% endif %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro dateField(name, value, label = '', options = {}) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.date(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro datetimeField(name, value, label = '', options = {}) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.datetime(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro colorField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%' }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.color(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro passwordField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%', 'can_regenerate': options.can_regenerate, 'clearable': options.clearable is defined ? options.clearable : not options.is_disclosable, 'is_copyable': options.is_disclosable ?? false }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.password(name, value, options) }} {% endset %} {# Add checkbox if needed to regenerate password (controler side) #} {% if options.can_regenerate %} {% set regenerate_chk %}   {% endset %} {% set field = field ~ regenerate_chk %} {% endif %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro emailField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%' }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.email(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro fileField(name, value, label = '', options = {}) %} {% set options = { 'id': '%id%', 'rand': random(), 'simple': false, }|merge(options) %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.file(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro imageField(name, value, label = '', options = {}, link_options = {}) %} {% set field %}
{% set clearable = options['clearable'] %} {% set url = options['url'] ?? null %} {% set options = options|filter((v, k) => k != 'url' and k != 'clearable') %} {% if url is not empty %} {% endif %} {% if url is not empty %} {% endif %} {% if clearable %} {% endif %}
{% endset %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro imageGalleryField(name, value, label = '', options = {}) %} {% set field %} {{ _self.fileField(name, null, '', { 'onlyimages': true, 'multiple': true, }) }} {% endset %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% set id = options.id|length > 0 ? options.id : (name ~ '_' ~ options.rand) %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.label(label, id, options) }} {{ _self.field(name, field, label, options|merge({ 'full_width': true, 'no_label': true })) }} {% endmacro %} {% macro hiddenField(name, value, label = '', options = {}) %} {% if options.no_label %} {% set options = { mb: 'mb-0' }|merge(options) %} {% endif %} {% set field %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.hidden(name, value, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro dropdownNumberField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'specific_tags': {'required': true}}|merge(options) %} {% endif %} {% set field %} {% do call('Dropdown::showNumber', [name, { 'value': value, 'rand': rand }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownArrayField(name, value, elements, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% set field %} {% do call('Dropdown::showFromArray', [name, elements, { 'value': value, 'rand': rand, }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownTimestampField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {% do call('Dropdown::showTimestamp', [name, { 'value': value, 'rand': rand, }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownYesNo(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {% do call('Dropdown::showYesNo', [name, value, -1, { 'rand': rand, }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownItemTypes(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set types = options['types']|default([]) %} {% set field %} {% do call('Dropdown::showItemTypes', [name, types, { 'rand': rand, 'value': value }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownItemsFromItemtypes(name, label = '', options = {}) %} {% set options = { 'rand': random() }|merge(options) %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% set field %} {% do call('Dropdown::showSelectItemFromItemtypes', [options]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownIcons(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {% do call('Dropdown::dropdownIcons', [name, value, constant('GLPI_ROOT') ~ '/pics/icones', { 'rand': rand, }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownWebIcons(name, value, label = '', options = {}) %} {% set options = { rand: random(), }|merge(options|merge({ noselect2: true, })) %} {# Trim 'ti ' prefix if it exists in the value #} {% set value = value|replace({'ti ': ''}) %} {{ _self.dropdownArrayField(name, value, {(value): value}, label, options) }} {% endmacro %} {% macro dropdownHoursField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {% do call('Dropdown::showHours', [name, { 'rand': rand, 'value': value }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownFrequency(name, value, label = '', options = {}) %} {% set options = {'rand': random()}|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({specific_tags: {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {% do call('Dropdown::showFrequency', [name, value, { 'rand': rand, 'width': '100%', 'value': value }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endmacro %} {% macro dropdownField(itemtype, name, value, label = '', options = {}) %} {% if options.multiple %} {# Needed for empty value as the input wont be sent in this case... we need something to know the input was displayed AND empty #} {% set defined_input_name = "_#{name}_defined" %} {# Multiple values will be set, input need to be an array #} {% set name = "#{name}[]" %} {% endif %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'specific_tags': {'required': true}}|merge(options) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if options.disabled %} {% set options = options|merge({'specific_tags': {'disabled': 'disabled'}}) %} {% endif %} {% set field %} {{ itemtype|itemtype_dropdown({ 'name': name, 'value': value, 'rand': rand, }|merge(options)) }} {% endset %} {% if field|trim is not empty %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name|replace({'[': '_', ']': '_'}) ~ options.rand})) }} {% endif %} {% endmacro %} {% macro htmlField(name, value, label = '', options = {}) %} {% if value|length == 0 %} {% set value = ' ' %} {% endif %} {% set options = { wrapper_class: 'form-control-plaintext' }|merge(options) %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% set value %} {{ value|raw }} {% endset %} {{ _self.field(name, value, label, options) }} {% endmacro %} {% macro field(name, field, label = '', options = {}) %} {% set options = { 'rand': random(), 'is_horizontal': true, 'include_field': true, 'add_field_html': '', 'locked': false, 'locked_fields': [], }|merge(options) %} {% if options.locked_fields[name] is defined %} {% set options = options|merge({'locked': true, 'locked_value': options.locked_fields[name]}) %} {% elseif name in options.locked_fields %} {% set options = options|merge({'locked': true}) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if not options.include_field %} {{ field }} {% else %} {% set id = options.id|length > 0 and options.id != '%id%' ? options.id : (name ~ '_' ~ options.rand) %} {% set field = field|replace({'%id%': id}) %} {% set add_field_html = options.add_field_html|length > 0 ? options.add_field_html : '' %} {% if options.fields_template is not defined or not options.fields_template.isHiddenField(name) %} {% if options.no_label %} {{ _self.noLabelField(field, id, add_field_html, options) }} {% elseif options.is_horizontal %} {{ _self.horizontalField(label, field, id, add_field_html, options|merge({'name': name})) }} {% else %} {{ _self.verticalField(label, field, id, add_field_html, options|merge({'name': name})) }} {% endif %} {% endif %} {% endif %} {% endmacro %} {% macro ajaxField(id, value, label = '', options = {}) %} {% set field %}
{% if value is not null %} {{ value|raw }} {% endif %}
{% endset %} {{ _self.field(id, field, label, options|merge({'id': id ~ '_' ~ options.rand})) }} {% endmacro %} {% macro nullField(options = {}) %} {% set options = {'is_horizontal': true}|merge(options) %} {% if options.is_horizontal %} {{ _self.horizontalField(label, field, id, add_field_html, options) }} {% else %} {{ _self.verticalField(label, field, id, add_field_html, options) }} {% endif %} {% endmacro %} {% macro noLabelField(field, id = '', add_field_html = '', options = {}) %} {% set options = { 'full_width': false, 'mb': 'mb-3', 'add_field_class': '', 'add_field_attribs': {}, }|merge(options) %} {% set class = options.field_class ?? 'col-12 col-sm-6' %} {% if options.full_width %} {% set class = 'col-12' %} {% endif %} {% set class = class ~ ' ' ~ options.add_field_class %} {% if options.add_field_attribs is not empty %} {% set extra_attribs = call('Html::parseAttributes', {options: options.add_field_attribs}) %} {% else %} {% set extra_attribs = '' %} {% endif %}
{{ field|raw }} {{ add_field_html|raw }}
{% endmacro %} {% macro horizontalField(label, field, id, add_field_html = '', options = {}) %} {% set options = { 'full_width': false, 'align_label_right': true, 'mb': 'mb-2', 'field_class': 'col-12 col-sm-6', 'container_id': '', 'add_field_class': '', 'add_label_class': '', 'add_field_attribs': {}, 'center': false, 'label_align': 'end', }|merge(options) %} {% if options.icon_label %} {% set options = { label_class: 'col-2', input_class: 'col-10', }|merge(options) %} {% endif %} {% if options.full_width %} {% set options = options|merge({ field_class: 'col-12 glpi-full-width', }) %} {% endif %} {% set options = { label_class: 'col-xxl-5', input_class: 'col-xxl-7', }|merge(options) %} {% if options.align_label_right %} {% set options = options|merge({ label_class: options.label_class ~ ' text-xxl-' ~ options.label_align, }) %} {% endif %} {% if options.add_field_attribs is not empty %} {% set extra_attribs = call('Html::parseAttributes', {options: options.add_field_attribs}) %} {% else %} {% set extra_attribs = '' %} {% endif %} {# Usefull for Ajax::updateItemOnSelectEvent (DOM to update) #} {% if options.container_id is not empty %} {% set container_id = 'id=' ~ options.container_id %} {% else %} {% set container_id = '' %} {% endif %}
{% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.label(label, id, options, 'col-form-label ' ~ options.label_class ~ ' ' ~ options.add_label_class) }} {% if options.center %} {% set flex_class = "d-flex align-items-center" %} {% endif %}
{{ field|raw }} {{ add_field_html|raw }}
{% endmacro %} {% macro verticalField(label, field, id, add_field_html = '', options = {}) %} {% set options = { 'full_width': false, 'mb': 'mb-2', 'field_class': 'col-12 col-sm-6', 'add_field_class': '', 'add_field_attribs': {}, 'insert_content_after_label': '', }|merge(options) %} {% if options.full_width %} {% set options = options|merge({ field_class: 'col-12', }) %} {% endif %} {% if options.add_field_attribs is not empty %} {% set extra_attribs = call('Html::parseAttributes', {options: options.add_field_attribs}) %} {% else %} {% set extra_attribs = '' %} {% endif %}
{% import 'components/form/basic_inputs_macros.html.twig' as _inputs %}
{{ _inputs.label(label, id, options, 'col-form-label ' ~ options.label_class) }} {{ options.insert_content_after_label|raw }}
{{ field|raw }}
{{ add_field_html|raw }}
{% endmacro %} {% macro label(label, id, options = {}, class = 'form-label') %} {% import 'components/form/basic_inputs_macros.html.twig' as _inputs %} {{ _inputs.label(label, id, options, class) }} {% endmacro %} {% macro codeField(name, value, label, options) %} {% set options = { single_line: false, language: 'twig', completions: [], helper: __('This field accepts %s content. Press Ctrl+Space to trigger autocompletion.')|format('Twig'), }|merge(options) %} {% if options.helper is not empty %} {% set options = options|merge({ helper: options.helper|format(options.language) }) %} {% endif %} {% set code_container_id = name ~ '_' ~ random() %} {% set code_container %}
{% endset %} {{ _self.htmlField(name, code_container, label, { wrapper_class: 'd-flex flex-grow-1', }|merge(options)) }} {% endmacro %}