Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Sep 25, 2024
1 parent 8b50d7b commit f5d6d04
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 49 deletions.
78 changes: 41 additions & 37 deletions src/CommonITILValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,23 +977,26 @@ public function showSummary(CommonDBTM $item)
Session::initNavigateListItems(
static::class,
//TRANS : %1$s is the itemtype name, %2$s is the name of the item (used for headings of a list)
sprintf(
__('%1$s = %2$s'),
$item::getTypeName(1),
$item->fields["name"]
)
sprintf(
__('%1$s = %2$s'),
$item::getTypeName(1),
$item->fields["name"]
)
);
$values = [];
foreach ($iterator as $row) {
$canedit = $this->canEdit($row["id"]);
Session::addToNavigateListItems($this->getType(), $row["id"]);
$bgcolor = self::getStatusColor($row['status']);
$status = "<div class='badge fw-normal fs-4 text-wrap' style='border-color:" . $bgcolor . ";border-width: 2px;'>" . self::getStatus($row['status']) . "</div>";
$status = sprintf(
'<div class="badge fw-normal fs-4 text-wrap" style="border-color: %s;border-width: 2px;">%s</div>',
htmlspecialchars(self::getStatusColor($row['status'])),
htmlspecialchars(self::getStatus($row['status']))
);

$comment_submission = RichText::getEnhancedHtml($this->fields['comment_submission'], ['images_gallery' => true]);
$type_name = null;
$target_name = null;
if ($row["itemtype_target"] === 'User') {
if ($row["itemtype_target"] === User::class) {
$type_name = User::getTypeName();
$target_name = getUserName($row["items_id_target"]);
} elseif (is_a($row["itemtype_target"], CommonDBTM::class, true)) {
Expand All @@ -1007,47 +1010,50 @@ public function showSummary(CommonDBTM $item)
$comment_validation = RichText::getEnhancedHtml($this->fields['comment_validation'] ?? '', ['images_gallery' => true]);

$doc_item = new Document_Item();
$docs = $doc_item->find(["itemtype" => static::class,
$docs = $doc_item->find([
"itemtype" => static::class,
"items_id" => $this->getID(),
"timeline_position" => ['>', CommonITILObject::NO_TIMELINE]
]);

$document = "";
foreach ($docs as $docs_values) {
$doc = new Document();
$doc->getFromDB($docs_values['documents_id']);
$document .= "<a ";
$document .= "href=\"" . htmlspecialchars(Document::getFormURLWithID($docs_values['documents_id']), ENT_QUOTES, 'UTF-8') . "\">";
$document .= htmlspecialchars($doc->getField('name'), ENT_QUOTES, 'UTF-8') . "</a><br>";
$doc = new Document();
if ($doc->getFromDB($docs_values['documents_id'])) {
$document .= sprintf(
'<a href="%s">%s</a><br />',
htmlspecialchars($doc->getLinkURL()),
htmlspecialchars($doc->getName())
);
}
}

$script = "";
if ($canedit) {
$params = ['type' => static::class,
$edit_title = __s('Edit');
$item_id = htmlspecialchars($item->fields['id']);
$row_id = htmlspecialchars($row["id"]);
$rand = htmlspecialchars($rand);
$view_validation_id = htmlspecialchars($this->fields[static::$items_id]);
$root_doc = htmlspecialchars($CFG_GLPI["root_doc"]);
$params_json = json_encode([
'type' => static::class,
'parenttype' => static::$itemtype,
static::$items_id => $this->fields[static::$items_id],
'id' => $row["id"]
];

$editTitle = htmlspecialchars(__('Edit'), ENT_QUOTES, 'UTF-8');
$itemId = htmlspecialchars($item->fields['id'], ENT_QUOTES, 'UTF-8');
$rowId = htmlspecialchars($row["id"], ENT_QUOTES, 'UTF-8');
$rand = htmlspecialchars($rand, ENT_QUOTES, 'UTF-8');
$viewValidationId = htmlspecialchars($this->fields[static::$items_id], ENT_QUOTES, 'UTF-8');
$rootDoc = htmlspecialchars($CFG_GLPI["root_doc"], ENT_QUOTES, 'UTF-8');
$paramsJson = json_encode($params, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
]);

$script = <<<HTML
<span class='far fa-edit' style='cursor:pointer' title='$editTitle'
onClick="viewEditValidation{$itemId}{$rowId}{$rand}();"
id='viewvalidation{$viewValidationId}{$rowId}{$rand}'>
</span>
<script type='text/javascript'>
function viewEditValidation{$itemId}{$rowId}{$rand}() {
$('#viewvalidation{$itemId}{$rand}').load('$rootDoc/ajax/viewsubitem.php', $paramsJson);
};
</script>
HTML;
<span class="far fa-edit" style="cursor:pointer" title="{$edit_title}"
onclick="viewEditValidation{$item_id}{$row_id}{$rand}();"
id="viewvalidation{$view_validation_id}{$row_id}{$rand}">
</span>
<script>
function viewEditValidation{$item_id}{$row_id}{$rand}() {
$('#viewvalidation{$item_id}{$rand}').load('$root_doc/ajax/viewsubitem.php', $params_json);
};
</script>
HTML;
}

$values[] = [
Expand All @@ -1071,11 +1077,9 @@ function viewEditValidation{$itemId}{$rowId}{$rand}() {
'itemtype' => static::$itemtype,
'tID' => $tID,
'donestatus' => array_merge($item->getSolvedStatusArray(), $item->getClosedStatusArray()),
'this' => $this,
'self' => self::getType(),
'validation' => $this,
'rand' => $rand,
'items_id' => static::$items_id,
'root_doc' => $CFG_GLPI["root_doc"]
]);

TemplateRenderer::getInstance()->display('components/datatable.html.twig', [
Expand Down
24 changes: 12 additions & 12 deletions templates/components/itilobject/validation.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
{% import 'components/form/fields_macros.html.twig' as fields %}

{% if canadd %}
<form method='post' name="form" action={{ call(itemtype ~ '::getFormURL') }}>
<form method='post' name="form" action={{ itemtype|itemtype_form_path }}>
{% endif %}
<div class="card border-0 shadow-none p-0 m-0 mt-3">
<div class="card-header mb-1 pt-2">
<h4 class="card-title ">
{{ this.getTypeName(2) }}
{{ validation.getTypeName(2) }}
</h4>
</div>
</div>

{{ fields.htmlField(
'',
call(self ~ '::getStatus', [item.fields["global_validation"], true])|raw,
validation.getStatus(item.fields["global_validation"], true),
__('Global approval status')
) }}

{{ fields.htmlField(
'',
call(self ~ '::getValidationStats', [tID]),
validation.getValidationStats(tID),
__('Approval status details')
) }}

Expand All @@ -61,9 +61,9 @@
'validation_percent',
item.fields["validation_percent"]
)|raw }}
<input type='submit' name='update' class='btn btn-primary' value='{{ _x('button', 'Save') }}'>
<input type="submit" name="update" class="btn btn-primary" value="{{ _x('button', 'Save') }}">
{% if tID is not null %}
<input type='hidden' name='id' value='{{ tID }}'>
<input type="hidden" name="id" value="{{ tID }}">
{% endif %}
{% endset %}

Expand Down Expand Up @@ -102,16 +102,16 @@
{% endif %}
</div>

<div id='viewvalidation{{ tID }}{{ rand }}'></div>
<div id="viewvalidation{{ tID }}{{ rand }}"></div>

<script type='text/javascript'>
<script>
function viewAddValidation{{ tID }}{{ rand }}() {
var params = {
type: '{{ this.getType() }}',
parenttype: '{{ itemtype }}',
{{ items_id }}: '{{ this.fields[items_id] }}',
type: '{{ get_class(validation)|e('js') }}',
parenttype: '{{ itemtype|e('js') }}',
{{ items_id }}: '{{ validation.fields[items_id]|e('js') }}',
id: -1
};
$('#viewvalidation{{ tID }}{{ rand }}').load('{{ root_doc }}/ajax/viewsubitem.php', params);
$('#viewvalidation{{ tID }}{{ rand }}').load('{{ config('root_doc')|e('js') }}/ajax/viewsubitem.php', params);
};
</script>

0 comments on commit f5d6d04

Please sign in to comment.