month.tpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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_id").val('').trigger("chosen:updated");
  15. /*$('#users_to_send_id')
  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_id option').eq(0).attr('selected', 'selected');
  105. // Update chz-select
  106. //$("#users_to_send_id").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. //This For make the CKEDITOR 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_id').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. // Don't follow the link.
  188. return false;
  189. calendar.fullCalendar('unselect');
  190. //Reload events
  191. calendar.fullCalendar("refetchEvents");
  192. calendar.fullCalendar("rerenderEvents");
  193. }
  194. },
  195. eventRender: function(event, element) {
  196. if (event.attachment) {
  197. /*element.qtip({
  198. hide: {
  199. delay: 2000
  200. },
  201. content: event.attachment,
  202. position: { at:'top right' , my:'bottom right'}
  203. }).removeData('qtip'); // this is an special hack to add multiple qtip in the same target
  204. */
  205. }
  206. if (event.description) {
  207. var comment = '';
  208. if (event.comment) {
  209. comment = event.comment;
  210. }
  211. /*element.qtip({
  212. hide: {
  213. delay: 2000
  214. },
  215. content: event.description + ' ' + comment,
  216. position: { at:'top left' , my:'bottom left'}
  217. });*/
  218. }
  219. },
  220. eventClick: function(calEvent, jsEvent, view) {
  221. var start_date = calEvent.start.format("YY-MM-DD");
  222. if (calEvent.allDay == 1) {
  223. var end_date = '';
  224. } else {
  225. var end_date = '';
  226. if (calEvent.end && calEvent.end != '') {
  227. var end_date = calEvent.end.format("YY-MM-DD");
  228. }
  229. }
  230. // Edit event.
  231. if (calEvent.editable) {
  232. $('#visible_to_input').hide();
  233. $('#add_as_announcement_div').hide();
  234. {% if type != 'admin' %}
  235. $('#visible_to_read_only').show();
  236. $("#visible_to_read_only_users").html(calEvent.sent_to);
  237. {% endif %}
  238. $('#color_calendar').html('{{type_label}}');
  239. $('#color_calendar').addClass('label_tag');
  240. $('#color_calendar').removeClass('course_event');
  241. $('#color_calendar').removeClass('personal_event');
  242. $('#color_calendar').removeClass('group_event');
  243. $('#color_calendar').addClass(calEvent.type+'_event');
  244. //It hides the CKEDITOR while clicking an existing Event
  245. $('#cke_content').hide();
  246. $('#start_date').html(calEvent.start.format("YY-MM-DD"));
  247. if (calEvent.end) {
  248. $('#end_date').html(' - '+calEvent.end.format("YY-MM-DD"));
  249. }
  250. if ($("#title").parent().find('#title_edit').length == 0) {
  251. $("#title").parent().append('<div id="title_edit"></div>');
  252. }
  253. $("#title_edit").html(calEvent.title);
  254. if ($("#content").parent().find('#content_edit').length == 0) {
  255. $("#content").parent().append('<div id="content_edit"></div>');
  256. }
  257. $("#content_edit").html(calEvent.description);
  258. if ($("#comment").parent().find('#comment_edit').length == 0) {
  259. $("#comment").parent().append('<div id="comment_edit"></div>');
  260. }
  261. if (calEvent.course_name) {
  262. $("#calendar_course_info").html(
  263. '<div class="form-group"><label class="col-sm-2 control-label">{{ 'Course' | get_lang }}</label>' +
  264. '<div class="class="col-sm-8">' + calEvent.course_name+"</div></div>"
  265. );
  266. } else {
  267. $("#calendar_course_info").html('');
  268. }
  269. if (calEvent.session_name) {
  270. $("#calendar_session_info").html(
  271. '<div class="form-group"><label class="col-sm-2 control-label">{{ 'Session' | get_lang }}</label>'+
  272. '<div class="class="col-sm-8">' + calEvent.session_name+"</div></div>"
  273. );
  274. } else {
  275. $("#calendar_session_info").html('');
  276. }
  277. $("#comment_edit").html(calEvent.comment);
  278. $("#title_edit").show();
  279. $("#content_edit").show();
  280. $("#comment_edit").show();
  281. $("#title").hide();
  282. $("#content").hide();
  283. $("#comment").hide();
  284. allFields.removeClass( "ui-state-error" );
  285. $("#dialog-form").dialog("open");
  286. 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;
  287. var delete_url = '{{ web_agenda_ajax_url }}&a=delete_event&id='+calEvent.id;
  288. $("#dialog-form").dialog({
  289. buttons: {
  290. '{{ "ExportiCalConfidential"|get_lang }}' : function() {
  291. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  292. window.location.href = url;
  293. },
  294. '{{ "ExportiCalPrivate"|get_lang }}': function() {
  295. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  296. window.location.href = url;
  297. },
  298. '{{ "ExportiCalPublic"|get_lang }}': function() {
  299. url = "{{ _p.web_main }}calendar/ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  300. window.location.href = url;
  301. },
  302. {% if type == 'not_available' %}
  303. '{{ "Edit" | get_lang }}' : function() {
  304. var bValid = true;
  305. bValid = bValid && checkLength( title, "title", 1, 255 );
  306. var params = $("#add_event_form").serialize();
  307. $.ajax({
  308. url: url+'&'+params,
  309. success:function() {
  310. calEvent.title = $("#title").val();
  311. calEvent.start = calEvent.start;
  312. calEvent.end = calEvent.end;
  313. calEvent.allDay = calEvent.allDay;
  314. calEvent.description = $("#content").val();
  315. calendar.fullCalendar('updateEvent',
  316. calEvent,
  317. true // make the event "stick"
  318. );
  319. $("#dialog-form").dialog("close");
  320. }
  321. });
  322. },
  323. {% endif %}
  324. '{{ "Edit"|get_lang }}' : function() {
  325. url = "{{ _p.web_main }}calendar/agenda.php?action=edit&type=fromjs&id=" + calEvent.id+'&course_id='+calEvent.course_id+"";
  326. window.location.href = url;
  327. $("#dialog-form").dialog( "close" );
  328. },
  329. '{{ "Delete"|get_lang }}': function() {
  330. if (calEvent.parent_event_id || calEvent.has_children != '') {
  331. var newDiv = $(document.createElement('div'));
  332. newDiv.dialog({
  333. modal: true,
  334. title: "{{ 'Confirmation' | get_lang }}"
  335. });
  336. var buttons = newDiv.dialog("option", "buttons");
  337. if (calEvent.has_children == '0') {
  338. $.extend(buttons, {
  339. '{{ "DeleteThisItem" | get_lang }}' : function() {
  340. $.ajax({
  341. url: delete_url,
  342. success:function() {
  343. calendar.fullCalendar('removeEvents',
  344. calEvent
  345. );
  346. calendar.fullCalendar("refetchEvents");
  347. calendar.fullCalendar("rerenderEvents");
  348. $("#dialog-form").dialog("close");
  349. newDiv.dialog( "close" );
  350. }
  351. });
  352. }
  353. });
  354. newDiv.dialog("option", "buttons", buttons);
  355. }
  356. var buttons = newDiv.dialog("option", "buttons");
  357. $.extend(buttons, {
  358. '{{ "DeleteAllItems" | get_lang }}' : function() {
  359. $.ajax({
  360. url: delete_url+'&delete_all_events=1',
  361. success:function() {
  362. calendar.fullCalendar('removeEvents',
  363. calEvent
  364. );
  365. calendar.fullCalendar("refetchEvents");
  366. calendar.fullCalendar("rerenderEvents");
  367. $("#dialog-form").dialog( "close" );
  368. newDiv.dialog( "close" );
  369. }
  370. });
  371. }
  372. });
  373. newDiv.dialog("option", "buttons", buttons);
  374. return true;
  375. }
  376. $.ajax({
  377. url: delete_url,
  378. success:function() {
  379. calendar.fullCalendar('removeEvents',
  380. calEvent
  381. );
  382. calendar.fullCalendar("refetchEvents");
  383. calendar.fullCalendar("rerenderEvents");
  384. $("#dialog-form").dialog( "close" );
  385. }
  386. });
  387. }
  388. },
  389. close: function() {
  390. $("#title_edit").hide();
  391. $("#content_edit").hide();
  392. $("#comment_edit").hide();
  393. $("#title").show();
  394. $("#content").show();
  395. $("#comment").show();
  396. $("#title_edit").html('');
  397. $("#content_edit").html('');
  398. $("#comment_edit").html('');
  399. $("#title").val('');
  400. $("#content").val('');
  401. $("#comment").val('');
  402. }
  403. });
  404. } else {
  405. // Simple form
  406. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  407. if (end_date != '') {
  408. $('#simple_start_date').html(calEvent.start.format("YY-MM-DD"));
  409. $('#simple_end_date').html(' ' + calEvent.end.format("YY-MM-DD"));
  410. }
  411. if (calEvent.course_name) {
  412. $("#calendar_course_info_simple").html(
  413. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Course' | get_lang }}</label>' +
  414. '<div class="col-sm-9">' + calEvent.course_name+"</div></div>"
  415. );
  416. } else {
  417. $("#calendar_course_info_simple").html('');
  418. }
  419. if (calEvent.session_name) {
  420. $("#calendar_session_info").html(
  421. '<div class="form-group"><label class="col-sm-3 control-label">{{ 'Session' | get_lang }}</label>' +
  422. '<div class="col-sm-9">' + calEvent.session_name+"</div></div>"
  423. );
  424. } else {
  425. $("#calendar_session_info").html('');
  426. }
  427. $("#simple_title").html(calEvent.title);
  428. $("#simple_content").html(calEvent.description);
  429. $("#simple_comment").html(calEvent.comment);
  430. $("#simple-dialog-form").dialog("open");
  431. $("#simple-dialog-form").dialog({
  432. buttons: {
  433. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  434. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  435. window.location.href = url;
  436. },
  437. '{{"ExportiCalPrivate"|get_lang}}': function() {
  438. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  439. window.location.href = url;
  440. },
  441. '{{"ExportiCalPublic"|get_lang}}': function() {
  442. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  443. window.location.href = url;
  444. }
  445. }
  446. });
  447. }
  448. },
  449. editable: true,
  450. events: "{{web_agenda_ajax_url}}&a=get_events",
  451. eventDrop: function(event, delta, revert_func) {
  452. $.ajax({
  453. url: '{{ web_agenda_ajax_url }}',
  454. data: {
  455. a: 'move_event',
  456. id: event.id,
  457. day_delta: delta.days(),
  458. minute_delta: delta.minutes()
  459. }
  460. });
  461. },
  462. eventResize: function(event, delta, revert_func) {
  463. $.ajax({
  464. url: '{{ web_agenda_ajax_url }}',
  465. data: {
  466. a: 'resize_event',
  467. id: event.id,
  468. day_delta: delta.days(),
  469. minute_delta: delta.minutes()
  470. }
  471. });
  472. },
  473. axisFormat: 'h(:mm)a',
  474. timeFormat: 'h:mm',
  475. loading: function(bool) {
  476. if (bool) $('#loading').show();
  477. else $('#loading').hide();
  478. }
  479. });
  480. });
  481. </script>
  482. {{ actions_div }}
  483. <div id="simple-dialog-form" style="display:none;">
  484. <div style="width:500px">
  485. <form name="form-simple" class="form-horizontal">
  486. <span id="calendar_course_info_simple"></span>
  487. <span id="calendar_session_info"></span>
  488. <div class="form-group">
  489. <label class="col-sm-3 control-label">
  490. <b>{{ "Date" |get_lang}}</b>
  491. </label>
  492. <div class="col-sm-9">
  493. <span id="simple_start_date"></span>
  494. <span id="simple_end_date"></span>
  495. </div>
  496. </div>
  497. <div class="form-group">
  498. <label class="col-sm-3 control-label">
  499. <b>{{ "Title" |get_lang}}</b>
  500. </label>
  501. <div class="col-sm-9">
  502. <div id="simple_title"></div>
  503. </div>
  504. </div>
  505. <div class="form-group">
  506. <label class="col-sm-3 control-label">
  507. <b>{{ "Description" |get_lang}}</b>
  508. </label>
  509. <div class="col-sm-9">
  510. <div id="simple_content"></div>
  511. </div>
  512. </div>
  513. <div class="form-group">
  514. <label class="col-sm-3 control-label">
  515. <b>{{ "Comment" |get_lang}}</b>
  516. </label>
  517. <div class="col-sm-9">
  518. <div id="simple_comment"></div>
  519. </div>
  520. </div>
  521. </form>
  522. </div>
  523. </div>
  524. <div id="dialog-form" style="display:none;">
  525. <div class="dialog-form-content">
  526. {{ form_add }}
  527. </div>
  528. </div>
  529. <div id="loading" style="margin-left:150px;position:absolute;display:none">
  530. {{ "Loading" | get_lang }}...
  531. </div>
  532. <div id="calendar"></div>