Skip to content

Commit

Permalink
feat(section): update condition count after section edition
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 23, 2023
1 parent c72901c commit 8c04048
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ajax/section_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
Session::addMessageAfterRedirect(__('Could not update the section', 'formcreator'), false, ERROR);
exit;
}
echo json_encode(['id' => $section->getID(), 'name' => $section->fields['name']], JSON_UNESCAPED_UNICODE);
echo json_encode(['id' => $section->getID(), 'name' => $section->getDesignLabel()], JSON_UNESCAPED_UNICODE);
18 changes: 18 additions & 0 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,22 @@ public function getTranslatableStrings(array $options = []) : array {

return $strings;
}

public function getDesignLabel(): string {
$sectionId = $this->getID();
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
'itemtype' => self::getType(),
'items_id' => $sectionId,
]);
$formId = $this->fields[PluginFormcreatorForm::getForeignKeyField()];
$onclick = 'plugin_formcreator.showSectionForm(' . $formId . ', ' . $sectionId . ');';
$html = '<a href="#" onclick=' . $onclick . '" data-field="name">';
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
$html .= '<span>';
$html .= empty($this->fields['name']) ? '(' . $sectionId . ')' : $this->fields['name'];
$html .= '</span>';
$html .= '</a>';

return $html;
}
}
2 changes: 1 addition & 1 deletion js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ var plugin_formcreator = new function() {
displayAjaxMessageAfterRedirect();
}).done(function (data) {
var section = $('.plugin_formcreator_form_design[data-itemtype="PluginFormcreatorForm"] [data-itemtype="PluginFormcreatorSection"][data-id="' + sectionId + '"]');
section.find('> a [data-field="name"]').text(data['name']);
section.find('[data-field="name"]').replaceWith(data['name']);
that.resetTabs();
}).complete(function () {
var myModal = form.closest('div.modal');
Expand Down
4 changes: 2 additions & 2 deletions templates/components/form/section_design.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

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

{# Delete a section #}
Expand Down

0 comments on commit 8c04048

Please sign in to comment.