calendar_archive.blade.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. @extends('layouts.frontend')
  2. @section('content')
  3. <div class="container" style="min-height: 450px;">
  4. <div class="row archivio-news">
  5. <br>
  6. <div class="title-section col-sm-12">
  7. <h1 style="width: 90%"><span>Archivio Calendari</span></h1>
  8. </div>
  9. <div class="col-sm-12">
  10. <form id="archiveFilterForm">
  11. <div class="row">
  12. <div class="col-md-12">
  13. <div class="form-group">
  14. <label for="season">Stagione:</label>
  15. <select id="season" name="season_id" class="form-control">
  16. <option value="">Seleziona Stagione</option>
  17. @foreach($seasons as $season)
  18. <option value="{{ $season->id }}">{{ $season->name }}</option>
  19. @endforeach
  20. </select>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="row mt-3" id="typeSection" style="display: none;">
  25. <div class="col-md-12">
  26. <div class="form-group">
  27. <label for="type">Tipo:</label>
  28. <select id="type" name="type" class="form-control">
  29. <option value="">Seleziona Tipo</option>
  30. @foreach($categories->pluck('type')->unique() as $type)
  31. <option value="{{ $type }}">
  32. @if($type == 'nation')
  33. NAZIONALE
  34. @elseif($type == 'region')
  35. REGIONALE
  36. @else
  37. {{ strtoupper($type) }}
  38. @endif
  39. </option>
  40. @endforeach
  41. </select>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="row mt-3" id="categorySection" style="display: none;">
  46. <div class="col-md-12">
  47. <div class="form-group">
  48. <label for="category">Categoria:</label>
  49. <select id="category" name="category_id" class="form-control">
  50. <option value="">Seleziona Categoria</option>
  51. </select>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="row mt-3" id="groupSection" style="display: none;">
  56. <div class="col-md-12">
  57. <div class="form-group">
  58. <label for="group">Gruppo:</label>
  59. <select id="group" name="group_id" class="form-control">
  60. <option value="">Seleziona Gruppo</option>
  61. </select>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="row mt-4" id="resultSection" style="display: none;">
  66. <div class="col-md-12 text-center">
  67. <div id="searchButtonSection">
  68. <button type="button" id="searchButton" class="btn btn-primary">
  69. Vai al Calendario
  70. </button>
  71. </div>
  72. <div id="noResultsSection" style="display: none;">
  73. <p class="text-danger">Nessun calendario in archivio per i dati inseriti</p>
  74. </div>
  75. </div>
  76. </div>
  77. </form>
  78. </div>
  79. </div>
  80. </div>
  81. @stop
  82. @section('extra_js')
  83. <script>
  84. $(document).ready(function() {
  85. const categories = @json($categories);
  86. const groups = @json($groups);
  87. const archivedCalendars = @json($archivedCalendars);
  88. function findCalendarsForSeason(seasonId) {
  89. return archivedCalendars.filter(cal => cal.season_id === parseInt(seasonId));
  90. }
  91. function findCalendarsForType(seasonId, type) {
  92. return archivedCalendars.filter(cal =>
  93. cal.season_id === parseInt(seasonId) &&
  94. cal.category?.type === type
  95. );
  96. }
  97. function findCalendarsForCategory(seasonId, categoryId) {
  98. return archivedCalendars.filter(cal =>
  99. cal.season_id === parseInt(seasonId) &&
  100. cal.category_id === parseInt(categoryId)
  101. );
  102. }
  103. $('#season').on('change', function() {
  104. const seasonId = $(this).val();
  105. if (seasonId) {
  106. const seasonCalendars = findCalendarsForSeason(seasonId);
  107. if (seasonCalendars.length > 0) {
  108. $('#typeSection').show();
  109. $('#resultSection, #noResultsSection').hide();
  110. } else {
  111. $('#typeSection, #categorySection, #groupSection').hide();
  112. $('#resultSection').show();
  113. $('#searchButtonSection').hide();
  114. $('#noResultsSection').show();
  115. }
  116. } else {
  117. $('#typeSection, #categorySection, #groupSection, #resultSection').hide();
  118. $('#type, #category, #group').val('');
  119. }
  120. });
  121. $('#type').on('change', function() {
  122. const selectedType = $(this).val();
  123. const seasonId = $('#season').val();
  124. if (selectedType && seasonId) {
  125. const typeCalendars = findCalendarsForType(seasonId, selectedType);
  126. if (typeCalendars.length > 0) {
  127. const filteredCategories = categories.filter(cat =>
  128. cat.type === selectedType &&
  129. typeCalendars.some(cal => cal.category_id === cat.id)
  130. );
  131. const categorySelect = $('#category');
  132. categorySelect.empty().append('<option value="">Seleziona Categoria</option>');
  133. filteredCategories.forEach(category => {
  134. categorySelect.append(`<option value="${category.id}">${category.name}</option>`);
  135. });
  136. $('#categorySection').show();
  137. $('#groupSection').hide();
  138. $('#group').val('');
  139. $('#resultSection, #noResultsSection').hide();
  140. } else {
  141. $('#categorySection, #groupSection').hide();
  142. $('#resultSection').show();
  143. $('#searchButtonSection').hide();
  144. $('#noResultsSection').show();
  145. }
  146. } else {
  147. $('#categorySection, #groupSection, #resultSection').hide();
  148. $('#category, #group').val('');
  149. }
  150. });
  151. $('#category').on('change', function() {
  152. const selectedCategoryId = $(this).val();
  153. const seasonId = $('#season').val();
  154. if (selectedCategoryId && seasonId) {
  155. const categoryCalendars = findCalendarsForCategory(seasonId, selectedCategoryId);
  156. if (categoryCalendars.length > 0) {
  157. const filteredGroups = groups.filter(group =>
  158. group.category_id === parseInt(selectedCategoryId) &&
  159. categoryCalendars.some(cal => cal.group_id === group.id)
  160. );
  161. if (filteredGroups.length > 0) {
  162. const groupSelect = $('#group');
  163. groupSelect.empty().append('<option value="">Seleziona Gruppo</option>');
  164. filteredGroups.forEach(group => {
  165. groupSelect.append(`<option value="${group.id}">${group.name}</option>`);
  166. });
  167. $('#groupSection').show();
  168. } else {
  169. $('#searchButtonSection').show();
  170. $('#noResultsSection').hide();
  171. }
  172. $('#resultSection').show();
  173. } else {
  174. $('#groupSection').hide();
  175. $('#resultSection').show();
  176. $('#searchButtonSection').hide();
  177. $('#noResultsSection').show();
  178. }
  179. } else {
  180. $('#groupSection, #searchButtonSection').hide();
  181. $('#group').val('');
  182. }
  183. });
  184. $('#group').on('change', function() {
  185. const groupId = $(this).val();
  186. if (groupId) {
  187. $('#searchButtonSection').show();
  188. $('#noResultsSection').hide();
  189. }
  190. });
  191. $('#searchButton').on('click', function() {
  192. const seasonId = $('#season').val();
  193. const categoryId = $('#category').val();
  194. const groupId = $('#group').val();
  195. const type = $('#type').val();
  196. const calendar = archivedCalendars.find(cal =>
  197. cal.season_id === parseInt(seasonId) &&
  198. cal.category_id === parseInt(categoryId) &&
  199. (!groupId || cal.group_id === parseInt(groupId)) &&
  200. cal.category?.type === type
  201. );
  202. if (calendar) {
  203. const categorySlug = calendar.category.name.toLowerCase()
  204. .normalize('NFD')
  205. .replace(/[\u0300-\u036f]/g, '')
  206. .replace(/[^\w\s-]/g, '')
  207. .replace(/\s+/g, '-');
  208. const groupSlug = calendar.group ? calendar.group.name.toLowerCase()
  209. .normalize('NFD')
  210. .replace(/[\u0300-\u036f]/g, '')
  211. .replace(/[^\w\s-]/g, '')
  212. .replace(/\s+/g, '-')
  213. : '';
  214. const url = `/calendario/${categorySlug}-${groupSlug}/${calendar.id}`;
  215. window.location.href = url;
  216. }
  217. });
  218. });
  219. </script>
  220. @stop