Skip to content

Commit

Permalink
Merge pull request #503 from DissNik/release-2.15
Browse files Browse the repository at this point in the history
Release 2.15
  • Loading branch information
DissNik authored Jun 17, 2024
2 parents 6e0a1fb + f22c655 commit 798ffe2
Show file tree
Hide file tree
Showing 16 changed files with 410 additions and 506 deletions.
27 changes: 27 additions & 0 deletions resources/views/pages/en/advanced/form_builder.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
['url' => '#apply', 'label' => 'Apply'],
['url' => '#method', 'label' => 'Calling methods'],
['url' => '#event', 'label' => 'Dispatch events'],
['url' => '#submit', 'label' => '"Submit" event'],
]
]"
>
Expand Down Expand Up @@ -464,4 +465,30 @@ public function updateSomething(MoonShineRequest $request)
->dispatchEvent(JsEvent::OFF_CANVAS_TOGGLED, 'default'), // [tl! focus]
</x-code>

<x-sub-title id="submit">&quot;Submit&quot; event</x-sub-title>

<x-p>
To submit a form, you can call the <em>Submit</em> event.
</x-p>

<x-code language="php">
AlpineJs::event(JsEvent::FORM_SUBMIT, 'componentName')
</x-code>

<x-moonshine::divider label="Example of calling an event on a form page" />

<x-code language="php">
public function formButtons(): array
{
return [
ActionButton::make('Save')->dispatchEvent(AlpineJs::event(JsEvent::FORM_SUBMIT, $this->uriKey()))
];
}
</x-code>

<x-moonshine::alert class="my-4" type="default" icon="heroicons.book-open">
For more information about AlpineJs helpers, please refer to
<x-link link="{{ to_page('advanced-js_events') }}#helper">Js events</x-link>.
</x-moonshine::alert>

</x-page>
50 changes: 50 additions & 0 deletions resources/views/pages/en/advanced/js_events.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
'Разделы' => [
['url' => '#blade-directives', 'label' => 'Blade directives'],
['url' => '#helper', 'label' => 'AlpineJs helper'],
['url' => '#default-events', 'label' => 'Default events'],
['url' => '#response-events', 'label' => 'Calling events via Response'],
]
]">

Expand Down Expand Up @@ -105,4 +107,52 @@
]);
</x-code>

<x-sub-title id="default-events">Default events</x-sub-title>

<x-p>
There are several default events defined in the <strong>MoonShine</strong> admin panel,
the names of which can be conveniently obtained via enum <em>JsEvent</em>.
</x-p>

<x-ul>
<li><code>JsEvent::FRAGMENT_UPDATED</code> - fragment update,</li>
<li><code>JsEvent::TABLE_UPDATED</code> - table update,</li>
<li><code>JsEvent::TABLE_REINDEX</code> - updating table indexes when sorting,</li>
<li><code>JsEvent::TABLE_ROW_UPDATED</code> - updating a row in the table,</li>
<li><code>JsEvent::CARDS_UPDATED</code> - updating the Cards list,</li>
<li><code>JsEvent::FORM_RESET</code> - form reset,</li>
<li><code>JsEvent::FORM_SUBMIT</code> - submitting the form,</li>
<li><code>JsEvent::MODAL_TOGGLED</code> - opening / closing a modal window,</li>
<li><code>JsEvent::OFF_CANVAS_TOGGLED</code> - opening / closing Offcanvas,</li>
<li><code>JsEvent::TOAST</code> - call Toast.</li>
</x-ul>

<x-sub-title id="response-events">Calling events via Response</x-sub-title>

<x-p>
In <strong>MoonShine</strong> you can return events to <em>MoonShineJsonResponse</em>, which will then be called.<br />
To do this, you need to use the <code>events()</code> method.
</x-p>

<x-code language="php">
events(array $events)
</x-code>

<x-ul>
<li><code>$events</code> - array of events to be called.</li>
</x-ul>

<x-code language="php">
use MoonShine\Enums\JsEvent;
use MoonShine\Http\Responses\MoonShineJsonResponse;
use MoonShine\Support\AlpineJs;

//...

return MoonShineJsonResponse::make()
->events([
AlpineJs::event(JsEvent::TABLE_UPDATED, 'index'),
]); // [tl! focus:-2]
</x-code>

</x-page>
252 changes: 0 additions & 252 deletions resources/views/pages/en/advanced/menu.blade.php

This file was deleted.

29 changes: 29 additions & 0 deletions resources/views/pages/en/fields/file.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
['url' => '#customname', 'label' => 'Custom file name'],
['url' => '#names', 'label' => 'Element names'],
['url' => '#item-attributes', 'label' => 'Item attributes'],
['url' => '#helper-methods', 'label' => 'Helper methods'],
]
]"
>
Expand Down Expand Up @@ -430,4 +431,32 @@ public function fields(): array
//...
</x-code>

<x-sub-title id="helper-methods">Helper methods</x-sub-title>

<x-moonshine::divider label="getRemainingValues()" />

<x-p>
The <code>getRemainingValues()</code> method allows you to get the values that remained in the form,
taking into account the deletion.
</x-p>

<x-code language="php">
getRemainingValues()
</x-code>

<x-moonshine::divider label="removeExcludedFiles()" />

<x-p>
The <code>removeExcludedFiles()</code> method allows you to physically remove files during the process.
</x-p>

<x-code language="php">
removeExcludedFiles()
</x-code>

<x-moonshine::alert type="primary" icon="heroicons.outline.book-open">
Recipe: <x-link link="{{ to_page('recipes') }}#images-in-linked-table">saving images</x-link>
in the linked table.
</x-moonshine::alert>

</x-page>
Loading

0 comments on commit 798ffe2

Please sign in to comment.