Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [UNRELEASED]

- Fix Composer autoloader collisions with other plugins
- Make the plugin compatible with the Content Security Policy

## [3.0.3] - 2026-08-11

Expand Down
116 changes: 116 additions & 0 deletions public/js/migration_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* -------------------------------------------------------------------------
* GenericObject plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GenericObject.
*
* GenericObject 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.
*
* GenericObject 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 GenericObject. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/genericobject
* -------------------------------------------------------------------------
*/

/* global CFG_GLPI */

const glpiGenericobjectDebounceTimers = new WeakMap();

function glpiGenericobjectUpdateCounter(input) {
clearTimeout(glpiGenericobjectDebounceTimers.get(input));
glpiGenericobjectDebounceTimers.set(input, setTimeout(() => glpiGenericobjectFetchSystemName(input), 300));
}

function glpiGenericobjectFetchSystemName(input) {
const maxLen = parseInt(input.getAttribute('maxlength'));
const counterId = input.dataset.counterTarget;
const warningId = input.dataset.warningTarget;
const resultId = input.dataset.resultTarget;
const counter = counterId ? document.getElementById(counterId) : null;
const warning = warningId ? document.getElementById(warningId) : null;
const result = resultId ? document.getElementById(resultId) : null;

fetch(
`${CFG_GLPI.root_doc}/plugins/genericobject/front/migration_status.php?action=get_system_name&name=${encodeURIComponent(input.value)}`,
)
.then(r => r.json())
.then(data => {
const currentLen = data.system_name.length;
if (counter) {
counter.textContent = currentLen + '/' + maxLen;
counter.className = 'small';
if (currentLen >= maxLen) {
counter.classList.add('text-danger', 'fw-bold');
} else {
counter.classList.add('text-muted');
}
}

if (warning) {
if (currentLen >= maxLen) {
warning.classList.remove('d-none');
} else {
warning.classList.add('d-none');
}
}

if (result) {
result.textContent = data.system_name;
}
})
.catch((e) => console.error(e.message));
}

document.addEventListener('shown.bs.modal', function (event) {
const input = event.target.querySelector('[data-counter-target]');
if (input) {
glpiGenericobjectUpdateCounter(input);
}
});

function copyCode() {
const codeBlock = document.getElementById('codeBlock');
const textArea = document.createElement('textarea');
textArea.value = codeBlock.textContent;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);

const copyBtn = document.querySelector('.copy-btn');
copyBtn.innerHTML = `<i class="ti ti-check"></i> ${copyBtn.dataset.genericobjectCopiedLabel} !`;
copyBtn.classList.remove('btn-outline-secondary');
copyBtn.classList.add('btn-success');

setTimeout(() => {
copyBtn.innerHTML = `<i class="ti ti-clipboard"></i> ${copyBtn.dataset.genericobjectCopyLabel}`;
copyBtn.classList.remove('btn-success');
copyBtn.classList.add('btn-outline-secondary');
}, 2000);
}

document.addEventListener('input', (e) => {
if (e.target.matches('[data-genericobject-update-counter]')) {
glpiGenericobjectUpdateCounter(e.target);
}
});

document.addEventListener('click', (e) => {
if (e.target.closest('[data-genericobject-copy-code]') !== null) {
copyCode();
}
});
1 change: 1 addition & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function plugin_version_genericobject()
'author' => "<a href=\"mailto:contact@teclib.com\">Teclib'</a> & siprossii",
'homepage' => 'https://github.com/pluginsGLPI/genericobject',
'license' => 'GPLv2+',
'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_GENERICOBJECT_MIN_GLPI,
Expand Down
81 changes: 3 additions & 78 deletions templates/migration_status.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
data-counter-target="{{ modal_id }}-counter"
data-warning-target="{{ modal_id }}-length-warning"
data-result-target="{{ modal_id }}-result"
oninput="glpiGenericobjectUpdateCounter(this)"
data-genericobject-update-counter
required
>
<div class="d-flex justify-content-between align-items-center mt-1">
Expand Down Expand Up @@ -331,7 +331,7 @@
<div class="bg-light border border-secondary rounded p-3 position-relative mt-3">
<div class="d-flex align-items-center justify-content-between">
<code id="codeBlock" class="mb-0 flex-grow-1 bg-transparent">php bin/console migration:genericobject_plugin_to_core</code>
<button class="btn btn-sm btn-outline-secondary ms-3 copy-btn" onclick="copyCode()" title="{{ __('Copy command', 'genericobject') }}">
<button class="btn btn-sm btn-outline-secondary ms-3 copy-btn" data-genericobject-copy-code data-genericobject-copy-label="{{ __('Copy') }}" data-genericobject-copied-label="{{ __('Copied') }}" title="{{ __('Copy command', 'genericobject') }}">
<i class="ti ti-clipboard"></i>
{{ __('Copy') }}
</button>
Expand Down Expand Up @@ -430,79 +430,4 @@
right: 0.5rem;
}
</style>
<script>
const glpiGenericobjectDebounceTimers = new WeakMap();

function glpiGenericobjectUpdateCounter(input) {
clearTimeout(glpiGenericobjectDebounceTimers.get(input));
glpiGenericobjectDebounceTimers.set(input, setTimeout(() => glpiGenericobjectFetchSystemName(input), 300));
}

function glpiGenericobjectFetchSystemName(input) {
const maxLen = parseInt(input.getAttribute('maxlength'));
const counterId = input.dataset.counterTarget;
const warningId = input.dataset.warningTarget;
const resultId = input.dataset.resultTarget;
const counter = counterId ? document.getElementById(counterId) : null;
const warning = warningId ? document.getElementById(warningId) : null;
const result = resultId ? document.getElementById(resultId) : null;

fetch(
'{{ config('root_doc') }}/plugins/genericobject/front/migration_status.php?action=get_system_name&name=' + encodeURIComponent(input.value),
)
.then(r => r.json())
.then(data => {
const currentLen = data.system_name.length;
if (counter) {
counter.textContent = currentLen + '/' + maxLen;
counter.className = 'small';
if (currentLen >= maxLen) {
counter.classList.add('text-danger', 'fw-bold');
} else {
counter.classList.add('text-muted');
}
}

if (warning) {
if (currentLen >= maxLen) {
warning.classList.remove('d-none');
} else {
warning.classList.add('d-none');
}
}

if (result) {
result.textContent = data.system_name;
}
})
.catch((e) => console.error(e.message));
}

document.addEventListener('shown.bs.modal', function (event) {
const input = event.target.querySelector('[data-counter-target]');
if (input) {
glpiGenericobjectUpdateCounter(input);
}
});

function copyCode() {
const codeBlock = document.getElementById('codeBlock');
const textArea = document.createElement('textarea');
textArea.value = codeBlock.textContent;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);

const copyBtn = document.querySelector('.copy-btn');
copyBtn.innerHTML = '<i class="ti ti-check"></i> {{ __("Copied") }} !';
copyBtn.classList.remove('btn-outline-secondary');
copyBtn.classList.add('btn-success');

setTimeout(() => {
copyBtn.innerHTML = '<i class="ti ti-clipboard"></i> {{ __("Copy") }}';
copyBtn.classList.remove('btn-success');
copyBtn.classList.add('btn-outline-secondary');
}, 2000);
}
</script>
{{ call('Html::script', ['/plugins/genericobject/js/migration_status.js', {'version': constant('PLUGIN_GENERICOBJECT_VERSION')}, false])|raw }}