Skip to content

Commit

Permalink
feat(dropdown): choose a root ticket category for display
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Dec 5, 2018
1 parent b2f825b commit 9a28a61
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
12 changes: 12 additions & 0 deletions inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public function displayField($canEdit = true) {
&& $decodedValues['show_ticket_categories_depth'] > 0) {
$dparams['condition'] .= " AND `level` <= '" . $decodedValues['show_ticket_categories_depth'] . "'";
}
if (isset($decodedValues['show_ticket_categories_root'])
&& (int) $decodedValues['show_ticket_categories_root'] > 0) {
$sons = (new DBUtils)->getSonsOf(
ItilCategory::getTable(),
$decodedValues['show_ticket_categories_root']
);
$sons = "'" . implode("', '", $sons) . "'";
$dparams['condition'] .= " AND `id` IN ('" . $decodedValues['show_ticket_categories_root'] . "')";
}
break;

default:
Expand Down Expand Up @@ -219,6 +228,9 @@ public function prepareQuestionInputForSave($input) {
} else {
$input['values']['show_ticket_categories_depth'] = $input['show_ticket_categories_depth'];
}
$input['values']['show_ticket_categories_root'] = isset($input['show_ticket_categories_root'])
? $input['show_ticket_categories_root']
: '';
}
$input['values'] = json_encode($input['values']);
unset($input['show_ticket_categories']);
Expand Down
34 changes: 30 additions & 4 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,29 @@ function plugin_formcreator_hideAllParameters() {
echo '</td>';
echo '</tr>';

echo '<tr class="line1" id="cat_root_tr">';
echo '<td>';
echo '<label for="dropdown_root_ticket_categories'.$rand.'" id="label_root_ticket_categories">';
echo __('ticket categories root', 'formcreator');
echo '</label>';
echo '</td>';
echo '<td>';
$decodedValue = json_decode($this->fields['values'], JSON_OBJECT_AS_ARRAY);
$rootValue = isset($decodedValue['show_ticket_categories_root'])
? $decodedValue['show_ticket_categories_root']
: Dropdown::EMPTY_VALUE;
Dropdown::show(ITILCategory::class, [
'name' => 'show_ticket_categories_root',
'value' => $rootValue,
'rand' => $rand,
]);
echo '</td>';
echo '<td>';
echo '</td>';
echo '<td>';
echo '</td>';
echo '</tr>';

echo '<tr class="line1" id="values_tr">';
echo '<td>';
echo '<label for="dropdown_default_values'.$rand.'" id="label_default_values">';
Expand Down Expand Up @@ -1172,26 +1195,29 @@ function showFields(required, default_values, values, range, show_empty, regex,
ddvalue = dd.options[dd.selectedIndex].value;
if(ddvalue == 'ITILCategory') {
document.getElementById('cat_restrict_tr').style.display = 'table-row';
document.getElementById('cat_root_tr').style.display = 'table-row';
} else {
document.getElementById('cat_restrict_tr').style.display = 'none';
document.getElementById('cat_root_tr').style.display = 'none';
}
} else {
document.getElementById('dropdown_values_field').style.display = 'none';
document.getElementById('label_dropdown_values').style.display = 'none';
document.getElementById('cat_restrict_tr').style.display = 'none';
document.getElementById('cat_root_tr').style.display = 'none';
}
if(glpi_object) {
document.getElementById('glpi_objects_field').style.display = 'inline';
document.getElementById('label_glpi_objects').style.display = 'inline';
document.getElementById('label_glpi_objects').style.display = 'inline';
} else {
document.getElementById('glpi_objects_field').style.display = 'none';
document.getElementById('label_glpi_objects').style.display = 'none';
document.getElementById('label_glpi_objects').style.display = 'none';
}
if (dropdown_value || glpi_object) {
document.getElementById('dropdown_default_value_field').style.display = 'inline';
document.getElementById('dropdown_default_value_field').style.display = 'inline';
document.getElementById('label_dropdown_default_value').style.display = 'inline';
} else {
document.getElementById('dropdown_default_value_field').style.display = 'none';
document.getElementById('dropdown_default_value_field').style.display = 'none';
document.getElementById('label_dropdown_default_value').style.display = 'none';
}
if(show_empty) {
Expand Down
1 change: 1 addition & 0 deletions tests/suite-unit/PluginFormcreatorDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function providerPrepareQuestionInputForSave() {
'itemtype' => \ITILCategory::class,
'show_ticket_categories' => '2',
'show_ticket_categories_depth' => '3',
'show_ticket_categories_root' => '',
]),
'dropdown_values' => \ITILCategory::class,
]
Expand Down

0 comments on commit 9a28a61

Please sign in to comment.