Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inc/entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function showForItemtype(Entity $entity, $itemtype = 'Entity')

$canedit = $itemtype === 'Entity' && $entity->canEdit($ID);

if ($itemtype === 'Entity') {
if ($itemtype === 'Entity' && $canedit) {
PluginCreditEntityConfig::showEntityConfigForm($entity->getID());
}

Expand Down Expand Up @@ -244,7 +244,7 @@ public static function showForItemtype(Entity $entity, $itemtype = 'Entity')
'itemtype' => PluginCreditEntity::class,
];

if ($itemtype === 'Entity' && $canedit) {
if ($itemtype === 'Entity') {
TemplateRenderer::getInstance()->display('@credit/creditentity.hmtl.twig', [
'form_url' => self::getFormUrl(),
'credittypeclass' => PluginCreditType::class,
Expand Down
22 changes: 12 additions & 10 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,18 @@ public static function showForTicket(Ticket $ticket)

$entries = [];

if ($number && $canedit) {
$massiveactionparams = [
'num_displayed' => min($number, $_SESSION['glpilist_limit']),
'container' => 'mass' . self::class . $rand,
'itemtype' => PluginCreditTicket::class,
'specific_actions' => [
'update' => _x('button', 'Update'),
'purge' => _x('button', 'Delete permanently'),
],
];
if ($number) {
if ($canedit) {
$massiveactionparams = [
'num_displayed' => min($number, $_SESSION['glpilist_limit']),
'container' => 'mass' . self::class . $rand,
'itemtype' => PluginCreditTicket::class,
'specific_actions' => [
'update' => _x('button', 'Update'),
'purge' => _x('button', 'Delete permanently'),
],
];
}
foreach (self::getAllForTicket($ID) as $data) {
$credit_entity = new PluginCreditEntity();
$credit_entity->getFromDB($data['plugin_credit_entities_id']);
Expand Down
2 changes: 2 additions & 0 deletions templates/creditentity.hmtl.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{% import "components/form/fields_macros.html.twig" as fields %}

{% set rand = random() %}
{% if canedit %}
<div name="firstbloc" id="firstbloc" class="">
<form name="creditentity_form{{ rand }}" id="creditentity_form{{ rand }}" method="post" action="{{ form_url }}">
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
Expand Down Expand Up @@ -121,6 +122,7 @@
<div class="hr mt-3 mb-3"></div>
</form>
</div>
{% endif %}
<div name="secondbloc" id="secondbloc" class="mb-5">
{% set datatable_params = {
'is_tab': true,
Expand Down
30 changes: 21 additions & 9 deletions templates/tickets/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
'entity': entity_id,
'condition': conditions,
'on_change': 'getQuantityRemainingForm(this.value);',
'on_change': 'getQuantityRemainingForm' ~ rand ~ '(this.value, this);',
'field_class': 'col-4 col-sm-4',
}
) }}
Expand All @@ -69,15 +69,27 @@
) }}

<script>
function getQuantityRemainingForm(val) {
var formblock = document.querySelector('.formblock');
var quantity = formblock.querySelector('[id*="plugin_credit_quantity"]');
var quantity_label = formblock.querySelector('[for*="plugin_credit_quantity"]');
function getQuantityRemainingForm{{ rand }}(val, source) {
var form = source ? source.closest('form') : document.getElementById('creditentity_form{{ rand }}');
if (!form) {
return;
}

var quantity = form.querySelector('[id*="plugin_credit_quantity"]');
var quantity_label = form.querySelector('[for*="plugin_credit_quantity"]');
if (!quantity || !quantity_label) {
return;
}

var form_help = quantity_label.querySelector('span.form-help');
if (!form_help) {
return;
}

if (val == 0) {
quantity.value = 0;
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : 0 ');
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : 0 ');
form_help.setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : 0 ');
form_help.setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : 0 ');
} else {
$.ajax({
type: 'POST',
Expand All @@ -88,8 +100,8 @@
}).done(function (data) {
quantity.max = data;
quantity.value = 0;
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
form_help.setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
form_help.setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
});
}
}
Expand Down