sms_comunications.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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)SMS Templates @else Inserimento/modifica template SMS @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">Caratteri</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($record->content, 50) }}
  37. </td>
  38. <td>
  39. @php
  40. $length = strlen($record->content);
  41. $badgeClass = $length > 160 ? 'bg-danger' : ($length > 140 ? 'bg-warning' : 'bg-success');
  42. @endphp
  43. <span class="badge {{ $badgeClass }}">{{ $length }}/160</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 SMS"><i class="fa-solid fa-paper-plane"></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="/sms_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="4" placeholder="Inserisci il contenuto del messaggio (max 160 caratteri)" maxlength="160"></textarea>
  82. <div class="form-text">
  83. Caratteri: <span class="fw-bold">{{ strlen($message) }}</span>/160
  84. @if(strlen($message) > 160)
  85. <span class="text-danger"> - Troppi caratteri!</span>
  86. @endif
  87. </div>
  88. @error('message')
  89. <div class="invalid-feedback">{{ $message }}</div>
  90. @enderror
  91. </div>
  92. </div>
  93. </div>
  94. @if($add)
  95. <div class="row mb-3">
  96. <div class="col">
  97. <label class="form-label">Destinatari</label>
  98. <div class="mb-2">
  99. <button type="button" class="btn btn-outline-primary btn-sm" onclick="selectAllUsers()">
  100. <i class="fas fa-users me-1"></i>Seleziona Tutti
  101. </button>
  102. <button type="button" class="btn btn-outline-secondary btn-sm ms-2" onclick="deselectAllUsers()">
  103. <i class="fas fa-times me-1"></i>Deseleziona Tutti
  104. </button>
  105. </div>
  106. <div style="max-height: 200px; overflow-y: auto; border: 1px solid #dee2e6; border-radius: 0.375rem; padding: 10px;">
  107. @foreach($members as $member)
  108. <div class="form-check mb-1">
  109. <input class="form-check-input" type="checkbox" value="{{ $member->id }}" wire:model="selectedRecipients" id="recipient_{{ $member->id }}">
  110. <label class="form-check-label" for="recipient_{{ $member->id }}">
  111. <strong>{{ $member->last_name }}</strong>
  112. @if($member->phone)
  113. <small class="text-muted">({{ $member->phone }})</small>
  114. @else
  115. <small class="text-danger">(no phone)</small>
  116. @endif
  117. </label>
  118. </div>
  119. @endforeach
  120. </div>
  121. <div class="form-text">
  122. <small class="text-muted">Selezionati: <span id="selectedCount">{{ count($selectedRecipients) }}</span> utenti</small>
  123. </div>
  124. @error('selectedRecipients')
  125. <div class="text-danger">{{ $message }}</div>
  126. @enderror
  127. </div>
  128. </div>
  129. <div class="row mb-3">
  130. <div class="col">
  131. <label class="form-label">Opzioni di Invio</label>
  132. <div class="form-check">
  133. <input class="form-check-input" type="radio" name="sendOption" id="sendNow" wire:model="sendNow" value="true">
  134. <label class="form-check-label" for="sendNow">
  135. <i class="fas fa-paper-plane me-2"></i>Invia Immediatamente
  136. </label>
  137. </div>
  138. <div class="form-check mt-2">
  139. <input class="form-check-input" type="radio" name="sendOption" id="scheduleFor" wire:model="sendNow" value="false">
  140. <label class="form-check-label" for="scheduleFor">
  141. <i class="fas fa-clock me-2"></i>Programma per dopo
  142. </label>
  143. </div>
  144. </div>
  145. </div>
  146. @if($sendNow === false || $sendNow === 'false')
  147. <div class="row mb-3">
  148. <div class="col-md-6">
  149. <label for="scheduledDateTime" class="form-label">Data e Ora di Invio</label>
  150. <input type="datetime-local" class="form-control @error('scheduledDateTime') is-invalid @enderror" id="scheduledDateTime" wire:model="scheduledDateTime">
  151. @error('scheduledDateTime')
  152. <div class="invalid-feedback">{{ $message }}</div>
  153. @enderror
  154. </div>
  155. </div>
  156. @endif
  157. @endif
  158. <div class="form--item">
  159. <button type="button" class="btn--ui lightGrey" wire:click="cancel()">Annulla</button>
  160. @if($add)
  161. <button type="submit" class="btn--ui" wire:click.prevent="store()">
  162. @if($sendNow === false || $sendNow === 'false')
  163. Salva e Invia
  164. @else
  165. Salva e Programma
  166. @endif
  167. </button>
  168. @endif
  169. @if($update)
  170. <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
  171. @endif
  172. </div>
  173. </form>
  174. </div>
  175. </div>
  176. </div>
  177. @endif
  178. </div>
  179. @if (session()->has('success'))
  180. <div class="alert alert-success alert-dismissible fade show mt-3" role="alert">
  181. {{ session()->get('success') }}
  182. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  183. </div>
  184. @endif
  185. @if (session()->has('error'))
  186. <div class="alert alert-danger alert-dismissible fade show mt-3" role="alert">
  187. {{ session()->get('error') }}
  188. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  189. </div>
  190. @endif
  191. @push('scripts')
  192. <link href="/css/datatables.css" rel="stylesheet" />
  193. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  194. <script src="/assets/js/datatables.js"></script>
  195. <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
  196. <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
  197. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
  198. <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
  199. @endpush
  200. @push('scripts')
  201. <script>
  202. $(document).ready(function() {
  203. loadDataTable();
  204. });
  205. Livewire.on('load-data-table', () => {
  206. loadDataTable();
  207. });
  208. function loadDataTable(){
  209. if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
  210. $('#tablesaw-350').DataTable().destroy();
  211. }
  212. $('#tablesaw-350').DataTable({
  213. thead: {
  214. 'th': {'background-color': 'blue'}
  215. },
  216. layout: {
  217. topStart : null,
  218. topEnd : null,
  219. top1A: {
  220. buttons: [
  221. {
  222. extend: 'collection',
  223. text: 'ESPORTA',
  224. buttons: [
  225. {
  226. extend: 'excelHtml5',
  227. title: 'Templates SMS',
  228. exportOptions: {
  229. columns: ":not(':last')"
  230. }
  231. },
  232. {
  233. extend: 'pdfHtml5',
  234. title: 'Templates SMS',
  235. exportOptions: {
  236. columns: ":not(':last')"
  237. }
  238. },
  239. {
  240. extend: 'print',
  241. text: 'Stampa',
  242. title: 'Templates SMS',
  243. exportOptions: {
  244. columns: ":not(':last')"
  245. }
  246. }
  247. ],
  248. dropup: true
  249. }
  250. ]
  251. },
  252. top1B : {
  253. pageLength: {
  254. menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
  255. }
  256. },
  257. top1C :'search',
  258. },
  259. pagingType: 'numbers',
  260. "language": {
  261. "url": "/assets/js/Italian.json"
  262. },
  263. "fnInitComplete": function (oSettings, json) {
  264. var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
  265. $(".dt-search").append(html);
  266. }
  267. });
  268. $('#tablesaw-350 thead tr th').addClass('col');
  269. $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
  270. $(document).ready(function() {
  271. $(document).on("click",".addData",function() {
  272. $(".title--section_addButton").trigger("click")
  273. });
  274. });
  275. }
  276. function selectAllUsers() {
  277. $('input[wire\\:model="selectedRecipients"]').prop('checked', true).trigger('change');
  278. updateSelectedCount();
  279. }
  280. function deselectAllUsers() {
  281. $('input[wire\\:model="selectedRecipients"]').prop('checked', false).trigger('change');
  282. updateSelectedCount();
  283. }
  284. function updateSelectedCount() {
  285. setTimeout(function() {
  286. let count = $('input[wire\\:model="selectedRecipients"]:checked').length;
  287. $('#selectedCount').text(count);
  288. }, 100);
  289. }
  290. // Update count when checkboxes change
  291. $(document).on('change', 'input[wire\\:model="selectedRecipients"]', function() {
  292. updateSelectedCount();
  293. });
  294. </script>
  295. @endpush