Skip to content

Commit

Permalink
Merge pull request #30 from ashleyhood/feat_listen_modal_cancelled
Browse files Browse the repository at this point in the history
feat: Livewire event triggered for cancelled modal
  • Loading branch information
saade authored Aug 4, 2022
2 parents 6060073 + b884cc1 commit 0a6b31a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ class CalendarWidget extends FullCalendarWidget

<br>

## Listening for cancelled modal

If you want to know when a modal has been cancelled, you can add for the following [Livewire events](https://laravel-livewire.com/docs/2.x/events#event-listeners) to your widgets `$listener` array:

```php
protected $listeners = [
'cancelledFullcalendarCreateEventModal' => 'onCreateEventCancelled',
'cancelledFullcalendarEditEventModal' => 'onEditEventCancelled',
];
```

# Refreshing calendar events

If you want to refresh the calendar events, you can call `$this->refreshEvents()` inside your widget class. This will call `getViewData()` and re-render the events on the calendar.
Expand Down
16 changes: 13 additions & 3 deletions resources/views/components/create-event-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@
</x-filament::modal.heading>
</x-slot>

@if($this->isListeningCancelledCreateModal())
<div x-on:close-modal.window="if ($event.detail.id === 'fullcalendar--create-event-modal') Livewire.emit('cancelledFullcalendarCreateEventModal')"></div>
@endif

{{ $this->createEventForm }}

<x-slot name="footer">
<x-filament::button type="submit" form="onCreateEventSubmit">
{{ __('filament::resources/pages/create-record.form.actions.create.label') }}
</x-filament::button>

<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
</x-filament::button>
@if($this->isListeningCancelledCreateModal())
<x-filament::button color="secondary" x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarCreateEventModal')">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
</x-filament::button>
@else
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
</x-filament::button>
@endif
</x-slot>
</x-filament::modal>
</x-filament::form>
16 changes: 13 additions & 3 deletions resources/views/components/edit-event-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@
</x-filament::modal.heading>
</x-slot>

@if($this->isListeningCancelledEditModal())
<div x-on:close-modal.window="if ($event.detail.id === 'fullcalendar--create-event-modal') Livewire.emit('cancelledFullcalendarEditEventModal')"></div>
@endif

{{ $this->editEventForm }}

<x-slot name="footer">
<x-filament::button type="submit" form="onEditEventSubmit">
{{ __('filament::resources/pages/edit-record.form.actions.save.label') }}
</x-filament::button>

<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
</x-filament::button>
@if($this->isListeningCancelledEditModal())
<x-filament::button color="secondary" x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarEditEventModal')">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
</x-filament::button>
@else
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
</x-filament::button>
@endif
</x-slot>
</x-filament::modal>
</x-filament::form>
10 changes: 10 additions & 0 deletions src/Widgets/Concerns/CanManageModals.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ protected function getModalWidth(): string
{
return $this->modalWidth;
}

public function isListeningCancelledEditModal(): bool
{
return in_array('cancelledFullcalendarEditEventModal', $this->getEventsBeingListenedFor());
}

public function isListeningCancelledCreateModal(): bool
{
return in_array('cancelledFullcalendarCreateEventModal', $this->getEventsBeingListenedFor());
}
}

0 comments on commit 0a6b31a

Please sign in to comment.