month.tpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <script>
  2. function checkLength( o, n, min, max ) {
  3. if ( o.val().length > max || o.val().length < min ) {
  4. o.addClass( "ui-state-error" );
  5. /*updateTips( "Length of " + n + " must be between " +
  6. min + " and " + max + "." );*/
  7. return false;
  8. } else {
  9. return true;
  10. }
  11. }
  12. function clean_user_select() {
  13. //Cleans the selected attr
  14. $("#users_to_send").val('').trigger("chosen:updated");
  15. /*$('#users_to_send')
  16. .find('option')
  17. .removeAttr('selected')
  18. .end();*/
  19. }
  20. var region_value = '{{ region_value }}';
  21. $(document).ready(function() {
  22. var date = new Date();
  23. // Reset button.
  24. $("button[type=reset]").click(function() {
  25. $("#session_id").find('option').removeAttr("selected");
  26. });
  27. $("#dialog-form").dialog({
  28. autoOpen: false,
  29. modal : false,
  30. width : 580,
  31. height : 480,
  32. zIndex: 20000 // added because of qtip2
  33. });
  34. $("#simple-dialog-form").dialog({
  35. autoOpen: false,
  36. modal : false,
  37. width : 580,
  38. height : 480,
  39. zIndex: 20000 // added because of qtip2
  40. });
  41. var title = $("#title"),
  42. content = $( "#content" ),
  43. allFields = $( [] ).add( title ).add( content ), tips = $(".validateTips");
  44. $("#select_form_id_search").change(function() {
  45. var temp ="&user_id="+$("#select_form_id_search").val();
  46. var position =String(window.location).indexOf("&user");
  47. var url_length = String(window.location).length;
  48. var url = String(window.location).substring(0,position)+temp;
  49. if (position > 0) {
  50. window.location.replace(url);
  51. } else {
  52. url = String(window.location)+temp;
  53. window.location.replace(url);
  54. }
  55. });
  56. $.datepicker.setDefaults( $.datepicker.regional[region_value] );
  57. var calendar = $('#calendar').fullCalendar({
  58. header: {
  59. left: 'today prev,next',
  60. center: 'title',
  61. right: 'month,agendaWeek,agendaDay'
  62. },
  63. {% if use_google_calendar == 1 %}
  64. eventSources: [
  65. // if you want to add more just add URL in this array
  66. '{{ google_calendar_url }}',
  67. {
  68. className: 'gcal-event' // an option!
  69. }
  70. ],
  71. {% endif %}
  72. defaultView: '{{ default_view }}',
  73. buttonText: {{ button_text }},
  74. monthNames: {{ month_names }},
  75. monthNamesShort:{{ month_names_short }},
  76. dayNames: {{ day_names }},
  77. dayNamesShort: {{ day_names_short }},
  78. firstHour: 8,
  79. firstDay: 1,
  80. selectable : true,
  81. selectHelper: true,
  82. viewDisplay: function(view) {
  83. /* When changing the view update the qtips */
  84. /*var api = $('.qtip').qtip('api'); // Access the API of the first tooltip on the page
  85. if (api) {
  86. api.destroy();
  87. //api.render();
  88. }*/
  89. },
  90. // Add event
  91. select: function(start, end, jsEvent, view) {
  92. var start_date = start.format("YY-MM-DD");
  93. var end_date = end.format("YY-MM-DD");
  94. var allDay = true;
  95. if (end.hasTime()) {
  96. allDay = false;
  97. }
  98. $('#visible_to_input').show();
  99. $('#add_as_announcement_div').show();
  100. $('#visible_to_read_only').hide();
  101. // Cleans the selected attr
  102. clean_user_select();
  103. // Sets the 1st item selected by default
  104. $('#users_to_send option').eq(0).attr('selected', 'selected');
  105. // Update chz-select
  106. //$("#users_to_send").trigger("chosen:updated");
  107. if ({{ can_add_events }} == 1) {
  108. var url = '{{ web_agenda_ajax_url }}&a=add_event&start='+start.format('YYYY-MM-DD 00:00:00')+'&end='+end.format('YYYY-MM-DD 00:00:00')+'&all_day='+allDay+'&view='+view.name;
  109. var start_date_value = start.format('{{ js_format_date }}');
  110. var end_date_value = end.format('{{ js_format_date }}');
  111. $('#start_date').html(start_date_value);
  112. if (start_date_value == end_date_value) {
  113. $('#end_date').html(' - ' + end_date_value);
  114. } else {
  115. $('#start_date').html('');
  116. $('#end_date').html(start_date_value+" - " + end_date_value);
  117. }
  118. $('#color_calendar').html('{{ type_label }}');
  119. $('#color_calendar').removeClass('group_event');
  120. $('#color_calendar').addClass('label_tag');
  121. $('#color_calendar').addClass('{{ type_event_class }}');
  122. //It shows the CKEDITOR while Adding an Event
  123. $('#cke_content').show();
  124. //It Fixing a minor bug with textarea ckeditor.remplace
  125. $('#content').css('display','none');
  126. //Reset the CKEditor content that persist in memory
  127. CKEDITOR.instances['content'].setData('');
  128. allFields.removeClass("ui-state-error");
  129. $("#dialog-form").dialog("open");
  130. $("#dialog-form").dialog({
  131. buttons: {
  132. '{{ "Add" | get_lang }}' : function() {
  133. var bValid = true;
  134. bValid = bValid && checkLength(title, "title", 1, 255);
  135. //Update the CKEditor Instance to the remplaced textarea, ready to be serializable
  136. for ( instance in CKEDITOR.instances ) {
  137. CKEDITOR.instances[instance].updateElement();
  138. }
  139. var params = $("#add_event_form").serialize();
  140. $.ajax({
  141. url: url+'&'+params,
  142. success:function(data) {
  143. var user = $('#users_to_send').val();
  144. if (user) {
  145. if (user.length > 1) {
  146. user = 0;
  147. } else {
  148. user = user[0];
  149. }
  150. var user_length = String(user).length;
  151. if (String(user).substring(0,1) == 'G') {
  152. var user_id = String(user).substring(6,user_length);
  153. var user_id = "G:"+user_id;
  154. } else {
  155. var user_id = String(user).substring(5,user_length);
  156. }
  157. var temp = "&user_id="+user_id;
  158. var position = String(window.location).indexOf("&user");
  159. var url_length = String(window.location).length;
  160. var url = String(window.location).substring(0, position)+temp;
  161. /*if (position > 0) {
  162. window.location.replace(url);
  163. } else {
  164. url = String(window.location)+temp;
  165. window.location.replace(url);
  166. }*/
  167. } else {
  168. /* calendar.fullCalendar("refetchEvents");
  169. calendar.fullCalendar("rerenderEvents");*/
  170. }
  171. $("#title").val('');
  172. $("#content").val('');
  173. $("#comment").val('');
  174. calendar.fullCalendar("refetchEvents");
  175. calendar.fullCalendar("rerenderEvents");
  176. $("#dialog-form").dialog("close");
  177. }
  178. });
  179. }
  180. },
  181. close: function() {
  182. $("#title").val('');
  183. $("#content").val('');
  184. $("#comment").val('');
  185. }
  186. });
  187. calendar.fullCalendar('unselect');
  188. //Reload events
  189. calendar.fullCalendar("refetchEvents");
  190. calendar.fullCalendar("rerenderEvents");
  191. }
  192. },
  193. eventRender: function(event, element) {
  194. if (event.attachment) {
  195. /*element.qtip({
  196. hide: {
  197. delay: 2000
  198. },
  199. content: event.attachment,
  200. position: { at:'top right' , my:'bottom right'}
  201. }).removeData('qtip'); // this is an special hack to add multiple qtip in the same target
  202. */
  203. }
  204. if (event.description) {
  205. var comment = '';
  206. if (event.comment) {
  207. comment = event.comment;
  208. }
  209. /*element.qtip({
  210. hide: {
  211. delay: 2000
  212. },
  213. content: event.description + ' ' + comment,
  214. position: { at:'top left' , my:'bottom left'}
  215. });*/
  216. }
  217. },
  218. eventClick: function(calEvent, jsEvent, view) {
  219. if (!calEvent.end) {
  220. calEvent.end = calEvent.start;
  221. }
  222. var start_date = calEvent.start.format("YY-MM-DD");
  223. if (calEvent.allDay == 1) {
  224. var end_date = '';
  225. } else {
  226. var end_date = '';
  227. if (calEvent.end && calEvent.end != '') {
  228. var end_date = calEvent.end.format("YY-MM-DD");
  229. }
  230. }
  231. // Edit event.
  232. if (calEvent.editable) {
  233. $('#visible_to_input').hide();
  234. $('#add_as_announcement_div').hide();
  235. {% if type != 'admin' %}
  236. $('#visible_to_read_only').show();
  237. $("#visible_to_read_only_users").html(calEvent.sent_to);
  238. {% endif %}
  239. $('#color_calendar').html('{{type_label}}');
  240. $('#color_calendar').addClass('label_tag');
  241. $('#color_calendar').removeClass('course_event');
  242. $('#color_calendar').removeClass('personal_event');
  243. $('#color_calendar').removeClass('group_event');
  244. $('#color_calendar').addClass(calEvent.type+'_event');
  245. //It hides the CKEDITOR while clicking an existing Event
  246. $('#cke_content').hide();
  247. $('#start_date').html(calEvent.start.format("YY-MM-DD"));
  248. if (calEvent.end) {
  249. $('#end_date').html(' - '+calEvent.end.format("YY-MM-DD"));
  250. }
  251. if ($("#title").parent().find('#title_edit').length == 0) {
  252. $("#title").parent().append('<div id="title_edit"></div>');
  253. }
  254. $("#title_edit").html(calEvent.title);
  255. if ($("#content").parent().find('#content_edit').length == 0) {
  256. $("#content").parent().append('<div id="content_edit"></div>');
  257. }
  258. $("#content_edit").html(calEvent.description);
  259. if ($("#comment").parent().find('#comment_edit').length == 0) {
  260. $("#comment").parent().append('<div id="comment_edit"></div>');
  261. }
  262. if (calEvent.course_name) {
  263. $("#calendar_course_info").html(
  264. '<div class="form-group"><label class="col-sm-2 control-label">{{ 'Course' | get_lang }}</label>' +
  265. '<div class="class="col-sm-8">' + calEvent.course_name+"</div></div>"
  266. );
  267. } else {
  268. $("#calendar_course_info").html('');
  269. }
  270. if (calEvent.session_name) {
  271. $("#calendar_session_info").html(
  272. '<div class="form-group"><label class="col-sm-2 control-label">{{ 'Session' | get_lang }}</label>'+
  273. '<div class="class="col-sm-8">' + calEvent.session_name+"</div></div>"
  274. );
  275. } else {
  276. $("#calendar_session_info").html('');
  277. }
  278. $("#comment_edit").html(calEvent.comment);
  279. $("#title_edit").show();
  280. $("#content_edit").show();
  281. $("#comment_edit").show();
  282. $("#title").hide();
  283. $("#content").hide();
  284. $("#comment").hide();
  285. allFields.removeClass( "ui-state-error" );
  286. $("#dialog-form").dialog("open");
  287. var url = '{{ web_agenda_ajax_url }}&a=edit_event&id='+calEvent.id+'&start='+calEvent.start.unix()+'&end='+calEvent.end.unix()+'&all_day='+calEvent.allDay+'&view='+view.name;
  288. var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
  289. $("#dialog-form").dialog({
  290. buttons: {
  291. '{{ "ExportiCalConfidential"|get_lang }}' : function() {
  292. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  293. window.location.href = url;
  294. },
  295. '{{ "ExportiCalPrivate"|get_lang }}': function() {
  296. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  297. window.location.href = url;
  298. },
  299. '{{ "ExportiCalPublic"|get_lang }}': function() {
  300. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  301. window.location.href = url;
  302. },
  303. {% if type == 'not_available' %}
  304. '{{ "Edit" | get_lang }}' : function() {
  305. var bValid = true;
  306. bValid = bValid && checkLength( title, "title", 1, 255 );
  307. var params = $("#add_event_form").serialize();
  308. $.ajax({
  309. url: url+'&'+params,
  310. success:function() {
  311. calEvent.title = $("#title").val();
  312. calEvent.start = calEvent.start;
  313. calEvent.end = calEvent.end;
  314. calEvent.allDay = calEvent.allDay;
  315. calEvent.description = $("#content").val();
  316. calendar.fullCalendar('updateEvent',
  317. calEvent,
  318. true // make the event "stick"
  319. );
  320. $("#dialog-form").dialog("close");
  321. }
  322. });
  323. },
  324. {% endif %}
  325. '{{ "Edit"|get_lang }}' : function() {
  326. url = "{{ _p.web_main }}calendar/agenda.php?action=edit&type=fromjs&id=" + calEvent.id+'&course_id='+calEvent.course_id+"";
  327. window.location.href = url;
  328. $("#dialog-form").dialog( "close" );
  329. },
  330. '{{ "Delete"|get_lang }}': function() {
  331. if (calEvent.parent_event_id || calEvent.has_children != '') {
  332. var newDiv = $('<div>');
  333. newDiv.dialog({
  334. modal: true,
  335. title: "{{ 'DeleteThisItem' | get_lang }}",
  336. buttons: []
  337. });
  338. var buttons = newDiv.dialog("option", "buttons");
  339. if (calEvent.has_children == '0') {
  340. buttons.push({
  341. text: '{{ "DeleteThisItem" | get_lang }}',
  342. click: function() {
  343. $.ajax({
  344. url: delete_url,
  345. success:function() {
  346. calendar.fullCalendar('removeEvents',
  347. calEvent
  348. );
  349. calendar.fullCalendar("refetchEvents");
  350. calendar.fullCalendar("rerenderEvents");
  351. $("#dialog-form").dialog("close");
  352. newDiv.dialog( "destroy" );
  353. }
  354. });
  355. }
  356. });
  357. newDiv.dialog("option", "buttons", buttons);
  358. }
  359. var buttons = newDiv.dialog("option", "buttons");
  360. buttons.push({
  361. text: '{{ "DeleteAllItems" | get_lang }}',
  362. click: function() {
  363. $.ajax({
  364. url: delete_url+'&delete_all_events=1',
  365. success:function() {
  366. calendar.fullCalendar('removeEvents',
  367. calEvent
  368. );
  369. calendar.fullCalendar("refetchEvents");
  370. calendar.fullCalendar("rerenderEvents");
  371. $("#dialog-form").dialog( "close" );
  372. newDiv.dialog( "destroy" );
  373. }
  374. });
  375. }
  376. });
  377. newDiv.dialog("option", "buttons", buttons);
  378. return true;
  379. }
  380. $.ajax({
  381. url: delete_url,
  382. success:function() {
  383. calendar.fullCalendar('removeEvents',
  384. calEvent
  385. );
  386. calendar.fullCalendar("refetchEvents");
  387. calendar.fullCalendar("rerenderEvents");
  388. $("#dialog-form").dialog( "close" );
  389. }
  390. });
  391. }
  392. },
  393. close: function() {
  394. $("#title_edit").hide();
  395. $("#content_edit").hide();
  396. $("#comment_edit").hide();
  397. $("#title").show();
  398. $("#content").show();
  399. $("#comment").show();
  400. $("#title_edit").html('');
  401. $("#content_edit").html('');
  402. $("#comment_edit").html('');
  403. $("#title").val('');
  404. $("#content").val('');
  405. $("#comment").val('');
  406. }
  407. });
  408. } else {
  409. // Simple form
  410. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  411. if (end_date != '') {
  412. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  413. $('#simple_end_date').html(' ' + calEvent.end.format("YY-MM-DD"));
  414. }
  415. if (calEvent.course_name) {
  416. $("#calendar_course_info_simple").html(
  417. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Course' | get_lang }}</label>' +
  418. '<div class="col-sm-9">' + calEvent.course_name+"</div></div>"
  419. );
  420. } else {
  421. $("#calendar_course_info_simple").html('');
  422. }
  423. if (calEvent.session_name) {
  424. $("#calendar_session_info").html(
  425. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Session' | get_lang }}</label>' +
  426. '<div class="col-sm-9">' + calEvent.session_name+"</div></div>"
  427. );
  428. } else {
  429. $("#calendar_session_info").html('');
  430. }
  431. $("#simple_title").html(calEvent.title);
  432. $("#simple_content").html(calEvent.description);
  433. $("#simple_comment").html(calEvent.comment);
  434. $("#simple-dialog-form").dialog("open");
  435. $("#simple-dialog-form").dialog({
  436. buttons: {
  437. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  438. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  439. window.location.href = url;
  440. },
  441. '{{"ExportiCalPrivate"|get_lang}}': function() {
  442. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  443. window.location.href = url;
  444. },
  445. '{{"ExportiCalPublic"|get_lang}}': function() {
  446. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  447. window.location.href = url;
  448. }
  449. }
  450. });
  451. }
  452. },
  453. editable: true,
  454. events: "{{web_agenda_ajax_url}}&a=get_events",
  455. eventDrop: function(event, delta, revert_func) {
  456. $.ajax({
  457. url: '{{ web_agenda_ajax_url }}',
  458. data: {
  459. a: 'move_event',
  460. id: event.id,
  461. day_delta: delta.days(),
  462. minute_delta: delta.minutes()
  463. }
  464. });
  465. },
  466. eventResize: function(event, delta, revert_func) {
  467. $.ajax({
  468. url: '{{ web_agenda_ajax_url }}',
  469. data: {
  470. a: 'resize_event',
  471. id: event.id,
  472. day_delta: delta.days(),
  473. minute_delta: delta.minutes()
  474. }
  475. });
  476. },
  477. axisFormat: 'h(:mm)a',
  478. timeFormat: 'h:mm',
  479. loading: function(bool) {
  480. if (bool) $('#loading').show();
  481. else $('#loading').hide();
  482. }
  483. });
  484. });
  485. </script>
  486. {{ actions_div }}
  487. {{ toolbar }}
  488. <div id="simple-dialog-form" style="display:none;">
  489. <div style="width:500px">
  490. <form name="form-simple" class="form-horizontal">
  491. <span id="calendar_course_info_simple"></span>
  492. <span id="calendar_session_info"></span>
  493. <div class="form-group">
  494. <label class="col-sm-3 control-label">
  495. <b>{{ "Date" |get_lang}}</b>
  496. </label>
  497. <div class="col-sm-9">
  498. <span id="simple_start_date"></span>
  499. <span id="simple_end_date"></span>
  500. </div>
  501. </div>
  502. <div class="form-group">
  503. <label class="col-sm-3 control-label">
  504. <b>{{ "Title" |get_lang}}</b>
  505. </label>
  506. <div class="col-sm-9">
  507. <div id="simple_title"></div>
  508. </div>
  509. </div>
  510. <div class="form-group">
  511. <label class="col-sm-3 control-label">
  512. <b>{{ "Description" |get_lang}}</b>
  513. </label>
  514. <div class="col-sm-9">
  515. <div id="simple_content"></div>
  516. </div>
  517. </div>
  518. <div class="form-group">
  519. <label class="col-sm-3 control-label">
  520. <b>{{ "Comment" |get_lang}}</b>
  521. </label>
  522. <div class="col-sm-9">
  523. <div id="simple_comment"></div>
  524. </div>
  525. </div>
  526. </form>
  527. </div>
  528. </div>
  529. <div id="dialog-form" style="display:none;">
  530. <div class="dialog-form-content">
  531. {{ form_add }}
  532. </div>
  533. </div>
  534. <div id="loading" style="margin-left:150px;position:absolute;display:none">
  535. {{ "Loading" | get_lang }}...
  536. </div>
  537. <div id="calendar"></div>