email_comunications.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <div class="col card--ui" id="card--dashboard">
  2. @if(!$add && !$update)
  3. <header id="title--section" style="display:none !important" class="d-flex align-items-center justify-content-between">
  4. <div class="title--section_name d-flex align-items-center justify-content-between">
  5. <i class="ico--ui title_section utenti me-2"></i>
  6. <h2 class="primary">@if(!$add && !$update)Email Templates @else Inserimento/modifica template Email @endif</h2>
  7. </div>
  8. @if(!$add && !$update)
  9. <div class="title--section_addButton" wire:click="add()" style="cursor: pointer;">
  10. <div class="btn--ui entrata d-flex justify-items-between">
  11. <a href="#" wire:click="add()" style="color:white">Aggiungi</a>
  12. </div>
  13. </div>
  14. @endif
  15. </header>
  16. <a class="btn--ui lightGrey" href="/settings?type=comunicazioni"><i class="fa-solid fa-arrow-left"></i></a><br>
  17. <section id="resume-table">
  18. <div class="compare--chart_wrapper d-none"></div>
  19. <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
  20. <thead>
  21. <tr>
  22. <th scope="col">Oggetto</th>
  23. <th scope="col">Messaggio</th>
  24. <th scope="col">Parole</th>
  25. <th scope="col">Data Creazione</th>
  26. <th scope="col">...</th>
  27. </tr>
  28. </thead>
  29. <tbody id="checkall-target">
  30. @foreach($records as $record)
  31. <tr>
  32. <td>
  33. <strong>{{$record->name}}</strong>
  34. </td>
  35. <td>
  36. {{ Str::limit(strip_tags($record->content), 80) }}
  37. </td>
  38. <td>
  39. @php
  40. $wordCount = str_word_count(strip_tags($record->content));
  41. $badgeClass = $wordCount > 500 ? 'bg-warning' : 'bg-info';
  42. @endphp
  43. <span class="badge {{ $badgeClass }}">{{ $wordCount }} parole</span>
  44. </td>
  45. <td>{{ $record->created_at->format('d/m/Y H:i') }}</td>
  46. <td>
  47. <button type="button" class="btn" wire:click="sendTemplate({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Invia Email"><i class="fa-solid fa-envelope"></i></button>
  48. <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
  49. </td>
  50. </tr>
  51. @endforeach
  52. </tbody>
  53. </table>
  54. </section>
  55. @else
  56. <div class="container">
  57. <a class="btn--ui lightGrey" href="/email_comunications"><i class="fa-solid fa-arrow-left"></i></a><br><br>
  58. @if (session()->has('error'))
  59. <div class="alert alert-danger" role="alert">
  60. {{ session()->get('error') }}
  61. </div>
  62. @endif
  63. <div class="row">
  64. <div class="col">
  65. <form action="">
  66. <div class="row mb-3">
  67. <div class="col">
  68. <div class="form--item">
  69. <label for="subject" class="form-label">Oggetto</label>
  70. <input type="text" class="form-control @error('subject') is-invalid @enderror" id="subject" wire:model="subject" placeholder="Inserisci l'oggetto del template">
  71. @error('subject')
  72. <div class="invalid-feedback">{{ $message }}</div>
  73. @enderror
  74. </div>
  75. </div>
  76. </div>
  77. <div class="row mb-3">
  78. <div class="col">
  79. <div class="form--item">
  80. <label for="message" class="form-label">Messaggio</label>
  81. <textarea class="form-control @error('message') is-invalid @enderror" id="message" wire:model="message" rows="10" placeholder="Inserisci il contenuto del messaggio (supporta HTML)"></textarea>
  82. <div class="form-text">
  83. <small class="text-muted">Puoi utilizzare HTML per formattare il messaggio. Parole: <span class="fw-bold">{{ str_word_count(strip_tags($message)) }}</span></small>
  84. </div>
  85. @error('message')
  86. <div class="invalid-feedback">{{ $message }}</div>
  87. @enderror
  88. </div>
  89. </div>
  90. </div>
  91. @if($add)
  92. <div class="row mb-3">
  93. <div class="col">
  94. <label class="form-label">Destinatari</label>
  95. <div class="mb-2">
  96. <button type="button" class="btn btn-outline-primary btn-sm" onclick="selectAllUsers()">
  97. <i class="fas fa-users me-1"></i>Seleziona Tutti
  98. </button>
  99. <button type="button" class="btn btn-outline-secondary btn-sm ms-2" onclick="deselectAllUsers()">
  100. <i class="fas fa-times me-1"></i>Deseleziona Tutti
  101. </button>
  102. </div>
  103. <div style="max-height: 200px; overflow-y: auto; border: 1px solid #dee2e6; border-radius: 0.375rem; padding: 10px;">
  104. @foreach($users as $user)
  105. <div class="form-check mb-1">
  106. <input class="form-check-input" type="checkbox" value="{{ $user->id }}" wire:model="selectedRecipients" id="recipient_{{ $user->id }}">
  107. <label class="form-check-label" for="recipient_{{ $user->id }}">
  108. <strong>{{ $user->name }}</strong>
  109. @if($user->email)
  110. <small class="text-muted">({{ $user->email }})</small>
  111. @else
  112. <small class="text-danger">(no email)</small>
  113. @endif
  114. </label>
  115. </div>
  116. @endforeach
  117. </div>
  118. <div class="form-text">
  119. <small class="text-muted">Selezionati: <span id="selectedCount">{{ count($selectedRecipients) }}</span> utenti</small>
  120. </div>
  121. @error('selectedRecipients')
  122. <div class="text-danger">{{ $message }}</div>
  123. @enderror
  124. </div>
  125. </div>
  126. <div class="row mb-3">
  127. <div class="col">
  128. <label class="form-label">Opzioni di Invio</label>
  129. <div class="form-check">
  130. <input class="form-check-input" type="radio" name="sendOption" id="sendNow" wire:model="sendNow" value="true">
  131. <label class="form-check-label" for="sendNow">
  132. <i class="fas fa-envelope me-2"></i>Invia Immediatamente
  133. </label>
  134. </div>
  135. <div class="form-check mt-2">
  136. <input class="form-check-input" type="radio" name="sendOption" id="scheduleFor" wire:model="sendNow" value="false">
  137. <label class="form-check-label" for="scheduleFor">
  138. <i class="fas fa-clock me-2"></i>Programma per dopo
  139. </label>
  140. </div>
  141. </div>
  142. </div>
  143. @if($sendNow === false || $sendNow === 'false')
  144. <div class="row mb-3">
  145. <div class="col-md-6">
  146. <label for="scheduledDateTime" class="form-label">Data e Ora di Invio</label>
  147. <input type="datetime-local"
  148. class="form-control @error('scheduledDateTime') is-invalid @enderror"
  149. id="scheduledDateTime"
  150. wire:model="scheduledDateTime"
  151. min="{{ now()->format('Y-m-d\TH:i') }}">
  152. <div class="form-text">
  153. <small class="text-muted">Seleziona quando vuoi che l'email venga inviata</small>
  154. </div>
  155. @error('scheduledDateTime')
  156. <div class="invalid-feedback">{{ $message }}</div>
  157. @enderror
  158. </div>
  159. </div>
  160. @endif
  161. @endif
  162. <div class="form--item">
  163. <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
  164. @if($add)
  165. <button type="submit" class="btn--ui" wire:click.prevent="store()">
  166. @if($sendNow === false || $sendNow === 'false')
  167. Salva e Invia
  168. @else
  169. Salva e Programma
  170. @endif
  171. </button>
  172. @endif
  173. @if($update)
  174. <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
  175. @endif
  176. </div>
  177. </form>
  178. </div>
  179. </div>
  180. </div>
  181. @endif
  182. </div>
  183. @if (session()->has('success'))
  184. <div class="alert alert-success alert-dismissible fade show mt-3" role="alert">
  185. {{ session()->get('success') }}
  186. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  187. </div>
  188. @endif
  189. @if (session()->has('error'))
  190. <div class="alert alert-danger alert-dismissible fade show mt-3" role="alert">
  191. {{ session()->get('error') }}
  192. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  193. </div>
  194. @endif
  195. @push('scripts')
  196. <link href="/css/datatables.css" rel="stylesheet" />
  197. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  198. <script src="/assets/js/datatables.js"></script>
  199. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  200. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  201. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  202. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  203. @endpush
  204. @push('scripts')
  205. <script>
  206. $(document).ready(function() {
  207. loadDataTable();
  208. });
  209. Livewire.on('load-data-table', () => {
  210. loadDataTable();
  211. });
  212. function loadDataTable(){
  213. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  214. $('#tablesaw-350').DataTable().destroy();
  215. }
  216. $('#tablesaw-350').DataTable({
  217. thead: {
  218. 'th': {'background-color': 'blue'}
  219. },
  220. layout: {
  221. topStart : null,
  222. topEnd : null,
  223. top1A: {
  224. buttons: [
  225. {
  226. extend: 'collection',
  227. text: 'ESPORTA',
  228. buttons: [
  229. {
  230. extend: 'excelHtml5',
  231. title: 'Templates Email',
  232. exportOptions: {
  233. columns: ":not(':last')"
  234. }
  235. },
  236. {
  237. extend: 'pdfHtml5',
  238. title: 'Templates Email',
  239. exportOptions: {
  240. columns: ":not(':last')"
  241. }
  242. },
  243. {
  244. extend: 'print',
  245. text: 'Stampa',
  246. title: 'Templates Email',
  247. exportOptions: {
  248. columns: ":not(':last')"
  249. }
  250. }
  251. ],
  252. dropup: true
  253. }
  254. ]
  255. },
  256. top1B : {
  257. pageLength: {
  258. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  259. }
  260. },
  261. top1C :'search',
  262. },
  263. pagingType: 'numbers',
  264. "language": {
  265. "url": "/assets/js/Italian.json"
  266. },
  267. "fnInitComplete": function (oSettings, json) {
  268. var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  269. $(".dt-search").append(html);
  270. }
  271. });
  272. $('#tablesaw-350 thead tr th').addClass('col');
  273. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  274. $(document).ready(function() {
  275. $(document).on("click",".addData",function() {
  276. $(".title--section_addButton").trigger("click")
  277. });
  278. });
  279. }
  280. document.addEventListener('DOMContentLoaded', function() {
  281. const datetimeInput = document.getElementById('scheduledDateTime');
  282. if (datetimeInput) {
  283. const now = new Date();
  284. now.setHours(now.getHours() + 1);
  285. const minDateTime = now.toISOString().slice(0, 16);
  286. datetimeInput.min = minDateTime;
  287. }
  288. const sendNowRadio = document.getElementById('sendNow');
  289. const scheduleForRadio = document.getElementById('scheduleFor');
  290. function updateButtonText() {
  291. const sendButton = document.querySelector('button[wire\\:click\\.prevent="store()"]');
  292. if (sendButton) {
  293. if (sendNowRadio && sendNowRadio.checked) {
  294. sendButton.textContent = 'Salva e Invia';
  295. } else if (scheduleForRadio && scheduleForRadio.checked) {
  296. sendButton.textContent = 'Salva e Programma';
  297. } else {
  298. sendButton.textContent = 'Salva e Invia';
  299. }
  300. }
  301. }
  302. if (sendNowRadio) {
  303. sendNowRadio.addEventListener('change', updateButtonText);
  304. }
  305. if (scheduleForRadio) {
  306. scheduleForRadio.addEventListener('change', updateButtonText);
  307. }
  308. updateButtonText();
  309. });
  310. document.addEventListener('livewire:load', function() {
  311. Livewire.on('load-data-table', function() {
  312. setTimeout(() => {
  313. const sendButton = document.querySelector('button[wire\\:click\\.prevent="store()"]');
  314. if (sendButton) {
  315. sendButton.textContent = 'Salva e Invia';
  316. }
  317. }, 100);
  318. });
  319. });
  320. </script>
  321. @endpush