From 9b6e46dc6b245a229b0b5af0efea88c2838ce56a Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 19 Apr 2019 15:32:56 +0200 Subject: calendar merge initial commit --- view/tpl/cdav_calendar.tpl | 202 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 163 insertions(+), 39 deletions(-) (limited to 'view/tpl/cdav_calendar.tpl') diff --git a/view/tpl/cdav_calendar.tpl b/view/tpl/cdav_calendar.tpl index a577e3120..56f3670ba 100644 --- a/view/tpl/cdav_calendar.tpl +++ b/view/tpl/cdav_calendar.tpl @@ -4,6 +4,14 @@ var new_event = {}; var new_event_id = Math.random().toString(36).substring(7); var views = {'dayGridMonth' : '{{$month}}', 'timeGridWeek' : '{{$week}}', 'timeGridDay' : '{{$day}}', 'listMonth' : '{{$list_month}}', 'listWeek' : '{{$list_week}}', 'listDay' : '{{$list_day}}'}; +var event_id; +var event_uri; + +var contact_allow = []; +var group_allow = []; +var contact_deny = []; +var group_deny = []; + $(document).ready(function() { var calendarEl = document.getElementById('calendar'); calendar = new FullCalendar.Calendar(calendarEl, { @@ -45,7 +53,7 @@ $(document).ready(function() { dtend.setHours(dtend.getHours() + 1); } - $('#event_uri').val(''); + event_uri = ''; $('#id_title').val('New event'); $('#calendar_select').val($("#calendar_select option:first").val()).attr('disabled', false); $('#id_dtstart').val(info.date.toUTCString()); @@ -61,15 +69,21 @@ $(document).ready(function() { eventClick: function(info) { + console.log(info); + var event = info.event._def; var dtstart = new Date(info.event._instance.range.start); var dtend = new Date(info.event._instance.range.end); - + if(event.publicId == new_event_id) { + $('#calendar_select').trigger('change'); + $('#event_submit').show(); + event_id = 0; $(window).scrollTop(0); $('.section-content-tools-wrapper, #event_form_wrapper').show(); $('#recurrence_warning').hide(); $('#id_title').focus().val(''); + return false; } @@ -79,18 +93,28 @@ $(document).ready(function() { new_event = {}; } + var calendar_id = ((event.extendedProps.calendar_id.constructor === Array) ? event.extendedProps.calendar_id[0] + ':' + event.extendedProps.calendar_id[1] : event.extendedProps.calendar_id); + if(!event.extendedProps.recurrent) { $(window).scrollTop(0); $('.section-content-tools-wrapper, #event_form_wrapper').show(); $('#recurrence_warning').hide(); - $('#event_uri').val(event.extendedProps.uri); + event_uri = event.extendedProps.uri; $('#id_title').val(event.title); - $('#calendar_select').val(event.extendedProps.calendar_id[0] + ':' + event.extendedProps.calendar_id[1]).attr('disabled', true); + $('#calendar_select').val(calendar_id).attr('disabled', true).trigger('change'); $('#id_dtstart').val(dtstart.toUTCString()); $('#id_dtend').val(dtend.toUTCString()); $('#id_description').val(event.extendedProps.description); $('#id_location').val(event.extendedProps.location); $('#event_submit').val('update_event').html('Update'); + $('#dbtn-acl').addClass('d-none'); + event_id = event.extendedProps.item ? event.extendedProps.item.id : 0; + + contact_allow = event.extendedProps.contact_allow || []; + group_allow = event.extendedProps.group_allow || []; + contact_deny = event.extendedProps.contact_deny || []; + group_deny = event.extendedProps.group_deny || []; + if(event.extendedProps.rw) { $('#event_delete').show(); $('#event_submit').show(); @@ -100,6 +124,11 @@ $(document).ready(function() { $('#id_dtend').attr('disabled', false); $('#id_description').attr('disabled', false); $('#id_location').attr('disabled', false); + + if(calendar_id == 'channel_calendar' && !event.extendedProps.is_editable) { + console.log(calendar_id) + $('#event_submit').hide(); + } } else { $('#event_submit').hide(); @@ -114,8 +143,8 @@ $(document).ready(function() { else if(event.extendedProps.recurrent && event.extendedProps.rw) { $('.section-content-tools-wrapper, #recurrence_warning').show(); $('#event_form_wrapper').hide(); - $('#event_uri').val(event.extendedProps.uri); - $('#calendar_select').val(event.extendedProps.calendar_id[0] + ':' + event.extendedProps.calendar_id[1]).attr('disabled', true); + event_uri = event.extendedProps.uri; + $('#calendar_select').val(calendar_id).attr('disabled', true).trigger('change'); } }, @@ -193,6 +222,13 @@ $(document).ready(function() { calendar.next(); $('#title').text(calendar.view.title); }); + + $('#calendar_select').on('change', function() { + if(this.value === 'channel_calendar') + $('#dbtn-acl').removeClass('d-none'); + else + $('#dbtn-acl').addClass('d-none'); + }); $('.color-edit').colorpicker({ input: '.color-edit-input' }); @@ -213,9 +249,16 @@ function changeView(action, viewName) { } function add_remove_json_source(source, color, editable, status) { - var parts = source.split('/'); - var id = parts[4]; - + var id, parts = []; + + if(source == '/channel_calendar/json') + id = 'channel_calendar' + + if(! id) { + parts = source.split('/'); + id = parts[4]; + } + var eventSource = calendar.getEventSourceById(id); var selector = '#calendar-btn-' + id; @@ -247,37 +290,102 @@ function updateSize() { } function on_submit() { - $.post( 'cdav/calendar', { - 'submit': $('#event_submit').val(), - 'target': $('#calendar_select').val(), - 'uri': $('#event_uri').val(), - 'title': $('#id_title').val(), - 'dtstart': $('#id_dtstart').val(), - 'dtend': $('#id_dtend').val(), - 'description': $('#id_description').val(), - 'location': $('#id_location').val() - }) - .done(function() { - var parts = $('#calendar_select').val().split(':'); - var eventSource = calendar.getEventSourceById(parts[0]); - eventSource.refetch(); - reset_form(); + if($('#calendar_select').val() == 'channel_calendar') { + if(new_event_id) { + $("input[name='contact_allow[]']").each(function() { + contact_allow.push($(this).val()); + }); + $("input[name='group_allow[]']").each(function() { + group_allow.push($(this).val()); + }); + $("input[name='contact_deny[]']").each(function() { + contact_deny.push($(this).val()); + }); + $("input[name='group_deny[]']").each(function() { + group_deny.push($(this).val()); + }); + } - }); + $.post( 'channel_calendar', { + 'event_id': event_id, + 'event_hash': event_uri, + 'xchan': '{{$channel_hash}}', + //'mid': mid, + 'type': 'event', + 'preview': 0, + 'summary': $('#id_title').val(), + 'dtstart': $('#id_dtstart').val(), + 'dtend': $('#id_dtend').val(), + 'adjust': 0, + 'category': '', + 'desc': $('#id_description').val(), + 'location': $('#id_location').val(), + 'submit': $('#event_submit').val(), + 'contact_allow[]': contact_allow, + 'group_allow[]': group_allow, + 'contact_deny[]': contact_deny, + 'group_deny[]': group_deny +/* + 'submit': $('#event_submit').val(), + 'target': $('#calendar_select').val(), + 'uri': $('#event_uri').val(), + 'title': $('#id_title').val(), + 'dtstart': $('#id_dtstart').val(), + 'dtend': $('#id_dtend').val(), + 'description': $('#id_description').val(), + 'location': $('#id_location').val() +*/ + }) + .done(function() { + var eventSource = calendar.getEventSourceById('channel_calendar'); + eventSource.refetch(); + reset_form(); + + }); + + } + else { + $.post( 'cdav/calendar', { + 'submit': $('#event_submit').val(), + 'target': $('#calendar_select').val(), + 'uri': event_uri, + 'title': $('#id_title').val(), + 'dtstart': $('#id_dtstart').val(), + 'dtend': $('#id_dtend').val(), + 'description': $('#id_description').val(), + 'location': $('#id_location').val() + }) + .done(function() { + var parts = $('#calendar_select').val().split(':'); + var eventSource = calendar.getEventSourceById(parts[0]); + eventSource.refetch(); + reset_form(); + + }); + } } function on_delete() { - $.post( 'cdav/calendar', { - 'delete': 'delete', - 'target': $('#calendar_select').val(), - 'uri': $('#event_uri').val(), - }) - .done(function() { - var parts = $('#calendar_select').val().split(':'); - var eventSource = calendar.getEventSourceById(parts[0]); - eventSource.refetch(); - reset_form(); - }); + if($('#calendar_select').val() == 'channel_calendar') { + $.get('channel_calendar/drop/' + event_uri, function() { + var eventSource = calendar.getEventSourceById('channel_calendar'); + eventSource.refetch(); + reset_form(); + }); + } + else { + $.post( 'cdav/calendar', { + 'delete': 'delete', + 'target': $('#calendar_select').val(), + 'uri': event_uri + }) + .done(function() { + var parts = $('#calendar_select').val().split(':'); + var eventSource = calendar.getEventSourceById(parts[0]); + eventSource.refetch(); + reset_form(); + }); + } } function reset_form() { @@ -285,7 +393,7 @@ function reset_form() { $('#event_submit').val(''); $('#calendar_select').val(''); - $('#event_uri').val(''); + event_uri = ''; $('#id_title').val(''); $('#id_dtstart').val(''); $('#id_dtend').val(''); @@ -311,6 +419,14 @@ function on_more() { } } +function exportDate() { + alert('not implemented'); + console.log('not implemented'); + //var moment = $('#events-calendar').fullCalendar('getDate'); + //var sT = 'events/' + moment.year() + '/' + (moment.month() + 1) + '/export'; + //window.location.href=sT; +} +
@@ -350,14 +466,20 @@ function on_more() {
-- cgit v1.2.3 From 2bd5ae361782d9c4a9bdfc1f037844d52d1fd502 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 19 Apr 2019 17:21:45 +0200 Subject: provide link to source and some cleanup --- view/tpl/cdav_calendar.tpl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'view/tpl/cdav_calendar.tpl') diff --git a/view/tpl/cdav_calendar.tpl b/view/tpl/cdav_calendar.tpl index 56f3670ba..f33ccda26 100644 --- a/view/tpl/cdav_calendar.tpl +++ b/view/tpl/cdav_calendar.tpl @@ -69,12 +69,20 @@ $(document).ready(function() { eventClick: function(info) { - console.log(info); - var event = info.event._def; var dtstart = new Date(info.event._instance.range.start); var dtend = new Date(info.event._instance.range.end); + if(event.extendedProps.plink) { + if(! $('#l2s').length) + $('#id_title_wrapper').prepend(''); + + $('#l2s').html(' ' + event.extendedProps.plink[1] + ''); + } + else { + $('#l2s').remove(); + } + if(event.publicId == new_event_id) { $('#calendar_select').trigger('change'); $('#event_submit').show(); @@ -470,12 +478,12 @@ function exportDate() { {{include file="field_input.tpl" field=$title}}