123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- function EventList()
- {
- this.events={};
- this.todos={};
- this.displayEventsArray={};
- this.displayTodosArray={};
- this.repeatable={};
- this.repeatableTodo={};
- this.reset=function()
- {
- this.events={};
- this.todos={};
- this.repeatable={};
- this.repeatableTodo={};
- this.displayEventsArray={};
- this.displayTodosArray={};
- }
- this.getNewUID=function()
- {
-
- var newUID=null;
- newUID=generateUID();
- return newUID;
- }
- this.getSortKey=function(vcalendar_clean)
- {
- var vcalendar_element=('\r\n'+vcalendar_clean).match(RegExp('\r\n'+vCalendar.re['contentline_N'], 'm'));
- if(vcalendar_element!=null && vcalendar_element.length==1)
- {
-
- var parsed=vcalendar_element[0].match(RegExp('\r\n'+vCalendar.re['contentline_parse'], 'm'));
-
- var parsed_value=vcalendarSplitValue(parsed[4], ';');
-
- if(parsed_value[0]!='' || parsed_value[1]!='')
- {
- var sort_value=parsed_value[0];
- if (sort_value!='' && parsed_value[1]!='')
- sort_value+=' ';
- sort_value+=parsed_value[1];
- }
- else
- {
- var vcalendar_element2=('\r\n'+vcalendar_clean).match(RegExp('\r\n'+vCalendar.re['contentline_FN'], 'm'));
- if(vcalendar_element2!=null && vcalendar_element2.length==1)
- {
-
- var parsed=vcalendar_element2[0].match(RegExp('\r\n'+vCalendar.re['contentline_parse'], 'm'));
- var sort_value=parsed[4];
- }
- }
- return sort_value;
- }
- else
- return false;
- }
-
- this.insertEvent=function(forceCall,inputCollection, inputEvent, forceReload, isEvent, isFromServer)
- {
- makeActive=null;
- var rid=inputEvent.uid.substring(0, inputEvent.uid.lastIndexOf('/')+1);
- var compObject = {};
- if(isEvent)
- compObject = globalEventList.events;
- else
- compObject = globalEventList.todos;
-
- if(compObject[rid][inputEvent.uid]!=undefined)
- {
- if(compObject[rid][inputEvent.uid].etag!=inputEvent.etag)
- {
- this.removeOldEvent(inputEvent.uid, false, isEvent);
- makeActive=inputEvent.uid;
- }
- else
- {
- checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType], false);
- return 0;
- }
- }
- if(isEvent)
- {
-
- var res=getvCalendarstart(inputEvent);
- if(res!=false && res!=-1 && res!=undefined && res!=null)
- inputEvent.sortStart=res;
- else
- {
- console.log("Error: '"+inputEvent.uid+"': unable to parse vEvent");
- checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType], true);
- return false;
- }
- globalEventList.events[rid][inputEvent.uid]=inputEvent;
- }
- else
- globalEventList.todos[rid][inputEvent.uid]=inputEvent;
- if(makeActive!=null)
- {
- globalEventList.loadEventByUID(makeActive, isEvent,isFromServer);
- return 0;
- }
- var inputUID=inputEvent.uid;
- rid=inputUID.substring(0, inputUID.lastIndexOf('/')+1);
- if(!isEvent)
- {
- if(vcalendarTodoData(inputCollection, inputEvent, true) == false)
- console.log("Error: '"+inputEvent.uid+"': unable to parse vTodo");
- }
- else
- {
- if(vcalendarToData(inputCollection, inputEvent, true) == false)
- console.log("Error: '"+inputEvent.uid+"': unable to parse vEvent");
- }
- if(isEvent)
- {
- if(inputEvent.counter==undefined)
- {
- if(globalVisibleCalDAVCollections.indexOf(rid)!=-1 || globalSettings.displayhiddenevents.value)
- refetchCalendarEvents();
- else
- {
- var beforeScroll = $('#main').width()-$('#calendar').width();
- $('#calendar').fullCalendar('removeEvents', 'fooUID');
- var afterScroll = $('#main').width()-$('#calendar').width();
- rerenderCalendar(beforeScroll!=afterScroll);
- }
- }
- }
- else
- {
- if(inputEvent.counter==undefined)
- {
- if(globalVisibleCalDAVTODOCollections.indexOf(rid)!=-1 || globalSettings.displayhiddenevents.value)
- refetchTodoEvents();
- }
- }
- if(inputEvent.counter!=undefined)
- checkEventLoader(globalResourceCalDAVList.counterList[inputCollection.uid+' '+inputCollection.listType], true);
- if(forceCall && !isEvent)
- $('#todoList').fullCalendar('selectEvent',$('[data-id="'+inputEvent.uid+'"]'));
- }
- this.checkAndTouchIfExists=function(calendarUID,inputUID,inputEtag,inputTimestamp)
- {
- if(globalEventList.events[calendarUID]!=undefined && globalEventList.events[calendarUID][inputUID]!=undefined)
- {
- globalEventList.events[calendarUID][inputUID].timestamp=inputTimestamp;
- if(globalEventList.events[calendarUID][inputUID].etag==inputEtag)
- return true;
- else
- return false;
- }
- else if(globalEventList.todos[calendarUID]!=undefined && globalEventList.todos[calendarUID][inputUID]!=undefined)
- {
- globalEventList.todos[calendarUID][inputUID].timestamp=inputTimestamp;
- if(globalEventList.todos[calendarUID][inputUID].etag==inputEtag)
- return true;
- else
- return false;
- }
- else
- return false;
- }
- this.removeOldEvents=function(inputUidBase, inputTimestamp, isEvent)
- {
- if(isEvent)
- {
- for(var i=0; i<globalResourceCalDAVList.collections.length;i++)
- if(globalResourceCalDAVList.collections[i].uid!=undefined)
- for(var key in globalEventList.events[globalResourceCalDAVList.collections[i].uid])
- {
- var event = globalEventList.events[globalResourceCalDAVList.collections[i].uid][key];
- if(event.timestamp!=undefined && event.uid.indexOf(inputUidBase)==0 && event.timestamp<inputTimestamp)
- globalEventList.removeOldEvent(event.uid, true, isEvent);
- }
- }
- else
- {
- for(var i=0; i<globalResourceCalDAVList.TodoCollections.length;i++)
- if(globalResourceCalDAVList.TodoCollections[i].uid!=undefined)
- for(var key in globalEventList.todos[globalResourceCalDAVList.TodoCollections[i].uid])
- {
- var event = globalEventList.todos[globalResourceCalDAVList.TodoCollections[i].uid][key];
- if(event.timestamp!=undefined && event.uid.indexOf(inputUidBase)==0 && event.timestamp<inputTimestamp)
- globalEventList.removeOldEvent(event.uid, true, isEvent);
- }
- }
- }
- this.removeOldEvent=function(inputUid, fromInterface, isEvent)
- {
- var rid=inputUid.substring(0, inputUid.lastIndexOf('/')+1);
- var uidRemoved=null;
- var isEvent=true;
- if(globalEventList.events[rid]!=undefined && globalEventList.events[rid][inputUid]!=undefined)
- {
- uidRemoved=inputUid;
- delete globalEventList.events[rid][inputUid];
- isEvent=true;
- }
- else if(globalEventList.todos[rid]!=undefined && globalEventList.todos[rid][inputUid]!=undefined)
- {
- uidRemoved=inputUid;
- delete globalEventList.todos[rid][inputUid];
- isEvent=false;
- }
-
- if(uidRemoved!=null)
- {
- if(fromInterface)
- {
- deleteEventFromArray(uidRemoved);
- if(isEvent)
- refetchCalendarEvents();
- else
- {
- var prevIndex = '';
- if(globalCalTodo!=null)
- prevIndex=$('.fc-view-todo .fc-list-day').find('.fc-event:visible').index($('[data-repeat-hash="'+globalCalTodo.repeatHash+'"]'));
- refetchTodoEvents();
- if(prevIndex!=-1 && $('.fc-view-todo .fc-list-day').find('.fc-event:visible').length > 0 && prevIndex>($('.fc-view-todo .fc-list-day').find('.fc-event:visible').length-1))
- $('#todoList').fullCalendar('selectEvent',$($('.fc-view-todo .fc-list-day').find('.fc-event:visible').get($('.fc-view-todo .fc-list-day').find('.fc-event:visible').length-1)));
- else if(prevIndex!=-1 && $('.fc-view-todo .fc-list-day').find('.fc-event:visible').length > 0 && prevIndex<=($('.fc-view-todo .fc-list-day').find('.fc-event:visible').length-1))
- $('#todoList').fullCalendar('selectEvent',$($('.fc-view-todo .fc-list-day').find('.fc-event:visible').get(prevIndex)));
- else
- $('#CATodo').attr('style','display:none');
- }
- }
- if(isEvent)
- delete globalEventList.repeatable[inputUid];
- else
- delete globalEventList.repeatableTodo[inputUid];
- }
- }
- this.loadEventByUID=function(inputUID, isEvent,isFromServer)
- {
- var rid='';
- if(inputUID.charAt(inputUID.length-1)!='/')
- {
- rid=inputUID.substring(0, inputUID.lastIndexOf('/')+1);
- if(isEvent)
- {
- if(globalEventList.events[rid][inputUID].uid!=undefined)
- {
- var evs='';
- if(!globalCalDAVInitLoad)
- evs=findEventInArray(globalEventList.events[rid][inputUID].uid, isEvent);
- if(evs!='' && evs.etag!=globalEventList.events[rid][inputUID].etag)
- {
- vcalendarToData(globalResourceCalDAVList.getCollectionByUID(rid), globalEventList.events[rid][inputUID], false);
- if(!isFromServer && (globalVisibleCalDAVCollections.indexOf(rid)!=-1 || globalSettings.displayhiddenevents.value))
- refetchCalendarEvents();
- else if(isFromServer)
- checkEventLoader(globalResourceCalDAVList.counterList[rid+' '+globalResourceCalDAVList.getCollectionByUID(rid).listType], true);
- }
- }
- }
- else
- {
- if(globalEventList.todos[rid][inputUID].uid!=undefined)
- {
- var evs='';
- if(!globalCalDAVInitLoad)
- evs=findEventInArray(globalEventList.todos[rid][inputUID].uid, isEvent);
- if(evs!='' && evs.etag!=globalEventList.todos[rid][inputUID].etag)
- {
- vcalendarTodoData(globalResourceCalDAVList.getCollectionByUID(rid), globalEventList.todos[rid][inputUID], false);
- if(globalVisibleCalDAVTODOCollections.indexOf(rid)!=-1 || globalSettings.displayhiddenevents.value)
- {
- $('#todoList').fullCalendar('allowSelectEvent',false);
- refetchTodoEvents();
- $('#todoList').fullCalendar('allowSelectEvent',true);
- if($('#showTODO').val()==inputUID)
- {
- var newTodo = findEventInArray(globalEventList.todos[rid][inputUID].uid,false,globalCalTodo!=null ? globalCalTodo.repeatHash : null);
- if(newTodo!='')
- {
- if(globalCalTodo!=null)
- {
- if(isFromServer && $('#showTODO').val()==inputUID && ($('#repeatTodo').val()=="true" || $('#recurrenceIDTODO').val()!=''))
- {
- if(globalCalTodo.repeatHash != newTodo.repeatHash)
- {
- var name=globalCalTodo.title;
- showTodoForm({title: name, id:inputUID}, 'show','', true);
- $('#editAllTODO').css('visibility','hidden');
- $('#editFutureTODO').css('visibility','hidden');
- $('#editOnlyOneTODO').css('visibility','hidden');
- $('#repeatConfirmBoxContentTODO').html('<b>'+name+"</b> "+localization[globalInterfaceLanguage].repeatChangeTxt);
- $('#repeatConfirmBoxQuestionTODO').html(localization[globalInterfaceLanguage].repeatTodoChangeTxtClose);
- }
- else
- $('#todoList').fullCalendar('selectEvent');
- }
- else
- {
- if($($('.fc-view-todo .fc-list-day').find('.fc-event[data-repeat-hash="'+$('#todoList').fullCalendar('getView').selectedElement+'"]')).length>0)
- $('#todoList').fullCalendar('selectEvent',$($('.fc-view-todo .fc-list-day').find('.fc-event[data-repeat-hash="'+$('#todoList').fullCalendar('getView').selectedElement+'"]')));
- else
- showTodoForm(globalCalTodo, 'show');
- }
- }
- }
- else
- $('#CATodo').attr('style','display:none');
- }
- else
- $('#todoList').fullCalendar('selectEvent',null,true);
- }
- }
- }
- }
- }
- }
- }
|