Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Filament\Support\Resources\Core\SurfPlayers\Pages\Actions;
- use App\Models\Core\Punishment\Utils\PunishmentTemplate;
- use App\Models\Core\SurfPlayer;
- use Filament\Actions\Action;
- use Filament\Forms\Components\Hidden;
- use Filament\Forms\Components\TextInput;
- use Filament\Schemas\Components\Actions;
- use Illuminate\Support\HtmlString;
- use Livewire\Livewire;
- class PunishAction extends Action
- {
- public static function getDefaultName(): ?string
- {
- return "punish";
- }
- private static array $permissions = [
- "punish_players",
- ];
- private static function checkPermission(): bool
- {
- $authUser = auth()->user();
- return $authUser && collect(self::$permissions)->every(function ($permission) use ($authUser) {
- return $authUser->can($permission);
- });
- }
- protected function setUp(): void
- {
- parent::setUp();
- $this->label("Punish");
- $this->icon("fas-gavel");
- $this->color("danger");
- $this->hidden(fn() => !self::checkPermission());
- $this->disabled(fn() => !self::checkPermission());
- $this->schema([
- Hidden::make("punishment_template")
- ->required()
- ->live()
- ->reactive()
- ->extraAttributes([
- "x-on:template-selected.window" => '$state = $event.detail.templateId'
- ])
- ->afterStateUpdated(function ($state, callable $set) {
- $template = PunishmentTemplate::find($state);
- if ($template) {
- $set("reason", $template->reason);
- }
- }),
- Actions::make([
- Action::make("select_template")
- ->label("Vorlage auswählen")
- ->modalHeading("Bestrafungsvorlage auswählen")
- ->modalSubmitAction(false)
- ->modalCancelActionLabel("Abbrechen")
- ->modalContent(fn($action) => new HtmlString(Livewire::mount("punishment.template-table")))
- ]),
- TextInput::make("template_preview")
- ->label("Vorschau")
- ->live()
- ->reactive()
- ->readOnly()
- ->formatStateUsing(function (callable $get) {
- $id = $get("punishment_template");
- if (!$id) return "Keine Vorlage ausgewählt.";
- $template = PunishmentTemplate::find($get("punishment_template"));
- if (!$template) return "Keine Vorlage ausgewählt.";
- return $template->format();
- })
- ]);
- $this->action(function (SurfPlayer $record, array $data): void {
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment