260 lines
12 KiB
PHP
260 lines
12 KiB
PHP
|
|
<?php $__env->startSection('title', 'Nuovo Gruppo'); ?>
|
||
|
|
<?php $__env->startSection('page_title', 'Nuovo Gruppo'); ?>
|
||
|
|
|
||
|
|
<?php $__env->startSection('content'); ?>
|
||
|
|
<form action="/gruppi" method="POST">
|
||
|
|
<?php echo csrf_field(); ?>
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-md-6">
|
||
|
|
<div class="card card-primary">
|
||
|
|
<div class="card-header">
|
||
|
|
<h3 class="card-title"><i class="fas fa-folder mr-2"></i>Dati Gruppo</h3>
|
||
|
|
</div>
|
||
|
|
<div class="card-body">
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Nome *</label>
|
||
|
|
<input type="text" name="nome" class="form-control <?php $__errorArgs = ['nome'];
|
||
|
|
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
|
||
|
|
if ($__bag->has($__errorArgs[0])) :
|
||
|
|
if (isset($message)) { $__messageOriginal = $message; }
|
||
|
|
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
|
||
|
|
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
|
||
|
|
endif;
|
||
|
|
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('nome')); ?>" required>
|
||
|
|
<?php $__errorArgs = ['nome'];
|
||
|
|
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
|
||
|
|
if ($__bag->has($__errorArgs[0])) :
|
||
|
|
if (isset($message)) { $__messageOriginal = $message; }
|
||
|
|
$message = $__bag->first($__errorArgs[0]); ?>
|
||
|
|
<span class="invalid-feedback"><?php echo e($message); ?></span>
|
||
|
|
<?php unset($message);
|
||
|
|
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
|
||
|
|
endif;
|
||
|
|
unset($__errorArgs, $__bag); ?>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Gruppo Padre</label>
|
||
|
|
<select name="parent_id" class="form-control">
|
||
|
|
<option value="">Nessuno (gruppo radice)</option>
|
||
|
|
<?php $__currentLoopData = $allGruppi; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $g): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
<option value="<?php echo e($g->id); ?>" <?php echo e(old('parent_id') == $g->id || ($selectedParent && $selectedParent->id == $g->id) ? 'selected' : ''); ?>>
|
||
|
|
<?php echo e($g->full_path); ?>
|
||
|
|
|
||
|
|
</option>
|
||
|
|
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
</select>
|
||
|
|
<?php if($selectedParent): ?>
|
||
|
|
<small class="form-text text-muted">
|
||
|
|
Verrà creato come sottogruppo di: <strong><?php echo e($selectedParent->nome); ?></strong>
|
||
|
|
</small>
|
||
|
|
<?php endif; ?>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Diocesi</label>
|
||
|
|
<select name="diocesi_id" class="form-control">
|
||
|
|
<option value="">Seleziona...</option>
|
||
|
|
<?php $__currentLoopData = $diocesi; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
<option value="<?php echo e($d->id); ?>" <?php echo e(old('diocesi_id') == $d->id ? 'selected' : ''); ?>><?php echo e($d->nome); ?></option>
|
||
|
|
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Responsabili</label>
|
||
|
|
<select name="responsabile_ids[]" class="form-control" multiple size="4" id="responsabile-select">
|
||
|
|
<option value="">-- Nessuno --</option>
|
||
|
|
</select>
|
||
|
|
<small class="text-muted">Ctrl+click per selezionare più responsabili</small>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Descrizione</label>
|
||
|
|
<textarea name="descrizione" class="form-control" rows="3"><?php echo e(old('descrizione')); ?></textarea>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-md-6">
|
||
|
|
<div class="card">
|
||
|
|
<div class="card-header"><h3 class="card-title"><i class="fas fa-map-marker-alt mr-2"></i>Luogo Incontro</h3></div>
|
||
|
|
<div class="card-body">
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Indirizzo</label>
|
||
|
|
<input type="text" name="indirizzo_incontro" class="form-control" value="<?php echo e(old('indirizzo_incontro')); ?>">
|
||
|
|
</div>
|
||
|
|
<div class="form-row">
|
||
|
|
<div class="form-group col-md-4">
|
||
|
|
<label>CAP</label>
|
||
|
|
<input type="text" name="cap_incontro" class="form-control" value="<?php echo e(old('cap_incontro')); ?>">
|
||
|
|
</div>
|
||
|
|
<div class="form-group col-md-5">
|
||
|
|
<label>Città</label>
|
||
|
|
<input type="text" name="città_incontro" class="form-control" value="<?php echo e(old('città_incontro')); ?>">
|
||
|
|
</div>
|
||
|
|
<div class="form-group col-md-3">
|
||
|
|
<label>Provincia</label>
|
||
|
|
<input type="text" name="sigla_provincia_incontro" class="form-control" maxlength="2" value="<?php echo e(old('sigla_provincia_incontro')); ?>">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group mb-0">
|
||
|
|
<label>URL Mappa</label>
|
||
|
|
<input type="url" name="mappa_posizione" class="form-control" value="<?php echo e(old('mappa_posizione')); ?>" placeholder="https://...">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="card mt-3">
|
||
|
|
<div class="card-header">
|
||
|
|
<h3 class="card-title"><i class="fas fa-users mr-2"></i>Membri</h3>
|
||
|
|
<button type="button" class="btn btn-xs btn-success float-right" onclick="aggiungiMembro()">
|
||
|
|
<i class="fas fa-plus mr-1"></i> Aggiungi Membro
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
<div class="card-body p-0">
|
||
|
|
<table class="table table-bordered mb-0" id="membri-table">
|
||
|
|
<thead class="thead-light">
|
||
|
|
<tr>
|
||
|
|
<th style="width: 30%;">Individuo</th>
|
||
|
|
<th>Codice</th>
|
||
|
|
<th>Contatti</th>
|
||
|
|
<th style="width: 20%;">Ruolo</th>
|
||
|
|
<th style="width: 100px;">Data Adesione</th>
|
||
|
|
<th style="width: 50px;"></th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody id="membri-tbody">
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
<div id="no-membri-msg" class="text-center text-muted py-4">
|
||
|
|
<p class="mb-0">Nessun membro aggiunto. Clicca su "Aggiungi Membro" per iniziare.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mt-3">
|
||
|
|
<button type="submit" class="btn btn-success">
|
||
|
|
<i class="fas fa-save mr-1"></i> Salva
|
||
|
|
</button>
|
||
|
|
<a href="/gruppi" class="btn btn-secondary">
|
||
|
|
<i class="fas fa-times mr-1"></i> Annulla
|
||
|
|
</a>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
<?php $__env->stopSection(); ?>
|
||
|
|
|
||
|
|
<?php $__env->startSection('scripts'); ?>
|
||
|
|
<script>
|
||
|
|
let membriIndex = 0;
|
||
|
|
const membriResponsabiliMap = new Map();
|
||
|
|
|
||
|
|
function aggiungiMembro() {
|
||
|
|
const tbody = document.getElementById('membri-tbody');
|
||
|
|
const noMsg = document.getElementById('no-membri-msg');
|
||
|
|
if (noMsg) noMsg.style.display = 'none';
|
||
|
|
|
||
|
|
const row = document.createElement('tr');
|
||
|
|
row.innerHTML = `
|
||
|
|
<td>
|
||
|
|
<select name="individui[${membriIndex}][individuo_id]" class="form-control" onchange="updateMembroInfo(this); updateResponsabiliFromMembri();" required>
|
||
|
|
<option value="">Seleziona...</option>
|
||
|
|
<?php $__currentLoopData = $individui; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
<option value="<?php echo e($i->id); ?>" data-codice="<?php echo e($i->codice_id); ?>" data-email="<?php echo e($i->email_primaria); ?>" data-telefono="<?php echo e($i->telefono_primario); ?>">
|
||
|
|
<?php echo e($i->cognome); ?> <?php echo e($i->nome); ?>
|
||
|
|
|
||
|
|
</option>
|
||
|
|
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
|
||
|
|
</select>
|
||
|
|
</td>
|
||
|
|
<td><span class="text-muted membro-codice">-</span></td>
|
||
|
|
<td><small class="text-muted membro-contatti">-</small></td>
|
||
|
|
<td><input type="text" name="individui[${membriIndex}][ruolo_nel_gruppo]" class="form-control" placeholder="Es. Membro"></td>
|
||
|
|
<td><input type="date" name="individui[${membriIndex}][data_adesione]" class="form-control"></td>
|
||
|
|
<td><button type="button" class="btn btn-danger btn-xs" onclick="rimuoviMembro(this); updateResponsabiliFromMembri();"><i class="fas fa-trash"></i></button></td>
|
||
|
|
`;
|
||
|
|
tbody.appendChild(row);
|
||
|
|
membriIndex++;
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateMembroInfo(select) {
|
||
|
|
const row = select.closest('tr');
|
||
|
|
const option = select.options[select.selectedIndex];
|
||
|
|
const codice = option.dataset.codice || '-';
|
||
|
|
const email = option.dataset.email || '';
|
||
|
|
const telefono = option.dataset.telefono || '';
|
||
|
|
|
||
|
|
row.querySelector('.membro-codice').textContent = codice;
|
||
|
|
|
||
|
|
let contatti = [];
|
||
|
|
if (email) contatti.push('<span class="text-primary">'+email+'</span>');
|
||
|
|
if (telefono) contatti.push('<span class="text-success">'+telefono+'</span>');
|
||
|
|
row.querySelector('.membro-contatti').innerHTML = contatti.length ? contatti.join(' | ') : '-';
|
||
|
|
}
|
||
|
|
|
||
|
|
function rimuoviMembro(btn) {
|
||
|
|
const row = btn.closest('tr');
|
||
|
|
row.remove();
|
||
|
|
if (document.getElementById('membri-tbody').children.length === 0) {
|
||
|
|
document.getElementById('no-membri-msg').style.display = 'block';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function updateResponsabiliFromMembri() {
|
||
|
|
const respSelect = document.getElementById('responsabile-select');
|
||
|
|
const currentSelected = Array.from(respSelect.selectedOptions).map(o => o.value);
|
||
|
|
const tbody = document.getElementById('membri-tbody');
|
||
|
|
const rows = tbody.querySelectorAll('tr');
|
||
|
|
|
||
|
|
const membroIds = new Set();
|
||
|
|
const membroNames = new Map();
|
||
|
|
|
||
|
|
rows.forEach(row => {
|
||
|
|
const select = row.querySelector('select[name*="individuo_id"]');
|
||
|
|
if (select && select.value) {
|
||
|
|
membroIds.add(select.value);
|
||
|
|
const option = select.options[select.selectedIndex];
|
||
|
|
membroNames.set(select.value, option.text);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
respSelect.innerHTML = '';
|
||
|
|
|
||
|
|
if (membroIds.size === 0) {
|
||
|
|
const opt = document.createElement('option');
|
||
|
|
opt.value = '';
|
||
|
|
opt.textContent = '-- Aggiungi prima dei membri --';
|
||
|
|
opt.disabled = true;
|
||
|
|
respSelect.appendChild(opt);
|
||
|
|
} else {
|
||
|
|
membroIds.forEach(id => {
|
||
|
|
const opt = document.createElement('option');
|
||
|
|
opt.value = id;
|
||
|
|
opt.textContent = membroNames.get(id);
|
||
|
|
if (currentSelected.includes(id)) opt.selected = true;
|
||
|
|
respSelect.appendChild(opt);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const respSelect = document.getElementById('responsabile-select');
|
||
|
|
const individuiList = <?php echo json_encode($individui->map(fn($i) => ['id' => $i->id, 'text' => $i->cognome . ' ' . $i->nome]), 512) ?>;
|
||
|
|
const initialResponsabili = <?php echo json_encode(old('responsabile_ids', []), 512) ?>;
|
||
|
|
|
||
|
|
const optPlaceholder = document.createElement('option');
|
||
|
|
optPlaceholder.value = '';
|
||
|
|
optPlaceholder.textContent = '-- Aggiungi prima dei membri --';
|
||
|
|
optPlaceholder.disabled = true;
|
||
|
|
respSelect.appendChild(optPlaceholder);
|
||
|
|
|
||
|
|
initialResponsabili.forEach(id => {
|
||
|
|
const match = individuiList.find(i => i.id == id);
|
||
|
|
if (match) {
|
||
|
|
const opt = document.createElement('option');
|
||
|
|
opt.value = match.id;
|
||
|
|
opt.textContent = match.text;
|
||
|
|
opt.selected = true;
|
||
|
|
respSelect.appendChild(opt);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
<?php $__env->stopSection(); ?>
|
||
|
|
<?php echo $__env->make('layouts.adminlte', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/glastree/resources/views/gruppi/create.blade.php ENDPATH**/ ?>
|