Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Shortcut;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?Shortcut $shortcut = null;
|
||||
public bool $global = false;
|
||||
|
||||
public string $label = '';
|
||||
public string $url = '';
|
||||
public string $icon = '';
|
||||
|
||||
public function mount(Organization $organization, ?Shortcut $shortcut = null, bool $global = false): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($shortcut?->exists) {
|
||||
abort_unless($shortcut->organization_id === $organization->id || $shortcut->isGlobal(), 404);
|
||||
|
||||
if ($shortcut->isGlobal()) {
|
||||
abort_unless(auth()->user()->hasRole('Administrateur'), 403);
|
||||
}
|
||||
|
||||
$this->shortcut = $shortcut;
|
||||
$this->global = $shortcut->isGlobal();
|
||||
$this->label = $shortcut->label;
|
||||
$this->url = $shortcut->url;
|
||||
$this->icon = $shortcut->icon ?? '';
|
||||
} else {
|
||||
abort_if($global && ! auth()->user()->hasRole('Administrateur'), 403);
|
||||
$this->global = $global;
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'label' => 'required|string|max:255',
|
||||
'url' => 'required|url|max:2048',
|
||||
'icon' => 'nullable|string|max:10',
|
||||
]);
|
||||
|
||||
if ($this->shortcut?->exists) {
|
||||
$this->shortcut->update($validated);
|
||||
session()->flash('status', "Raccourci « {$this->shortcut->label} » mis à jour.");
|
||||
} else {
|
||||
Shortcut::create([
|
||||
...$validated,
|
||||
'organization_id' => $this->global ? null : $this->organization->id,
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
session()->flash('status', "Raccourci « {$this->label} » créé.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.shortcuts.index', $this->organization, navigate: true);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="max-w-lg">
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||
{{ $shortcut?->exists ? 'Modifier le raccourci' : 'Nouveau raccourci' }}
|
||||
</h1>
|
||||
|
||||
@if ($global)
|
||||
<p class="mb-4 rounded border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-700">
|
||||
Ce raccourci sera visible depuis toutes les organisations.
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<div class="grid grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Icône</label>
|
||||
<input type="text" wire:model="icon" placeholder="🔗" maxlength="10"
|
||||
class="mt-1 w-full rounded border-slate-300 text-center text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div class="col-span-3">
|
||||
<label class="block text-sm font-medium text-slate-700">Libellé</label>
|
||||
<input type="text" wire:model="label" placeholder="ex. Portail client"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('label') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">URL</label>
|
||||
<input type="url" wire:model="url" placeholder="https://exemple.com"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('url') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
<button type="submit"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
Enregistrer
|
||||
</button>
|
||||
<a href="{{ route('organizations.shortcuts.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user