diff --git a/ajax/section_update.php b/ajax/section_update.php index dc908c470..813a06e61 100644 --- a/ajax/section_update.php +++ b/ajax/section_update.php @@ -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); \ No newline at end of file +echo json_encode(['id' => $section->getID(), 'name' => $section->getDesignLabel()], JSON_UNESCAPED_UNICODE); \ No newline at end of file diff --git a/inc/section.class.php b/inc/section.class.php index 7865d7c78..b2aaac7c2 100644 --- a/inc/section.class.php +++ b/inc/section.class.php @@ -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 = ''; + $html .= "$nb"; + $html .= ''; + $html .= empty($this->fields['name']) ? '(' . $sectionId . ')' : $this->fields['name']; + $html .= ''; + $html .= ''; + + return $html; + } } diff --git a/js/scripts.js b/js/scripts.js index 0f388d980..10b0df54b 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -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'); diff --git a/templates/components/form/section_design.html.twig b/templates/components/form/section_design.html.twig index 379009930..7292ed0d9 100644 --- a/templates/components/form/section_design.html.twig +++ b/templates/components/form/section_design.html.twig @@ -32,7 +32,7 @@
  • {% set conditionsCount = call('PluginFormcreatorCondition::countForItem', [item]) %} - + {# TODO : Show count of conditions #} {{ conditionsCount }} {% if item.fields['name'] is empty %} @@ -40,7 +40,7 @@ {% else %} {% set name = call('Glpi\\Toolbox\\Sanitizer::unsanitize', [item.fields['name']]) %} {% endif %} - {{ name }} + {{ name }} {# Delete a section #}