diff --git a/docs/callbacks.rst b/docs/callbacks.rst index 95b2ea4b54..b60f33b67f 100644 --- a/docs/callbacks.rst +++ b/docs/callbacks.rst @@ -210,7 +210,7 @@ When you trigger callback, you'll see the output:: {"success": true, "message": "Success", "eval": "alert(\"ok\")"} This is how JsCallback renders actions and sends them back to the browser. In order to retrieve and execute actions, -you'll need a JavaScript routine. Luckily JsCallback also implements JsExpressionable, so it, in itself is an action. +you'll need a JavaScript routine. Luckily JsCallback can be passed to :php:meth:`View::on()` as an JS action. Let me try this again. JsCallback is an :ref:`js_action` which will execute request towards a callback-URL that will execute PHP method returning one or more :ref:`js_action` which will be received and executed by the original action. diff --git a/src/Console.php b/src/Console.php index 88ae288cb5..6d56d1788d 100644 --- a/src/Console.php +++ b/src/Console.php @@ -138,7 +138,7 @@ public function set($fx = null, $event = null) */ public function jsExecute() { - return $this->sse; + return $this->sse->getJsCallback(); } private function escapeOutputHtml(string $message): string diff --git a/src/JsCallback.php b/src/JsCallback.php index 2f8ab03abb..8feefd4b81 100644 --- a/src/JsCallback.php +++ b/src/JsCallback.php @@ -4,7 +4,7 @@ namespace Atk4\Ui; -class JsCallback extends Callback implements JsExpressionable +class JsCallback extends Callback { /** @var array Holds information about arguments passed in to the callback. */ public $args = []; @@ -47,7 +47,7 @@ protected function flattenArray(array $response): array return $res; } - public function jsRender(): string + public function getJsCallback(): JsExpression { $this->getApp(); // assert has App @@ -57,7 +57,7 @@ public function jsRender(): string 'confirm' => $this->confirm, 'apiConfig' => $this->apiConfig, 'storeName' => $this->storeName, - ])->jsRender(); + ]); } /** diff --git a/src/View.php b/src/View.php index 977648f06a..79effd6560 100644 --- a/src/View.php +++ b/src/View.php @@ -1021,7 +1021,9 @@ public function on(string $event, $selector = null, $action = null, array $defau return $action($chain, ...$args); }, $arguments); - $actions[] = $cb; + $actions[] = $cb->getJsCallback(); + } elseif ($action instanceof JsCallback) { + $actions[] = $action->getJsCallback(); } elseif ($action instanceof UserAction\ExecutorInterface || $action instanceof Model\UserAction) { // Setup UserAction executor. $ex = $action instanceof Model\UserAction ? $this->getExecutorFactory()->create($action, $this) : $action; @@ -1044,7 +1046,7 @@ public function on(string $event, $selector = null, $action = null, array $defau if ($defaults['apiConfig'] ?? null) { $ex->apiConfig = $defaults['apiConfig']; } - $actions[] = $ex; + $actions[] = $ex->getJsCallback(); $ex->executeModelAction($arguments); } else { throw new Exception('Executor must be of type UserAction\JsCallbackExecutor or extend View and implement UserAction\JsExecutorInterface');