diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index 15daf3723..6ad5e22ba 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -2956,6 +2956,9 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir refDict = [moduleSettings objectForKey: @"NotifyUserOnPersonalModifications"]; [refDict removeObjectForKey: reference]; + refArray = [moduleSettings objectForKey: @"FoldersOrder"]; + [refArray removeObject: nameInContainer]; + refArray = [moduleSettings objectForKey: @"InactiveFolders"]; [refArray removeObject: nameInContainer]; diff --git a/UI/Scheduler/UIxCalMainView.m b/UI/Scheduler/UIxCalMainView.m index b88992ecc..db05c2a28 100644 --- a/UI/Scheduler/UIxCalMainView.m +++ b/UI/Scheduler/UIxCalMainView.m @@ -1,6 +1,6 @@ /* UIxCalMainView.m - this file is part of SOGo * - * Copyright (C) 2006-2015 Inverse inc. + * Copyright (C) 2006-2016 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -301,6 +301,27 @@ return (state && [state compare: @"collapse"] == NSOrderedSame)? @"display: none;" : @""; } +- (WOResponse *) saveFoldersOrderAction +{ + WORequest *request; + NSDictionary *params; + NSArray *list; + + [self _setupContext]; + request = [context request]; + params = [[request contentAsString] objectFromJSONString]; + + list = [params objectForKey: @"folders"]; + if (list) + [moduleSettings setObject: list + forKey: @"FoldersOrder"]; + else + [moduleSettings removeObjectForKey: @"FoldersOrder"]; + [us synchronize]; + + return [self responseWithStatus: 204]; +} + - (unsigned int) firstDayOfWeek { SOGoUserDefaults *ud; diff --git a/UI/Scheduler/UIxCalendarSelector.m b/UI/Scheduler/UIxCalendarSelector.m index 6194b2769..e973f06f9 100644 --- a/UI/Scheduler/UIxCalendarSelector.m +++ b/UI/Scheduler/UIxCalendarSelector.m @@ -1,6 +1,6 @@ /* UIxCalendarSelector.m - this file is part of SOGo * - * Copyright (C) 2007-2015 Inverse inc. + * Copyright (C) 2007-2016 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #import #import +#import #import #import @@ -89,26 +90,77 @@ _intValueFromHex (NSString *hexString) - (NSArray *) calendars { - NSMutableDictionary *calendar, *notifications, *urls, *acls; - NSString *userLogin, *folderName, *fDisplayName, *owner; + BOOL objectCreator, objectEraser, reloadOnLogin, synchronize, dirty; + NSArray *folders, *allACLs; + NSMutableArray *sortedFolders, *sortedFolderNames; + NSMutableDictionary *moduleSettings, *calendar, *notifications, *urls, *acls; NSNumber *isActive, *fActiveTasks; + NSString *userLogin, *folderName, *fDisplayName, *owner; + NSUInteger count, index, max; SOGoAppointmentFolder *folder; SOGoAppointmentFolders *co; - NSArray *folders, *allACLs; + SOGoUser *activeUser; + SOGoUserSettings *us; - BOOL objectCreator, objectEraser, reloadOnLogin, synchronize; - NSUInteger count, max; - if (!calendars) { co = [self clientObject]; - userLogin = [[context activeUser] login]; + activeUser = [context activeUser]; + userLogin = [activeUser login]; folders = [co subFolders]; + + // Sort calendars according to user settings + dirty = NO; + us = [activeUser userSettings]; + moduleSettings = [us objectForKey: [co nameInContainer]]; + sortedFolders = [NSMutableArray arrayWithArray: [moduleSettings objectForKey: @"FoldersOrder"]]; + + max = [folders count]; + for (count = 0; count < max; count++) + { + folder = [folders objectAtIndex: count]; + folderName = [folder nameInContainer]; + index = [sortedFolders indexOfObject: folderName]; + if (index == NSNotFound) + { + // Calendar is missing from user's "FoldersOrder" setting; add it + dirty = YES; + [sortedFolders addObject: folder]; + } + else + [sortedFolders replaceObjectAtIndex: index withObject: folder]; + } + + max = [sortedFolders count]; + sortedFolderNames = [NSMutableArray arrayWithCapacity: max]; + for (count = max; count > -1; count--) + { + if ([[sortedFolders objectAtIndex: count] isKindOfClass: [NSString class]]) + { + // Calendar no longer exists; remove it from user's "FoldersOrder" setting + dirty = YES; + [sortedFolders removeObjectAtIndex: count]; + } + else + { + folder = [sortedFolders objectAtIndex: count]; + folderName = [folder nameInContainer]; + [sortedFolderNames addObject: folderName]; + } + } + + if (dirty) + { + // Synchronize user's settings + [moduleSettings setObject: sortedFolderNames forKey: @"FoldersOrder"]; + [us synchronize]; + } + max = [folders count]; calendars = [[NSMutableArray alloc] initWithCapacity: max]; for (count = 0; count < max; count++) { - folder = [folders objectAtIndex: count]; + folder = [sortedFolders objectAtIndex: count]; owner = [folder ownerInContext: context]; calendar = [NSMutableDictionary dictionary]; folderName = [folder nameInContainer]; @@ -195,7 +247,7 @@ _intValueFromHex (NSString *hexString) [calendars addObject: calendar]; } - } + } return calendars; } diff --git a/UI/Scheduler/product.plist b/UI/Scheduler/product.plist index eed817146..fe98cd9ab 100644 --- a/UI/Scheduler/product.plist +++ b/UI/Scheduler/product.plist @@ -65,6 +65,11 @@ pageName = "UIxCalMainView"; actionName = "saveListState"; }; + saveFoldersOrder = { + protectedBy = "View"; + pageName = "UIxCalMainView"; + actionName = "saveFoldersOrder"; + }; dateselector = { protectedBy = "View"; pageName = "UIxCalDateSelector";