Skip to content

Commit

Permalink
replace getOwner with getModel calls on UserAction
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 30, 2021
1 parent 03fc2f8 commit 7ea93aa
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions demos/collection/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function addFormTo(\Atk4\Ui\View $view): \Atk4\Ui\Form

$result = parent::addFormTo($left);

if ($this->action->getOwner()->get(File::hinting()->fieldName()->is_folder)) {
if ($this->action->getModel()->get(File::hinting()->fieldName()->is_folder)) {
\Atk4\Ui\Grid::addTo($right, ['menu' => false, 'ipp' => 5])
->setModel(File::assertInstanceOf($this->action->getOwner())->SubFolder);
->setModel(File::assertInstanceOf($this->action->getModel())->SubFolder);
} else {
\Atk4\Ui\Message::addTo($right, ['Not a folder', 'warning']);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ public function addAction(Model\UserAction $action, $executor, $button = null)

$page->add($executor = new $executor());

$action->getOwner()->assertIsEntity(); // TODO remove before #1623 merge
$action->getOwner()->load($id);
$action->getModel()->assertIsEntity(); // TODO remove before #1623 merge
$action->getModel()->load($id);

$executor->setAction($action);
});
Expand Down
2 changes: 1 addition & 1 deletion src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected function getNotifier(string $msg = null, Model\UserAction $action = nu
protected function jsModelReturn(Model\UserAction $action = null, string $msg = 'Done!'): array
{
$js[] = $this->getNotifier($msg, $action);
if ($action->getOwner()->loaded() && $card = $this->findCard($action->getOwner())) {
if ($action->getModel()->loaded() && $card = $this->findCard($action->getModel())) {
$js[] = $card->jsReload($this->getReloadArgs());
} else {
$js[] = $this->container->jsReload($this->getReloadArgs());
Expand Down
2 changes: 1 addition & 1 deletion src/UserAction/BasicExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function executeModelAction()
$return = $this->action->execute(...$args);

$success = $this->jsSuccess instanceof \Closure
? ($this->jsSuccess)($this, $this->action->getOwner())
? ($this->jsSuccess)($this, $this->action->getModel())
: $this->jsSuccess;

return ($this->hook(self::HOOK_AFTER_EXECUTE, [$return]) ?: $success) ?: new JsToast('Success' . (is_string($return) ? (': ' . $return) : ''));
Expand Down
10 changes: 5 additions & 5 deletions src/UserAction/ConfirmationExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public function executeModelAction()
{
$id = $this->stickyGet($this->name);
if ($id && $this->action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD) {
$this->action->getOwner()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getOwner()->tryLoad($id);
$this->action->getModel()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getModel()->tryLoad($id);
}

$this->loader->set(function ($modal) {
Expand Down Expand Up @@ -170,7 +170,7 @@ public function doConfirmation(View $modal)
$this->loader->jsload(
[
'step' => 'exec',
$this->name => $this->action->getOwner()->getId(),
$this->name => $this->action->getModel()->getId(),
],
['method' => 'post']
),
Expand Down Expand Up @@ -207,7 +207,7 @@ protected function doFinal(View $modal)
{
$return = $this->action->execute([]);

$this->_jsSequencer($modal, $this->jsGetExecute($return, $this->action->getOwner()->getId()));
$this->_jsSequencer($modal, $this->jsGetExecute($return, $this->action->getModel()->getId()));
}

/**
Expand All @@ -216,7 +216,7 @@ protected function doFinal(View $modal)
protected function jsGetExecute($obj, $id): array
{
$success = $this->jsSuccess instanceof \Closure
? ($this->jsSuccess)($this, $this->action->getOwner(), $id)
? ($this->jsSuccess)($this, $this->action->getModel(), $id)
: $this->jsSuccess;

return [
Expand Down
4 changes: 2 additions & 2 deletions src/UserAction/FormExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function initPreview()
// Setup form model using action fields.
if (!$this->form->model) {
if (!$this->action->fields) {
$this->action->fields = $this->getModelFields($this->action->getOwner());
$this->action->fields = $this->getModelFields($this->action->getModel());
}
$this->form->setModel($this->action->getOwner(), $this->action->fields);
$this->form->setModel($this->action->getModel(), $this->action->fields);
}

$this->form->onSubmit(function (Form $form) {
Expand Down
10 changes: 5 additions & 5 deletions src/UserAction/JsCallbackExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getAction(): Model\UserAction
public function setAction(Model\UserAction $action)
{
$this->action = $action;
if (!$this->action->enabled && $this->getOwner() instanceof View) {
if (!$this->action->enabled && $this->getModel() instanceof View) {
$this->getOwner()->addClass('disabled');
}

Expand All @@ -62,10 +62,10 @@ public function executeModelAction(array $args = [])
{
$this->set(function ($j) {
// may be id is passed as 'id' or model->id_field within $post args.
$id = $_POST['c0'] ?? $_POST['id'] ?? $_POST[$this->action->getOwner()->id_field] ?? null;
$id = $_POST['c0'] ?? $_POST['id'] ?? $_POST[$this->action->getModel()->id_field] ?? null;
if ($id && $this->action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD) {
$this->action->getOwner()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getOwner()->tryLoad($id);
$this->action->getModel()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getModel()->tryLoad($id);
}

if ($errors = $this->_hasAllArguments()) {
Expand All @@ -78,7 +78,7 @@ public function executeModelAction(array $args = [])

$return = $this->action->execute(...$args);
$success = $this->jsSuccess instanceof \Closure
? ($this->jsSuccess)($this, $this->action->getOwner(), $id, $return)
? ($this->jsSuccess)($this, $this->action->getModel(), $id, $return)
: $this->jsSuccess;

$js = $this->hook(BasicExecutor::HOOK_AFTER_EXECUTE, [$return, $id]) ?: $success ?: new JsToast('Success' . (is_string($return) ? (': ' . $return) : ''));
Expand Down
22 changes: 11 additions & 11 deletions src/UserAction/ModalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function executeModelAction()
{
$id = $this->stickyGet($this->name);
if ($id && $this->action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD) {
$this->action->getOwner()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getOwner()->tryLoad($id);
$this->action->getModel()->assertIsEntity(); // TODO remove before #1623 merge
$this->action->getModel()->tryLoad($id);
}

if ($this->action->fields === true) {
Expand Down Expand Up @@ -315,7 +315,7 @@ protected function doFields(View $modal)
$this->_addStepTitle($modal, $this->step);
$form = $this->addFormTo($modal);

$form->setModel($this->action->getOwner(), $this->action->fields);
$form->setModel($this->action->getModel(), $this->action->fields);
// set Fields value if set from another step.
$this->setFormField($form, $this->getActionData('fields'), $this->step);

Expand Down Expand Up @@ -350,7 +350,7 @@ protected function doPreview(View $modal)
if ($prev = $this->getPreviousStep($this->step)) {
$chain = $this->loader->jsload([
'step' => $prev,
$this->name => $this->action->getOwner()->getId(),
$this->name => $this->action->getModel()->getId(),
], ['method' => 'post'], $this->loader->name);

$modal->js(true, $this->prevStepBtn->js()->on('click', new JsFunction([$chain])));
Expand All @@ -366,7 +366,7 @@ protected function doPreview(View $modal)
$this->loader->jsload(
[
'step' => 'final',
$this->name => $this->action->getOwner()->getId(),
$this->name => $this->action->getModel()->getId(),
],
['method' => 'post'],
$this->loader->name
Expand Down Expand Up @@ -403,12 +403,12 @@ protected function doPreview(View $modal)
protected function doFinal(View $modal)
{
foreach ($this->getActionData('fields') as $field => $value) {
$this->action->getOwner()->set($field, $value);
$this->action->getModel()->set($field, $value);
}

$return = $this->action->execute(...$this->_getActionArgs($this->getActionData('args')));

$this->_jsSequencer($modal, $this->jsGetExecute($return, $this->action->getOwner()->getId()));
$this->_jsSequencer($modal, $this->jsGetExecute($return, $this->action->getModel()->getId()));
}

protected function getActionData(string $step): array
Expand All @@ -429,7 +429,7 @@ protected function getStep(): string
protected function jsGetExecute($obj, $id)
{
$success = $this->jsSuccess instanceof \Closure
? ($this->jsSuccess)($this, $this->action->getOwner(), $id, $obj)
? ($this->jsSuccess)($this, $this->action->getModel(), $id, $obj)
: $this->jsSuccess;

return [
Expand Down Expand Up @@ -550,14 +550,14 @@ protected function jsStepSubmit(string $step)
if ($this->isLastStep($step)) {
// collect argument and execute action.
$return = $this->action->execute(...$this->_getActionArgs($this->getActionData('args')));
$js = $this->jsGetExecute($return, $this->action->getOwner()->getId());
$js = $this->jsGetExecute($return, $this->action->getModel()->getId());
} else {
// store data and setup reload.
$js = [
$this->loader->jsAddStoreData($this->actionData, true),
$this->loader->jsload([
'step' => $this->getNextStep($step),
$this->name => $this->action->getOwner()->getId(),
$this->name => $this->action->getModel()->getId(),
], ['method' => 'post'], $this->loader->name),
];
}
Expand Down Expand Up @@ -653,7 +653,7 @@ protected function jsSetPrevHandler(View $view, string $step)
if ($prev = $this->getPreviousStep($step)) {
$chain = $this->loader->jsload([
'step' => $prev,
$this->name => $this->action->getOwner()->getId(),
$this->name => $this->action->getModel()->getId(),
], ['method' => 'post'], $this->loader->name);

$view->js(true, $this->prevStepBtn->js()->on('click', new JsFunction([$chain])));
Expand Down

0 comments on commit 7ea93aa

Please sign in to comment.