month.tpl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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')
  15. .find('option')
  16. .removeAttr('selected')
  17. .end();
  18. }
  19. var region_value = '{{region_value}}';
  20. $(document).ready(function() {
  21. /*$("body").delegate(".datetime", "focusin", function(){
  22. $(this).datepicker({
  23. stepMinute: 10,
  24. dateFormat: 'dd/mm/yy',
  25. timeFormat: 'hh:mm:ss'
  26. });
  27. });*/
  28. var date = new Date();
  29. var d = date.getDate();
  30. var m = date.getMonth();
  31. var y = date.getFullYear();
  32. $("#dialog-form").dialog({
  33. autoOpen: false,
  34. modal : false,
  35. width : 550,
  36. height : 480,
  37. zIndex: 20000 // added because of qtip2
  38. });
  39. $("#simple-dialog-form").dialog({
  40. autoOpen: false,
  41. modal : false,
  42. width : 550,
  43. height : 480,
  44. zIndex: 20000 // added because of qtip2
  45. });
  46. var title = $( "#title" ),
  47. content = $( "#content" ),
  48. allFields = $( [] ).add( title ).add( content ), tips = $(".validateTips");
  49. $('#users_to_send_id').bind('change', function() {
  50. var selected_counts = $("#users_to_send_id option:selected").size();
  51. //alert(selected_counts);
  52. /* if (selected_counts >= 1 && $("#users_to_send_id option[value='everyone']").attr('selected') == 'selected') {
  53. clean_user_select();
  54. $('#users_to_send_id option').eq(0).attr('selected', 'selected');
  55. //deleting the everyone
  56. $("#users_to_send_id").trigger("liszt:updated");
  57. deleted_items = true;
  58. }*/
  59. $("#users_to_send_id").trigger("liszt:updated");
  60. /*
  61. if (selected_counts >= 1) {
  62. $('#users_to_send_id option').eq(0).removeAttr('selected');
  63. }
  64. */
  65. //clean_user_select();
  66. //$("#users_to_send_id").trigger("liszt:updated");
  67. //alert($("#users_to_send_id option[value='everyone']").attr('selected'));
  68. if ($("#users_to_send_id option[value='everyone']").attr('selected') == 'selected') {
  69. //clean_user_select();
  70. //$('#users_to_send_id option').eq(0).attr('selected', 'selected');
  71. //$("#users_to_send_id").trigger("liszt:updated");
  72. }
  73. });
  74. $.datepicker.setDefaults( $.datepicker.regional[region_value] );
  75. var calendar = $('#calendar').fullCalendar({
  76. header: {
  77. left: 'today prev,next',
  78. center: 'title',
  79. right: 'month,agendaWeek,agendaDay',
  80. },
  81. {% if use_google_calendar == 1 %}
  82. eventSources: [
  83. '{{google_calendar_url}}', //if you want to add more just add URL in this array
  84. {
  85. className: 'gcal-event', // an option!
  86. }
  87. ],
  88. {% endif %}
  89. buttonText: {{button_text}},
  90. monthNames: {{month_names}},
  91. monthNamesShort:{{month_names_short}},
  92. dayNames: {{day_names}},
  93. dayNamesShort: {{day_names_short}},
  94. firstHour: 8,
  95. firstDay: 1,
  96. selectable : true,
  97. selectHelper: true,
  98. viewDisplay: function(view) {
  99. /* When changing the view update the qtips */
  100. var api = $('.qtip').qtip('api'); // Access the API of the first tooltip on the page
  101. if (api) {
  102. api.destroy();
  103. //api.render();
  104. }
  105. },
  106. //add event
  107. select: function(start, end, allDay, jsEvent, view) {
  108. /* When selecting one day or several days */
  109. var start_date = Math.round(start.getTime() / 1000);
  110. var end_date = Math.round(end.getTime() / 1000);
  111. $('#visible_to_input').show();
  112. $('#add_as_announcement_div').show();
  113. $('#visible_to_read_only').hide();
  114. //Cleans the selected attr
  115. clean_user_select();
  116. //Sets the 1st item selected by default
  117. //$('#users_to_send_id option').eq(0).attr('selected', 'selected');
  118. //Update chz-select
  119. $("#users_to_send_id").trigger("liszt:updated");
  120. if ({{can_add_events}} == 1) {
  121. var url = '{{web_agenda_ajax_url}}&a=add_event&start='+start_date+'&end='+end_date+'&all_day='+allDay+'&view='+view.name;
  122. var start_date_value = $.datepicker.formatDate('{{js_format_date}}', start);
  123. var end_date_value = $.datepicker.formatDate('{{js_format_date}}', end);
  124. $('#start_date').html(start_date_value + " " + start.toTimeString().substr(0, 8));
  125. if (view.name != 'month') {
  126. $('#start_date').html(start_date_value + " " + start.toTimeString().substr(0, 8));
  127. if (start.toDateString() == end.toDateString()) {
  128. $('#end_date').html(' - '+end.toTimeString().substr(0, 8));
  129. } else {
  130. $('#end_date').html(' - '+start_date_value+" " + end.toTimeString().substr(0, 8));
  131. }
  132. } else {
  133. $('#start_date').html(start_date_value);
  134. $('#end_date').html(' ');
  135. }
  136. $('#color_calendar').html('{{type_label}}');
  137. $('#color_calendar').removeClass('group_event');
  138. $('#color_calendar').addClass('label_tag');
  139. $('#color_calendar').addClass('{{type}}_event');
  140. allFields.removeClass( "ui-state-error" );
  141. $("#dialog-form").dialog("open");
  142. $("#dialog-form").dialog({
  143. buttons: {
  144. {{"Add"|get_lang}}: function() {
  145. var bValid = true;
  146. bValid = bValid && checkLength( title, "title", 1, 255 );
  147. //bValid = bValid && checkLength( content, "content", 1, 255 );
  148. var params = $("#add_event_form").serialize();
  149. $.ajax({
  150. url: url+'&'+params,
  151. success:function(data) {
  152. calendar.fullCalendar("refetchEvents");
  153. calendar.fullCalendar("rerenderEvents");
  154. $("#dialog-form").dialog("close");
  155. }
  156. });
  157. },
  158. },
  159. close: function() {
  160. $("#title").attr('value', '');
  161. $("#content").attr('value', '');
  162. }
  163. });
  164. //prevent the browser to follow the link
  165. return false;
  166. calendar.fullCalendar('unselect');
  167. }
  168. },
  169. eventRender: function(event, element) {
  170. if (event.attachment) {
  171. element.qtip({
  172. hide: {
  173. delay: 2000
  174. },
  175. content: event.attachment,
  176. position: { at:'top right' , my:'bottom right'},
  177. }).removeData('qtip'); // this is an special hack to add multipl qtip in the same target!
  178. }
  179. if (event.description) {
  180. element.qtip({
  181. hide: {
  182. delay: 2000
  183. },
  184. content: event.description,
  185. position: { at:'top left' , my:'bottom left'},
  186. });
  187. }
  188. },
  189. eventClick: function(calEvent, jsEvent, view) {
  190. var start_date = Math.round(calEvent.start.getTime() / 1000);
  191. if (calEvent.allDay == 1) {
  192. var end_date = '';
  193. } else {
  194. var end_date = '';
  195. if (calEvent.end && calEvent.end != '') {
  196. var end_date = Math.round(calEvent.end.getTime() / 1000);
  197. }
  198. }
  199. //edit event
  200. if (calEvent.editable) {
  201. $('#visible_to_input').hide();
  202. $('#add_as_announcement_div').hide();
  203. {% if type != 'admin' %}
  204. $('#visible_to_read_only').show();
  205. $("#visible_to_read_only_users").html(calEvent.sent_to);
  206. {% endif %}
  207. $('#color_calendar').html('{{type_label}}');
  208. $('#color_calendar').addClass('label_tag');
  209. $('#color_calendar').removeClass('course_event');
  210. $('#color_calendar').removeClass('personal_event');
  211. $('#color_calendar').removeClass('group_event');
  212. $('#color_calendar').addClass(calEvent.type+'_event');
  213. $('#start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear());
  214. if (end_date != '') {
  215. $('#end_date').html(' '+calEvent.end.getDate() +"/"+ calEvent.end.getMonth() +"/"+calEvent.end.getFullYear());
  216. }
  217. $("#title").attr('value', calEvent.title);
  218. $("#content").attr('value', calEvent.description);
  219. allFields.removeClass( "ui-state-error" );
  220. $("#dialog-form").dialog("open");
  221. var url = '{{web_agenda_ajax_url}}&a=edit_event&id='+calEvent.id+'&start='+start_date+'&end='+end_date+'&all_day='+calEvent.allDay+'&view='+view.name;
  222. var delete_url = '{{web_agenda_ajax_url}}&a=delete_event&id='+calEvent.id;
  223. $("#dialog-form").dialog({
  224. buttons: {
  225. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  226. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  227. window.location.href = url;
  228. },
  229. '{{"ExportiCalPrivate"|get_lang}}': function() {
  230. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  231. window.location.href = url;
  232. },
  233. '{{"ExportiCalPublic"|get_lang}}': function() {
  234. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  235. window.location.href = url;
  236. },
  237. '{{"Edit"|get_lang}}' : function() {
  238. var bValid = true;
  239. bValid = bValid && checkLength( title, "title", 1, 255 );
  240. var params = $("#add_event_form").serialize();
  241. $.ajax({
  242. url: url+'&'+params,
  243. success:function() {
  244. calEvent.title = $("#title").val();
  245. calEvent.start = calEvent.start;
  246. calEvent.end = calEvent.end;
  247. calEvent.allDay = calEvent.allDay;
  248. calEvent.description = $("#content").val();
  249. calendar.fullCalendar('updateEvent',
  250. calEvent,
  251. true // make the event "stick"
  252. );
  253. $("#dialog-form").dialog("close");
  254. }
  255. });
  256. },
  257. '{{"Delete"|get_lang}}': function() {
  258. $.ajax({
  259. url: delete_url,
  260. success:function() {
  261. calendar.fullCalendar('removeEvents',
  262. calEvent
  263. );
  264. calendar.fullCalendar("refetchEvents");
  265. calendar.fullCalendar("rerenderEvents");
  266. $("#dialog-form").dialog( "close" );
  267. }
  268. });
  269. }
  270. },
  271. close: function() {
  272. $("#title").attr('value', '');
  273. $("#content").attr('value', '');
  274. }
  275. });
  276. } else { //simple form
  277. $('#simple_start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear());
  278. if (end_date != '') {
  279. $('#simple_start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear() +" - "+calEvent.start.toLocaleTimeString());
  280. $('#simple_end_date').html(' '+calEvent.end.getDate() +"/"+ calEvent.end.getMonth() +"/"+calEvent.end.getFullYear() +" - "+calEvent.end.toLocaleTimeString());
  281. }
  282. $("#simple_title").html(calEvent.title);
  283. $("#simple_content").html(calEvent.description);
  284. $("#simple-dialog-form").dialog("open");
  285. $("#simple-dialog-form").dialog({
  286. buttons: {
  287. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  288. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  289. window.location.href = url;
  290. },
  291. '{{"ExportiCalPrivate"|get_lang}}': function() {
  292. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  293. window.location.href = url;
  294. },
  295. '{{"ExportiCalPublic"|get_lang}}': function() {
  296. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  297. window.location.href = url;
  298. }
  299. }
  300. });
  301. }
  302. },
  303. editable: true,
  304. events: "{{web_agenda_ajax_url}}&a=get_events",
  305. eventDrop: function(event, day_delta, minute_delta, all_day, revert_func) {
  306. $.ajax({
  307. url: '{{web_agenda_ajax_url}}',
  308. data: {
  309. a:'move_event', id: event.id, day_delta: day_delta, minute_delta: minute_delta
  310. }
  311. });
  312. },
  313. eventResize: function(event, day_delta, minute_delta, revert_func) {
  314. $.ajax({
  315. url: '{{web_agenda_ajax_url}}',
  316. data: {
  317. a:'resize_event', id: event.id, day_delta: day_delta, minute_delta: minute_delta
  318. }
  319. });
  320. },
  321. axisFormat: 'HH(:mm)',
  322. timeFormat: 'HH:mm{ - HH:mm}',
  323. loading: function(bool) {
  324. if (bool) $('#loading').show();
  325. else $('#loading').hide();
  326. }
  327. });
  328. });
  329. </script>
  330. <div id="simple-dialog-form" style="display:none;">
  331. <div style="width:500px">
  332. <form name="form-simple" class="form-vertical" >
  333. <div class="control-group">
  334. <label class="control-label"><b>{{"Date"|get_lang}}</b></label>
  335. <div class="controls">
  336. <span id="simple_start_date"></span><span id="simple_end_date"></span>
  337. </div>
  338. </div>
  339. <div class="control-group">
  340. <label class="control-label"><b>{{"Title"|get_lang}}</b></label>
  341. <div class="controls">
  342. <div id="simple_title"></div>
  343. </div>
  344. </div>
  345. <div class="control-group">
  346. <label class="control-label"><b>{{"Description"|get_lang}}</b></label>
  347. <div class="controls">
  348. <div id="simple_content"></div>
  349. </div>
  350. </div>
  351. </form>
  352. </div>
  353. </div>
  354. <div id="dialog-form" style="display:none;">
  355. <div style="width:500px">
  356. <form class="form-horizontal" id="add_event_form" name="form">
  357. {% if visible_to is not null %}
  358. <div id="visible_to_input" class="control-group">
  359. <label class="control-label" for="date">{{"To"|get_lang}}</label>
  360. <div class="controls">
  361. {{visible_to}}
  362. </div>
  363. </div>
  364. {% endif %}
  365. <div id="visible_to_read_only" class="control-group" style="display:none">
  366. <label class="control-label" for="date">{{"To"|get_lang}}</label>
  367. <div class="controls">
  368. <div id="visible_to_read_only_users"></div>
  369. </div>
  370. </div>
  371. <div class="control-group">
  372. <label class="control-label" for="date">{{"Agenda"|get_lang}}</label>
  373. <div class="controls">
  374. <div id="color_calendar"></div>
  375. </div>
  376. </div>
  377. <div class="control-group">
  378. <label class="control-label" for="date">{{"Date"|get_lang}}</label>
  379. <div class="controls">
  380. <span id="start_date"></span><span id="end_date"></span>
  381. </div>
  382. </div>
  383. <div class="control-group">
  384. <label class="control-label" for="name">{{"Title"|get_lang}}</label>
  385. <div class="controls">
  386. <input type="text" name="title" id="title" size="40" />
  387. </div>
  388. </div>
  389. <div class="control-group">
  390. <label class="control-label" for="name">{{"Description"|get_lang}}</label>
  391. <div class="controls">
  392. <textarea name="content" id="content" class="span3" rows="5"></textarea>
  393. </div>
  394. </div>
  395. {% if type == 'course' %}
  396. <div id="add_as_announcement_div">
  397. <div class="control-group">
  398. <label></label>
  399. <div class="controls">
  400. <label class="checkbox inline" for="add_as_annonuncement">
  401. {{"AddAsAnnouncement"|get_lang}}
  402. <input type="checkbox" name="add_as_annonuncement" id="add_as_annonuncement" />
  403. </label>
  404. </div>
  405. </div>
  406. </div>
  407. {% endif %}
  408. </form>
  409. </div>
  410. </div>
  411. <div id="loading" style="margin-left:150px;position:absolute;display:none">{{"Loading"|get_lang}}...</div>
  412. <div id="calendar"></div>