Skip to content

Commit

Permalink
Entity assistance UI + some AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Jun 13, 2024
1 parent 9265fe9 commit 262a8ef
Show file tree
Hide file tree
Showing 23 changed files with 727 additions and 1,029 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ The present file will list all changes made to the project; according to the
- `ajax/ticketassigninformation.php` script. Use `ajax/actorinformation.php` instead.
- `ajax/planningcheck.php` script. Use `Planning::showPlanningCheck()` instead.
- `test_ldap` and `test_ldap_replicate` actions in `front/authldap.form.php`. Use `ajax/ldap.php` instead.
- `ajax/ticketsatisfaction.php` and `ajax/changesatisfaction.php` scripts. Access `ajax/commonitilsatisfaction.php` directly instead.


## [10.0.16] unreleased
Expand Down
10 changes: 2 additions & 8 deletions ajax/cable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
break;

case 'get_socket_dropdown':
if (
(isset($_GET['itemtype']) && class_exists($_GET['itemtype']))
&& isset($_GET['items_id'])
) {
if (isset($_GET['itemtype'], $_GET['items_id']) && class_exists($_GET['itemtype'])) {
Socket::dropdown(['name' => $_GET['dom_name'],
'condition' => ['socketmodels_id' => $_GET['socketmodels_id'] ?? 0,
'itemtype' => $_GET['itemtype'],
Expand All @@ -87,10 +84,7 @@


case 'get_item_breadcrum':
if (
(isset($_GET['itemtype']) && class_exists($_GET['itemtype']))
&& isset($_GET['items_id']) && $_GET['items_id'] > 0
) {
if (isset($_GET['itemtype'], $_GET['items_id']) && class_exists($_GET['itemtype']) && $_GET['items_id'] > 0) {
if (method_exists($_GET['itemtype'], 'renderDcBreadcrumb')) {
echo $_GET['itemtype']::renderDcBreadcrumb($_GET['items_id']);
}
Expand Down
52 changes: 0 additions & 52 deletions ajax/changesatisfaction.php

This file was deleted.

191 changes: 29 additions & 162 deletions ajax/commonitilsatisfaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@
*/

/**
* Following variables have to be defined before inclusion of this file:
* @var string|CommonITILObject $itemtype
* @var string|CommonITILSatisfaction $inquest_itemtype
* @var bool|null $AJAX_INCLUDE
*/
global $AJAX_INCLUDE;

$AJAX_INCLUDE = 1;
include('../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

use Glpi\Application\View\TemplateRenderer;

$itemtype = $_POST['itemtype'];
$ent = new Entity();
// Get suffix for entity config fields. For backwards compatibility, ticket values have no suffix.
$config_suffix = $itemtype::getType() === 'Ticket' ? '' : ('_' . strtolower($itemtype::getType()));

if (isset($_POST['inquest_config' . $config_suffix]) && isset($_POST['entities_id'])) {
if (isset($_POST['inquest_config' . $config_suffix], $_POST['entities_id'])) {
if ($ent->getFromDB($_POST['entities_id'])) {
if (!$ent->canViewItem()) {
http_response_code(403);
die();
}
$inquest_delay = $ent->getfield('inquest_delay' . $config_suffix);
$inquest_rate = $ent->getfield('inquest_rate' . $config_suffix);
$inquest_duration = $ent->getfield('inquest_duration' . $config_suffix);
Expand All @@ -62,163 +73,19 @@
$max_closedate = '';
}

if ($_POST['inquest_config' . $config_suffix] > 0) {
echo "<table class='tab_cadre_fixe' width='50%'>";
echo "<tr class='tab_bg_1'><td width='50%'>" . __('Create survey after') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_delay' . $config_suffix,
['value' => $inquest_delay,
'min' => 1,
'max' => 90,
'step' => 1,
'toadd' => ['0' => __('As soon as possible')],
'unit' => 'day'
]
);
echo "</td></tr>";

echo "<tr class='tab_bg_1'>" .
"<td>" . __('Rate to trigger survey') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_rate' . $config_suffix,
[
'value' => $inquest_rate,
'min' => 10,
'max' => 100,
'step' => 10,
'toadd' => [0 => __('Disabled')],
'unit' => '%'
]
);
echo "</td></tr>";

echo "<tr class='tab_bg_1' data-field='duration{$config_suffix}'><td width='50%'>" . __('Duration of survey') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_duration' . $config_suffix,
[
'value' => $inquest_duration,
'min' => 1,
'max' => 180,
'step' => 1,
'toadd' => ['0' => __('Unspecified')],
'unit' => 'day'
]
);
echo "</td></tr>";
echo "<tr class='tab_bg_1' data-field='max_rate{$config_suffix}'><td width='50%'>" . __('Max rate') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_max_rate' . $config_suffix,
[
'value' => $inquest_max_rate,
'min' => 1,
'max' => 10,
'step' => 1,
'unit' => ''
]
);
echo "</td></tr>";

echo "<tr class='tab_bg_1' data-field='default_rate{$config_suffix}'><td width='50%'>" . __('Default rate') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_default_rate' . $config_suffix,
[
'value' => $inquest_default_rate,
'min' => 1,
'max' => 10,
'step' => 1,
'unit' => ''
]
);
echo "</td></tr>";

echo "<tr class='tab_bg_1' data-field='mandatory_comment{$config_suffix}'><td width='50%'>" . __('Comment required if score is <= to') . "</td>";
echo "<td>";
Dropdown::showNumber(
'inquest_mandatory_comment' . $config_suffix,
[
'value' => $inquest_mandatory_comment,
'min' => 1,
'max' => 10,
'step' => 1,
'toadd' => ['0' => __('Disabled')],
'unit' => ''
]
);
echo "</td></tr>";

echo "<tr class='tab_bg_1' data-field='max_closedate{$config_suffix}'><td>" . sprintf(__('For %s closed after'), $itemtype::getTypeName(Session::getPluralNumber())) . "</td><td>";
Html::showDateTimeField(
"max_closedate" . $config_suffix,
[
'value' => $max_closedate,
'timestep' => 1,
'maybeempty' => false,
]
);
echo "</td></tr>";

$tag_prefix = strtoupper($itemtype::getType());
$ticket_only_tags = "[REQUESTTYPE_ID] [REQUESTTYPE_NAME] [TICKETTYPE_NAME] [TICKETTYPE_ID] ";
$ticket_only_tags .= "[SLA_TTO_ID] [SLA_TTO_NAME] [SLA_TTR_ID] [SLA_TTR_NAME] [SLALEVEL_ID] [SLALEVEL_NAME]";

if ($_POST['inquest_config' . $config_suffix] == 2) {
echo "<tr class='tab_bg_1' data-field='url{$config_suffix}'>";
echo "<td>" . __('Valid tags') . "</td><td>" .
"[{$tag_prefix}_ID] [{$tag_prefix}_NAME] [{$tag_prefix}_CREATEDATE] [{$tag_prefix}_SOLVEDATE] " .
"[{$tag_prefix}_PRIORITY] [{$tag_prefix}_PRIORITYNAME] " .
"[ITILCATEGORY_ID] [ITILCATEGORY_NAME] " .
"[SOLUTIONTYPE_ID] [SOLUTIONTYPE_NAME] " .
($itemtype === 'Ticket' ? (' ' . $ticket_only_tags) : '') .
"</td></tr>";

echo "<tr class='tab_bg_1'><td>" . __('URL') . "</td>";
echo "<td>";
echo Html::input('inquest_URL' . $config_suffix, ['value' => $ent->fields['inquest_URL' . $config_suffix]]);
echo "</td></tr>";
}

echo "</table>";
$js = <<<JS
$(document).ready(() => {
const rate_dropdown = $('select[name="inquest_rate{$config_suffix}"]');
const refresh_param_rows = () => {
const param_rows = [
$('tr[data-field="duration{$config_suffix}"]'),
$('tr[data-field="max_rate{$config_suffix}"]'),
$('tr[data-field="default_rate{$config_suffix}"]'),
$('tr[data-field="mandatory_comment{$config_suffix}"]'),
$('tr[data-field="max_closedate{$config_suffix}"]'),
$('tr[data-field="url{$config_suffix}"]')
];
if (rate_dropdown.val() == 0) {
// Hide all param rows if they exist
param_rows.forEach(row => {
if (row.length > 0) {
row.hide();
}
});
} else {
// Show all param rows if they exist
param_rows.forEach(row => {
if (row.length > 0) {
row.show();
}
});
}
};
$(rate_dropdown).on('change', () => {
refresh_param_rows();
});
refresh_param_rows();
});
JS;
echo Html::scriptBlock($js);
if ((int) $_POST['inquest_config' . $config_suffix] > 0) {
TemplateRenderer::getInstance()->display('pages/admin/entity/survey_config.html.twig', [
'itemtype' => $itemtype,
'inquest_config' => $_POST['inquest_config' . $config_suffix],
'config_suffix' => $config_suffix,
'inquest_delay' => $inquest_delay,
'inquest_rate' => $inquest_rate,
'inquest_duration' => $inquest_duration,
'inquest_default_rate' => $inquest_default_rate,
'inquest_max_rate' => $inquest_max_rate,
'inquest_mandatory_comment' => $inquest_mandatory_comment,
'max_closedate' => $max_closedate,
'inquest_URL' => $ent->fields['inquest_URL' . $config_suffix] ?? ''
]);
}
}
5 changes: 3 additions & 2 deletions ajax/dropdownAllItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@
$params['entity_restrict'] = $_POST['entity_restrict'];
}

$name = htmlspecialchars($_POST["name"]);
Ajax::updateItemOnSelectEvent(
$field_id,
"showItemSpecificity_" . $_POST["name"] . "$rand",
"showItemSpecificity_" . $name . "$rand",
$_POST['showItemSpecificity'],
$params
);

echo "<br><span id='showItemSpecificity_" . $_POST["name"] . "$rand'>&nbsp;</span>\n";
echo "<br><span id='showItemSpecificity_" . $name . "$rand'>&nbsp;</span>\n";
}
}
6 changes: 3 additions & 3 deletions ajax/dropdownItilActors.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@
if ($CFG_GLPI["notifications_mailing"]) {
echo "<br><span id='notif_user_$rand'>";
if ($withemail) {
echo __('Email followup') . '&nbsp;';
echo __s('Email followup') . '&nbsp;';
$rand = Dropdown::showYesNo('_itil_' . $_POST["actortype"] . '[use_notification]', $_POST["use_notif"]);
echo '<br>';
printf(
__('%1$s: %2$s'),
_n('Email', 'Emails', 1),
_sn('Email', 'Emails', 1),
"<input type='text' size='25' name='_itil_" . $_POST["actortype"] .
"[alternative_email]'>"
);
Expand Down Expand Up @@ -224,7 +224,7 @@
if ($CFG_GLPI["notifications_mailing"]) {
echo "<br><span id='notif_supplier_$rand'>";
if ($withemail) {
echo __('Email followup') . '&nbsp;';
echo __s('Email followup') . '&nbsp;';
$rand = Dropdown::showYesNo('_itil_' . $_POST["actortype"] . '[use_notification]', $_POST['use_notif']);
echo '<br>';
printf(
Expand Down
19 changes: 13 additions & 6 deletions ajax/dropdownMassiveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* ---------------------------------------------------------------------
*/

/** @var array $CFG_GLPI */
global $CFG_GLPI;
use Glpi\Application\View\TemplateRenderer;

include('../inc/includes.php');

Expand All @@ -44,10 +43,18 @@
try {
$ma = new MassiveAction($_POST, $_GET, 'specialize');
} catch (\Throwable $e) {
echo "<div class='center'><img src='" . $CFG_GLPI["root_doc"] . "/pics/warning.png' alt='" .
__s('Warning') . "'><br><br>";
echo "<span class='b'>" . $e->getMessage() . "</span><br>";
echo "</div>";
$twig_params = [
'title' => __('Warning'),
'text' => $e->getMessage(),
];
// language=Twig
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
<div class="alert alert-warning">
<i class="alert-icon ti ti-alert-triangle"></i>
<div class="alert-title">{{ title }}</div>
<div class="text-secondary">{{ text }}</div>
</div>
TWIG, $twig_params);
exit();
}

Expand Down
4 changes: 2 additions & 2 deletions ajax/dropdownMassiveActionAddValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
]);
echo Html::hidden($itemtype_name, ['value' => 'User']);

echo "<br><br>" . __('Comments') . " ";
echo "<br><br>" . __s('Comments') . " ";
echo "<textarea name='comment_submission' cols='50' rows='6'></textarea>&nbsp;";

echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='btn btn-primary'>";
Expand All @@ -85,7 +85,7 @@
]);
echo Html::hidden($itemtype_name, ['value' => 'Group']);

echo "<br><br>" . __('Comments') . " ";
echo "<br><br>" . __s('Comments') . " ";
echo "<textarea name='comment_submission' cols='50' rows='6'></textarea>&nbsp;";

echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='btn btn-primary'>";
Expand Down
Loading

0 comments on commit 262a8ef

Please sign in to comment.