{# # --------------------------------------------------------------------- # # 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 input(name, value, options = {}) %} {% set options = { 'id': null, 'type': 'text', 'input_addclass': '', 'additional_attributes': {}, 'readonly': false, 'disabled': false, 'multiple': false, 'required': false, 'is_disclosable': false, 'is_copyable': false, 'clearable': false, }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = options|merge({'required': true}) %} {% endif %} {% if options.fields_template.isReadonlyField(name) %} {% set options = options|merge({'readonly': true}) %} {% endif %} {% if (options.is_disclosable or options.is_copyable) and id is null %} {% set options = options|merge({ id: name|slug ~ '_' ~ random() }) %} {% endif %} {% set input %} {% endset %} {% set more_html %} {% if options.is_disclosable %}
{% endif %} {% if options.is_copyable %}
{% endif %} {% endset %} {% if more_html|trim|length > 0 %} {% set input %}
{{ input }} {{ more_html }}
{% endset %} {% endif %} {{ input }} {% if options.clearable %} {% endif %} {% endmacro %} {% macro text(name, value, options = {}) %} {% if options.copyable %}
{% endif %} {{ _self.input(name, value, options|merge({'type': 'text'})) }} {% if options.copyable %}
{% endif %} {% endmacro %} {% macro number(name, value, options = {}) %} {% set options = { 'step': 1, }|merge(options) %} {% if value == "" %} {% set value = (options.min is defined ? options.min : 0) %} {% endif %} {% 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 %} {{ _self.input(name, value, options|merge({'type': 'number'})) }} {% endmacro %} {% macro color(name, value, options = {}) %} {% set options = { id: name ~ '_' ~ options.rand }|merge(options) %} {{ _self.input(name, value, options|merge({ 'type': 'text', 'input_addclass': 'rounded-0', })) }} {% endmacro %} {% macro password(name, value, options = {}) %} {{ _self.input(name, value, options|merge({'type': 'password'})) }} {% endmacro %} {% macro email(name, value, options = {}) %} {{ _self.input(name, value, options|merge({'type': 'email'})) }} {% endmacro %} {% macro file(name, value, options = {}) %} {% set options = { 'simple': false, }|merge(options) %} {% if options.simple %} {{ _self.input(name, value, options|merge({'type': 'file'})) }} {% else %} {% do call('Html::file', [ options|merge({ 'name': name, }) ]) %} {% endif %} {% endmacro %} {% macro hidden(name, value, options = {}) %} {{ _self.input(name, value, options|merge({'type': 'hidden'})) }} {% endmacro %} {% macro date(name, value, options = {}) %} {% set options = { 'rand': random(), 'enableTime': false, 'checkIsExpired ': false, 'clearable': false, }|merge(options) %} {% set options = { 'id': name|slug ~ '_' ~ options.rand }|merge(options) %} {% if value == 'NULL' %} {% set value = null %} {% endif %} {% set final_expiration_class = '' %} {% if options.checkIsExpired %} {% if value|date('Y-m-d H:i:s') < "now"|date('Y-m-d H:i:s') %} {% set final_expiration_class = ' warn' %} {% endif %} {% else %} {% if options.expiration_class is defined %} {% set final_expiration_class = ' ' ~ options.expiration_class %} {% else %} {% set final_expiration_class = '' %} {% endif %} {% endif %}
{{ _self.input(name, value, options|merge({ 'type': 'text', 'id': options.id ~ '_input', 'additional_attributes': {'data-input': ''}, 'input_addclass': options.input_addclass ~ final_expiration_class, 'clearable': false })) }} {% if not options.readonly %} {% set calendar_icon = options.enableTime ? 'ti ti-calendar-time' : 'ti ti-calendar' %} {# maybeempty has no distinct purpose, but it was here first #} {% if options.clearable or options.maybeempty %} {% endif %} {% endif %}
{% set locale = get_current_locale() %} {% set date_format = options.enableTime ? 'Y-m-d H:i:S' : 'Y-m-d' %} {% set alt_format = call('Toolbox::getDateFormat', ['js']) ~ (options.enableTime ? ' H:i:S' : '') %} {% endmacro %} {% macro datetime(name, value, options = {}) %} {{ _self.date(name, value, options|merge({ 'enableTime': true })) }} {% endmacro %} {% macro textarea(name, value, options = {}) %} {% set options = { 'rand': random(), 'rows': 3, 'enable_richtext': false, 'enable_images': true, 'enable_mentions': false, 'entities_id': session('glpiactive_entity'), 'readonly': false, 'disabled': false, 'required': false, 'add_body_classes': [], 'toolbar': true, 'toolbar_location': 'top', 'init': true, 'placeholder': "", 'enable_form_tags': false, 'form_tags_form_id': null, 'aria_label': "", 'statusbar': true, 'content_style': "", }|merge(options) %} {% if options.fields_template.isMandatoryField(name) %} {% set options = {'required': true}|merge(options) %} {% endif %} {% set options = options|merge({ 'id': options.id|length > 0 ? options.id : (name ~ '_' ~ options.rand) }) %} {# 100% width is here to prevent width issues with tinymce #} {% if options.enable_richtext %} {% do call('Html::initEditorSystem', [ options.id, options.rand, true, options.disabled|default(false), options.enable_images, options.editor_height|default(150), options.add_body_classes, options.toolbar_location, options.init, options.placeholder, options.toolbar, options.statusbar, options.content_style, ]) %} {% endif %} {% if options.enable_form_tags %} {% endif %} {% if options.enable_mentions and config('use_notifications') %} {% endif %} {% endmacro %} {% macro checkbox(name, value, options = {}) %} {% set options = { 'id': null, 'input_addclass': '', 'readonly': false, 'disabled': false, 'required': false, }|merge(options) %} {% endmacro %} {% macro button(name, label = '', type = 'button', value = '', options = {}) %} {% set options = { 'type': 'submit', 'class': 'btn btn-primary', 'icon': '', 'icon_title': '', 'additional_attributes': {}, }|merge(options) %} {% endmacro %} {% macro submit(name, label = '', value = '', options = {}) %} {{ _self.button(name, label, 'submit', value, options) }} {% endmacro %} {% macro label(label, id, options = {}, class = 'form-label') %} {% set options = { locked: false, locked_value: null, tpl_mark: 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 %} {# `|escape` must be called before call to `|nl2br` to ensure that special chars in the text will escaped twice. #} {# Indeed, otherwise, due to the usage of `data-bs-html="true"`, any code snippet would be interpreted. #} {% set helper_safe_text = options.helper|escape|nl2br %} {% 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 %}