diff --git a/CHANGELOG.md b/CHANGELOG.md
index a57ea7bf..f75b60b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [UNRELEASED]
+### Changed
+
+- Make the plugin compatible with the Content Security Policy
+
### Fixed
- Fix form submission error when a multiple dropdown field question is left empty
diff --git a/inc/container.class.php b/inc/container.class.php
index a5a78af4..93faf7c0 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -1471,7 +1471,8 @@ public static function showFormItemtype($params = [])
*/
public static function showFormSubtype($params, $display = false)
{
- $out = "";
+ $out = '';
+ $tab_tr_display = 'hide';
if (isset($params['type']) && $params['type'] == 'domtab' && class_exists($params['itemtype'])) {
$dbu = new DbUtils();
$item = $dbu->getItemForItemtype($params['itemtype']);
@@ -1509,11 +1510,14 @@ public static function showFormSubtype($params, $display = false)
'display' => false,
],
);
- $out .= "";
+ $tab_tr_display = 'show';
}
}
}
+ $out .= sprintf("
';
if ($canedit) {
echo "| ";
Html::showMassiveActionCheckBox(self::class, $data['id']);
@@ -247,23 +243,6 @@ public static function showTranslations(CommonDBTM $item)
}
echo ' | ';
- if ($canedit) {
- $ajax_params = [
- 'type' => self::class,
- 'itemtype' => $item::getType(),
- 'items_id' => $item->getID(),
- 'id' => $data['id'],
- ];
- echo Html::scriptBlock('
- viewEditTranslation' . $data['id'] . $rand . ' = function() {
- $("#viewtranslation' . $item->getID() . $rand . '").load(
- "' . $CFG_GLPI['root_doc'] . '/plugins/fields/ajax/viewtranslations.php",
- ' . json_encode($ajax_params) . '
- );
- };
- ');
- }
-
echo Dropdown::getLanguageName($data['language']);
echo ' | ';
echo htmlspecialchars((string) $data['label'], ENT_QUOTES);
diff --git a/public/js/container_subtype.js b/public/js/container_subtype.js
new file mode 100644
index 00000000..d8efd272
--- /dev/null
+++ b/public/js/container_subtype.js
@@ -0,0 +1,37 @@
+/**
+ * -------------------------------------------------------------------------
+ * 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
+ * -------------------------------------------------------------------------
+ */
+
+// Loaded right after its marker, not on DOM ready: keep the original timing.
+$('[data-fields-tab-tr]:not([data-fields-ready])').each(function () {
+ const marker = $(this).attr('data-fields-ready', '');
+ if (marker.attr('data-fields-tab-tr') === 'show') {
+ $('#tab_tr').show();
+ } else {
+ $('#tab_tr').hide();
+ }
+});
diff --git a/public/js/fields.js b/public/js/fields.js
new file mode 100644
index 00000000..eb580bc9
--- /dev/null
+++ b/public/js/fields.js
@@ -0,0 +1,131 @@
+/**
+ * -------------------------------------------------------------------------
+ * 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
+ * -------------------------------------------------------------------------
+ */
+
+// Load a subitem form into a target element. Used by links and table rows.
+$(document).on('click', '[data-fields-load-target]', function (e) {
+ if ($(this).is('a')) {
+ e.preventDefault();
+ }
+ $($(this).attr('data-fields-load-target')).load(
+ $(this).attr('data-fields-load-url'),
+ JSON.parse($(this).attr('data-fields-load-params'))
+ );
+});
+
+// Container display conditions list
+$(document).on('click', '[data-fields-conditions] button[name="edit"]', function (e) {
+ const row = $(e.currentTarget).closest('tr');
+ const id = row.find('input[name="id"]').val();
+ const container_id = row.find('input[name="plugin_fields_containers_id"]').val();
+
+ glpi_ajax_dialog(
+ {
+ title: __('Edit condition to hide block', 'fields'),
+ url: CFG_GLPI.root_doc + '/plugins/fields/ajax/container_display_condition.php',
+ method: 'get',
+ params: {
+ action: 'get_edit_form',
+ id: id,
+ plugin_fields_containers_id: container_id
+ },
+ dialogclass: 'modal-xl'
+ }
+ );
+});
+
+$(document).on('click', '[data-fields-conditions] button[name="switch_add"]', function (e) {
+ const container_id = $(e.currentTarget).attr('data-container-id');
+
+ glpi_ajax_dialog(
+ {
+ title: __('Add condition to hide block', 'fields'),
+ url: CFG_GLPI.root_doc + '/plugins/fields/ajax/container_display_condition.php',
+ method: 'get',
+ params: {
+ action: 'get_add_form',
+ plugin_fields_containers_id: container_id
+ },
+ dialogclass: 'modal-xl'
+ }
+ );
+});
+
+// Status overrides list
+$(document).on('click', '[data-fields-status-overrides] button[name="edit"]', function (e) {
+ const row = $(e.currentTarget).closest('tr');
+ const id = row.find('input[name="id"]').val();
+ const container_id = row.find('input[name="container_id"]').val();
+
+ glpi_ajax_dialog(
+ {
+ title: __('Edit status override', 'fields'),
+ url: CFG_GLPI.root_doc + '/plugins/fields/ajax/status_override.php',
+ method: 'get',
+ params: {
+ action: 'get_edit_form',
+ id: id,
+ container_id: container_id
+ },
+ dialogclass: 'modal-xl'
+ }
+ );
+});
+
+$(document).on('click', '[data-fields-status-overrides] button[name="switch_add"]', function (e) {
+ const container_id = $(e.currentTarget).attr('data-container-id');
+
+ glpi_ajax_dialog(
+ {
+ title: __('Add new status override', 'fields'),
+ url: CFG_GLPI.root_doc + '/plugins/fields/ajax/status_override.php',
+ method: 'get',
+ params: {
+ action: 'get_add_form',
+ container_id: container_id
+ },
+ dialogclass: 'modal-xl'
+ }
+ );
+});
+
+// Status override form: refresh the status list when the item type changes
+$(document).on('change', 'form[data-fields-status-override] select[name="itemtype"]', function () {
+ const form = $(this).closest('form');
+ const rand = form.attr('data-fields-status-override');
+
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/fields/ajax/status_override.php',
+ method: 'GET',
+ data: {
+ action: 'get_status_dropdown',
+ itemtype: $(this).val()
+ }
+ }).then((result) => {
+ $('#status_inner_container' + rand).html(result);
+ });
+});
diff --git a/public/js/question_type.js b/public/js/question_type.js
new file mode 100644
index 00000000..63f7a69a
--- /dev/null
+++ b/public/js/question_type.js
@@ -0,0 +1,51 @@
+/**
+ * -------------------------------------------------------------------------
+ * 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
+ * -------------------------------------------------------------------------
+ */
+
+// Question type field: init (existing or new question) then lock the mandatory input.
+// init is "none" on an AJAX reload, where only the lock applies.
+$('[data-fields-question-type]:not([data-fields-ready])').each(function () {
+ const marker = $(this).attr('data-fields-ready', '');
+ const rand = marker.attr('data-fields-question-type');
+ const init = marker.attr('data-fields-question-type-init');
+ const mandatory = marker.attr('data-fields-mandatory') === '1' ? 1 : 0;
+
+ import(CFG_GLPI.root_doc + GLPI_PLUGINS_PATH.fields + '/js/modules/QuestionField.js').then((m) => {
+ const questionField = new m.GlpiPluginFieldsQuestionTypeField();
+
+ if (init === 'existing') {
+ questionField.initExistingQuestion(rand);
+ } else if (init === 'new') {
+ questionField.initEventHandlers();
+ }
+
+ questionField.lockMandatoryInput(
+ $('[data-glpi-form-editor-question-type-fields-field-id-selector="' + rand + '"]').closest('[data-glpi-form-editor-question-details]'),
+ mandatory
+ );
+ });
+});
diff --git a/setup.php b/setup.php
index 1ed1bebc..1a3ab5ec 100644
--- a/setup.php
+++ b/setup.php
@@ -186,6 +186,8 @@ function plugin_init_fields()
// Add/delete profiles to automaticaly to container
$PLUGIN_HOOKS['item_add']['fields']['Profile'] = ['PluginFieldsProfile', 'addNewProfile'];
$PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = ['PluginFieldsProfile', 'deleteProfile'];
+ // Event handlers for the subitem loaders and the display conditions and status overrides lists
+ $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/fields.js';
//load drag and drop javascript library on Package Interface
@@ -238,12 +240,13 @@ function plugin_fields_script_endswith($scriptname)
function plugin_version_fields()
{
return [
- 'name' => __('Additional fields', 'fields'),
- 'version' => PLUGIN_FIELDS_VERSION,
- 'author' => "Teclib', Olivier Moron",
- 'homepage' => 'https://github.com/pluginsGLPI/fields',
- 'license' => 'GPLv2+',
- 'requirements' => [
+ 'name' => __('Additional fields', 'fields'),
+ 'version' => PLUGIN_FIELDS_VERSION,
+ 'author' => "Teclib', Olivier Moron",
+ 'homepage' => 'https://github.com/pluginsGLPI/fields',
+ 'license' => 'GPLv2+',
+ 'csp_compliant' => true,
+ 'requirements' => [
'glpi' => [
'min' => PLUGIN_FIELDS_MIN_GLPI,
'max' => PLUGIN_FIELDS_MAX_GLPI,
diff --git a/templates/container_display_conditions.html.twig b/templates/container_display_conditions.html.twig
index bcd543ce..2844882f 100644
--- a/templates/container_display_conditions.html.twig
+++ b/templates/container_display_conditions.html.twig
@@ -29,7 +29,7 @@
{% import 'components/form/fields_macros.html.twig' as fields %}
{% set rand = random() %}
-
+
{{ __('The engine is used for hide block when main object meets condition') }}
@@ -103,46 +103,4 @@
{# .flex-row #}
{# .card-body #}
-
diff --git a/templates/forms/status_override.html.twig b/templates/forms/status_override.html.twig
index 9c52a5a8..05bda3ea 100644
--- a/templates/forms/status_override.html.twig
+++ b/templates/forms/status_override.html.twig
@@ -29,7 +29,7 @@
{% import 'components/form/fields_macros.html.twig' as fields %}
{% set rand = random() %}
-
-
diff --git a/templates/question_type_administration.html.twig b/templates/question_type_administration.html.twig
index 47ceaf16..ec41f941 100644
--- a/templates/question_type_administration.html.twig
+++ b/templates/question_type_administration.html.twig
@@ -75,31 +75,7 @@
}
) }}
-{% if not is_ajax_reload %}
-
-{% else %}
-
-{% endif %}
+
+{{ call('Html::script', ['/plugins/fields/js/question_type.js', {}, false])|raw }}
diff --git a/templates/status_overrides.html.twig b/templates/status_overrides.html.twig
index 09a3edca..b3ea8195 100644
--- a/templates/status_overrides.html.twig
+++ b/templates/status_overrides.html.twig
@@ -29,7 +29,7 @@
{% import 'components/form/fields_macros.html.twig' as fields %}
{% set rand = random() %}
-
+
@@ -112,46 +112,4 @@
{# .flex-row #}
{# .card-body #}
-
|