Skip to content

Commit

Permalink
feat(formanswer): update anwers when validating
Browse files Browse the repository at this point in the history
but not when refusing

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Mar 25, 2021
1 parent dbc5ae4 commit 571e9ce
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ public function showForm($ID, $options = []) {
$form = $this->getForm();

$canEdit = $this->fields['status'] == self::STATUS_REFUSED
&& $_SESSION['glpiID'] == $this->fields['requester_id'];
&& Session::getLoginUserID() == $this->fields['requester_id']
|| $this->fields['status'] == self::STATUS_WAITING
&& $this->canValidate();

// form title
echo "<h1 class='form-title'>";
Expand Down Expand Up @@ -578,9 +580,10 @@ public function showForm($ID, $options = []) {

echo '</li>';
}
if ($canEdit) {

if ($canEdit || $editMode) {
echo Html::scriptBlock('$(function() {
plugin_formcreator.showFields($("form[name=\'form\']"));
plugin_formcreator.showFields($("form[name=\'' . $formName . '\']"));
})');
}

Expand Down Expand Up @@ -729,8 +732,14 @@ public function prepareInputForUpdate($input) {
$input['status'] = self::STATUS_ACCEPTED;
if (isset($input['refuse_formanswer'])) {
$input['status'] = self::STATUS_REFUSED;
// Update is restricted to a subset of fields
$input = [
'id' => $input['id'],
'status' => $input['status'],
'comment' => isset($input['comment']) ? $input['comment'] : 'NULL',
];
$skipValidation = true;
}
$skipValidation = true;
} else {
// The form answer is being updated
$input['status'] = self::STATUS_WAITING;
Expand All @@ -741,13 +750,6 @@ public function prepareInputForUpdate($input) {
return false;
}

// Update is restricted to a subset of fields
$input = [
'id' => $input['id'],
'status' => $input['status'],
'comment' => isset($input['comment']) ? $input['comment'] : 'NULL',
];

return $input;
}

Expand Down

0 comments on commit 571e9ce

Please sign in to comment.