From ce2c2b207742ec497a1b4efe5773c10be3bc69d1 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 17 Oct 2024 11:20:56 +0200 Subject: [PATCH] Fix document fields readonly --- src/Document.php | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/Document.php b/src/Document.php index 323e9a9bcd3..a416dbb0672 100644 --- a/src/Document.php +++ b/src/Document.php @@ -1714,11 +1714,21 @@ public static function dropdown($options = []) $values[$data['id']] = $data['name']; } $rand = mt_rand(); - $out = Dropdown::showFromArray('_rubdoc', $values, ['width' => '30%', + $readonly = $p['readonly'] ?? false; + $out = ''; + $width = '30%'; + if ($readonly) { + $width = '100%'; + $out .= '
'; + $out .= '
'; + } + $out .= Dropdown::showFromArray('_rubdoc', $values, [ + 'width' => $width, 'rand' => $rand, 'display' => false, 'display_emptychoice' => true, 'value' => $p['rubdoc'] ?? 0, + 'readonly' => $readonly ]); $field_id = Html::cleanId("dropdown__rubdoc$rand"); @@ -1729,6 +1739,10 @@ public static function dropdown($options = []) 'used' => $p['used'] ]; + if ($readonly) { + $out .= '
'; + $out .= '
'; + } $out .= Ajax::updateItemOnSelectEvent( $field_id, "show_" . $p['name'] . $rand, @@ -1741,12 +1755,31 @@ public static function dropdown($options = []) $params['rubdoc'] = $p['rubdoc'] ?? 0; $params['value'] = $p['value'] ?? 0; - $out .= Ajax::updateItem( - "show_" . $p['name'] . $rand, - $CFG_GLPI["root_doc"] . "/ajax/dropdownRubDocument.php", - $params, - false - ); + if ($readonly) { + $document = new Document(); + $doclist = $document->find([]); + foreach ($doclist as $doc) { + $docvalue[$doc['id']] = $doc['name']; + } + + $out .= Dropdown::showFromArray('document', $docvalue ?? [], [ + 'width' => $width, + 'rand' => $rand, + 'display' => false, + 'display_emptychoice' => true, + 'value' => $p['value'] ?? 0, + 'readonly' => $readonly + ]); + $out .= '
'; + $out .= '
'; + } else { + $out .= Ajax::updateItem( + "show_" . $p['name'] . $rand, + $CFG_GLPI["root_doc"] . "/ajax/dropdownRubDocument.php", + $params, + false + ); + } if ($p['display']) { echo $out; return $rand;