Skip to content

Commit

Permalink
fix(question): missing conditions count after update
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 26, 2023
1 parent 936ccd4 commit ea185be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ajax/question_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
http_response_code(500);
exit();
}
echo json_encode(['name' => Sanitizer::unsanitize($question->fields['name'])], JSON_UNESCAPED_UNICODE);
echo json_encode(['name' => $question->getDesignLabel()], JSON_UNESCAPED_UNICODE);
26 changes: 17 additions & 9 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ public static function showForForm(CommonDBTM $item, $withtemplate = '') {
return true;
}

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

return $html;
}

/**
* Get the HTML for the question in form designer
*
Expand Down Expand Up @@ -218,16 +234,8 @@ public function getDesignHtml() : string {

// Question name
$html .= $field->getHtmlIcon() . '&nbsp;';
$onclick = 'plugin_formcreator.showQuestionForm(' . $sectionId . ', ' . $questionId . ');';
$html .= '<a href="javascript:' . $onclick . '" data-field="name">';
// Show count of conditions
$nb = (new DBUtils())->countElementsInTable(PluginFormcreatorCondition::getTable(), [
'itemtype' => PluginFormcreatorQuestion::getType(),
'items_id' => $this->getID(),
]);
$html .= "<sup class='plugin_formcreator_conditions_count' title='" . __('Count of conditions', 'formcreator') ."'>$nb</sup>";
$html .= empty($this->fields['name']) ? '(' . $questionId . ')' : $this->fields['name'];
$html .= '</a>';
$html .= $this->getDesignLabel();

// Delete the question
$html .= "<span class='form_control pointer'>";
Expand Down
2 changes: 1 addition & 1 deletion js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ var plugin_formcreator = new function() {
displayAjaxMessageAfterRedirect();
}).done(function(data) {
var question = $('.plugin_formcreator_form_design[data-itemtype="PluginFormcreatorForm"] [data-itemtype="PluginFormcreatorQuestion"][data-id="' + questionId + '"]');
question.find('[data-field="name"]').text(data['name'])
$(question.find('[data-field="name"]')).replaceWith(data['name']);
that.resetTabs();
});

Expand Down

0 comments on commit ea185be

Please sign in to comment.