From 76cbe7854cf25d179e3d6df738f0c4b0c09838b9 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 3 Jul 2020 10:43:20 -0400 Subject: [PATCH] feat(preferences): button to reset contacts categories to defaults --- UI/PreferencesUI/UIxJSONPreferences.m | 15 ++++++----- UI/PreferencesUI/UIxPreferences.h | 8 +----- UI/PreferencesUI/UIxPreferences.m | 25 +++++++++++++------ UI/Templates/PreferencesUI/UIxPreferences.wox | 6 +++++ .../js/Preferences/PreferencesController.js | 5 ++++ 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index 83e5d8751..025d48233 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -29,6 +29,7 @@ #import +#import #import #import #import @@ -299,14 +300,16 @@ static SoProduct *preferencesProduct = nil; // if (![defaults contactsCategories]) { - categoryLabels = [[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]] - componentsSeparatedByString: @","] - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + NSArray *contactsCategories; - if (!categoryLabels) - categoryLabels = [NSArray array]; + contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]] + componentsSeparatedByString: @","] trimmedComponents] + sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; - [defaults setContactsCategories: categoryLabels]; + if (!contactsCategories) + contactsCategories = [NSArray array]; + + [defaults setContactsCategories: contactsCategories]; } if (![[defaults source] objectForKey: @"SOGoMailAddOutgoingAddresses"]) diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 361862dc5..d0de5593f 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -36,13 +36,7 @@ // Addressbook NSMutableDictionary *addressBooksIDWithDisplayName; - - // Calendar categories - NSString *category; - NSArray *calendarCategories; - NSDictionary *calendarCategoriesColors; - - NSArray *contactsCategories; + NSCalendarDate *today; // Sieve filtering diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 1206bcf48..07af33772 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -113,10 +113,6 @@ static NSArray *reminderValues = nil; referenceDate = [referenceDate addYear:0 month:0 day:(-[referenceDate dayOfMonth] + 1) hour:0 minute:0 second:0]; ASSIGN (today, referenceDate); - calendarCategories = nil; - calendarCategoriesColors = nil; - category = nil; - ASSIGN (daysOfWeek, [locale objectForKey: NSWeekDayNameArray]); dd = [user domainDefaults]; @@ -157,10 +153,6 @@ static NSArray *reminderValues = nil; [user release]; [sieveFilters release]; [vacationOptions release]; - [calendarCategories release]; - [calendarCategoriesColors release]; - [category release]; - [contactsCategories release]; [forwardOptions release]; [daysOfWeek release]; [addressBooksIDWithDisplayName release]; @@ -863,6 +855,23 @@ static NSArray *reminderValues = nil; return [defaultCategoriesColors jsonRepresentation]; } +// +// Used by templates +// +- (NSString *) defaultContactsCategories +{ + NSArray *contactsCategories; + + contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [self resourceManager]] + componentsSeparatedByString: @","] trimmedComponents] + sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + + if (!contactsCategories) + contactsCategories = [NSArray array]; + + return [contactsCategories jsonRepresentation]; +} + // // Used by templates // diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 297b04a68..bb60a9d3f 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -20,6 +20,7 @@ var timeZonesList = ; var defaultEmailAddresses = ; var defaultCalendarCategories = ; + var defaultContactsCategories = ; var forwardConstraints = ; var forwardConstraintsDomains = ; var sieveCapabilities = ; @@ -545,6 +546,11 @@
+ + + diff --git a/UI/WebServerResources/js/Preferences/PreferencesController.js b/UI/WebServerResources/js/Preferences/PreferencesController.js index a2037b3da..64bfa4a07 100644 --- a/UI/WebServerResources/js/Preferences/PreferencesController.js +++ b/UI/WebServerResources/js/Preferences/PreferencesController.js @@ -55,6 +55,11 @@ }); }; + this.resetContactsCategories = function(form) { + this.preferences.defaults.SOGoContactsCategories = $window.defaultContactsCategories; + form.$setDirty(); + }; + this.resetCalendarCategories = function(form) { this.preferences.defaults.SOGoCalendarCategories = _.keys($window.defaultCalendarCategories); this.preferences.defaults.SOGoCalendarCategoriesColorsValues = _.values($window.defaultCalendarCategories);