Skip to content

Commit 33775dd

Browse files
committed
feat(dropdownfield,glpiselectfield): choose if subtree root is selectable
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 31c2f24 commit 33775dd

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

ajax/commontree.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
}
3838

3939
// Load parameters
40-
$itemtype = $_GET['itemtype'];
41-
$root = $_GET['root'];
42-
$depth = $_GET['maxDepth'];
40+
$itemtype = $_GET['itemtype'];
41+
$root = $_GET['root'];
42+
$depth = $_GET['maxDepth'];
43+
$selectableRoot = $_GET['selectableRoot'];
4344

4445
// This should only be used for dropdowns
4546
if (!is_a($itemtype, CommonTreeDropdown::class, true)) {
@@ -53,6 +54,10 @@
5354
$additions .= '<label for="dropdown_show_tree_root'.$rand.'" id="label_show_tree_root">';
5455
$additions .= __('Subtree root', 'formcreator');
5556
$additions .= '</label>';
57+
$additions .= '<br>';
58+
$additions .= '<label for="dropdown_selectable_tree_root'.$rand.'" id="label_selectable_tree_root">';
59+
$additions .= __('Selectable', 'formcreator');
60+
$additions .= '</label>';
5661
$additions .= '</td>';
5762
$additions .= '<td>';
5863
$additions .= Dropdown::show($itemtype, [
@@ -61,6 +66,8 @@
6166
'rand' => $rand,
6267
'display' => false,
6368
]);
69+
$additions .= '<br>';
70+
$additions .= Dropdown::showYesNo('selectable_tree_root', $selectableRoot, -1, ['display' => false]);
6471
$additions .= '</td>';
6572
$additions .= '<td>';
6673
$additions .= '<label for="dropdown_show_tree_depth'.$rand.'" id="label_show_tree_depth">';

inc/field/dropdownfield.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function getDesignSpecializationField(): array {
7676

7777
$root = $decodedValues['show_tree_root'] ?? Dropdown::EMPTY_VALUE;
7878
$maxDepth = $decodedValues['show_tree_depth'] ?? Dropdown::EMPTY_VALUE;
79+
$selectableRoot = $decodedValues['selectable_tree_root'] ?? '0';
7980

8081
$optgroup = Dropdown::getStandardDropdownItemTypes();
8182

@@ -136,6 +137,7 @@ public function getDesignSpecializationField(): array {
136137
$additions .= '<td>';
137138
$additions .= "<input id='commonTreeDropdownRoot' type='hidden' value='$root'>";
138139
$additions .= "<input id='commonTreeDropdownMaxDepth' type='hidden' value='$maxDepth'>";
140+
$additions .= "<input id='commonTreeDropdownSelectableRoot' type='hidden' value='$selectableRoot'>";
139141
$additions .= '</td>';
140142
$additions .= '<td>';
141143
$additions .= '</td>';
@@ -308,11 +310,16 @@ public function buildParams($rand = null) {
308310
$itemtype::getTable(),
309311
$decodedValues['show_ticket_categories_root']
310312
);
313+
if (!isset($decodedValues['selectable_tree_root']) || $decodedValues['selectable_tree_root'] == '0') {
314+
unset($sons[$decodedValues['show_tree_root']]);
315+
}
316+
311317
$dparams_cond_crit[$itemtype::getTable() . '.id'] = $sons;
312318
$rootItem = new $itemtype();
313319
if ($rootItem->getFromDB($decodedValues['show_ticket_categories_root'])) {
314320
$baseLevel = $rootItem->fields['level'];
315321
}
322+
316323
}
317324

318325
// Apply max depth if defined (CommonTreeDropdown)
@@ -518,6 +525,7 @@ public function prepareQuestionInputForSave($input) {
518525
// Set default for depth setting
519526
$input['values']['show_tree_depth'] = (string) (int) ($input['show_tree_depth'] ?? '-1');
520527
$input['values']['show_tree_root'] = ($input['show_tree_root'] ?? '');
528+
$input['values']['selectable_tree_root'] = ($input['selectable_tree_root'] ?? '0');
521529
} else if ($input['dropdown_values'] == SLA::getType()
522530
|| $input['dropdown_values'] == OLA::getType()
523531
) {
@@ -532,6 +540,7 @@ public function prepareQuestionInputForSave($input) {
532540
unset($input['show_ticket_categories']);
533541
unset($input['show_tree_depth']);
534542
unset($input['show_tree_root']);
543+
unset($input['selectable_tree_root']);
535544
unset($input['dropdown_values']);
536545

537546
return $input;

inc/field/glpiselectfield.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function getDesignSpecializationField(): array {
9797

9898
$root = $decodedValues['show_tree_root'] ?? '0';
9999
$maxDepth = $decodedValues['show_tree_depth'] ?? Dropdown::EMPTY_VALUE;
100+
$selectableRoot = $decodedValues['selectable_tree_root'] ?? '0';
100101

101102
$additions = '<tr class="plugin_formcreator_question_specific">';
102103
$additions .= '<td>';
@@ -109,6 +110,7 @@ public function getDesignSpecializationField(): array {
109110
$additions .= '<td>';
110111
$additions .= "<input id='commonTreeDropdownRoot' type='hidden' value='$root'>";
111112
$additions .= "<input id='commonTreeDropdownMaxDepth' type='hidden' value='$maxDepth'>";
113+
$additions .= "<input id='commonTreeDropdownSelectableRoot' type='hidden' value='$selectableRoot'>";
112114
$additions .= '</td>';
113115
$additions .= '<td>';
114116
$additions .= '</td>';
@@ -162,13 +164,15 @@ public function prepareQuestionInputForSave($input) {
162164
// Set default for depth setting
163165
$input['values']['show_tree_depth'] = (int) ($input['show_tree_depth'] ?? '-1');
164166
$input['values']['show_tree_root'] = ($input['show_tree_root'] ?? '');
167+
$input['values']['selectable_tree_root'] = ($input['selectable_tree_root'] ?? '0');
165168
}
166169

167170
$input['values'] = json_encode($input['values']);
168171

169172
unset($input['dropdown_default_value']);
170173
unset($input['show_tree_root']);
171174
unset($input['show_tree_depth']);
175+
unset($input['selectable_tree_root']);
172176

173177
return $input;
174178
}

js/scripts.js.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ function plugin_formcreator_changeDropdownItemtype(rand) {
14671467
itemtype: dropdown_type,
14681468
root: $("#commonTreeDropdownRoot").val(),
14691469
maxDepth: $("#commonTreeDropdownMaxDepth").val(),
1470+
selectableRoot: $("#commonTreeDropdownSelectableRoot").val(),
14701471
},
14711472
}).done(function(response) {
14721473
$('.plugin_formcreator_dropdown').html(response);
@@ -1500,6 +1501,7 @@ function plugin_formcreator_changeGlpiObjectItemType() {
15001501
itemtype: glpi_object,
15011502
root: $("#commonTreeDropdownRoot").val(),
15021503
maxDepth: $("#commonTreeDropdownMaxDepth").val(),
1504+
selectableRoot: $("#commonTreeDropdownSelectableRoot").val(),
15031505
},
15041506
}).done(function(response) {
15051507
$('.plugin_formcreator_dropdown').html(response);

0 commit comments

Comments
 (0)