{# # --------------------------------------------------------------------- # # GLPI - Gestionnaire Libre de Parc Informatique # # http://glpi-project.org # # @copyright 2015-2023 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) %} {% set margins = 'mt-3' %} {% if first %} {% set margins = 'mt-n2' %} {% endif %}

{% if icon|length %}
{% endif %} {{ label }}

{% endmacro %} {% macro smallTitle(label, icon = '') %} {% set margins = 'mt-2 mb-2' %}

{% if icon|length %}
{% endif %} {{ label }}

{% endmacro %} {% macro autoNameField(name, item, label = '', withtemplate, options = {}) %} {% set tpl_value = option.value|length > 0 ? option.value : item.fields[name]|verbatim_value %} {% set tplmark = '' %} {% if item.isTemplate() %} {# TODO exluded types #} {% set tplmark = 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]|verbatim_value, name, (withtemplate == 2), item.getType(), item.fields['entities_id']]) %} {% else %} {% set value = null %} {% endif %} {% set label = __('%1$s%2$s')|format(label, tplmark) %} {{ _self.textField(name, value, label, options) }} {% endmacro %} {% macro textField(name, value, label = '', options = {}) %} {% set options = {'type': 'text'}|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% set field %} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro checkboxField(name, value, label = '', options = {}) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% set options = { 'center': true, }|merge(options) %} {% set field %} {% 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 %} {% 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 = {}) %} {% if options.step != 'any' and options.step|round(0, 'floor') != options.step %} {# Only format number if not a whole number #} {% set value = call('Html::formatNumber', [value, true]) %} {% endif %} {% if value == "" %} {% set value = (options.min is defined ? options.min : 0) %} {% endif %} {% set field %} {% 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|verbatim_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': [] }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% set id = options.id|length > 0 ? options.id : (name ~ '_' ~ options.rand) %} {% set field %} {# 100% width is here to prevent width issues with tinymce #} {% endset %} {% if options.enable_richtext %} {% do call('Html::initEditorSystem', [ id, options.rand, true, options.disabled|default(false), options.enable_images ]) %} {% endif %} {% set add_html = '' %} {% if not options.readonly and options.enable_fileupload %} {% set add_html %} {% do call('Html::file', [{ 'editor_id': 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': 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) }} {% if options.enable_mentions and config('use_notifications') %} {% endif %} {% endmacro %} {% macro flatpickrHtmlInput(name, value, label = '', options = {}) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% if value == 'NULL' %} {% set value = null %} {% endif %} {% if options.checkIsExpired %} {% if value|date('Y-m-d H:i:s') < "now"|date('Y-m-d H:i:s') %} {% set class = 'warn' %} {% endif %} {% else %} {% if options.expiration_class is defined %} {% set class = options.expiration_class %} {% else %} {% set class = '' %} {% endif %} {% endif %}
{# .rounded-start added to prevent issue with bootstrap .input-group #} {# the first element is an input[type=hidden] added by flatpickr and so we don't have border-radius on the start #} {% if not options.readonly %} {% endif %}
{% endmacro %} {% macro dateField(name, value, label = '', options = {}) %} {% set options = {'rand': random()}|merge(options) %} {% set options = {'id': name|slug ~ '_' ~ options.rand}|merge(options) %} {% set locale = get_current_locale() %} {% set field %} {{ _self.flatpickrHtmlInput(name, value, label, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro datetimeField(name, value, label = '', options = {}) %} {% set options = {'rand': random()}|merge(options) %} {% set options = {'id': name|slug ~ '_' ~ options.rand}|merge(options) %} {% set locale = get_current_locale() %} {% set field %} {{ _self.flatpickrHtmlInput(name, value, label, options) }} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro colorField(name, value, label = '', options = {}) %} {% set field %} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro passwordField(name, value, label = '', options = {}) %} {% set options = { 'autocomplete': 'new-password', 'is_disclosable': false, 'rand': options.rand ?? random() }|merge(options) %} {% set options = { 'id': options.id is defined ? options.id : name ~ random(), 'clearable': options.clearable is defined ? options.clearable : not options.is_disclosable, }|merge(options) %} {% set field %} {% endset %} {% set btn_group %}     {% endset %} {% if options.is_disclosable %} {% set label = label ~ btn_group %} {% endif %} {% if options.clearable %} {% set clear_chk %}   {% endset %} {% set field = field ~ clear_chk %} {% endif %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro emailField(name, value, label = '', options = {}) %} {% set options = {'type': 'email'}|merge(options) %} {{ _self.textField(name, value, label, options) }} {% endmacro %} {% macro fileField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'name': name, 'simple': false, }|merge(options) %} {% set field %} {% if options.simple %} {% else %} {% do call('Html::file', [options]) %} {% endif %} {% 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 %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro imageGalleryField(name, value, label = '', options = {}) %} {% set field %} {{ _self.fileField(name, null, '', { 'onlyimages': true, 'multiple': true, }) }} {% endset %} {% set id = options.id|length > 0 ? options.id : (name ~ '_' ~ options.rand) %} {{ _self.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 %} {% endset %} {{ _self.field(name, field, label, options) }} {% endmacro %} {% macro dropdownNumberField(name, value, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% 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 ~ '_' ~ options.rand})) }} {% endmacro %} {% macro dropdownArrayField(name, value, elements, label = '', options = {}) %} {% set options = { 'rand': random(), 'width': '100%', }|merge(options) %} {% 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|verbatim_value, 'rand': rand, }|merge(options)]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name ~ '_' ~ 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.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 ~ '_' ~ 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.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 ~ '_' ~ 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.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 ~ '_' ~ options.rand})) }} {% endmacro %} {% macro dropdownItemsFromItemtypes(name, label = '', options = {}) %} {% set options = { 'rand': random() }|merge(options) %} {% set field %} {% do call('Dropdown::showSelectItemFromItemtypes', [options]) %} {% endset %} {{ _self.field(name, field, label, options|merge({'id': 'dropdown_' ~ name ~ '_' ~ 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.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 ~ '_' ~ options.rand})) }} {% 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.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 ~ '_' ~ 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.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 ~ '_' ~ options.rand})) }} {% endif %} {% endmacro %} {% macro htmlField(name, value, label = '', options = {}) %} {% if value|length == 0 %} {% set value = ' ' %} {% 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 not options.include_field %} {{ field }} {% else %} {% set id = options.id|length > 0 ? 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', }|merge(options) %} {% set class = options.field_class ?? 'col-12 col-sm-6' %} {% if options.full_width %} {% set class = 'col-12' %} {% endif %}
{{ field|raw }} {{ add_field_html|raw }}
{% endmacro %} {% macro horizontalField(label, field, id, add_field_html = '', options = {}) %} {% set options = { 'full_width': false, 'full_width_adapt_column': true, 'align_label_right': true, 'mb': 'mb-2', 'field_class': 'col-12 col-sm-6', 'label_class': 'col-xxl-5', 'input_class': 'col-xxl-7', 'add_field_class': '', 'add_field_attribs': {}, 'center': false, }|merge(options) %} {% if options.full_width %} {% set options = options|merge({ field_class: 'col-12', }) %} {% if options.full_width_adapt_column %} {% set options = options|merge({ label_class: 'col-xxl-4', input_class: 'col-xxl-8', }) %} {% endif %} {% endif %} {% if options.icon_label %} {% set options = options|merge({ label_class: 'col-2', input_class: 'col-10', }) %} {% endif %} {% if options.align_label_right %} {% set options = options|merge({ label_class: options.label_class ~ ' text-xxl-end', }) %} {% 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 %}
{{ _self.label(label, id, options, 'col-form-label ' ~ options.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': {}, }|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 %}
{{ _self.label(label, id, options, 'col-form-label ' ~ options.label_class) }}
{{ field|raw }}
{{ add_field_html|raw }}
{% endmacro %} {% macro label(label, id, options = {}, class = 'form-label') %} {% set options = { locked: false, locked_value: null }|merge(options) %} {% set required_mark = '' %} {% if options.fields_template.isMandatoryField(options.name) or options.required %} {% set required_mark = '*' %} {% endif %} {% set helper = '' %} {% if options.helper %} {% set helper %} ? {% endset %} {% endif %} {% set locked_mark = '' %} {% if options.locked %} {% set locked_mark %} {% set locked_title %}{{ __('Field will not be updated from inventory') }}{% endset %} {% if options.locked_value is not empty %} {% set locked_title %}{{ locked_title }} - {{ __('Last inventory value was:') ~ ' ' ~ options.locked_value }}{% endset %} {% endif %} {% endset %} {% endif %} {% endmacro %}