Skip to content

Commit

Permalink
Remove StepExecutorTrait::jsStepSubmit exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 2, 2023
1 parent c2638e9 commit de259e0
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions src/UserAction/StepExecutorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use Atk4\Core\Factory;
use Atk4\Data\Model;
use Atk4\Data\Model\UserAction;
use Atk4\Data\ValidationException;
use Atk4\Ui\Button;
use Atk4\Ui\Form;
use Atk4\Ui\Js\JsBlock;
use Atk4\Ui\Js\JsExpressionable;
use Atk4\Ui\Js\JsFunction;
use Atk4\Ui\Loader;
use Atk4\Ui\Message;
use Atk4\Ui\View;

trait StepExecutorTrait
Expand Down Expand Up @@ -405,42 +403,29 @@ protected function jsSetSubmitButton(View $view, Form $form, string $step): void

/**
* Get proper JS after submitting a form in a step.
*
* @return JsBlock|View
*/
protected function jsStepSubmit(string $step)
protected function jsStepSubmit(string $step): JsBlock
{
try {
if (count($this->steps) === 1) {
// collect argument and execute action
$return = $this->action->execute(...$this->getActionArgs($this->getActionData('args')));
$js = $this->jsGetExecute($return, $this->action->getEntity()->getId());
} else {
// store data and setup reload
$js = new JsBlock([
$this->loader->jsAddStoreData($this->actionData, true),
$this->loader->jsLoad(
[
'step' => $this->isLastStep($step) ? 'final' : $this->getNextStep($step),
$this->name => $this->action->getEntity()->getId(),
],
['method' => 'POST'],
$this->loader->name
),
]);
}

return $js;
} catch (ValidationException $e) {
throw $e; // handled by Form::onSubmit() method
} catch (\Throwable $e) {
$msg = new Message(['Error executing ' . $this->action->caption, 'type' => 'error', 'class.red' => true]);
$msg->setApp($this->getApp());
$msg->invokeInit();
$msg->text->content = $this->getApp()->renderExceptionHtml($e);

return $msg;
if (count($this->steps) === 1) {
// collect argument and execute action
$return = $this->action->execute(...$this->getActionArgs($this->getActionData('args')));
$js = $this->jsGetExecute($return, $this->action->getEntity()->getId());
} else {
// store data and setup reload
$js = new JsBlock([
$this->loader->jsAddStoreData($this->actionData, true),
$this->loader->jsLoad(
[
'step' => $this->isLastStep($step) ? 'final' : $this->getNextStep($step),
$this->name => $this->action->getEntity()->getId(),
],
['method' => 'POST'],
$this->loader->name
),
]);
}

return $js;
}

protected function getActionData(string $step): array
Expand Down

0 comments on commit de259e0

Please sign in to comment.