/* InfCloud - the open source CalDAV/CardDAV Web Client Copyright (C) 2011-2015 Jan Mate Andrej Lezo Matej Mihalik This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ function handleCalDAVError(isError, inputResource) { var collections=''; collections=globalResourceCalDAVList.collections; for(var i=0; i0) while(low'); newElement.append(headerObject.displayvalue); if(todoString=='') newElement.find('input[type=checkbox]').attr('onclick','resourceChBoxClick(this, \'#\'+$(this).parent().parent().attr(\'id\'), \''+resHeader+'\', false);if(isCalDAVLoaded && $(this).parent().parent().attr(\'id\')== \'ResourceCalDAV'+todoString+'List\'){$(this).prop(\'checked\')?enableResource($(this).parent()):disableResource($(this).parent());}'); else newElement.find('input[type=checkbox]').attr('onclick','resourceChBoxClick(this, \'#\'+$(this).parent().parent().attr(\'id\'), \''+resHeader+'\', false);if(isCalDAVLoaded && $(this).parent().parent().attr(\'id\')== \'ResourceCalDAV'+todoString+'List\'){$(this).prop(\'checked\')?enableResourceTodo($(this).parent()):disableResourceTodo($(this).parent());}'); newElement.css('display', 'none'); newElement=newElement.parent().html(); $('#ResourceCalDAV'+todoString+'List').children().eq(insertIndex).after(newElement); } // insert the resource to interface var newElement = $('#ResourceCalDAV'+todoString+'ListTemplate').find('.resourceCalDAV'+todoString+'_item').clone().wrap('
'); var par=inputResource.uid.split('/'); if(inputResource.permissions.read_only) newElement.addClass('resourceCalDAV_item_ro'); newElement.attr('data-id', inputResource.uid); if(globalCalDAVInitLoad) newElement.addClass('r_operate'); newElement.html("
"+$('
').text(inputResource.displayvalue).html()); newElement.attr('title', $('
').text(inputResource.displayvalue).html()); if(todoString=='') newElement.find('input[type=checkbox]').attr({'data-id':inputResource.uid, 'onclick':'var evt = arguments[0];evt.stopPropagation();collectionChBoxClick(this, \'#\'+$(this).parent().parent().attr(\'id\'), \''+resHeader+'\', \''+resItem+'\', null, false);if(isCalDAVLoaded && $(this).parent().parent().attr(\'id\')== \'ResourceCalDAV'+todoString+'List\'){$(this).prop(\'checked\')?enableCalendar(\''+inputResource.uid+'\'):disableCalendar(\''+inputResource.uid+'\');}'}); else newElement.find('input[type=checkbox]').attr({'data-id':inputResource.uid, 'onclick':'var evt = arguments[0];evt.stopPropagation();collectionChBoxClick(this, \'#\'+$(this).parent().parent().attr(\'id\'), \''+resHeader+'\', \''+resItem+'\', null, false);if(isCalDAVLoaded && $(this).parent().parent().attr(\'id\')== \'ResourceCalDAV'+todoString+'List\'){$(this).prop(\'checked\')?enableCalendarTodo(\''+inputResource.uid+'\'):disableCalendarTodo(\''+inputResource.uid+'\');}'}); newElement.click(function(e){ if(($(this).hasClass('resourceCalDAV_item')&&globalEventCollectionsLoading) || ($(this).hasClass('resourceCalDAVTODO_item')&&globalTodoCollectionsLoading)) return true; if(e.shiftKey) { if(isEvent) enableOne($(this).attr('data-id')); else enableOneTodo($(this).attr('data-id')); } $('#ResourceCalDAV'+todoString+'List .resourceCalDAV_item_selected').removeClass('resourceCalDAV_item_selected'); $(this).addClass('resourceCalDAV_item_selected'); }); if(typeof globalCalendarColorPropertyXmlns== 'undefined' || globalCalendarColorPropertyXmlns== null || globalCalendarColorPropertyXmlns==='' || globalCalendarColorPropertyXmlns!==false) bindColorPickerClick(newElement.find('.resourceCalDAVColor')); $('#ResourceCalDAV'+todoString+'List').children().eq(insertIndex+headerMiss).after(newElement); if(inputResource.makeLoaded) { var resDOMHeader=newElement.prevUntil('.resourceCalDAV'+todoString+'_header').last().prev(); if(!resDOMHeader.length) resDOMHeader=newElement.prev(); resDOMHeader.css('display','block'); var rex=vCalendar.pre['accountUidParts']; var tmp=inputResource.accountUID.match(rex); var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4]; var resourceCalDAV_user=tmp[2]; for(var i=0;i=0;i--) { if(this.collections[i]!=undefined && !this.collections[i].subscription && this.collections[i].timestamp!=undefined && this.collections[i].uid.indexOf(inputUidBase)==0 && this.collections[i].timestamp0) //{ var beforeScroll = $('#main').width()-$('#calendar').width(); $('#calendar').fullCalendar('removeEventSource', this.collections[i].fcSource); var afterScroll = $('#main').width()-$('#calendar').width(); rerenderCalendar(beforeScroll!=afterScroll); //} var item=$('#ResourceCalDAVList').find('.resourceCalDAV_item[data-id^="'+jqueryEscapeSelector(this.collections[i].uid)+'"]'); var item_header=item.prevUntil('.resourceCalDAV_header').last().prev(); if(!item_header.length) item_header=item.prev(); item.remove(); this.collections.splice(i, 1); // if next item is undefined or it is a header and the previous item is header delete it if((this.collections[i]==undefined || this.collections[i].headerOnly==true) && this.collections[i-1].headerOnly==true) { item_header.remove(); this.collections.splice(--i, 1); } else { var firstVisibleCollection=null; for(var vi=i-1;vi>0;vi--) { if(this.collections[vi].headerOnly==true) break; if(this.collections[vi].makeLoaded) { firstVisibleCollection=this.collections[vi]; break; } } if(firstVisibleCollection==null) { for(var vi=i;vi=0;i--) { if(this.TodoCollections[i]!=undefined && !this.TodoCollections[i].subscription && this.TodoCollections[i].timestamp!=undefined && this.TodoCollections[i].uid.indexOf(inputUidBase)==0 && this.TodoCollections[i].timestamp0) //{ var beforeScroll = $('#mainTODO').width()-$('#todoList').width(); $('#todoList').fullCalendar('removeEventSource', this.TodoCollections[i].fcSource); var afterScroll = $('#mainTODO').width()-$('#todoList').width(); rerenderTodo(beforeScroll!=afterScroll); //} var item=$('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item[data-id^="'+jqueryEscapeSelector(this.TodoCollections[i].uid)+'"]'); var item_header=item.prevUntil('.resourceCalDAVTODO_header').last().prev(); if(!item_header.length) item_header=item.prev(); item.remove(); this.TodoCollections.splice(i, 1); // if next item is undefined or it is a header and the previous item is header delete it if((this.TodoCollections[i]==undefined || this.TodoCollections[i].headerOnly==true) && this.TodoCollections[i-1].headerOnly==true) { item_header.remove(); this.TodoCollections.splice(--i, 1); } else { var firstVisibleCollection=null; for(var vi=i-1;vi>0;vi--) { if(this.TodoCollections[vi].headerOnly==true) break; if(this.TodoCollections[vi].makeLoaded) { firstVisibleCollection=this.TodoCollections[vi]; break; } } if(firstVisibleCollection==null) { for(var vi=i;vi=0;i--) if(this.collections[i].uid==inputUid) { var uidRemoved=this.collections[i].uid; var item=$('#ResourceCalDAVList').find('[data-id^="'+jqueryEscapeSelector(this.collections[i].uid)+'"]'); var item_prev=item.prev(); item.remove(); this.collections.splice(i, 1); // if next item is undefined or it is a header and the previous item is header delete it if((this.collections[i]==undefined || this.collections[i].headerOnly==true) && i>0 && this.collections[i-1].headerOnly==true) { item_prev.remove(); this.collections.splice(i, 1); } } } else for(var i=this.TodoCollections.length-1;i>=0;i--) if(this.TodoCollections[i].uid==inputUid) { var uidRemoved=this.TodoCollections[i].uid; var item=$('#ResourceCalDAVTODOList').find('[data-id^="'+jqueryEscapeSelector(this.TodoCollections[i].uid)+'"]'); var item_prev=item.prev(); item.remove(); this.TodoCollections.splice(i, 1); // if next item is undefined or it is a header and the previous item is header delete it if((this.TodoCollections[i]==undefined || this.TodoCollections[i].headerOnly==true) && i>0 && this.TodoCollections[i-1].headerOnly==true) { item_prev.remove(); this.TodoCollections.splice(i, 1); } } }; this.getCollectionByUID=function(inputUID) { for(var i=0;i we need to remove and reinsert it { nameChanged=true; makeActive=$('#ResourceCardDAVList').find('[data-id='+jqueryEscapeSelector(inputCollection.uid)+']').hasClass('resourceCardDAV_selected'); makeChecked=$('#ResourceCardDAVList').find('[data-id='+jqueryEscapeSelector(inputCollection.uid)+']').find('input[type=checkbox]').not('.unloadCheck').prop('checked'); makeIndeterminate=$('#ResourceCardDAVList').find('[data-id='+jqueryEscapeSelector(inputCollection.uid)+']').find('input[type=checkbox]').not('.unloadCheck').prop('indeterminate'); // here get the list of vcard groups with the current state (we need to re-add them to the interface) $('#ResourceCardDAVList').find('.group[data-id^='+jqueryEscapeSelector(inputCollection.uid)+']').not('[data-id='+jqueryEscapeSelector(inputCollection.uid)+']').each( function(index, element) { makeContactGroups.push({uid: $(element).attr('data-id'), isActive: $(element).hasClass('resourceCardDAV_selected'), isChecked: $(element).find('input[type=checkbox]').prop('checked')}); } ); // the collection name is changed and must be moved to correct place (we first remove it and then reinsert) this.removeResource(inputCollection.uid, false); break; } } if(!globalCardDAVInitLoad&&!nameChanged) { var uidParts=inputCollection.uid.match(RegExp('^(https?://)([^@/]+(?:@[^@/]+)?)@(.*)')); var checkHref = uidParts[1]+uidParts[3]; var isLoaded=false; if(typeof globalCrossServerSettingsURL!='undefined'&&globalCrossServerSettingsURL!=null&globalCrossServerSettingsURL) { var uidParts=inputCollection.uid.match(RegExp('/([^/]+/[^/]+/)$')); var tmpParts = uidParts[1].match('^(.*/)([^/]+)/$'); var checkHref3=decodeURIComponent(tmpParts[1])+tmpParts[2]+'/'; var found=false; for(var l=0;l0) while(low0) return false; else { globalAddressbookList.applyABFilter(collectionChBoxClick(this, \'#ResourceCardDAVList\', \'.resourceCardDAV_header\', \'.resourceCardDAV\', \'.contact_group\', true), false); }'}); newElement.find('.resourceCardDAV').append(inputCollection.displayvalue); newElement.find('.resourceCardDAV').attr('title',inputCollection.displayvalue); $('#ResourceCardDAVList').children().eq(insertIndex+headerMiss).after(newElement); if(inputCollection.makeLoaded) { var resDOMHeader=newElement.prevUntil('.resourceCardDAV_header').last().prev(); if(!resDOMHeader.length) resDOMHeader=newElement.prev(); resDOMHeader.css('display','block'); var rex=vCard.pre['accountUidParts']; var tmp=inputCollection.accountUID.match(rex); var resourceCalDAV_href=tmp[1]+tmp[3]+tmp[4]; var resourceCalDAV_user=tmp[2]; for(var i=0;i0) for(var i=0;i=0;i--) if(this.collections[i].uid==inputCollectionUID) { var uidRemoved=this.collections[i].uid; var item=$('#ResourceCardDAVList').find('.resourceCardDAV[data-id^="'+jqueryEscapeSelector(this.collections[i].uid)+'"]'); var item_prev=item.parent().prev(); var item_was_selected=item.hasClass('resourceCardDAV_selected'); if(activateNextIfNeeded && item_was_selected) { // select the nearest candidate to load if((i+1)<=(this.collections.length-1)) { if(this.collections[i+1].headerOnly!=true) nextCandidateToActive=this.collections[i+1]; else if((i+2)<=(this.collections.length-1)) nextCandidateToActive=this.collections[i+2]; } if(nextCandidateToActive==null && (i-1)>0) { if(this.collections[i-1].headerOnly!=true) nextCandidateToActive=this.collections[i-1]; else if((i-2)>0) nextCandidateToActive=this.collections[i-2]; } } // remove the item item.parent().remove(); this.collections.splice(i,1); // if the next item is undefined or is header, and the previous item is header, then delete the header if((this.collections[i]==undefined || this.collections[i].headerOnly==true) && this.collections[i-1].headerOnly==true) { item_prev.remove(); this.collections.splice(--i,1); } // make another resource active if(activateNextIfNeeded && nextCandidateToActive!=null) this.resourceOrGroupClick(nextCandidateToActive.uid); break; } } // DONE this.removeOldResources=function(inputUidBase, inputTimestamp) { for(var i=this.collections.length-1;i>=0;i--) if(this.collections[i].timestamp!=undefined && this.collections[i].uid.indexOf(inputUidBase)==0 && this.collections[i].timestamp0 && this.collections[i-1].headerOnly==true) { item_header.remove(); this.collections.splice(--i,1); } else { var firstVisibleCollection=null; for(var vi=i-1;vi>0;vi--) { if(this.collections[vi].headerOnly==true) break; if(this.collections[vi].makeLoaded) { firstVisibleCollection=this.collections[vi]; break; } } if(firstVisibleCollection==null) { for(var vi=i;vi