95 lines
3.7 KiB
PHP
95 lines
3.7 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Admin\Resources\Proposals\Pages;
|
||
|
||
use App\Filament\Admin\Resources\Proposals\ProposalResource;
|
||
use Filament\Actions\Action;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Resources\Pages\EditRecord;
|
||
use Filament\Support\Enums\Width;
|
||
use Illuminate\Support\Str;
|
||
|
||
class EditProposal extends EditRecord
|
||
{
|
||
protected static string $resource = ProposalResource::class;
|
||
|
||
public function getTitle(): string
|
||
{
|
||
return __('proposal.edit');
|
||
}
|
||
|
||
public function getMaxContentWidth(): Width | string | null
|
||
{
|
||
return Width::Full;
|
||
}
|
||
|
||
protected function getHeaderActions(): array
|
||
{
|
||
return [
|
||
// Teklif linkini tarayıcı panosuna kopyala
|
||
Action::make('copy_link')
|
||
->label(__('proposal.copy_link'))
|
||
->icon('heroicon-o-clipboard-document-check')
|
||
->color('info')
|
||
->action(function () {
|
||
$url = route('proposals.show', $this->record->slug);
|
||
|
||
// Livewire v3: sunucu tarafında JS enjekte et (user-gesture gerektirmez)
|
||
$escaped = addslashes($url);
|
||
$this->js("(function(){var t=document.createElement('textarea');t.value='{$escaped}';t.style.position='fixed';t.style.opacity='0';document.body.appendChild(t);t.focus();t.select();try{document.execCommand('copy')}catch(e){}document.body.removeChild(t);})();");
|
||
|
||
Notification::make()
|
||
->title(__('proposal.link_copied'))
|
||
->body($url)
|
||
->success()
|
||
->duration(6000)
|
||
->send();
|
||
})
|
||
->visible(fn () => $this->record !== null),
|
||
|
||
// Yeni rastgele benzersiz slug üret ve kaydet
|
||
Action::make('regenerate_slug')
|
||
->label(__('proposal.regenerate_slug'))
|
||
->icon('heroicon-o-arrow-path')
|
||
->color('warning')
|
||
->requiresConfirmation()
|
||
->modalHeading(__('proposal.regenerate_slug_confirm_heading'))
|
||
->modalDescription(__('proposal.regenerate_slug_confirm_body'))
|
||
->modalSubmitActionLabel(__('proposal.regenerate_slug_confirm_button'))
|
||
->action(function () {
|
||
$newSlug = 'teklif-' . strtolower(Str::random(4)) . '-' . date('ymd') . '-' . strtolower(Str::random(4));
|
||
|
||
// Benzersizliği garanti et
|
||
while (\App\Models\Proposal::where('slug', $newSlug)->where('id', '!=', $this->record->id)->exists()) {
|
||
$newSlug = 'teklif-' . strtolower(Str::random(4)) . '-' . date('ymd') . '-' . strtolower(Str::random(4));
|
||
}
|
||
|
||
$this->record->update(['slug' => $newSlug]);
|
||
|
||
$newUrl = route('proposals.show', $newSlug);
|
||
|
||
Notification::make()
|
||
->title(__('proposal.regenerate_slug_success'))
|
||
->body($newUrl)
|
||
->success()
|
||
->duration(8000)
|
||
->send();
|
||
|
||
// Formu yenile
|
||
$this->fillForm();
|
||
})
|
||
->visible(fn () => $this->record !== null),
|
||
|
||
// Teklifi yeni sekmede önizle
|
||
Action::make('preview')
|
||
->label(__('proposal.preview'))
|
||
->icon('heroicon-o-eye')
|
||
->color('gray')
|
||
->url(fn () => $this->record ? route('proposals.show', $this->record->slug) : '#')
|
||
->openUrlInNewTab()
|
||
->visible(fn () => $this->record !== null),
|
||
];
|
||
}
|
||
}
|
||
|