month.tpl 20 KB

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