calendar.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. /**
  2. * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
  3. * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. Calendar={
  9. UI:{
  10. loading: function(isLoading){
  11. if (isLoading){
  12. $('#loading').show();
  13. }else{
  14. $('#loading').hide();
  15. }
  16. },
  17. startEventDialog:function(){
  18. Calendar.UI.loading(false);
  19. $('.tipsy').remove();
  20. $('#calendar_holder').fullCalendar('unselect');
  21. Calendar.UI.lockTime();
  22. $( "#from" ).datepicker({
  23. dateFormat : 'dd-mm-yy'
  24. });
  25. $( "#to" ).datepicker({
  26. dateFormat : 'dd-mm-yy'
  27. });
  28. $('#fromtime').timepicker({
  29. showPeriodLabels: false
  30. });
  31. $('#totime').timepicker({
  32. showPeriodLabels: false
  33. });
  34. $('#category').multiple_autocomplete({source: categories});
  35. Calendar.UI.repeat('init');
  36. $('#end').change(function(){
  37. Calendar.UI.repeat('end');
  38. });
  39. $('#repeat').change(function(){
  40. Calendar.UI.repeat('repeat');
  41. });
  42. $('#advanced_year').change(function(){
  43. Calendar.UI.repeat('year');
  44. });
  45. $('#advanced_month').change(function(){
  46. Calendar.UI.repeat('month');
  47. });
  48. $( "#event" ).tabs({ selected: 0});
  49. $('#event').dialog({
  50. width : 500,
  51. height: 600,
  52. close : function(event, ui) {
  53. $(this).dialog('destroy').remove();
  54. }
  55. });
  56. },
  57. newEvent:function(start, end, allday){
  58. start = Math.round(start.getTime()/1000);
  59. if (end){
  60. end = Math.round(end.getTime()/1000);
  61. }
  62. if($('#event').dialog('isOpen') == true){
  63. // TODO: save event
  64. $('#event').dialog('destroy').remove();
  65. }else{
  66. Calendar.UI.loading(true);
  67. $('#dialog_holder').load(OC.filePath('calendar', 'ajax/event', 'new.form.php'), {start:start, end:end, allday:allday?1:0}, Calendar.UI.startEventDialog);
  68. }
  69. },
  70. editEvent:function(calEvent, jsEvent, view){
  71. if (calEvent.editable == false || calEvent.source.editable == false) {
  72. return;
  73. }
  74. var id = calEvent.id;
  75. if($('#event').dialog('isOpen') == true){
  76. // TODO: save event
  77. $('#event').dialog('destroy').remove();
  78. }else{
  79. Calendar.UI.loading(true);
  80. $('#dialog_holder').load(OC.filePath('calendar', 'ajax/event', 'edit.form.php'), {id: id}, Calendar.UI.startEventDialog);
  81. }
  82. },
  83. submitDeleteEventForm:function(url){
  84. var post = $( '#event_form' ).serialize();
  85. $('#errorbox').empty();
  86. Calendar.UI.loading(true);
  87. $.post(url, post, function(data){
  88. Calendar.UI.loading(false);
  89. if(data.status == 'success'){
  90. $('#calendar_holder').fullCalendar('removeEvents', $('#event_form input[name=id]').val());
  91. $('#event').dialog('destroy').remove();
  92. } else {
  93. $('#errorbox').html(t('calendar', 'Deletion failed'));
  94. }
  95. }, "json");
  96. },
  97. validateEventForm:function(url){
  98. var post = $( "#event_form" ).serialize();
  99. $("#errorbox").empty();
  100. Calendar.UI.loading(true);
  101. $.post(url, post,
  102. function(data){
  103. Calendar.UI.loading(false);
  104. if(data.status == "error"){
  105. var output = missing_field + ": <br />";
  106. if(data.title == "true"){
  107. output = output + missing_field_title + "<br />";
  108. }
  109. if(data.cal == "true"){
  110. output = output + missing_field_calendar + "<br />";
  111. }
  112. if(data.from == "true"){
  113. output = output + missing_field_fromdate + "<br />";
  114. }
  115. if(data.fromtime == "true"){
  116. output = output + missing_field_fromtime + "<br />";
  117. }
  118. if(data.to == "true"){
  119. output = output + missing_field_todate + "<br />";
  120. }
  121. if(data.totime == "true"){
  122. output = output + missing_field_totime + "<br />";
  123. }
  124. if(data.endbeforestart == "true"){
  125. output = output + missing_field_startsbeforeends + "!<br/>";
  126. }
  127. if(data.dberror == "true"){
  128. output = "There was a database fail!";
  129. }
  130. $("#errorbox").html(output);
  131. } else
  132. if(data.status == 'success'){
  133. $('#event').dialog('destroy').remove();
  134. $('#calendar_holder').fullCalendar('refetchEvents');
  135. }
  136. },"json");
  137. },
  138. moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){
  139. $('.tipsy').remove();
  140. Calendar.UI.loading(true);
  141. $.post(OC.filePath('calendar', 'ajax/event', 'move.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified},
  142. function(data) {
  143. Calendar.UI.loading(false);
  144. if (data.status == 'success'){
  145. event.lastmodified = data.lastmodified;
  146. console.log("Event moved successfully");
  147. }else{
  148. revertFunc();
  149. $('#calendar_holder').fullCalendar('refetchEvents');
  150. }
  151. });
  152. },
  153. resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){
  154. $('.tipsy').remove();
  155. Calendar.UI.loading(true);
  156. $.post(OC.filePath('calendar', 'ajax/event', 'resize.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified},
  157. function(data) {
  158. Calendar.UI.loading(false);
  159. if (data.status == 'success'){
  160. event.lastmodified = data.lastmodified;
  161. console.log("Event resized successfully");
  162. }else{
  163. revertFunc();
  164. $('#calendar_holder').fullCalendar('refetchEvents');
  165. }
  166. });
  167. },
  168. showadvancedoptions:function(){
  169. $("#advanced_options").slideDown('slow');
  170. $("#advanced_options_button").css("display", "none");
  171. },
  172. showadvancedoptionsforrepeating:function(){
  173. if($("#advanced_options_repeating").is(":hidden")){
  174. $('#advanced_options_repeating').slideDown('slow');
  175. }else{
  176. $('#advanced_options_repeating').slideUp('slow');
  177. }
  178. },
  179. getEventPopupText:function(event){
  180. if (event.allDay){
  181. var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}")
  182. }else{
  183. var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy] ' + defaulttime + '{ -[ ddd d MMMM yyyy]' + defaulttime + '}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy] HH:mm{ -[ ddd d MMMM yyyy] HH:mm}")
  184. // Tue 18 October 2011 08:00 - 16:00
  185. }
  186. var html =
  187. '<div class="summary">' + event.title + '</div>' +
  188. '<div class="timespan">' + timespan + '</div>';
  189. if (event.description){
  190. html += '<div class="description">' + event.description + '</div>';
  191. }
  192. return html;
  193. },
  194. lockTime:function(){
  195. if($('#allday_checkbox').is(':checked')) {
  196. $("#fromtime").attr('disabled', true)
  197. .addClass('disabled');
  198. $("#totime").attr('disabled', true)
  199. .addClass('disabled');
  200. } else {
  201. $("#fromtime").attr('disabled', false)
  202. .removeClass('disabled');
  203. $("#totime").attr('disabled', false)
  204. .removeClass('disabled');
  205. }
  206. },
  207. showCalDAVUrl:function(username, calname){
  208. $('#caldav_url').val(totalurl + '/' + username + '/' + calname);
  209. $('#caldav_url').val(encodeURI($('#caldav_url').val()));
  210. $('#caldav_url').show();
  211. $("#caldav_url_close").show();
  212. },
  213. initScroll:function(){
  214. if(window.addEventListener)
  215. document.addEventListener('DOMMouseScroll', Calendar.UI.scrollCalendar, false);
  216. //}else{
  217. document.onmousewheel = Calendar.UI.scrollCalendar;
  218. //}
  219. },
  220. scrollCalendar:function(event){
  221. $('.tipsy').remove();
  222. var direction;
  223. if(event.detail){
  224. if(event.detail < 0){
  225. direction = 'top';
  226. }else{
  227. direction = 'down';
  228. }
  229. }
  230. if (event.wheelDelta){
  231. if(event.wheelDelta > 0){
  232. direction = 'top';
  233. }else{
  234. direction = 'down';
  235. }
  236. }
  237. var scroll = $(document).scrollTop(),
  238. doc_height = $(document).height(),
  239. win_height = $(window).height();
  240. if(direction == 'down' && win_height == (doc_height - scroll)){
  241. $('#calendar_holder').fullCalendar('next');
  242. $(document).scrollTop(0);
  243. event.preventDefault();
  244. }else if (direction == 'top' && scroll == 0) {
  245. $('#calendar_holder').fullCalendar('prev');
  246. $(document).scrollTop(win_height);
  247. event.preventDefault();
  248. }
  249. },
  250. repeat:function(task){
  251. if(task=='init'){
  252. $('#byweekno').multiselect({
  253. header: false,
  254. noneSelectedText: $('#advanced_byweekno').attr('title'),
  255. selectedList: 2,
  256. minWidth:'auto'
  257. });
  258. $('#weeklyoptions').multiselect({
  259. header: false,
  260. noneSelectedText: $('#weeklyoptions').attr('title'),
  261. selectedList: 2,
  262. minWidth:'auto'
  263. });
  264. $('input[name="bydate"]').datepicker({
  265. dateFormat : 'dd-mm-yy'
  266. });
  267. $('#byyearday').multiselect({
  268. header: false,
  269. noneSelectedText: $('#byyearday').attr('title'),
  270. selectedList: 2,
  271. minWidth:'auto'
  272. });
  273. $('#bymonth').multiselect({
  274. header: false,
  275. noneSelectedText: $('#bymonth').attr('title'),
  276. selectedList: 2,
  277. minWidth:'auto'
  278. });
  279. $('#bymonthday').multiselect({
  280. header: false,
  281. noneSelectedText: $('#bymonthday').attr('title'),
  282. selectedList: 2,
  283. minWidth:'auto'
  284. });
  285. Calendar.UI.repeat('end');
  286. Calendar.UI.repeat('month');
  287. Calendar.UI.repeat('year');
  288. Calendar.UI.repeat('repeat');
  289. }
  290. if(task == 'end'){
  291. $('#byoccurrences').css('display', 'none');
  292. $('#bydate').css('display', 'none');
  293. if($('#end option:selected').val() == 'count'){
  294. $('#byoccurrences').css('display', 'block');
  295. }
  296. if($('#end option:selected').val() == 'date'){
  297. $('#bydate').css('display', 'block');
  298. }
  299. }
  300. if(task == 'repeat'){
  301. $('#advanced_month').css('display', 'none');
  302. $('#advanced_weekday').css('display', 'none');
  303. $('#advanced_weekofmonth').css('display', 'none');
  304. $('#advanced_byyearday').css('display', 'none');
  305. $('#advanced_bymonth').css('display', 'none');
  306. $('#advanced_byweekno').css('display', 'none');
  307. $('#advanced_year').css('display', 'none');
  308. $('#advanced_bymonthday').css('display', 'none');
  309. if($('#repeat option:selected').val() == 'monthly'){
  310. $('#advanced_month').css('display', 'block');
  311. Calendar.UI.repeat('month');
  312. }
  313. if($('#repeat option:selected').val() == 'weekly'){
  314. $('#advanced_weekday').css('display', 'block');
  315. }
  316. if($('#repeat option:selected').val() == 'yearly'){
  317. $('#advanced_year').css('display', 'block');
  318. Calendar.UI.repeat('year');
  319. }
  320. if($('#repeat option:selected').val() == 'doesnotrepeat'){
  321. $('#advanced_options_repeating').slideUp('slow');
  322. }
  323. }
  324. if(task == 'month'){
  325. $('#advanced_weekday').css('display', 'none');
  326. $('#advanced_weekofmonth').css('display', 'none');
  327. if($('#advanced_month_select option:selected').val() == 'weekday'){
  328. $('#advanced_weekday').css('display', 'block');
  329. $('#advanced_weekofmonth').css('display', 'block');
  330. }
  331. }
  332. if(task == 'year'){
  333. $('#advanced_weekday').css('display', 'none');
  334. $('#advanced_byyearday').css('display', 'none');
  335. $('#advanced_bymonth').css('display', 'none');
  336. $('#advanced_byweekno').css('display', 'none');
  337. $('#advanced_bymonthday').css('display', 'none');
  338. if($('#advanced_year_select option:selected').val() == 'byyearday'){
  339. //$('#advanced_byyearday').css('display', 'block');
  340. }
  341. if($('#advanced_year_select option:selected').val() == 'byweekno'){
  342. $('#advanced_byweekno').css('display', 'block');
  343. }
  344. if($('#advanced_year_select option:selected').val() == 'bydaymonth'){
  345. $('#advanced_bymonth').css('display', 'block');
  346. $('#advanced_bymonthday').css('display', 'block');
  347. $('#advanced_weekday').css('display', 'block');
  348. }
  349. }
  350. },
  351. setViewActive: function(view){
  352. $('#view input[type="button"]').removeClass('active');
  353. var id;
  354. switch (view) {
  355. case 'agendaWeek':
  356. id = 'oneweekview_radio';
  357. break;
  358. case 'month':
  359. id = 'onemonthview_radio';
  360. break;
  361. case 'list':
  362. id = 'listview_radio';
  363. break;
  364. }
  365. $('#'+id).addClass('active');
  366. },
  367. categoriesChanged:function(newcategories){
  368. categories = $.map(newcategories, function(v) {return v;});
  369. console.log('Calendar categories changed to: ' + categories);
  370. $('#category').multiple_autocomplete('option', 'source', categories);
  371. },
  372. Calendar:{
  373. overview:function(){
  374. if($('#choosecalendar_dialog').dialog('isOpen') == true){
  375. $('#choosecalendar_dialog').dialog('moveToTop');
  376. }else{
  377. Calendar.UI.loading(true);
  378. $('#dialog_holder').load(OC.filePath('calendar', 'ajax/calendar', 'overview.php'), function(){
  379. $('#choosecalendar_dialog').dialog({
  380. width : 600,
  381. height: 400,
  382. close : function(event, ui) {
  383. $(this).dialog('destroy').remove();
  384. }
  385. });
  386. Calendar.UI.loading(false);
  387. });
  388. }
  389. },
  390. activation:function(checkbox, calendarid)
  391. {
  392. Calendar.UI.loading(true);
  393. $.post(OC.filePath('calendar', 'ajax/calendar', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 },
  394. function(data) {
  395. Calendar.UI.loading(false);
  396. if (data.status == 'success'){
  397. checkbox.checked = data.active == 1;
  398. if (data.active == 1){
  399. $('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
  400. }else{
  401. $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
  402. }
  403. }
  404. });
  405. },
  406. newCalendar:function(object){
  407. var tr = $(document.createElement('tr'))
  408. .load(OC.filePath('calendar', 'ajax/calendar', 'new.form.php'),
  409. function(){Calendar.UI.Calendar.colorPicker(this)});
  410. $(object).closest('tr').after(tr).hide();
  411. },
  412. edit:function(object, calendarid){
  413. var tr = $(document.createElement('tr'))
  414. .load(OC.filePath('calendar', 'ajax/calendar', 'edit.form.php'), {calendarid: calendarid},
  415. function(){Calendar.UI.Calendar.colorPicker(this)});
  416. $(object).closest('tr').after(tr).hide();
  417. },
  418. deleteCalendar:function(calid){
  419. var check = confirm("Do you really want to delete this calendar?");
  420. if(check == false){
  421. return false;
  422. }else{
  423. $.post(OC.filePath('calendar', 'ajax/calendar', 'delete.php'), { calendarid: calid},
  424. function(data) {
  425. if (data.status == 'success'){
  426. var url = 'ajax/events.php?calendar_id='+calid;
  427. $('#calendar_holder').fullCalendar('removeEventSource', url);
  428. $('#choosecalendar_dialog').dialog('destroy').remove();
  429. Calendar.UI.Calendar.overview();
  430. $('#calendar_holder').fullCalendar('refetchEvents');
  431. }
  432. });
  433. }
  434. },
  435. submit:function(button, calendarid){
  436. var displayname = $.trim($("#displayname_"+calendarid).val());
  437. var active = $("#edit_active_"+calendarid+":checked").length;
  438. var description = $("#description_"+calendarid).val();
  439. var calendarcolor = $("#calendarcolor_"+calendarid).val();
  440. if(displayname == ''){
  441. $("#displayname_"+calendarid).css('background-color', '#FF2626');
  442. $("#displayname_"+calendarid).focus(function(){
  443. $("#displayname_"+calendarid).css('background-color', '#F8F8F8');
  444. });
  445. }
  446. var url;
  447. if (calendarid == 'new'){
  448. url = OC.filePath('calendar', 'ajax/calendar', 'new.php');
  449. }else{
  450. url = OC.filePath('calendar', 'ajax/calendar', 'update.php');
  451. }
  452. $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
  453. function(data){
  454. if(data.status == 'success'){
  455. $(button).closest('tr').prev().html(data.page).show().next().remove();
  456. $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
  457. $('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
  458. if (calendarid == 'new'){
  459. $('#choosecalendar_dialog > table:first').append('<tr><td colspan="6"><a href="#" onclick="Calendar.UI.Calendar.newCalendar(this);"><input type="button" value="' + newcalendar + '"></a></td></tr>');
  460. }
  461. }else{
  462. $("#displayname_"+calendarid).css('background-color', '#FF2626');
  463. $("#displayname_"+calendarid).focus(function(){
  464. $("#displayname_"+calendarid).css('background-color', '#F8F8F8');
  465. });
  466. }
  467. }, 'json');
  468. },
  469. cancel:function(button, calendarid){
  470. $(button).closest('tr').prev().show().next().remove();
  471. },
  472. colorPicker:function(container){
  473. // based on jquery-colorpicker at jquery.webspirited.com
  474. var obj = $('.colorpicker', container);
  475. var picker = $('<div class="calendar-colorpicker"></div>');
  476. //build an array of colors
  477. var colors = {};
  478. $(obj).children('option').each(function(i, elm) {
  479. colors[i] = {};
  480. colors[i].color = $(elm).val();
  481. colors[i].label = $(elm).text();
  482. });
  483. for (var i in colors) {
  484. picker.append('<span class="calendar-colorpicker-color ' + (colors[i].color == $(obj).children(":selected").val() ? ' active' : '') + '" rel="' + colors[i].label + '" style="background-color: ' + colors[i].color + ';"></span>');
  485. }
  486. picker.delegate(".calendar-colorpicker-color", "click", function() {
  487. $(obj).val($(this).attr('rel'));
  488. $(obj).change();
  489. picker.children('.calendar-colorpicker-color.active').removeClass('active');
  490. $(this).addClass('active');
  491. });
  492. $(obj).after(picker);
  493. $(obj).css({
  494. position: 'absolute',
  495. left: -10000
  496. });
  497. }
  498. },
  499. Share:{
  500. currentid: 'false',
  501. idtype: '',
  502. activation:function(object,owner,id){
  503. $.post(OC.filePath('calendar', 'ajax/share', 'activation.php'),{id:id, idtype:'calendar', activation:object.checked?1:0});
  504. $('#calendar_holder').fullCalendar('refetchEvents');
  505. },
  506. dropdown:function(userid, calid){
  507. $('.calendar_share_dropdown').remove();
  508. var element = document.getElementById(userid+'_'+calid);
  509. $('<div class="calendar_share_dropdown"></div>').appendTo(element);
  510. $.post(OC.filePath('calendar', 'ajax/share', 'dropdown.php'), {calid: calid}, function(data){
  511. $('.calendar_share_dropdown').html(data);
  512. $('.calendar_share_dropdown').show('blind');
  513. $('#share_user').chosen();
  514. $('#share_group').chosen();
  515. });
  516. Calendar.UI.Share.currentid = calid;
  517. Calendar.UI.Share.idtype = 'calendar';
  518. },
  519. share:function(id, idtype, sharewith, sharetype){
  520. $.post(OC.filePath('calendar', 'ajax/share', 'share.php'),{id:id, idtype:idtype, sharewith:sharewith, sharetype:sharetype}, function(data){
  521. if(sharetype == 'public'){
  522. $('#public_token').val(parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=calendar&t='+data.message);
  523. $('#public_token').css('display', 'block');
  524. }
  525. });
  526. },
  527. unshare:function(id, idtype, sharewith, sharetype){
  528. $.post(OC.filePath('calendar', 'ajax/share', 'unshare.php'),{id:id, idtype:idtype, sharewith:sharewith, sharetype:sharetype}, function(){
  529. if(sharetype == 'public'){
  530. $('#public_token').val('');
  531. $('#public_token').css('display', 'none');
  532. }
  533. });
  534. },
  535. changepermission:function(id, idtype, sharewith, sharetype, permission){
  536. $.post(OC.filePath('calendar', 'ajax/share', 'changepermission.php'),{id:id, idtype:idtype, sharewith: sharewith, sharetype:sharetype, permission: (permission?1:0)});
  537. },
  538. init:function(){
  539. $('.calendar_share_dropdown').live('mouseleave', function(){
  540. $('.calendar_share_dropdown').hide('blind', function(){
  541. $('.calendar_share_dropdown').remove();
  542. });
  543. });
  544. $('#share_user').live('change', function(){
  545. if($('#sharewithuser_' + $('#share_user option:selected').text()).length == 0){
  546. Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $('#share_user option:selected').text(), 'user');
  547. var newitem = '<li id="sharewithuser_' + $('#share_user option:selected').text() +'"><input type="checkbox" width="12px" style="visibility:hidden;" title="' + $('#share_user option:selected').text() + '">' + $('#share_user option:selected').text() + '<img src="' + oc_webroot + '/core/img/actions/delete.svg" class="svg action" style="display:none;float:right;"></li>';
  548. $('#sharewithuser_list').append(newitem);
  549. $('#sharewithuser_' + $('#share_user option:selected').text() + ' > img').click(function(){
  550. $('#share_user option[value="' + $(this).parent().text() + '"]').removeAttr('disabled');
  551. Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'user' );
  552. $("#share_user").trigger("liszt:updated");
  553. $(this).parent().remove();
  554. });
  555. $('#share_user option:selected').attr('disabled', 'disabled');
  556. $("#share_user").trigger("liszt:updated");
  557. }
  558. });
  559. $('#share_group').live('change', function(){
  560. if($('#sharewithgroup_' + $('#share_group option:selected').text()).length == 0){
  561. Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $('#share_group option:selected').text(), 'group');
  562. var newitem = '<li id="sharewithgroup_' + $('#share_group option:selected').text() +'"><input type="checkbox" width="12px" style="visibility:hidden;" title="' + $('#share_group option:selected').text() + '">' + $('#share_group option:selected').text() + '<img src="' + oc_webroot + '/core/img/actions/delete.svg" class="svg action" style="display:none;float:right;"></li>';
  563. $('#sharewithgroup_list').append(newitem);
  564. $('#sharewithgroup_' + $('#share_group option:selected').text() + ' > img').click(function(){
  565. $('#share_group option[value="' + $(this).parent().text() + '"]').removeAttr('disabled');
  566. Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'group');
  567. $("#share_group").trigger("liszt:updated");
  568. $(this).parent().remove();
  569. });
  570. $('#share_group option:selected').attr('disabled', 'disabled');
  571. $("#share_group").trigger("liszt:updated");
  572. }
  573. });
  574. $('#sharewithuser_list > li > input:checkbox').live('change', function(){
  575. Calendar.UI.Share.changepermission(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'user', this.checked);
  576. });
  577. $('#sharewithgroup_list > li > input:checkbox').live('change', function(){
  578. Calendar.UI.Share.changepermission(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, $(this).parent().text(), 'group', this.checked);
  579. });
  580. $('#publish').live('change', function(){
  581. if(this.checked == 1){
  582. Calendar.UI.Share.share(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, '', 'public');
  583. }else{
  584. Calendar.UI.Share.unshare(Calendar.UI.Share.currentid, Calendar.UI.Share.idtype, '', 'public');
  585. }
  586. });
  587. $('#sharewithuser_list').live('mouseenter', function(){
  588. $('#sharewithuser_list > li > img').css('display', 'block');
  589. $('#sharewithuser_list > li > input').css('visibility', 'visible');
  590. });
  591. $('#sharewithuser_list').live('mouseleave', function(){
  592. $('#sharewithuser_list > li > img').css('display', 'none');
  593. $('#sharewithuser_list > li > input').css('visibility', 'hidden');
  594. });
  595. $('#sharewithgroup_list').live('mouseenter', function(){
  596. $('#sharewithgroup_list > li > img').css('display', 'block');
  597. $('#sharewithgroup_list > li > input').css('visibility', 'visible');
  598. });
  599. $('#sharewithgroup_list').live('mouseleave', function(){
  600. $('#sharewithgroup_list > li > img').css('display', 'none');
  601. $('#sharewithgroup_list > li > input').css('visibility', 'hidden');
  602. });
  603. /*var permissions = (this.checked) ? 1 : 0;*/
  604. }
  605. },
  606. Drop:{
  607. init:function(){
  608. if (typeof window.FileReader === 'undefined') {
  609. console.log('The drop-import feature is not supported in your browser :(');
  610. return false;
  611. }
  612. droparea = document.getElementById('calendar_holder');
  613. droparea.ondrop = function(e){
  614. e.preventDefault();
  615. Calendar.UI.Drop.drop(e);
  616. }
  617. console.log('Drop initialized successfully');
  618. },
  619. drop:function(e){
  620. var files = e.dataTransfer.files;
  621. for(var i = 0;i < files.length;i++){
  622. var file = files[i]
  623. reader = new FileReader();
  624. reader.onload = function(event){
  625. if(file.type != 'text/calendar'){
  626. $('#notification').html('At least one file don\'t seems to be a calendar file. File skipped.');
  627. $('#notification').slideDown();
  628. window.setTimeout(function(){$('#notification').slideUp();}, 5000);
  629. return false;
  630. }else{
  631. Calendar.UI.Drop.import(event.target.result);
  632. $('#calendar_holder').fullCalendar('refetchEvents');
  633. }
  634. }
  635. reader.readAsDataURL(file);
  636. }
  637. },
  638. import:function(data){
  639. $.post(OC.filePath('calendar', 'ajax/import', 'dropimport.php'), {'data':data},function(result) {
  640. if(result.status == 'success'){
  641. return true;
  642. }else{
  643. $('#notification').html('ownCloud wasn\'t able to import at least one file. File skipped.');
  644. $('#notification').slideDown();
  645. window.setTimeout(function(){$('#notification').slideUp();}, 5000);
  646. }
  647. });
  648. }
  649. }
  650. }
  651. }
  652. $.fullCalendar.views.list = ListView;
  653. function ListView(element, calendar) {
  654. var t = this;
  655. // imports
  656. jQuery.fullCalendar.views.month.call(t, element, calendar);
  657. var opt = t.opt;
  658. var trigger = t.trigger;
  659. var eventElementHandlers = t.eventElementHandlers;
  660. var reportEventElement = t.reportEventElement;
  661. var formatDate = calendar.formatDate;
  662. var formatDates = calendar.formatDates;
  663. var addDays = $.fullCalendar.addDays;
  664. var cloneDate = $.fullCalendar.cloneDate;
  665. function skipWeekend(date, inc, excl) {
  666. inc = inc || 1;
  667. while (!date.getDay() || (excl && date.getDay()==1 || !excl && date.getDay()==6)) {
  668. addDays(date, inc);
  669. }
  670. return date;
  671. }
  672. // overrides
  673. t.name='list';
  674. t.render=render;
  675. t.renderEvents=renderEvents;
  676. t.setHeight=setHeight;
  677. t.setWidth=setWidth;
  678. t.clearEvents=clearEvents;
  679. function setHeight(height, dateChanged) {
  680. }
  681. function setWidth(width) {
  682. }
  683. function clearEvents() {
  684. this.reportEventClear();
  685. }
  686. // main
  687. function sortEvent(a, b) {
  688. return a.start - b.start;
  689. }
  690. function render(date, delta) {
  691. if (!t.start){
  692. t.start = addDays(cloneDate(date, true), -7);
  693. t.end = addDays(cloneDate(date, true), 7);
  694. }
  695. if (delta) {
  696. if (delta < 0){
  697. addDays(t.start, -7);
  698. if (!opt('weekends')) {
  699. skipWeekend(t.start, delta < 0 ? -1 : 1);
  700. }
  701. }else{
  702. addDays(t.end, 7);
  703. if (!opt('weekends')) {
  704. skipWeekend(t.end, delta < 0 ? -1 : 1);
  705. }
  706. }
  707. }
  708. t.title = formatDates(
  709. t.start,
  710. t.end,
  711. opt('titleFormat', 'week')
  712. );
  713. t.visStart = cloneDate(t.start);
  714. t.visEnd = cloneDate(t.end);
  715. }
  716. function eventsOfThisDay(events, theDate) {
  717. var start = cloneDate(theDate, true);
  718. var end = addDays(cloneDate(start), 1);
  719. var retArr = new Array();
  720. for (i in events) {
  721. var event_end = t.eventEnd(events[i]);
  722. if (events[i].start < end && event_end >= start) {
  723. retArr.push(events[i]);
  724. }
  725. }
  726. return retArr;
  727. }
  728. function renderEvent(event) {
  729. if (event.allDay) { //all day event
  730. var time = opt('allDayText');
  731. }
  732. else {
  733. var time = formatDates(event.start, event.end, opt('timeFormat', 'agenda'));
  734. }
  735. var classes = ['fc-event', 'fc-list-event'];
  736. classes = classes.concat(event.className);
  737. if (event.source) {
  738. classes = classes.concat(event.source.className || []);
  739. }
  740. var html = '<tr>' +
  741. '<td>&nbsp;</td>' +
  742. '<td class="fc-list-time">' +
  743. time +
  744. '</td>' +
  745. '<td>&nbsp;</td>' +
  746. '<td class="fc-list-event">' +
  747. '<span id="list' + event.id + '"' +
  748. ' class="' + classes.join(' ') + '"' +
  749. '>' +
  750. '<span class="fc-event-title">' +
  751. event.title +
  752. '</span>' +
  753. '</span>' +
  754. '</td>' +
  755. '</tr>';
  756. return html;
  757. }
  758. function renderDay(date, events) {
  759. var dayRows = $('<tr>' +
  760. '<td colspan="4" class="fc-list-date">' +
  761. '<span>' +
  762. formatDate(date, opt('titleFormat', 'day')) +
  763. '</span>' +
  764. '</td>' +
  765. '</tr>');
  766. for (i in events) {
  767. var event = events[i];
  768. var eventElement = $(renderEvent(event));
  769. triggerRes = trigger('eventRender', event, event, eventElement);
  770. if (triggerRes === false) {
  771. eventElement.remove();
  772. }else{
  773. if (triggerRes && triggerRes !== true) {
  774. eventElement.remove();
  775. eventElement = $(triggerRes);
  776. }
  777. $.merge(dayRows, eventElement);
  778. eventElementHandlers(event, eventElement);
  779. reportEventElement(event, eventElement);
  780. }
  781. }
  782. return dayRows;
  783. }
  784. function renderEvents(events, modifiedEventId) {
  785. events = events.sort(sortEvent);
  786. var table = $('<table class="fc-list-table"></table>');
  787. var total = events.length;
  788. if (total > 0) {
  789. var date = cloneDate(t.visStart);
  790. while (date <= t.visEnd) {
  791. var dayEvents = eventsOfThisDay(events, date);
  792. if (dayEvents.length > 0) {
  793. table.append(renderDay(date, dayEvents));
  794. }
  795. date=addDays(date, 1);
  796. }
  797. }
  798. this.element.html(table);
  799. }
  800. }
  801. $(document).ready(function(){
  802. Calendar.UI.initScroll();
  803. $('#calendar_holder').fullCalendar({
  804. header: false,
  805. firstDay: firstDay,
  806. editable: true,
  807. defaultView: defaultView,
  808. timeFormat: {
  809. agenda: agendatime,
  810. '': defaulttime
  811. },
  812. columnFormat: {
  813. month: t('calendar', 'ddd'), // Mon
  814. week: t('calendar', 'ddd M/d'), // Mon 9/7
  815. day: t('calendar', 'dddd M/d') // Monday 9/7
  816. },
  817. titleFormat: {
  818. month: t('calendar', 'MMMM yyyy'),
  819. // September 2009
  820. week: t('calendar', "MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}"),
  821. // Sep 7 - 13 2009
  822. day: t('calendar', 'dddd, MMM d, yyyy'),
  823. // Tuesday, Sep 8, 2009
  824. },
  825. axisFormat: defaulttime,
  826. monthNames: monthNames,
  827. monthNamesShort: monthNamesShort,
  828. dayNames: dayNames,
  829. dayNamesShort: dayNamesShort,
  830. allDayText: allDayText,
  831. viewDisplay: function(view) {
  832. $('#datecontrol_date').val($('<p>').html(view.title).text());
  833. if (view.name != defaultView) {
  834. $.post(OC.filePath('calendar', 'ajax', 'changeview.php'), {v:view.name});
  835. defaultView = view.name;
  836. }
  837. Calendar.UI.setViewActive(view.name);
  838. if (view.name == 'agendaWeek') {
  839. $('#calendar_holder').fullCalendar('option', 'aspectRatio', 0.1);
  840. }
  841. else {
  842. $('#calendar_holder').fullCalendar('option', 'aspectRatio', 1.35);
  843. }
  844. },
  845. columnFormat: {
  846. week: 'ddd d. MMM'
  847. },
  848. selectable: true,
  849. selectHelper: true,
  850. select: Calendar.UI.newEvent,
  851. eventClick: Calendar.UI.editEvent,
  852. eventDrop: Calendar.UI.moveEvent,
  853. eventResize: Calendar.UI.resizeEvent,
  854. eventRender: function(event, element) {
  855. element.find('.fc-event-title').html(element.find('.fc-event-title').text());
  856. element.tipsy({
  857. className: 'tipsy-event',
  858. opacity: 0.9,
  859. gravity:$.fn.tipsy.autoBounds(150, 's'),
  860. fade:true,
  861. delayIn: 400,
  862. html:true,
  863. title:function() {
  864. return Calendar.UI.getEventPopupText(event);
  865. }
  866. });
  867. },
  868. loading: Calendar.UI.loading,
  869. eventSources: eventSources
  870. });
  871. $('#datecontrol_date').datepicker({
  872. changeMonth: true,
  873. changeYear: true,
  874. showButtonPanel: true,
  875. beforeShow: function(input, inst) {
  876. var calendar_holder = $('#calendar_holder');
  877. var date = calendar_holder.fullCalendar('getDate');
  878. inst.input.datepicker('setDate', date);
  879. inst.input.val(calendar_holder.fullCalendar('getView').title);
  880. return inst;
  881. },
  882. onSelect: function(value, inst) {
  883. var date = inst.input.datepicker('getDate');
  884. $('#calendar_holder').fullCalendar('gotoDate', date);
  885. }
  886. });
  887. fillWindow($('#content'));
  888. OCCategories.changed = Calendar.UI.categoriesChanged;
  889. OCCategories.app = 'calendar';
  890. $('#oneweekview_radio').click(function(){
  891. $('#calendar_holder').fullCalendar('changeView', 'agendaWeek');
  892. });
  893. $('#onemonthview_radio').click(function(){
  894. $('#calendar_holder').fullCalendar('changeView', 'month');
  895. });
  896. $('#listview_radio').click(function(){
  897. $('#calendar_holder').fullCalendar('changeView', 'list');
  898. });
  899. $('#today_input').click(function(){
  900. $('#calendar_holder').fullCalendar('today');
  901. });
  902. $('#datecontrol_left').click(function(){
  903. $('#calendar_holder').fullCalendar('prev');
  904. });
  905. $('#datecontrol_right').click(function(){
  906. $('#calendar_holder').fullCalendar('next');
  907. });
  908. Calendar.UI.Share.init();
  909. Calendar.UI.Drop.init();
  910. });