|
255 | 255 | title="{{ __('Only letters and numbers, must start with a letter.', 'genericobject') }}" |
256 | 256 | data-counter-target="{{ modal_id }}-counter" |
257 | 257 | data-warning-target="{{ modal_id }}-length-warning" |
| 258 | + data-result-target="{{ modal_id }}-result" |
258 | 259 | oninput="glpiGenericobjectUpdateCounter(this)" |
259 | 260 | required |
260 | 261 | > |
261 | 262 | <div class="d-flex justify-content-between align-items-center mt-1"> |
| 263 | + |
| 264 | + <div class="d-flex flex-grow-1 gap-2" style="min-width: 0;"> |
| 265 | + <small class="text-muted"> |
| 266 | + {{ __('Use system name:', 'genericobject') }} |
| 267 | + </small> |
| 268 | + |
| 269 | + <small id="{{ modal_id }}-result" |
| 270 | + class="text-muted fw-bold text-truncate" |
| 271 | + style="min-width: 0; max-width: 50%;"> |
| 272 | + {{ call('PluginGenericobjectType::getSystemName', [genericobject_type.name]) }} |
| 273 | + </small> |
| 274 | + </div> |
| 275 | + |
| 276 | + <small id="{{ modal_id }}-counter" |
| 277 | + class="text-muted flex-shrink-0"> |
| 278 | + {{ genericobject_type.name|length }}/{{ constant('PluginGenericobjectType::MAX_TYPE_NAME_LENGTH') }} |
| 279 | + </small> |
| 280 | + |
| 281 | + </div> |
| 282 | + <div> |
262 | 283 | <small class="text-muted">{{ __('Only letters and numbers, must start with a letter.', 'genericobject') }}</small> |
263 | | - <small id="{{ modal_id }}-counter" class="text-muted">{{ genericobject_type.name|length }}/{{ constant('PluginGenericobjectType::MAX_TYPE_NAME_LENGTH') }}</small> |
264 | 284 | </div> |
265 | 285 | <div id="{{ modal_id }}-length-warning" class="text-danger small mt-1 d-none"> |
266 | 286 | <i class="ti ti-alert-circle me-1"></i> |
|
417 | 437 | <script> |
418 | 438 | function glpiGenericobjectUpdateCounter(input) { |
419 | 439 | const maxLen = parseInt(input.getAttribute('maxlength')); |
420 | | - const currentLen = input.value.length; |
421 | 440 | const counterId = input.dataset.counterTarget; |
422 | 441 | const warningId = input.dataset.warningTarget; |
| 442 | + const resultId = input.dataset.resultTarget; |
423 | 443 | const counter = counterId ? document.getElementById(counterId) : null; |
424 | 444 | const warning = warningId ? document.getElementById(warningId) : null; |
| 445 | + const result = resultId ? document.getElementById(resultId) : null; |
425 | 446 |
|
426 | | - if (counter) { |
427 | | - counter.textContent = currentLen + '/' + maxLen; |
428 | | - counter.className = 'small'; |
429 | | - if (currentLen >= maxLen) { |
430 | | - counter.classList.add('text-danger', 'fw-bold'); |
431 | | - } else { |
432 | | - counter.classList.add('text-muted'); |
| 447 | + fetch( |
| 448 | + '{{ config('root_doc') }}/plugins/genericobject/front/migration_status.php?action=get_system_name&name=' + encodeURIComponent(input.value), |
| 449 | + ) |
| 450 | + .then(r => r.json()) |
| 451 | + .then(data => { |
| 452 | + const currentLen = data.system_name.length; |
| 453 | + if (counter) { |
| 454 | + counter.textContent = currentLen + '/' + maxLen; |
| 455 | + counter.className = 'small'; |
| 456 | + if (currentLen >= maxLen) { |
| 457 | + counter.classList.add('text-danger', 'fw-bold'); |
| 458 | + } else { |
| 459 | + counter.classList.add('text-muted'); |
| 460 | + } |
433 | 461 | } |
434 | | - } |
435 | 462 |
|
436 | | - if (warning) { |
437 | | - if (currentLen >= maxLen) { |
438 | | - warning.classList.remove('d-none'); |
439 | | - } else { |
440 | | - warning.classList.add('d-none'); |
| 463 | + if (warning) { |
| 464 | + if (currentLen >= maxLen) { |
| 465 | + warning.classList.remove('d-none'); |
| 466 | + } else { |
| 467 | + warning.classList.add('d-none'); |
| 468 | + } |
441 | 469 | } |
442 | | - } |
| 470 | +
|
| 471 | + if (result) { |
| 472 | + result.textContent = data.system_name; |
| 473 | + } |
| 474 | + }) |
| 475 | + .catch((e) => console.error(e.message)); |
443 | 476 | } |
444 | 477 |
|
445 | 478 | document.addEventListener('shown.bs.modal', function (event) { |
|
0 commit comments