Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Assistance Tab UI + some AJAX #17023

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -357,6 +357,7 @@ The present file will list all changes made to the project; according to the
- `$CFG_GLPI['debug_sql']` and `$CFG_GLPI['debug_vars']` configuration options.
- `DropdownTranslation::getTranslationByName()`
- `addgroup` and `deletegroup` actions in `front/user.form.php`.
- `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
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
47 changes: 0 additions & 47 deletions ajax/changesatisfaction.php

This file was deleted.

190 changes: 26 additions & 164 deletions ajax/commonitilsatisfaction.php
Expand Up @@ -33,18 +33,24 @@
* ---------------------------------------------------------------------
*/

/**
* Following variables have to be defined before inclusion of this file:
* @var string|CommonITILObject $itemtype
* @var string|CommonITILSatisfaction $inquest_itemtype
*/
$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 +68,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
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
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
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
Expand Up @@ -80,7 +80,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 @@ -95,7 +95,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