month.html.twig 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. {% autoescape false %}
  2. <script>
  3. function checkLength( o, n, min, max ) {
  4. if ( o.val().length > max || o.val().length < min ) {
  5. o.addClass( "ui-state-error" );
  6. /*updateTips( "Length of " + n + " must be between " +
  7. min + " and " + max + "." );*/
  8. return false;
  9. } else {
  10. return true;
  11. }
  12. }
  13. function clean_user_select() {
  14. //Cleans the selected attr
  15. $("#users_to_send").val('').trigger("chosen:updated");
  16. }
  17. var region_value = '{{ region_value }}';
  18. $(function() {
  19. var cookieData = Cookies.getJSON('agenda_cookies');
  20. var defaultView = (cookieData && cookieData.view) || '{{ default_view }}';
  21. var defaultStartDate = (cookieData && cookieData.start) || moment.now();
  22. // Reset button.
  23. $("button[type=reset]").click(function() {
  24. $("#session_id").find('option').removeAttr("selected");
  25. });
  26. function loadColors(calEvent){
  27. $("#calendarModal #color_calendar").removeClass();
  28. $("#calendarModal #color_calendar").html('{{ type_label | escape('js') }}');
  29. $("#calendarModal #color_calendar").addClass('label_tag');
  30. $("#calendarModal #color_calendar").addClass(calEvent.type+'_event');
  31. }
  32. var title = $("#title"),
  33. content = $("#content"),
  34. allFields = $([]).add( title ).add( content ), tips = $(".validateTips");
  35. $("#select_form_id_search").change(function() {
  36. var temp ="&user_id="+$("#select_form_id_search").val();
  37. var position =String(window.location).indexOf("&user");
  38. var url = String(window.location).substring(0,position)+temp;
  39. if (position > 0) {
  40. window.location.replace(url);
  41. } else {
  42. url = String(window.location)+temp;
  43. window.location.replace(url);
  44. }
  45. });
  46. var calendar = $('#calendar').fullCalendar({
  47. themeSystem: 'bootstrap4',
  48. contentHeight: 650,
  49. handleWindowResize: true,
  50. header: {
  51. left: 'prev,next today',
  52. center: 'title',
  53. right: 'month,agendaWeek,agendaDay,listMonth'
  54. },
  55. views: {
  56. /*listDay: { buttonText: 'list day' },
  57. listWeek: { buttonText: 'list week' },*/
  58. listMonth: { buttonText: 'list month' },
  59. },
  60. locale: region_value,
  61. {% if use_google_calendar == 1 %}
  62. eventSources: [
  63. // if you want to add more just add URL in this array
  64. '{{ google_calendar_url }}',
  65. {
  66. className: 'gcal-event' // an option!
  67. }
  68. ],
  69. {% endif %}
  70. defaultView: defaultView,
  71. defaultDate: defaultStartDate,
  72. firstHour: 8,
  73. firstDay: 1,
  74. selectable : true,
  75. selectHelper: true,
  76. viewRender: function(view, element) {
  77. var data = {
  78. 'view': view.name,
  79. 'start': view.intervalStart.format("YYYY-MM-DD")
  80. };
  81. Cookies.set('agenda_cookies', data, 1); // Expires 1 day
  82. },
  83. // Add event
  84. select: function(start, end, jsEvent, view) {
  85. //var start_date = start.format("YYYY-MM-DD h:mm");
  86. //var end_date = end.format("YYYY-MM-DD h:mm");
  87. var diffDays = moment(end).diff(start, 'days');
  88. var allDay = true;
  89. if (end.hasTime()) {
  90. allDay = false;
  91. }
  92. $('#visible_to_input').show();
  93. $('#add_as_announcement_div').show();
  94. $('#visible_to_read_only').hide();
  95. // Cleans the selected attr
  96. clean_user_select();
  97. // Sets the 1st item selected by default
  98. $('#users_to_send option').eq(0).attr('selected', 'selected');
  99. // Update chz-select
  100. //$("#users_to_send").trigger("chosen:updated");
  101. if ({{ can_add_events }} == 1) {
  102. var url = '{{ web_agenda_ajax_url }}&a=add_event&start='+start.format("YYYY-MM-DD HH:mm:00")+'&end='+end.format("YYYY-MM-DD HH:mm:00")+'&all_day='+allDay+'&view='+view.name;
  103. var start_date_value = start.format('{{ js_format_date }}');
  104. $('#start_date').html(start_date_value);
  105. if (diffDays > 1) {
  106. $('#start_date').html('');
  107. var end_date_value = '';
  108. if (end) {
  109. var clone = end.clone();
  110. end_date_value = clone.subtract(1, 'days').format('{{ js_format_date }}');
  111. }
  112. $('#end_date').html(start_date_value + " - " + end_date_value);
  113. } else if (diffDays == 0) {
  114. var start_date_value = start.format('ll');
  115. var startTime = start.format('LT');
  116. var endTime = end.format('LT');
  117. $('#start_date').html('');
  118. $('#end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
  119. } else {
  120. $('#end_date').html('');
  121. }
  122. $('#color_calendar')
  123. .html('{{ type_label | escape('js')}}')
  124. .removeClass('group_event')
  125. .addClass('label_tag')
  126. .addClass('{{ type_event_class | escape('js') }}')
  127. .css('background-color', '{{ type_event_color }}');
  128. //It shows the CKEDITOR while Adding an Event
  129. $('#cke_content').show();
  130. //Reset the CKEditor content that persist in memory
  131. CKEDITOR.instances['content'].setData('');
  132. allFields.removeClass("ui-state-error");
  133. $("#modalDialogForm").modal();
  134. var btnSave = '<button id="btnSave" type="button" class="btn btn-primary">{{ "Add" | get_lang }}</button>';
  135. $("#modalDialogForm #modalFooter").html(btnSave);
  136. $("#btnSave").click( function() {
  137. var bValid = true;
  138. bValid = bValid && checkLength(title, "title", 1, 255);
  139. //Update the CKEditor Instance to the remplaced textarea, ready to be serializable
  140. for ( instance in CKEDITOR.instances ) {
  141. CKEDITOR.instances[instance].updateElement();
  142. }
  143. var params = $("#add_event_form").serialize();
  144. $.ajax({
  145. url: url+'&'+params,
  146. success:function(data) {
  147. var user = $('#users_to_send').val();
  148. if (user) {
  149. if (user.length > 1) {
  150. user = 0;
  151. } else {
  152. user = user[0];
  153. }
  154. var user_length = String(user).length;
  155. if (String(user).substring(0,1) == 'G') {
  156. var user_id = String(user).substring(6,user_length);
  157. var user_id = "G:"+user_id;
  158. } else {
  159. var user_id = String(user).substring(5,user_length);
  160. }
  161. //var temp = "&user_id="+user_id;
  162. //var position = String(window.location).indexOf("&user");
  163. //var url = String(window.location).substring(0, position)+temp;
  164. /*if (position > 0) {
  165. window.location.replace(url);
  166. } else {
  167. url = String(window.location)+temp;
  168. window.location.replace(url);
  169. }*/
  170. }
  171. calendar.fullCalendar('refetchEvents');
  172. calendar.fullCalendar('rerenderEvents');
  173. $('#modalDialogForm').modal('toggle');
  174. }
  175. });
  176. });
  177. calendar.fullCalendar('unselect');
  178. //Reload events
  179. calendar.fullCalendar("refetchEvents");
  180. calendar.fullCalendar("rerenderEvents");
  181. }
  182. },
  183. eventClick: function(calEvent, jsEvent, view) {
  184. var start = calEvent.start;
  185. var end = calEvent.end;
  186. var diffDays = moment(end).diff(start, 'days');
  187. var endDateMinusOne = '';
  188. if (end) {
  189. var clone = end.clone();
  190. endDateMinusOne = clone.subtract(1, 'days').format('{{ js_format_date }}');
  191. }
  192. var startDateToString = start.format("{{ js_format_date }}");
  193. // Edit event.
  194. if (calEvent.editable) {
  195. $('#visible_to_input').hide();
  196. $('#add_as_announcement_div').hide();
  197. {% if type != 'admin' %}
  198. $('#visible_to_read_only').show();
  199. $("#visible_to_read_only_users").html(calEvent.sent_to);
  200. $(".user-sender").show();
  201. {% endif %}
  202. loadColors(calEvent);
  203. $('#simple_start_date').html(startDateToString);
  204. if (diffDays > 1) {
  205. $('#simple_end_date').html(' - ' + endDateMinusOne);
  206. } else if (diffDays == 0) {
  207. var start_date_value = start.format('ll');
  208. var startTime = start.format('LT');
  209. var endTime = end.format('LT');
  210. $('#simple_start_date').html('');
  211. $('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
  212. } else {
  213. $('#simple_end_date').html('');
  214. }
  215. $("#simple_title").html(calEvent.title);
  216. $("#simple_content").html(calEvent.description);
  217. $("#simple_comment").html(calEvent.comment);
  218. if (calEvent.course_name) {
  219. $("#calendar_course_info_simple").html(calEvent.course_name);
  220. $("#type_course").html("{{ 'Course' | get_lang }}");
  221. } else {
  222. $("#calendar_course_info_simple").html('');
  223. }
  224. if (calEvent.session_name) {
  225. $("#calendar_course_info_simple").html(calEvent.session_name);
  226. $('#type_course').html("{{ 'Session' | get_lang }}");
  227. } else {
  228. $("#calendar_course_info_simple").html('');
  229. }
  230. allFields.removeClass( "ui-state-error" );
  231. $('#calendarModal #modalTitle').html(calEvent.title);
  232. $('#calendarModal').modal();
  233. var url = '{{ web_agenda_ajax_url }}&a=edit_event&id='+calEvent.id+'&view='+view.name;
  234. var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
  235. var urlOne = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  236. var urlTwo = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  237. var urlThree = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  238. var urlEdit = "{{ _p.web_main }}calendar/agenda.php?action=edit&type=fromjs&id="+calEvent.id+'&course_id='+calEvent.course_id+"";
  239. var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"ExportiCalConfidential"|get_lang}}</a>';
  240. var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
  241. var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
  242. var btnEdit = '<a href="'+urlEdit+'" id="btnEdit" class="btn btn-primary">{{ "Edit" | get_lang }}</a>';
  243. var btnDelete = '<button type="button" id="btnDelete" class="btn btn-danger">{{ "Delete" | get_lang }}</button>';
  244. $('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic+btnEdit+btnDelete);
  245. {% if type == 'not_available' %}
  246. $('#btnEdit').click(function() {
  247. var bValid = true;
  248. bValid = bValid && checkLength( title, "title", 1, 255 );
  249. var params = $("#add_event_form").serialize();
  250. $.ajax({
  251. url: url+'&'+params,
  252. success:function() {
  253. calEvent.title = $("#title").val();
  254. calEvent.start = calEvent.start;
  255. calEvent.end = calEvent.end;
  256. calEvent.allDay = calEvent.allDay;
  257. calEvent.description = $("#content").val();
  258. calendar.fullCalendar('updateEvent',
  259. calEvent,
  260. true // make the event "stick"
  261. );
  262. //close modal
  263. $('#calendarModal').modal('toggle');
  264. }
  265. });
  266. });
  267. {% endif %}
  268. $('#btnDelete').click(function() {
  269. if (calEvent.parent_event_id || calEvent.has_children != '') {
  270. var newDiv = $('<div>');
  271. newDiv.dialog({
  272. modal: true,
  273. title: "{{ 'DeleteThisItem' | get_lang }}",
  274. buttons: []
  275. });
  276. var buttons = newDiv.dialog("option", "buttons");
  277. if (calEvent.has_children == '0') {
  278. buttons.push({
  279. text: '{{ "DeleteThisItem" | get_lang }}',
  280. click: function() {
  281. $.ajax({
  282. url: delete_url,
  283. success:function() {
  284. calendar.fullCalendar('removeEvents',
  285. calEvent
  286. );
  287. calendar.fullCalendar("refetchEvents");
  288. calendar.fullCalendar("rerenderEvents");
  289. $("#dialog-form").dialog("close");
  290. newDiv.dialog( "destroy" );
  291. }
  292. });
  293. }
  294. });
  295. newDiv.dialog("option", "buttons", buttons);
  296. }
  297. var buttons = newDiv.dialog("option", "buttons");
  298. buttons.push({
  299. text: '{{ "DeleteAllItems" | get_lang }}',
  300. click: function() {
  301. $.ajax({
  302. url: delete_url+'&delete_all_events=1',
  303. success:function() {
  304. calendar.fullCalendar('removeEvents',
  305. calEvent
  306. );
  307. calendar.fullCalendar('refetchEvents');
  308. calendar.fullCalendar('rerenderEvents');
  309. $("#dialog-form").dialog('close');
  310. newDiv.dialog( "destroy" );
  311. }
  312. });
  313. }
  314. });
  315. newDiv.dialog("option", "buttons", buttons);
  316. return true;
  317. }
  318. $.ajax({
  319. url: delete_url,
  320. success:function() {
  321. calendar.fullCalendar('removeEvents',
  322. calEvent
  323. );
  324. calendar.fullCalendar('refetchEvents');
  325. calendar.fullCalendar('rerenderEvents');
  326. //close modal
  327. $('#calendarModal').modal('toggle');
  328. }
  329. });
  330. });
  331. } else {
  332. // Simple form
  333. $('#simple_start_date').html(startDateToString);
  334. if (diffDays > 1) {
  335. $('#simple_end_date').html(' - ' + endDateMinusOne);
  336. } else if (diffDays == 0) {
  337. var start_date_value = start.format('ll');
  338. var startTime = start.format('LT');
  339. var endTime = end.format('LT');
  340. $('#simple_start_date').html('');
  341. $('#simple_end_date').html(start_date_value + " (" + startTime + " - " + endTime+") ");
  342. } else {
  343. $('#simple_end_date').html('');
  344. }
  345. loadColors(calEvent);
  346. if (calEvent.course_name) {
  347. $("#calendar_course_info_simple").html(calEvent.course_name);
  348. $("#type_course").html("{{ 'Course' | get_lang }}");
  349. } else {
  350. $("#calendar_course_info_simple").html('');
  351. }
  352. if (calEvent.session_name) {
  353. $("#type_course").append("{{ 'Session' | get_lang }}");
  354. $("#calendar_session_info").html(calEvent.session_name);
  355. } else {
  356. $("#calendar_session_info").html('');
  357. }
  358. $("#simple_title").html(calEvent.title);
  359. $("#simple_content").html(calEvent.description);
  360. $("#simple_comment").html(calEvent.comment);
  361. $('#modalTitle').html(calEvent.title);
  362. $('#calendarModal').modal();
  363. var urlOne = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  364. var exportCalConfidential = '<a href="'+urlOne+'" class="btn btn-light">{{"ExportiCalConfidential"|get_lang}}</a>';
  365. var urlTwo = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  366. var exportCalPrivate = '<a href="'+urlTwo+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
  367. var urlThree = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  368. var exportCalPublic = '<a href="'+urlThree+'" class="btn btn-light">{{"ExportiCalPrivate"|get_lang}}</a>';
  369. $('#calendarModal #modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic);
  370. }
  371. },
  372. editable: true,
  373. events: "{{web_agenda_ajax_url}}&a=get_events",
  374. eventDrop: function(event, delta, revert_func) {
  375. var allDay = 0;
  376. if (event.allDay == true) {
  377. allDay = 1;
  378. }
  379. $.ajax({
  380. url: '{{ web_agenda_ajax_url }}',
  381. data: {
  382. a: 'move_event',
  383. id: event.id,
  384. all_day: allDay,
  385. minute_delta: delta.asMinutes()
  386. }
  387. });
  388. },
  389. eventResize: function(event, delta, revert_func) {
  390. $.ajax({
  391. url: '{{ web_agenda_ajax_url }}',
  392. data: {
  393. a: 'resize_event',
  394. id: event.id,
  395. minute_delta: delta.asMinutes()
  396. }
  397. });
  398. },
  399. axisFormat: 'H(:mm)', // pm-am format -> h(:mm)a
  400. timeFormat: 'H:mm', // pm-am format -> h:mm
  401. loading: function(bool) {
  402. if (bool) $('#loading').show();
  403. else $('#loading').hide();
  404. }
  405. });
  406. });
  407. </script>
  408. {{ actions_div }}
  409. {{ toolbar }}
  410. {% if legend_list %}
  411. {% for color, text in legend_list %}
  412. <span style="background-color: {{ color }}" class="label label-default">&nbsp;</span> {{ text }} &nbsp;&nbsp;
  413. {% endfor %}
  414. <br /><br />
  415. {% endif %}
  416. <div id="loading" style="margin-left:150px;position:absolute;display:none">
  417. {{ "Loading" | get_lang }}...
  418. </div>
  419. <div id="calendar"></div>
  420. <div id="modalDialogForm" class="modal" tabindex="-1" role="dialog">
  421. <div class="modal-dialog modal-lg" role="document">
  422. <div class="modal-content">
  423. <div class="modal-header">
  424. <h5 class="modal-title">{{ "Add event" | get_lang }}</h5>
  425. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  426. <span aria-hidden="true">&times;</span>
  427. </button>
  428. </div>
  429. <div class="modal-body">
  430. {{ form_add }}
  431. </div>
  432. <div id="modalFooter" class="modal-footer">
  433. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  434. <button type="button" class="btn btn-primary">Save changes</button>
  435. </div>
  436. </div>
  437. </div>
  438. </div>
  439. <div id="calendarModal" class="modal" tabindex="-1" role="dialog">
  440. <div class="modal-dialog modal-lg" role="document">
  441. <div class="modal-content">
  442. <div class="modal-header">
  443. <h5 id="modalTitle" class="modal-title"></h5>
  444. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  445. <span aria-hidden="true">&times;</span>
  446. </button>
  447. </div>
  448. <div id="modalBody" class="modal-body">
  449. <dl class="row">
  450. <!--- type event course o session -->
  451. <dt id="type_course" class="col-sm-2"></dt>
  452. <dd class="col-sm-10">
  453. <span id="calendar_course_info_simple"></span>
  454. </dd>
  455. <!--- user sender -->
  456. <dt class="user-sender col-sm-2" style="display: none;">
  457. {{ "To" |get_lang }}
  458. </dt>
  459. <dd class="user-sender col-sm-10" style="display: none">
  460. <span id="visible_to_read_only_users"></span>
  461. </dd>
  462. <!--- type agenda -->
  463. <dt class="col-sm-2">
  464. {{ "Agenda" |get_lang }}
  465. </dt>
  466. <dd class="col-sm-10">
  467. <div id="color_calendar"></div>
  468. </dd>
  469. <dt class="col-sm-2">{{ "Title" |get_lang }}</dt>
  470. <dd class="col-sm-10">
  471. <div id="simple_title"></div>
  472. </dd>
  473. <dt class="col-sm-2">{{ "Date" |get_lang }}</dt>
  474. <dd class="col-sm-10">
  475. <span id="simple_start_date"></span>
  476. <span id="simple_end_date"></span>
  477. </dd>
  478. <dt class="col-sm-2">{{ "Description" |get_lang }}</dt>
  479. <dd class="col-sm-10">
  480. <div id="simple_content"></div>
  481. </dd>
  482. <dt class="col-sm-2">{{ "Comment" |get_lang }}</dt>
  483. <dd class="col-sm-10">
  484. <div id="simple_comment"></div>
  485. </dd>
  486. </dl>
  487. </div>
  488. <div id="modalFooter" class="modal-footer">
  489. </div>
  490. </div>
  491. </div>
  492. </div>
  493. {% endautoescape %}