month.tpl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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 : 580,
  36. height : 480,
  37. zIndex: 20000 // added because of qtip2
  38. });
  39. $("#simple-dialog-form").dialog({
  40. autoOpen: false,
  41. modal : false,
  42. width : 580,
  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. //Removing UTC stuff
  109. var start_date = $.datepicker.formatDate("yy-mm-dd", start) + " " + start.toTimeString().substr(0, 8);
  110. var end_date = $.datepicker.formatDate("yy-mm-dd", end) + " " + end.toTimeString().substr(0, 8);
  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_class }}');
  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. //Don't follow the link
  165. return false;
  166. calendar.fullCalendar('unselect');
  167. //Reload events
  168. calendar.fullCalendar("refetchEvents");
  169. calendar.fullCalendar("rerenderEvents");
  170. }
  171. },
  172. eventRender: function(event, element) {
  173. if (event.attachment) {
  174. element.qtip({
  175. hide: {
  176. delay: 2000
  177. },
  178. content: event.attachment,
  179. position: { at:'top right' , my:'bottom right'},
  180. }).removeData('qtip'); // this is an special hack to add multiple qtip in the same target
  181. }
  182. if (event.description) {
  183. element.qtip({
  184. hide: {
  185. delay: 2000
  186. },
  187. content: event.description,
  188. position: { at:'top left' , my:'bottom left'},
  189. });
  190. }
  191. },
  192. eventClick: function(calEvent, jsEvent, view) {
  193. //var start_date = Math.round(calEvent.start.getTime() / 1000);
  194. var start_date = $.datepicker.formatDate("yy-mm-dd", calEvent.start) + " " + calEvent.start.toTimeString().substr(0, 8);
  195. if (calEvent.allDay == 1) {
  196. var end_date = '';
  197. } else {
  198. var end_date = '';
  199. if (calEvent.end && calEvent.end != '') {
  200. //var end_date = Math.round(calEvent.end.getTime() / 1000);
  201. var end_date = $.datepicker.formatDate("yy-mm-dd", calEvent.end) + " " + calEvent.end.toTimeString().substr(0, 8);
  202. }
  203. }
  204. //edit event
  205. if (calEvent.editable) {
  206. $('#visible_to_input').hide();
  207. $('#add_as_announcement_div').hide();
  208. {% if type != 'admin' %}
  209. $('#visible_to_read_only').show();
  210. $("#visible_to_read_only_users").html(calEvent.sent_to);
  211. {% endif %}
  212. $('#color_calendar').html('{{type_label}}');
  213. $('#color_calendar').addClass('label_tag');
  214. $('#color_calendar').removeClass('course_event');
  215. $('#color_calendar').removeClass('personal_event');
  216. $('#color_calendar').removeClass('group_event');
  217. $('#color_calendar').addClass(calEvent.type+'_event');
  218. $('#start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear());
  219. if (end_date != '') {
  220. $('#end_date').html(' '+calEvent.end.getDate() +"/"+ calEvent.end.getMonth() +"/"+calEvent.end.getFullYear());
  221. }
  222. $("#title").attr('value', calEvent.title);
  223. $("#content").attr('value', calEvent.description);
  224. allFields.removeClass( "ui-state-error" );
  225. $("#dialog-form").dialog("open");
  226. 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;
  227. var delete_url = '{{web_agenda_ajax_url}}&a=delete_event&id='+calEvent.id;
  228. $("#dialog-form").dialog({
  229. buttons: {
  230. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  231. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  232. window.location.href = url;
  233. },
  234. '{{"ExportiCalPrivate"|get_lang}}': function() {
  235. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  236. window.location.href = url;
  237. },
  238. '{{"ExportiCalPublic"|get_lang}}': function() {
  239. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  240. window.location.href = url;
  241. },
  242. '{{"Edit"|get_lang}}' : function() {
  243. var bValid = true;
  244. bValid = bValid && checkLength( title, "title", 1, 255 );
  245. var params = $("#add_event_form").serialize();
  246. $.ajax({
  247. url: url+'&'+params,
  248. success:function() {
  249. calEvent.title = $("#title").val();
  250. calEvent.start = calEvent.start;
  251. calEvent.end = calEvent.end;
  252. calEvent.allDay = calEvent.allDay;
  253. calEvent.description = $("#content").val();
  254. calendar.fullCalendar('updateEvent',
  255. calEvent,
  256. true // make the event "stick"
  257. );
  258. $("#dialog-form").dialog("close");
  259. }
  260. });
  261. },
  262. '{{"Delete"|get_lang}}': function() {
  263. $.ajax({
  264. url: delete_url,
  265. success:function() {
  266. calendar.fullCalendar('removeEvents',
  267. calEvent
  268. );
  269. calendar.fullCalendar("refetchEvents");
  270. calendar.fullCalendar("rerenderEvents");
  271. $("#dialog-form").dialog( "close" );
  272. }
  273. });
  274. }
  275. },
  276. close: function() {
  277. $("#title").attr('value', '');
  278. $("#content").attr('value', '');
  279. }
  280. });
  281. } else { //simple form
  282. $('#simple_start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear());
  283. if (end_date != '') {
  284. $('#simple_start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear() +" - "+calEvent.start.toLocaleTimeString());
  285. $('#simple_end_date').html(' '+calEvent.end.getDate() +"/"+ calEvent.end.getMonth() +"/"+calEvent.end.getFullYear() +" - "+calEvent.end.toLocaleTimeString());
  286. }
  287. $("#simple_title").html(calEvent.title);
  288. $("#simple_content").html(calEvent.description);
  289. $("#simple-dialog-form").dialog("open");
  290. $("#simple-dialog-form").dialog({
  291. buttons: {
  292. '{{"ExportiCalConfidential"|get_lang}}' : function() {
  293. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
  294. window.location.href = url;
  295. },
  296. '{{"ExportiCalPrivate"|get_lang}}': function() {
  297. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
  298. window.location.href = url;
  299. },
  300. '{{"ExportiCalPublic"|get_lang}}': function() {
  301. url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=public";
  302. window.location.href = url;
  303. }
  304. }
  305. });
  306. }
  307. },
  308. editable: true,
  309. events: "{{web_agenda_ajax_url}}&a=get_events",
  310. eventDrop: function(event, day_delta, minute_delta, all_day, revert_func) {
  311. $.ajax({
  312. url: '{{web_agenda_ajax_url}}',
  313. data: {
  314. a:'move_event', id: event.id, day_delta: day_delta, minute_delta: minute_delta
  315. }
  316. });
  317. },
  318. eventResize: function(event, day_delta, minute_delta, revert_func) {
  319. $.ajax({
  320. url: '{{web_agenda_ajax_url}}',
  321. data: {
  322. a:'resize_event', id: event.id, day_delta: day_delta, minute_delta: minute_delta
  323. }
  324. });
  325. },
  326. axisFormat: 'HH(:mm)',
  327. timeFormat: 'HH:mm{ - HH:mm}',
  328. loading: function(bool) {
  329. if (bool) $('#loading').show();
  330. else $('#loading').hide();
  331. }
  332. });
  333. });
  334. </script>
  335. <div id="simple-dialog-form" style="display:none;">
  336. <div style="width:500px">
  337. <form name="form-simple" class="form-vertical" >
  338. <div class="control-group">
  339. <label class="control-label"><b>{{"Date"|get_lang}}</b></label>
  340. <div class="controls">
  341. <span id="simple_start_date"></span><span id="simple_end_date"></span>
  342. </div>
  343. </div>
  344. <div class="control-group">
  345. <label class="control-label"><b>{{"Title"|get_lang}}</b></label>
  346. <div class="controls">
  347. <div id="simple_title"></div>
  348. </div>
  349. </div>
  350. <div class="control-group">
  351. <label class="control-label"><b>{{"Description"|get_lang}}</b></label>
  352. <div class="controls">
  353. <div id="simple_content"></div>
  354. </div>
  355. </div>
  356. </form>
  357. </div>
  358. </div>
  359. <div id="dialog-form" style="display:none;">
  360. <div style="width:500px">
  361. <form class="form-horizontal" id="add_event_form" name="form">
  362. {% if visible_to is not null %}
  363. <div id="visible_to_input" class="control-group">
  364. <label class="control-label" for="date">{{"To"|get_lang}}</label>
  365. <div class="controls">
  366. {{visible_to}}
  367. </div>
  368. </div>
  369. {% endif %}
  370. <div id="visible_to_read_only" class="control-group" style="display:none">
  371. <label class="control-label" for="date">{{"To"|get_lang}}</label>
  372. <div class="controls">
  373. <div id="visible_to_read_only_users"></div>
  374. </div>
  375. </div>
  376. <div class="control-group">
  377. <label class="control-label" for="date">{{"Agenda"|get_lang}}</label>
  378. <div class="controls">
  379. <div id="color_calendar"></div>
  380. </div>
  381. </div>
  382. <div class="control-group">
  383. <label class="control-label" for="date">{{"Date"|get_lang}}</label>
  384. <div class="controls">
  385. <span id="start_date"></span><span id="end_date"></span>
  386. </div>
  387. </div>
  388. <div class="control-group">
  389. <label class="control-label" for="name">{{"Title"|get_lang}}</label>
  390. <div class="controls">
  391. <input type="text" name="title" id="title" size="40" />
  392. </div>
  393. </div>
  394. <div class="control-group">
  395. <label class="control-label" for="name">{{"Description"|get_lang}}</label>
  396. <div class="controls">
  397. <textarea name="content" id="content" class="span3" rows="5"></textarea>
  398. </div>
  399. </div>
  400. {% if type == 'course' %}
  401. <div id="add_as_announcement_div">
  402. <div class="control-group">
  403. <label></label>
  404. <div class="controls">
  405. <label class="checkbox inline" for="add_as_annonuncement">
  406. {{ "AddAsAnnouncement"|get_lang }} ({{ "SendEmail" | get_lang }})
  407. <input type="checkbox" name="add_as_annonuncement" id="add_as_annonuncement" />
  408. </label>
  409. </div>
  410. </div>
  411. </div>
  412. {% endif %}
  413. </form>
  414. </div>
  415. </div>
  416. <div id="loading" style="margin-left:150px;position:absolute;display:none">{{"Loading"|get_lang}}...</div>
  417. <div id="calendar"></div>