allegati-modal.blade.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <div wire:ignore.self class="modal fade" id="allegatiModal" tabindex="-1" aria-labelledby="allegatiModalLabel" aria-hidden="true" data-keyboard="false" data-backdrop="static">
  2. <div class="modal-dialog modal-xl">
  3. <div class="modal-content">
  4. <div class="modal-header">
  5. <h5 class="modal-title" id="allegatiModalLabel">
  6. @if($allegatoId > 0)
  7. Modifica allegato
  8. @else
  9. Nuovo allegato
  10. @endif
  11. </h5>
  12. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  13. <span aria-hidden="true">&times;</span>
  14. </button>
  15. </div>
  16. <div class="modal-body">
  17. <div class="row mt-3">
  18. <div class="col-md-4">
  19. <label for="allegatoName" class="form-label">Nome</label>
  20. </div>
  21. <div class="col-md-8">
  22. <input class="form-control @error('allegatoName') is-invalid @enderror" type="text" id="allegatoName" placeholder="Nome" wire:model="allegatoName">
  23. @error('allegatoName')
  24. <div class="invalid-feedback">{{ $message }}</div>
  25. @enderror
  26. </div>
  27. </div>
  28. <div class="row mt-3">
  29. <div class="col-md-4">
  30. <label for="allegatoGallery" class="form-label">Tipologia</label>
  31. </div>
  32. <div class="col-md-8">
  33. <select class="form-control @error('allegatoGallery') is-invalid @enderror" style="width:100%" wire:model="allegatoGallery" id="allegatoGallery">
  34. <option value="">Seleziona...</option>
  35. @foreach ($allegatiType as $t)
  36. <option value="{{ $t->id }}">{{ $t->name }}</option>
  37. @endforeach
  38. </select>
  39. @error('allegatoGallery')
  40. <div class="invalid-feedback">{{ $message }}</div>
  41. @enderror
  42. </div>
  43. </div>
  44. <div class="row mt-3">
  45. <div class="col-md-4">
  46. <label for="allegati" class="form-label">Files</label>
  47. </div>
  48. <div class="col-md-8">
  49. <div class="form-group">
  50. <input wire:model="allegati" type="file" class="form-control-file" id="allegati" multiple>
  51. </div>
  52. <div id="files-container" class="mt-2">
  53. @if(!empty($allegatiFiles) && count($allegatiFiles) > 0)
  54. <div class="card">
  55. <div class="card-header bg-light d-flex justify-content-between align-items-center">
  56. <strong>File caricati ({{ count($allegatiFiles) }})</strong>
  57. </div>
  58. <div class="card-body p-2">
  59. <ul class="list-group list-group-flush">
  60. @foreach ($allegatiFiles as $a)
  61. <li class="list-group-item d-flex justify-content-between align-items-center py-2">
  62. <span>{{ $a }}</span>
  63. <button class="btn btn-sm btn-outline-danger"
  64. wire:click.prevent="removeFile('{{ $a }}')">
  65. <i class="fa fa-times"></i>
  66. </button>
  67. </li>
  68. @endforeach
  69. </ul>
  70. </div>
  71. </div>
  72. @endif
  73. </div>
  74. </div>
  75. </div>
  76. <div class="row mt-3">
  77. <div class="col-md-4">
  78. <label for="allegatoVisible" class="form-label">Visibile in stampa</label>
  79. </div>
  80. <div class="col-md-8">
  81. <div class="custom-control custom-switch custom-switch-md">
  82. <input type="checkbox" class="custom-control-input" id="allegatoVisible" wire:model="allegatoVisible">
  83. <label class="custom-control-label" for="allegatoVisible">&nbsp;</label>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="modal-footer">
  89. <button type="button" class="btn btn-secondary" data-dismiss="modal">Annulla</button>
  90. @if (!$this->validated)
  91. <button type="button" class="btn btn-primary" wire:click.prevent="saveAllegato()">Salva</button>
  92. @endif
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. @push('scripts')
  98. <script>
  99. document.addEventListener('livewire:load', function () {
  100. window.livewire.on('open-allegati-modal', function () {
  101. $('#allegatiModal').modal('show');
  102. console.log('Modal opened');
  103. });
  104. window.livewire.on('close-modal', function () {
  105. $('#allegatiModal').modal('hide');
  106. });
  107. window.livewire.on('attachments', function (files) {
  108. console.log('Attachments updated:', files);
  109. setTimeout(function() {
  110. window.livewire.emit('refresh');
  111. }, 200);
  112. });
  113. });
  114. </script>
  115. @endpush