";
- echo "";
+ echo Html::script('/plugins/order/js/order_items.js', [], false);
}
@@ -474,10 +477,10 @@ public static function showOrderSupplierSurvey($ID)
echo "
";
echo sprintf(" | ", $arrow);
echo "";
- echo sprintf("", $formname) . __s('Check all') . " | ";
+ echo sprintf("", htmlescape($formname)) . __s('Check all') . "";
echo "/ | ";
echo "";
- echo sprintf("", $formname) . __s('Uncheck all') . " | ";
+ echo sprintf("", htmlescape($formname)) . __s('Uncheck all') . "";
echo "";
echo ".
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2009-2023 by Order plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/order
+ * -------------------------------------------------------------------------
+ */
+
+$(document).on('click', '[data-order-mark-checkboxes]', function (e) {
+ if (markCheckboxes($(this).attr('data-order-mark-checkboxes'))) {
+ e.preventDefault();
+ }
+});
+
+$(document).on('click', '[data-order-unmark-checkboxes]', function (e) {
+ if (unMarkCheckboxes($(this).attr('data-order-unmark-checkboxes'))) {
+ e.preventDefault();
+ }
+});
+
+$(document).on('click', '[data-order-show-div]', function (e) {
+ const root_doc = CFG_GLPI.root_doc;
+ showHideDiv(
+ $(this).attr('data-order-show-div'),
+ $(this).attr('data-order-show-img'),
+ root_doc + '/pics/plus.png',
+ root_doc + '/pics/moins.png'
+ );
+ e.preventDefault();
+});
+
+$(document).on('click', '[data-order-select-container]', function () {
+ selectNItems(
+ $(this).attr('data-order-select-container'),
+ $(this).attr('data-order-select-target')
+ );
+});
+
+document.addEventListener('click', (e) => {
+ const element = e.target.closest('[data-order-confirm]');
+ if (element && !window.confirm(element.dataset.orderConfirm)) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ }
+}, true);
+
+$(document).on('click', '[data-order-reload-tab]', function (e) {
+ e.preventDefault();
+ reloadTab($(this).attr('data-order-reload-tab'));
+});
+
+$(document).on('click', '[data-order-check-all]', function () {
+ checkAsCheckboxes(this, $(this).attr('data-order-check-all'), '.massive_action_checkbox');
+});
+
+function selectNItems(container_id, select_id) {
+ var selectElement = document.getElementById(select_id);
+ if (!selectElement) {
+ console.error("Select element not found:", select_id);
+ return;
+ }
+ var n = parseInt(selectElement.value);
+ if (isNaN(n) || n <= 0) {
+ console.error("Invalid number selected:", selectElement.value);
+ return;
+ }
+ var checked = 0;
+ var selector = "#" + container_id + " input[type='checkbox'][name^='item[PluginOrderLink]']";
+ var checkboxes = document.querySelectorAll(selector);
+ checkboxes.forEach(function(checkbox) {
+ checkbox.checked = false;
+ });
+ checkboxes.forEach(function(checkbox) {
+ if (checked < n) {
+ checkbox.checked = true;
+ checked++;
+ }
+ });
+}
+
+$(document).on('click', '[data-order-add-reference]', function () {
+ plugin_order_checkboxAction();
+});
+
+$(document).on('click', '[data-order-bulk-reception]', function (e) {
+ e.preventDefault();
+ window[$(this).attr('data-order-bulk-reception')]();
+});
+
+$(document).on('click', '[data-order-toggle-table]', function () {
+ const toggle = $(this);
+ const div_table = $('[name="' + toggle.attr('data-order-toggle-table') + '"]');
+ const icon = toggle.find('i');
+ const textSpan = icon.next('span');
+ const container_name = toggle.attr('data-order-toggle-container');
+ const countainer = $('#' + container_name);
+
+ let isVisible = !div_table.is(':hidden');
+
+ if (!isVisible) {
+ div_table.show();
+ icon.removeClass('ti-sort-descending').addClass('ti-sort-ascending');
+ textSpan.text(toggle.attr('data-order-collapse-label'));
+ countainer.val('true');
+ isVisible = true;
+ } else {
+ div_table.hide();
+ icon.removeClass('ti-sort-ascending').addClass('ti-sort-descending');
+ textSpan.text(toggle.attr('data-order-expand-label'));
+ countainer.val('false');
+ isVisible = false;
+ }
+
+ // Update all reloadTab buttons to reflect the new visibility state
+ $('[data-order-reload-tab]').each(function () {
+ let params = $(this).attr('data-order-reload-tab');
+
+ let paramsObj = {};
+ params.split('&').forEach(function (param) {
+ let [key, value] = param.split('=');
+ paramsObj[key] = value;
+ });
+
+ paramsObj[container_name + 'visible'] = isVisible ? '1' : '0';
+
+ let newParams = Object.entries(paramsObj).map(([key, value]) => `${key}=${value}`).join('&');
+ $(this).attr('data-order-reload-tab', newParams);
+ });
+});
+
+$(document).on('click', '[data-order-inline-edit]', function () {
+ const trigger = $(this);
+ trigger.hide();
+ $('#' + trigger.attr('data-order-inline-form')).show();
+ $.ajax({
+ url: trigger.attr('data-order-inline-url'),
+ method: 'POST',
+ data: JSON.parse(trigger.attr('data-order-inline-params')),
+ success: function (data) {
+ $('#' + trigger.attr('data-order-inline-view')).html(data).show();
+ }
+ });
+});
+
+$(document).on('click', '[data-order-inline-cancel]', function () {
+ const form_id = $(this).attr('data-order-inline-cancel');
+ $('[data-order-inline-form="' + form_id + '"]').each(function () {
+ $(this).show();
+ $('#' + $(this).attr('data-order-inline-view') + ' input').remove();
+ });
+ $('#' + form_id).hide();
+});
diff --git a/public/js/order_generate_item.js b/public/js/order_generate_item.js
new file mode 100644
index 0000000000..7c148c6854
--- /dev/null
+++ b/public/js/order_generate_item.js
@@ -0,0 +1,289 @@
+/**
+ * -------------------------------------------------------------------------
+ * Order plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Order.
+ *
+ * Order 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.
+ *
+ * Order 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 Order. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2009-2023 by Order plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/order
+ * -------------------------------------------------------------------------
+ */
+
+function plugin_order_config() {
+ return JSON.parse($("[data-order-generate-config]").first().attr("data-order-generate-config"));
+}
+
+ function plugin_order_adaptOnSelectedEntity(id, value) {
+ // Make AJAX call
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': value,
+ 'action': 'show_location_by_entity',
+ 'id': id
+ },
+ success: function(response) {
+ // This part is missing - updating the target element with response
+ $('#show_location_by_entity_id_' + id).html(response);
+ }
+ });
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': value,
+ 'action': 'show_group_by_entity',
+ 'multiple': plugin_order_config().multiple,
+ 'id': id
+ },
+ success: function(response) {
+ $('#show_group_by_entity_id_' + id).html(response);
+ }
+ });
+
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': value,
+ 'action': 'show_state_by_entity',
+ 'id': id,
+ },
+ success: function(response) {
+ $('#show_state_by_entity_id_' + id).html(response);
+ }
+ });
+ }
+
+ function plugin_order_setAllEntities(value) {
+ var elements = document.querySelectorAll('[id^="show_entity"]');
+ plugin_order_adaptOnSelectedEntity('mass', value);
+ for (var i = 0; i < elements.length; i++) {
+ (function(index) {
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': 0,
+ 'action': 'update_entity',
+ 'id': index,
+ 'value': value
+ },
+ success: function(response) {
+ $('#show_entity_id_' + index).html(response);
+ plugin_order_adaptOnSelectedEntity(index, value);
+ }
+ });
+ })(i);
+ }
+ }
+
+ function plugin_order_setAllLocations(value) {
+ var elements = document.querySelectorAll('[id^="show_location_by"]');
+ for (var i = 0; i < elements.length; i++) {
+ (function(index) {
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': 0,
+ 'action': 'show_location_by_entity',
+ 'id': index,
+ 'value': value
+ },
+ success: function(response) {
+ $('#show_location_by_entity_id_' + index).html(response);
+ }
+ });
+ })(i);
+ }
+ }
+
+ function plugin_order_setAllGroups(dom_select) {
+
+ const values = Array.from(dom_select.selectedOptions).map(
+ option => option.value
+ );
+
+ var elements = document.querySelectorAll('[id^="show_group_by"]');
+ for (var i = 0; i < elements.length; i++) {
+ (function(index) {
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': 0,
+ 'action': 'show_group_by_entity',
+ 'id': index,
+ 'value': values,
+ 'multiple': plugin_order_config().multiple
+ },
+ success: function(response) {
+ $('#show_group_by_entity_id_' + index).html(response);
+ }
+ });
+ })(i);
+ }
+ }
+
+ function plugin_order_setAllStates(value) {
+ var elements = document.querySelectorAll('[id^="show_state_by"]');
+ for (var i = 0; i < elements.length; i++) {
+ (function(index) {
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'entities': 0,
+ 'action': 'show_state_by_entity',
+ 'id': index,
+ 'value': value
+ },
+ success: function(response) {
+ $('#show_state_by_entity_id_' + index).html(response);
+ }
+ });
+ })(i);
+ }
+ }
+
+ function plugin_order_setFieldsFromTextarea(value, type) {
+ var lines = value.split(/\r?\n/);
+ var nameFields = document.querySelectorAll('input[name$="[' + type + ']"]');
+
+ for (var i = 0; i < nameFields.length; i++) {
+ var field = nameFields[i];
+ if (i < lines.length) {
+ field.value = lines[i].trim();
+ } else {
+ field.value = '';
+ }
+ var event = new Event('change', { bubbles: true });
+ field.dispatchEvent(event);
+ $(field).trigger('change');
+ }
+ }
+
+ $(function() {
+ // Namespaced off().on(): this script is re-executed each time the form is rendered
+ $('#mass_name_insertion').off('input.order_generate').on('input.order_generate', function() {
+ plugin_order_setFieldsFromTextarea(this.value, 'name');
+ });
+
+ $('#mass_serial_insertion').off('input.order_generate').on('input.order_generate', function() {
+ plugin_order_setFieldsFromTextarea(this.value, 'serial');
+ });
+
+ $('#mass_otherserial_insertion').off('input.order_generate').on('input.order_generate', function() {
+ plugin_order_setFieldsFromTextarea(this.value, 'otherserial');
+ });
+
+ if (plugin_order_config().can_immo) {
+ $('#mass_immo_number_insertion').off('input.order_generate').on('input.order_generate', function() {
+ plugin_order_setFieldsFromTextarea(this.value, 'immo_number');
+ });
+ }
+
+ // Mass dropdowns: replaces the former inline on_change attributes
+ $(document).off('change.order_generate')
+ .on('change.order_generate', 'select[name="mass[entities_id]"]', function() {
+ plugin_order_setAllEntities(this.value);
+ })
+ .on('change.order_generate', 'select[name="mass[locations_id]"]', function() {
+ plugin_order_setAllLocations(this.value);
+ })
+ .on('change.order_generate', 'select[name="mass[groups_id]"]', function() {
+ plugin_order_setAllGroups(this);
+ })
+ .on('change.order_generate', 'select[name="mass[states_id]"]', function() {
+ plugin_order_setAllStates(this.value);
+ })
+ .on('change.order_generate', 'select[name^="id["][name$="[entities_id]"]', function() {
+ plugin_order_adaptOnSelectedEntity(parseInt(this.name.match(/^id\[(\d+)\]/)[1], 10), this.value);
+ });
+ });
+
+ function sendFieldUpdateToServer(field, fieldType) {
+ // Get field value
+ var fieldValue = field.value;
+
+ // If field is empty, just remove validation states and return
+ if (fieldValue.trim() === '') {
+ $(field).removeClass('is-invalid');
+ $(field).removeAttr('required');
+ $(field).next('.invalid-feedback').remove();
+ return;
+ }
+
+ // Extract item ID from field name using regex
+ var namePattern = /id\[(\d+)\]\[/;
+ var matches = field.name.match(namePattern);
+ var itemId = matches ? matches[1] : 0;
+
+ // Find itemtype - this should be passed from your PHP controller or set globally
+ var itemtype = $('input[name="id[' + itemId + '][itemtype]"]').val();
+
+ // Make AJAX call
+ $.ajax({
+ url: CFG_GLPI.root_doc + '/plugins/order/ajax/linkactions.php',
+ type: 'POST',
+ data: {
+ 'action': 'check_unicity',
+ 'field': fieldType,
+ 'field_value': fieldValue,
+ 'itemtype': itemtype
+ },
+ success: function(response) {
+ if (response.trim() == 'false') {
+ if ($(field).hasClass('is-invalid')) {
+ return;
+ }
+
+ $(field).addClass('is-invalid');
+ // Create field type label for the message
+ let fieldTypeLabel = '';
+ if (fieldType === 'name') fieldTypeLabel = plugin_order_config().name_label;
+ if (fieldType === 'serial') fieldTypeLabel = plugin_order_config().serial_label;
+
+ // Add error message after the input
+ $(field).after(' ' + plugin_order_config().unicity_error + ' ');
+
+ // Add required attribute for visual indication
+ $(field).attr('required', 'required');
+ } else {
+ $(field).removeClass('is-invalid');
+ $(field).removeAttr('required');
+ $(field).next('.invalid-feedback').remove();
+ }
+ }
+ });
+ }
+
+ $(function() {
+ // Namespaced off().on(): this script is re-executed each time the form is rendered
+ $('input[name^="id["][name$="[name]"]').off('input.order_generate change.order_generate').on('input.order_generate change.order_generate', function() {
+ sendFieldUpdateToServer(this, 'name');
+ });
+
+ $('input[name^="id["][name$="[serial]"]').off('input.order_generate change.order_generate').on('input.order_generate change.order_generate', function() {
+ sendFieldUpdateToServer(this, 'serial');
+ });
+ });
diff --git a/public/js/order_items.js b/public/js/order_items.js
new file mode 100644
index 0000000000..ad8ac2d151
--- /dev/null
+++ b/public/js/order_items.js
@@ -0,0 +1,46 @@
+/**
+ * -------------------------------------------------------------------------
+ * Order plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Order.
+ *
+ * Order 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.
+ *
+ * Order 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 Order. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2009-2023 by Order plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/order
+ * -------------------------------------------------------------------------
+ */
+
+// Init of the order items tables, run each time a table is rendered
+(function () {
+ $('.filter-select-multiple:not(.select2-hidden-accessible)').select2();
+
+ $('[data-order-rateit]:not([data-order-ready])').each(function () {
+ $(this).attr('data-order-ready', '');
+ $(this).rateit(JSON.parse($(this).attr('data-order-rateit')));
+ });
+
+ $('[data-order-old-name]:not([data-order-ready])').each(function () {
+ $(this).attr('data-order-ready', '');
+ $('body').append($('', {
+ type: 'hidden',
+ name: $(this).attr('data-order-old-name'),
+ value: $(this).attr('data-order-old-value')
+ }));
+ });
+})();
diff --git a/setup.php b/setup.php
index 2c13e36ec6..bef3124b4d 100644
--- a/setup.php
+++ b/setup.php
@@ -196,6 +196,7 @@ function plugin_init_order()
/*if glpi is loaded */
if (Session::getLoginUserID()) {
$PLUGIN_HOOKS['add_css']['order'][] = 'css/order.css';
+ $PLUGIN_HOOKS['add_javascript']['order'][] = 'js/order.js';
/* link to the config page in plugins menu */
if (Session::haveRight("config", UPDATE)) {
@@ -231,6 +232,7 @@ function plugin_version_order()
'author' => 'The plugin order team',
'homepage' => 'https://github.com/pluginsGLPI/order',
'license' => 'GPLv2+',
+ 'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_ORDER_MIN_GLPI,
diff --git a/templates/generate_item.html.twig b/templates/generate_item.html.twig
index 52c80bb57c..e499271b43 100644
--- a/templates/generate_item.html.twig
+++ b/templates/generate_item.html.twig
@@ -82,7 +82,7 @@
"mass[entities_id]",
0,
"",
- fields_option|merge({'on_change': 'plugin_order_setAllEntities(this.value)'})
+ fields_option
) }}
|
{% endif %}
@@ -93,7 +93,7 @@
"mass[locations_id]",
0,
"",
- fields_option|merge({'on_change': 'plugin_order_setAllLocations(this.value)'})
+ fields_option
) }}
@@ -108,8 +108,7 @@
fields_option|merge({
'entity': -1,
'condition': {'is_itemgroup': 1},
- 'multiple': assignableitem ? true : false,
- 'on_change': 'plugin_order_setAllGroups(this)'
+ 'multiple': assignableitem ? true : false
})
) }}
@@ -122,7 +121,7 @@
"mass[states_id]",
0,
"",
- fields_option|merge({'on_change': 'plugin_order_setAllStates(this.value)'})
+ fields_option
) }}
@@ -213,7 +212,7 @@
"id[" ~ item.i ~ "][entities_id]",
item.order_entity_id,
"",
- fields_option|merge({'on_change': 'plugin_order_adaptOnSelectedEntity(' ~ item.i ~ ', this.value)'})
+ fields_option
) }}
@@ -268,244 +267,11 @@