Skip to content

Commit

Permalink
feat(preferences): button to reset contacts categories to defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Jul 3, 2020
1 parent 9c49fae commit 76cbe78
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
15 changes: 9 additions & 6 deletions UI/PreferencesUI/UIxJSONPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#import <SOPE/NGCards/iCalRecurrenceRule.h>

#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSObject+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
Expand Down Expand Up @@ -299,14 +300,16 @@ - (NSString *) jsonDefaults
//
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:)];

if (!contactsCategories)
contactsCategories = [NSArray array];

[defaults setContactsCategories: categoryLabels];
[defaults setContactsCategories: contactsCategories];
}

if (![[defaults source] objectForKey: @"SOGoMailAddOutgoingAddresses"])
Expand Down
8 changes: 1 addition & 7 deletions UI/PreferencesUI/UIxPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@

// Addressbook
NSMutableDictionary *addressBooksIDWithDisplayName;

// Calendar categories
NSString *category;
NSArray *calendarCategories;
NSDictionary *calendarCategoriesColors;

NSArray *contactsCategories;

NSCalendarDate *today;

// Sieve filtering
Expand Down
25 changes: 17 additions & 8 deletions UI/PreferencesUI/UIxPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ - (id) init
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];
Expand Down Expand Up @@ -157,10 +153,6 @@ - (void) dealloc
[user release];
[sieveFilters release];
[vacationOptions release];
[calendarCategories release];
[calendarCategoriesColors release];
[category release];
[contactsCategories release];
[forwardOptions release];
[daysOfWeek release];
[addressBooksIDWithDisplayName release];
Expand Down Expand Up @@ -863,6 +855,23 @@ - (NSString *) defaultCalendarCategoriesColors
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
//
Expand Down
6 changes: 6 additions & 0 deletions UI/Templates/PreferencesUI/UIxPreferences.wox
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var timeZonesList = <var:string value="timeZonesList" const:escapeHTML="NO"/>;
var defaultEmailAddresses = <var:string value="defaultEmailAddresses" const:escapeHTML="NO"/>;
var defaultCalendarCategories = <var:string value="defaultCalendarCategoriesColors" const:escapeHTML="NO"/>;
var defaultContactsCategories = <var:string value="defaultContactsCategories" const:escapeHTML="NO"/>;
var forwardConstraints = <var:string value="forwardConstraints" const:escapeHTML="NO"/>;
var forwardConstraintsDomains = <var:string value="forwardConstraintsDomains" const:escapeHTML="NO"/>;
var sieveCapabilities = <var:string value="sieveCapabilities" const:escapeHTML="NO"/>;
Expand Down Expand Up @@ -545,6 +546,11 @@
</md-list>

<div layout="row" layout-align="end center">
<md-button type="button"
label:aria-label="Reset to defaults"
ng-click="app.resetContactsCategories(preferencesForm)">
<var:string label:value="Reset to defaults"/>
</md-button>
<md-button type="button"
label:aria-label="Add Contact Category"
ng-click="app.addContactCategory(preferencesForm)">
Expand Down
5 changes: 5 additions & 0 deletions UI/WebServerResources/js/Preferences/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 76cbe78

Please sign in to comment.