Skip to content

Commit 8c04048

Browse files
committed
feat(section): update condition count after section edition
1 parent c72901c commit 8c04048

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

ajax/section_update.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
Session::addMessageAfterRedirect(__('Could not update the section', 'formcreator'), false, ERROR);
5151
exit;
5252
}
53-
echo json_encode(['id' => $section->getID(), 'name' => $section->fields['name']], JSON_UNESCAPED_UNICODE);
53+
echo json_encode(['id' => $section->getID(), 'name' => $section->getDesignLabel()], JSON_UNESCAPED_UNICODE);

inc/section.class.php

+18
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,22 @@ public function getTranslatableStrings(array $options = []) : array {
541541

542542
return $strings;
543543
}
544+
545+
public function getDesignLabel(): string {
546+
$sectionId = $this->getID();
547+
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
548+
'itemtype' => self::getType(),
549+
'items_id' => $sectionId,
550+
]);
551+
$formId = $this->fields[PluginFormcreatorForm::getForeignKeyField()];
552+
$onclick = 'plugin_formcreator.showSectionForm(' . $formId . ', ' . $sectionId . ');';
553+
$html = '<a href="#" onclick=' . $onclick . '" data-field="name">';
554+
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
555+
$html .= '<span>';
556+
$html .= empty($this->fields['name']) ? '(' . $sectionId . ')' : $this->fields['name'];
557+
$html .= '</span>';
558+
$html .= '</a>';
559+
560+
return $html;
561+
}
544562
}

js/scripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ var plugin_formcreator = new function() {
10431043
displayAjaxMessageAfterRedirect();
10441044
}).done(function (data) {
10451045
var section = $('.plugin_formcreator_form_design[data-itemtype="PluginFormcreatorForm"] [data-itemtype="PluginFormcreatorSection"][data-id="' + sectionId + '"]');
1046-
section.find('> a [data-field="name"]').text(data['name']);
1046+
section.find('[data-field="name"]').replaceWith(data['name']);
10471047
that.resetTabs();
10481048
}).complete(function () {
10491049
var myModal = form.closest('div.modal');

templates/components/form/section_design.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232

3333
<li class="plugin_formcreator_section" data-itemtype="PluginFormcreatorSection" data-id="{{ item.fields['id'] }}">
3434
{% set conditionsCount = call('PluginFormcreatorCondition::countForItem', [item]) %}
35-
<a href="#" onclick="plugin_formcreator.showSectionForm({{ item.fields['plugin_formcreator_forms_id'] }}, {{ item.fields['id'] }})">
35+
<a href="#" onclick="plugin_formcreator.showSectionForm({{ item.fields['plugin_formcreator_forms_id'] }}, {{ item.fields['id'] }})" data-field="name">
3636
{# TODO : Show count of conditions #}
3737
<sup class="plugin_formcreator_conditions_count" title="{{ __('Count of conditions', 'formcreator') }}">{{ conditionsCount }}</sup>
3838
{% if item.fields['name'] is empty %}
3939
{% set name = '(' ~ item.fields['id'] ~ ')' %}
4040
{% else %}
4141
{% set name = call('Glpi\\Toolbox\\Sanitizer::unsanitize', [item.fields['name']]) %}
4242
{% endif %}
43-
<span data-field="name">{{ name }}</span>
43+
<span>{{ name }}</span>
4444
</a>
4545

4646
{# Delete a section #}

0 commit comments

Comments
 (0)