From 6f9cf9e443278687929471976edfcdc70c9658a3 Mon Sep 17 00:00:00 2001 From: Alexander Nikushkin Date: Tue, 16 Apr 2024 18:08:48 +0500 Subject: [PATCH] docs(action-buttons): description method() issue #424 --- .../views/pages/en/action_button.blade.php | 70 +++++++++++++++++++ .../views/pages/ru/action_button.blade.php | 70 +++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/resources/views/pages/en/action_button.blade.php b/resources/views/pages/en/action_button.blade.php index 14642bc9..aa15b706 100644 --- a/resources/views/pages/en/action_button.blade.php +++ b/resources/views/pages/en/action_button.blade.php @@ -506,6 +506,11 @@ public function components(): array } + + For the table-updated-index-table event to work + async mode must be enabled. + + @@ -545,6 +550,30 @@ public function components(): array ActionButton without having to create additional controllers. + +method( + string $method, + array|Closure $params = [], + ?string $message = null, + ?string $selector = null, + array $events = [], + string|AsyncCallback|null $callback = null, + ?Page $page = null, + ?ResourceContract $resource = null +) + + + +
  • $method - name of the method
  • +
  • $params - parameters for the request,
  • +
  • $message - messages
  • +
  • $selector - selector of the element whose content will change
  • +
  • $events - events to be called after a successful request,
  • +
  • $callback - js callback function after receiving a response
  • +
  • $page - page containing the method
  • +
  • $resource - resource containing the method.
  • +
    + public function components(): array { @@ -585,6 +614,47 @@ public function updateSomething(MoonShineRequest $request) Methods called via ActionButton in a resource must be public! + + Для доступа к данным из реквеста, необходимо передать их в параметрах. + + + + + + Если в запросе присутствует resourceItem, + то в ресурсе вы можете получить доступ к текущему элементу через метод getItem(). + + + +
  • + When there is a model in the data and the button is created in the buttons() method + TableBuilder, + CardsBuilder + or FormBuilder, + then it is automatically filled with data and the parameters will contain resourceItem. +
  • +
  • + When the button is on the ModelResource form page, you can pass the id of the current element. + +ActionButton::make('Click me') + ->method( + 'updateSomething', + params: ['resourceItem' => $this->getResource()->getItemID()] // [tl! focus] + ) + +
  • +
  • + When the button is in the ModelResource index table, you need to use a closure. + +ActionButton::make('Click me') + ->method( + 'updateSomething', + params: ['resourceItem' => fn($item) ['resourceItem' => $item->getKey()]] // [tl! focus] + ) + +
  • +
    + Dispatch events diff --git a/resources/views/pages/ru/action_button.blade.php b/resources/views/pages/ru/action_button.blade.php index 8074a48d..ef9a679d 100644 --- a/resources/views/pages/ru/action_button.blade.php +++ b/resources/views/pages/ru/action_button.blade.php @@ -506,6 +506,11 @@ public function components(): array }
    + + Для работы события table-updated-index-table + должен быть включен асинхронный режим. + + @@ -545,6 +550,30 @@ public function components(): array ActionButton без необходимости создавать дополнительные контроллеры. + +method( + string $method, + array|Closure $params = [], + ?string $message = null, + ?string $selector = null, + array $events = [], + string|AsyncCallback|null $callback = null, + ?Page $page = null, + ?ResourceContract $resource = null +) + + + +
  • $method - наименование метода,
  • +
  • $params - параметры для запроса,
  • +
  • $message - сообщения,
  • +
  • $selector - selector элемента у которого будет изменяться контент,
  • +
  • $events - вызываемые события после успешного запроса,
  • +
  • $callback - js callback функция после получения ответа,
  • +
  • $page - страница содержащая метод,
  • +
  • $resource - ресурс содержащий метод.
  • +
    + public function components(): array { @@ -585,6 +614,47 @@ public function updateSomething(MoonShineRequest $request) Методы в вызываемые через ActionButton в ресурсе должны быть публичными! + + Для доступа к данным из реквеста, необходимо передать их в параметрах. + + + + + + Если в запросе присутствует resourceItem, + то в ресурсе вы можете получить доступ к текущему элементу через метод getItem(). + + + +
  • + Когда в данных присутствует модель и кнопка создается в методе buttons() + TableBuilder, + CardsBuilder + или FormBuilder, + то она автоматически наполняется данными и в параметрах будет resourceItem. +
  • +
  • + Когда кнопка находится на странице формы ModelResource то можно передать id текущего элемента. + +ActionButton::make('Click me') + ->method( + 'updateSomething', + params: ['resourceItem' => $this->getResource()->getItemID()] // [tl! focus] + ) + +
  • +
  • + Когда кнопка находится в индексной таблице ModelResource, то необходимо воспользоваться замыканием. + +ActionButton::make('Click me') + ->method( + 'updateSomething', + params: ['resourceItem' => fn($item) ['resourceItem' => $item->getKey()]] // [tl! focus] + ) + +
  • +
    + Вызов событий