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 = $(document.createElement('div'));
  333. newDiv.dialog({
  334. modal: true,
  335. title: "{{ 'DeleteThisItem' | get_lang }}"
  336. });
  337. var buttons = newDiv.dialog("option", "buttons");
  338. if (calEvent.has_children == '0') {
  339. buttons.push({
  340. text: '{{ "DeleteThisItem" | get_lang }}',
  341. click: function() {
  342. $.ajax({
  343. url: delete_url,
  344. success:function() {
  345. calendar.fullCalendar('removeEvents',
  346. calEvent
  347. );
  348. calendar.fullCalendar("refetchEvents");
  349. calendar.fullCalendar("rerenderEvents");
  350. $("#dialog-form").dialog("close");
  351. newDiv.dialog( "close" );
  352. }
  353. });
  354. }
  355. });
  356. newDiv.dialog("option", "buttons", buttons);
  357. }
  358. var buttons = newDiv.dialog("option", "buttons");
  359. buttons.push({
  360. text: '{{ "DeleteAllItems" | get_lang }}',
  361. click: function() {
  362. $.ajax({
  363. url: delete_url+'&delete_all_events=1',
  364. success:function() {
  365. calendar.fullCalendar('removeEvents',
  366. calEvent
  367. );
  368. calendar.fullCalendar("refetchEvents");
  369. calendar.fullCalendar("rerenderEvents");
  370. $("#dialog-form").dialog( "close" );
  371. newDiv.dialog( "close" );
  372. }
  373. });
  374. }
  375. });
  376. newDiv.dialog("option", "buttons", buttons);
  377. return true;
  378. }
  379. $.ajax({
  380. url: delete_url,
  381. success:function() {
  382. calendar.fullCalendar('removeEvents',
  383. calEvent
  384. );
  385. calendar.fullCalendar("refetchEvents");
  386. calendar.fullCalendar("rerenderEvents");
  387. $("#dialog-form").dialog( "close" );
  388. }
  389. });
  390. }
  391. },
  392. close: function() {
  393. $("#title_edit").hide();
  394. $("#content_edit").hide();
  395. $("#comment_edit").hide();
  396. $("#title").show();
  397. $("#content").show();
  398. $("#comment").show();
  399. $("#title_edit").html('');
  400. $("#content_edit").html('');
  401. $("#comment_edit").html('');
  402. $("#title").val('');
  403. $("#content").val('');
  404. $("#comment").val('');
  405. }
  406. });
  407. } else {
  408. // Simple form
  409. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  410. if (end_date != '') {
  411. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  412. $('#simple_end_date').html(' ' + calEvent.end.format("YY-MM-DD"));
  413. }
  414. if (calEvent.course_name) {
  415. $("#calendar_course_info_simple").html(
  416. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Course' | get_lang }}</label>' +
  417. '<div class="col-sm-9">' + calEvent.course_name+"</div></div>"
  418. );
  419. } else {
  420. $("#calendar_course_info_simple").html('');
  421. }
  422. if (calEvent.session_name) {
  423. $("#calendar_session_info").html(
  424. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Session' | get_lang }}</label>' +
  425. '<div class="col-sm-9">' + calEvent.session_name+"</div></div>"
  426. );
  427. } else {
  428. $("#calendar_session_info").html('');
  429. }
  430. $("#simple_title").html(calEvent.title);
  431. $("#simple_content").html(calEvent.description);
  432. $("#simple_comment").html(calEvent.comment);
  433. $("#simple-dialog-form").dialog("open");
  434. $("#simple-dialog-form").dialog({
  435. buttons: {
  436. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  437. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  438. window.location.href = url;
  439. },
  440. '{{"ExportiCalPrivate"|get_lang}}': function() {
  441. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  442. window.location.href = url;
  443. },
  444. '{{"ExportiCalPublic"|get_lang}}': function() {
  445. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  446. window.location.href = url;
  447. }
  448. }
  449. });
  450. }
  451. },
  452. editable: true,
  453. events: "{{web_agenda_ajax_url}}&a=get_events",
  454. eventDrop: function(event, delta, revert_func) {
  455. $.ajax({
  456. url: '{{ web_agenda_ajax_url }}',
  457. data: {
  458. a: 'move_event',
  459. id: event.id,
  460. day_delta: delta.days(),
  461. minute_delta: delta.minutes()
  462. }
  463. });
  464. },
  465. eventResize: function(event, delta, revert_func) {
  466. $.ajax({
  467. url: '{{ web_agenda_ajax_url }}',
  468. data: {
  469. a: 'resize_event',
  470. id: event.id,
  471. day_delta: delta.days(),
  472. minute_delta: delta.minutes()
  473. }
  474. });
  475. },
  476. axisFormat: 'h(:mm)a',
  477. timeFormat: 'h:mm',
  478. loading: function(bool) {
  479. if (bool) $('#loading').show();
  480. else $('#loading').hide();
  481. }
  482. });
  483. });
  484. </script>
  485. {{ actions_div }}
  486. {{ toolbar }}
  487. <div id="simple-dialog-form" style="display:none;">
  488. <div style="width:500px">
  489. <form name="form-simple" class="form-horizontal">
  490. <span id="calendar_course_info_simple"></span>
  491. <span id="calendar_session_info"></span>
  492. <div class="form-group">
  493. <label class="col-sm-3 control-label">
  494. <b>{{ "Date" |get_lang}}</b>
  495. </label>
  496. <div class="col-sm-9">
  497. <span id="simple_start_date"></span>
  498. <span id="simple_end_date"></span>
  499. </div>
  500. </div>
  501. <div class="form-group">
  502. <label class="col-sm-3 control-label">
  503. <b>{{ "Title" |get_lang}}</b>
  504. </label>
  505. <div class="col-sm-9">
  506. <div id="simple_title"></div>
  507. </div>
  508. </div>
  509. <div class="form-group">
  510. <label class="col-sm-3 control-label">
  511. <b>{{ "Description" |get_lang}}</b>
  512. </label>
  513. <div class="col-sm-9">
  514. <div id="simple_content"></div>
  515. </div>
  516. </div>
  517. <div class="form-group">
  518. <label class="col-sm-3 control-label">
  519. <b>{{ "Comment" |get_lang}}</b>
  520. </label>
  521. <div class="col-sm-9">
  522. <div id="simple_comment"></div>
  523. </div>
  524. </div>
  525. </form>
  526. </div>
  527. </div>
  528. <div id="dialog-form" style="display:none;">
  529. <div class="dialog-form-content">
  530. {{ form_add }}
  531. </div>
  532. </div>
  533. <div id="loading" style="margin-left:150px;position:absolute;display:none">
  534. {{ "Loading" | get_lang }}...
  535. </div>
  536. <div id="calendar"></div>