Skip to content

Commit

Permalink
fix(condition): some display failures
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 31, 2022
1 parent 4e997e5 commit c456a5d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
15 changes: 12 additions & 3 deletions ajax/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@
http_response_code(400);
die();
}

// Build an empty item or load it from DB
/** @var CommonDBTM $parent */
$parent = new $_POST['itemtype'];
$parent->getEmpty();
$parent->fields = array_intersect_key($_POST, $parent->fields);
if ($parent::isNewID((int) $_POST['items_id'])) {
$parent->getEmpty();
$parent->fields = array_intersect_key($_POST, $parent->fields);
} else {
if (!$parent->getFromDB((int) $_POST['items_id'])) {
http_response_code(404);
die();
}
}

// get an empty condition HTML table row
$condition = new PluginFormcreatorCondition();
$condition->fields['itemtype'] = $_POST['itemtype'];
$condition->fields['items_id'] = $_POST['items_id'];
$condition->fields['items_id'] = (int) $_POST['items_id'];
echo $condition->getConditionHtml($parent);
3 changes: 2 additions & 1 deletion inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2525,10 +2525,11 @@ final public static function showConditions(self $item) {
$options = [];
$item->initForm($item->getID(), $options);
$options['candel'] = false;
$options['formoptions'] = sprintf('data-itemtype="%s"', self::getType());
$options['formoptions'] = sprintf('data-itemtype="%s" data-id="%s"', self::getType(), $item->getID());
TemplateRenderer::getInstance()->display('@formcreator/pages/condition_for_item.html.twig', [
'item' => $item,
'params' => $options,
'parent' => $item,
]);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ public function isPublicAccess() : bool {
* @param CommonDBTM $item
* @return null|self
*/
public static function getByItem(CommonDBTM $item): ?self {
public static function getByItem( $item): ?self {
global $DB;

if ($item::getType() == self::getType()) {
Expand Down
3 changes: 2 additions & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getForbiddenStandardMassiveAction() {
public static function showForForm(CommonDBTM $item, $withtemplate = '') {
$options = [
'candel' => false,
'formoptions' => sprintf('data-itemtype="%s"', $item::getType()),
'formoptions' => sprintf('data-itemtype="%s" data-id="%s"', $item::getType(), $item->getID()),
];
TemplateRenderer::getInstance()->display('@formcreator/pages/question_for_form.html.twig', [
'item' => $item,
Expand Down Expand Up @@ -760,6 +760,7 @@ public function showForm($ID, $options = []) {
. ' method="post"'
. ' action="javascript:;"'
. ' data-itemtype="' . self::class . '"'
. ' data-id="' . $ID . '"'
. '>';
echo '<table class="tab_cadre_fixe">';

Expand Down
2 changes: 1 addition & 1 deletion inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public static function getSectionsFromForm($formId) {
public function showForm($ID, $options = []) {
$this->initForm($ID, $options);
$options['candel'] = false;
$options['formoptions'] = sprintf('data-itemtype="%s"', self::getType());
$options['formoptions'] = sprintf('data-itemtype="%s" data-id="%s"', self::getType(), $ID);
$options['target'] = "javascript:;";
TemplateRenderer::getInstance()->display('@formcreator/pages/section.html.twig', [
'item' => $this,
Expand Down
3 changes: 2 additions & 1 deletion js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,8 @@ function plugin_formcreator_addEmptyCondition(target) {
var form = target.closest('form[data-itemtype]');
var itemtype = form.getAttribute('data-itemtype');
// value of the hidden id input field
var id = form.querySelector('[name="id"]') ? form.querySelector('[name="id"]').value : 0;
// var id = form.querySelector('[name="id"]') ? form.querySelector('[name="id"]').value : 0;
var id = form.getAttribute('data-id') || null;
var data = new FormData(form);
data.append('itemtype', itemtype);
data.append('items_id', id);
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/targetticket.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{ required: true, full_width: true }
) }}

{{ fields.smallTitle(_n('Target ticket', 'Target changes', 1, 'formcreator')) }}
{{ fields.smallTitle(_n('Target ticket', 'Target tickets', 1, 'formcreator')) }}

{{ fields.textField(
'target_name',
Expand Down

0 comments on commit c456a5d

Please sign in to comment.