Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change modal label #28

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ public function onEventDrop($newEvent, $oldEvent, $relatedEvents): void

Since [v1.0.0](https://github.com/saade/filament-fullcalendar/releases/tag/v1.0.0) you can create and edit events using a modal.

To change the modal size, override the `protected string $modalWidth` property in your widget.
To customise the modal, override the following properties in your widget:

- `protected string $modalWidth`
- `protected string $modalLabel`

The process of saving and editing the event is up to you, since this plugin does not rely on a Model to save the calendar events.

Expand Down Expand Up @@ -240,11 +243,11 @@ public function editEvent(array $data): void
* 1. $this->record_id
* 2. $this->record
*/

# $this->record_id
// the value is retrieved from event's id key
// eg: Appointment::find($this->record);

# $this->record
// model instance is resolved by user defined resolveEventRecord() funtion. See example below
// eg: $this->record->update($data);
Expand Down
30 changes: 17 additions & 13 deletions resources/views/components/create-event-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<x-filament::modal id="fullcalendar--create-event-modal" :width="$this->getModalWidth()">
<x-slot name="heading">
{{ __('filament::resources/pages/create-record.title', ['label' => 'Event']) }}
</x-slot>
<x-filament::form wire:submit.prevent="onCreateEventSubmit">
<x-filament::modal id="fullcalendar--create-event-modal" :width="$this->getModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{ __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]) }}
</x-filament::modal.heading>
</x-slot>

<x-filament::form wire:submit.prevent="onCreateEventSubmit">
{{ $this->createEventForm }}

<x-filament::button type="submit" form="onCreateEventSubmit">
{{ __('filament::resources/pages/create-record.form.actions.create.label') }}
</x-filament::button>
<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>
</x-filament::form>
</x-filament::modal>
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/create-record.form.actions.cancel.label') }}
</x-filament::button>
</x-slot>
</x-filament::modal>
</x-filament::form>
30 changes: 17 additions & 13 deletions resources/views/components/edit-event-modal.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<x-filament::modal id="fullcalendar--edit-event-modal" :width="$this->getModalWidth()">
<x-slot name="heading">
{{ __('filament::resources/pages/edit-record.title', ['label' => 'Event']) }}
</x-slot>
<x-filament::form wire:submit.prevent="onEditEventSubmit">
<x-filament::modal id="fullcalendar--edit-event-modal" :width="$this->getModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{ __('filament::resources/pages/edit-record.title', ['label' => $this->getModalLabel()]) }}
</x-filament::modal.heading>
</x-slot>

<x-filament::form wire:submit.prevent="onEditEventSubmit">
{{ $this->editEventForm }}

<x-filament::button type="submit" form="onEditEventSubmit">
{{ __('filament::resources/pages/edit-record.form.actions.save.label') }}
</x-filament::button>
<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>
</x-filament::form>
</x-filament::modal>
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
</x-filament::button>
</x-slot>
</x-filament::modal>
</x-filament::form>
8 changes: 1 addition & 7 deletions src/Widgets/Concerns/CanManageEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
trait CanManageEvents
{
use AuthorizesActions;
use CanManageModals;
use CreateEventForm;
use EditEventForm;
use EvaluateClosures;

protected string $modalWidth = 'sm';

public ?int $record_id = null;

public ?Model $record = null;
Expand All @@ -41,11 +40,6 @@ protected function getForms(): array
];
}

protected function getModalWidth(): string
{
return $this->modalWidth;
}

public function onEventClick($event): void
{
if (! static::canEdit($event)) {
Expand Down
20 changes: 20 additions & 0 deletions src/Widgets/Concerns/CanManageModals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Saade\FilamentFullCalendar\Widgets\Concerns;

trait CanManageModals
{
protected string $modalLabel = 'Event';

protected string $modalWidth = 'sm';

protected function getModalLabel(): string
{
return $this->modalLabel;
}

protected function getModalWidth(): string
{
return $this->modalWidth;
}
}