Improved preferences module (save/load, checks on enabled modules, etc.)
parent
48b74b0f6b
commit
2bc44dec9b
|
@ -35,25 +35,28 @@
|
|||
|
||||
@implementation UIxJSONPreferences
|
||||
|
||||
- (WOResponse *) _makeResponse: (SOGoUserProfile *) profile
|
||||
- (WOResponse *) _makeResponse: (NSDictionary *) values
|
||||
{
|
||||
WOResponse *response;
|
||||
|
||||
response = [context response];
|
||||
[response setHeader: @"text/plain; charset=utf-8"
|
||||
forKey: @"content-type"];
|
||||
[response appendContentString: [profile jsonRepresentation]];
|
||||
[response appendContentString: [values jsonRepresentation]];
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- (WOResponse *) jsonDefaultsAction
|
||||
{
|
||||
NSMutableDictionary *values;
|
||||
SOGoUserDefaults *defaults;
|
||||
NSArray *categoryLabels;
|
||||
|
||||
BOOL dirty;
|
||||
|
||||
defaults = [[context activeUser] userDefaults];
|
||||
|
||||
dirty = NO;
|
||||
|
||||
if (![[defaults source] objectForKey: @"SOGoLongDateFormat"])
|
||||
[[defaults source] setObject: @"default" forKey: @"SOGoLongDateFormat"];
|
||||
|
||||
|
@ -65,6 +68,7 @@
|
|||
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
|
||||
|
||||
[defaults setCalendarCategories: categoryLabels];
|
||||
dirty = YES;
|
||||
}
|
||||
|
||||
// Populate default contact categories, based on the user's preferred language
|
||||
|
@ -78,6 +82,7 @@
|
|||
categoryLabels = [NSArray array];
|
||||
|
||||
[defaults setContactsCategories: categoryLabels];
|
||||
dirty = YES;
|
||||
}
|
||||
|
||||
// Populate default mail lablels, based on the user's preferred language
|
||||
|
@ -90,12 +95,19 @@
|
|||
// TODO - translate + refactor to not pass self since it's not a component
|
||||
//[defaults setMailLabelsColors: [SOGoMailLabel labelsFromDefaults: v component: self]];
|
||||
[defaults setMailLabelsColors: v];
|
||||
dirty = YES;
|
||||
}
|
||||
|
||||
|
||||
[defaults synchronize];
|
||||
|
||||
return [self _makeResponse: [defaults source]];
|
||||
if (dirty)
|
||||
[defaults synchronize];
|
||||
|
||||
// We inject our default mail account, something we don't want to do before we
|
||||
// call -synchronize on our defaults.
|
||||
values = [[[[defaults source] values] mutableCopy] autorelease];
|
||||
[[values objectForKey: @"AuxiliaryMailAccounts"] insertObject: [[[context activeUser] mailAccounts] objectAtIndex: 0]
|
||||
atIndex: 0];
|
||||
|
||||
return [self _makeResponse: values];
|
||||
}
|
||||
|
||||
- (WOResponse *) jsonSettingsAction
|
||||
|
@ -104,7 +116,7 @@
|
|||
|
||||
settings = [[context activeUser] userSettings];
|
||||
|
||||
return [self _makeResponse: [settings source]];
|
||||
return [self _makeResponse: [[settings source] values]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1746,7 +1746,12 @@ static NSArray *reminderValues = nil;
|
|||
return [[user domainDefaults] mailAuxiliaryUserAccountsEnabled];
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (void) _extractMainIdentity: (NSDictionary *) identity
|
||||
inDictionary: (NSMutableDictionary *) target
|
||||
|
||||
{
|
||||
/* We perform some validation here as we have no guaranty on the input
|
||||
validity. */
|
||||
|
@ -1755,9 +1760,11 @@ static NSArray *reminderValues = nil;
|
|||
if ([identity isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
value = [identity objectForKey: @"signature"];
|
||||
if (!value)
|
||||
value = @"";
|
||||
[userDefaults setMailSignature: value];
|
||||
|
||||
if (value)
|
||||
[target setObject: value forKey: @"SOGoMailSignature"];
|
||||
else
|
||||
[target removeObjectForKey: @"SOGoMailSignature"];
|
||||
|
||||
if (mailCustomFromEnabled)
|
||||
{
|
||||
|
@ -1769,22 +1776,37 @@ static NSArray *reminderValues = nil;
|
|||
if ([value length] == 0
|
||||
|| [[user allEmails] containsObject: value])
|
||||
value = nil;
|
||||
[userDefaults setMailCustomEmail: value];
|
||||
|
||||
if (value)
|
||||
[target setObject: value forKey: @"SOGoMailCustomEmail"];
|
||||
else
|
||||
[target removeObjectForKey: @"SOGoMailCustomEmail"];
|
||||
|
||||
value = [[identity objectForKey: @"fullName"]
|
||||
stringByTrimmingSpaces];
|
||||
if ([value length] == 0
|
||||
|| [[user cn] isEqualToString: value])
|
||||
value = nil;
|
||||
[userDefaults setMailCustomFullName: value];
|
||||
|
||||
if (value)
|
||||
[target setObject: value forKey: @"SOGoMailCustomFullName"];
|
||||
else
|
||||
[target removeObjectForKey: @"SOGoMailCustomFullName"];
|
||||
}
|
||||
|
||||
value = [[identity objectForKey: @"replyTo"]
|
||||
stringByTrimmingSpaces];
|
||||
[userDefaults setMailReplyTo: value];
|
||||
|
||||
if (value && [value length] > 0)
|
||||
[target setObject: value forKey: @"SOGoMailReplyTo"];
|
||||
else
|
||||
[target removeObjectForKey: @"SOGoMailReplyTo"];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (BOOL) _validateReceiptAction: (NSString *) action
|
||||
{
|
||||
return ([action isKindOfClass: [NSString class]]
|
||||
|
@ -1793,7 +1815,12 @@ static NSArray *reminderValues = nil;
|
|||
|| [action isEqualToString: @"ask"]));
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (void) _extractMainReceiptsPreferences: (NSDictionary *) receipts
|
||||
inDictionary: (NSMutableDictionary *) target
|
||||
|
||||
{
|
||||
/* We perform some validation here as we have no guaranty on the input
|
||||
validity. */
|
||||
|
@ -1802,31 +1829,39 @@ static NSArray *reminderValues = nil;
|
|||
if ([receipts isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
action = [receipts objectForKey: @"receiptAction"];
|
||||
[userDefaults
|
||||
setAllowUserReceipt: [action isEqualToString: @"allow"]];
|
||||
[target setObject: @"1" forKey: @"SOGoMailReceiptAllow"];
|
||||
|
||||
action = [receipts objectForKey: @"receiptNonRecipientAction"];
|
||||
if ([self _validateReceiptAction: action])
|
||||
[userDefaults setUserReceiptNonRecipientAction: action];
|
||||
|
||||
[target setObject: action forKey: @"SOGoMailReceiptNonRecipientAction"];
|
||||
|
||||
action = [receipts objectForKey: @"receiptOutsideDomainAction"];
|
||||
if ([self _validateReceiptAction: action])
|
||||
[userDefaults setUserReceiptOutsideDomainAction: action];
|
||||
|
||||
[target setObject: action forKey: @"SOGoMailReceiptOutsideDomainAction"];
|
||||
|
||||
action = [receipts objectForKey: @"receiptAnyAction"];
|
||||
if ([self _validateReceiptAction: action])
|
||||
[userDefaults setUserReceiptAnyAction: action];
|
||||
[target setObject: action forKey: @"SOGoMailReceiptAnyAction"];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (void) _extractMainCustomFrom: (NSDictionary *) account
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (void) _extractMainReplyTo: (NSDictionary *) account
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (BOOL) _validateAccountIdentities: (NSArray *) identities
|
||||
{
|
||||
static NSString *identityKeys[] = { @"fullName", @"email", nil };
|
||||
|
@ -1880,6 +1915,9 @@ static NSArray *reminderValues = nil;
|
|||
return valid;
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (BOOL) _validateAccount: (NSDictionary *) account
|
||||
{
|
||||
static NSString *accountKeys[] = { @"name", @"serverName", @"userName",
|
||||
|
@ -1934,7 +1972,11 @@ static NSArray *reminderValues = nil;
|
|||
return valid;
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (void) _extractMainAccountSettings: (NSDictionary *) account
|
||||
inDictionary: (NSMutableDictionary *) target
|
||||
{
|
||||
NSArray *identities;
|
||||
|
||||
|
@ -1943,12 +1985,15 @@ static NSArray *reminderValues = nil;
|
|||
identities = [account objectForKey: @"identities"];
|
||||
if ([identities isKindOfClass: [NSArray class]]
|
||||
&& [identities count] > 0)
|
||||
[self _extractMainIdentity: [identities objectAtIndex: 0]];
|
||||
[self _extractMainReceiptsPreferences: [account objectForKey: @"receipts"]];
|
||||
[self _extractMainIdentity: [identities objectAtIndex: 0] inDictionary: target];
|
||||
[self _extractMainReceiptsPreferences: [account objectForKey: @"receipts"] inDictionary: target];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _extractAuxiliaryAccounts: (NSArray *) accounts
|
||||
//
|
||||
// Used internally
|
||||
//
|
||||
- (NSArray *) _extractAuxiliaryAccounts: (NSArray *) accounts
|
||||
{
|
||||
int count, max, oldMax;
|
||||
NSArray *oldAccounts;
|
||||
|
@ -1984,7 +2029,7 @@ static NSArray *reminderValues = nil;
|
|||
}
|
||||
}
|
||||
|
||||
[userDefaults setAuxiliaryMailAccounts: auxAccounts];
|
||||
return auxAccounts;
|
||||
}
|
||||
|
||||
// - (void) setMailAccounts: (NSString *) newMailAccounts
|
||||
|
@ -2027,6 +2072,9 @@ static NSArray *reminderValues = nil;
|
|||
return (mailCustomFromEnabled ? @"true" : @"false");
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (id <WOActionResults>) saveAction
|
||||
{
|
||||
id o, v;
|
||||
|
@ -2037,8 +2085,8 @@ static NSArray *reminderValues = nil;
|
|||
if ((v = [o objectForKey: @"defaults"]))
|
||||
{
|
||||
NSMutableDictionary *sanitizedLabels;
|
||||
NSArray *allKeys, *accounts;
|
||||
NSDictionary *newLabels;
|
||||
NSArray *allKeys;
|
||||
NSString *name;
|
||||
int i;
|
||||
|
||||
|
@ -2068,6 +2116,22 @@ static NSArray *reminderValues = nil;
|
|||
[v setObject: sanitizedLabels forKey: @"SOGoMailLabelsColors"];
|
||||
}
|
||||
|
||||
// We sanitize our auxilary mail accounts
|
||||
accounts = [v objectForKey: @"AuxiliaryMailAccounts"];
|
||||
if (accounts && [accounts isKindOfClass: [NSArray class]])
|
||||
{
|
||||
if ([accounts count] > 0)
|
||||
{
|
||||
[self _extractMainAccountSettings: [accounts objectAtIndex: 0] inDictionary: v];
|
||||
if ([self mailAuxiliaryUserAccountsEnabled])
|
||||
accounts = [self _extractAuxiliaryAccounts: accounts];
|
||||
else
|
||||
accounts = [NSArray array];
|
||||
|
||||
[v setObject: accounts forKey: @"AuxiliaryMailAccounts"];
|
||||
}
|
||||
}
|
||||
|
||||
[[[user userDefaults] source] setValues: v];
|
||||
[[user userDefaults] synchronize];
|
||||
}
|
||||
|
|
|
@ -669,21 +669,22 @@
|
|||
|
||||
|
||||
<!-- MAIL > FILTERS -->
|
||||
<md-tab id="mailFiltersTab"
|
||||
aria-controls="mailFiltersTab-content"
|
||||
label:label="Filters">
|
||||
<div role="tabpanel" aria-labelledby="mailFiltersView"
|
||||
id="mailFiltersView-content">
|
||||
|
||||
<md-list>
|
||||
<var:if condition="isSieveScriptsEnabled">
|
||||
<md-tab id="mailFiltersTab"
|
||||
aria-controls="mailFiltersTab-content"
|
||||
label:label="Filters">
|
||||
<div role="tabpanel" aria-labelledby="mailFiltersView"
|
||||
id="mailFiltersView-content">
|
||||
|
||||
<md-list>
|
||||
<md-item ng-repeat="item in
|
||||
preferences.defaults.SOGoSieveFilters
|
||||
track by $index">
|
||||
<md-item-content>
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.SOGoSieveFilters[$index].active"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<!-- active or not-->
|
||||
</md-checkbox>
|
||||
<md-input-container>
|
||||
|
@ -705,8 +706,9 @@
|
|||
<div class="md-icon-add"><!-- create --></div>
|
||||
</md-button>
|
||||
</div>
|
||||
</div>
|
||||
</md-tab>
|
||||
</div>
|
||||
</md-tab>
|
||||
</var:if>
|
||||
<!-- END OF MAIL > FILTERS -->
|
||||
|
||||
<!-- MAIL > LABELS -->
|
||||
|
@ -748,112 +750,119 @@
|
|||
track by $index">
|
||||
<md-item-content>
|
||||
<md-input-container>
|
||||
<input type="text" ng-model="preferences.defaults.AuxiliaryMailAccounts[$index].name"/>
|
||||
<input type="text"
|
||||
ng-model="preferences.defaults.AuxiliaryMailAccounts[$index].name"
|
||||
ng-readonly="$index == 0"/>
|
||||
</md-input-container>
|
||||
<md-button ng-click="editMailAccount($index)" type="button">
|
||||
<div class="md-icon-edit md-icon-lg"><!-- edit --></div>
|
||||
</md-button>
|
||||
<md-button ng-click="removeMailAccount()" type="button">
|
||||
<md-button ng-click="removeMailAccount()"
|
||||
ng-show="$index > 0" type="button">
|
||||
<div class="md-icon-remove md-icon-lg"><!-- delete --></div>
|
||||
</md-button>
|
||||
</md-item-content>
|
||||
</md-item>
|
||||
</md-list>
|
||||
|
||||
<div class="bottomToolbar">
|
||||
<md-button ng-click="addMailAccount()" type="button">
|
||||
<div class="md-icon-add"><!-- create --></div>
|
||||
</md-button>
|
||||
</div>
|
||||
|
||||
<var:if condition="mailAuxiliaryUserAccountsEnabled">
|
||||
<div class="bottomToolbar">
|
||||
<md-button ng-click="addMailAccount()" type="button">
|
||||
<div class="md-icon-add"><!-- create --></div>
|
||||
</md-button>
|
||||
</div>
|
||||
</var:if>
|
||||
|
||||
</md-tab>
|
||||
<!-- END OF MAIL > ACCOUNTS -->
|
||||
|
||||
|
||||
<!-- MAIL > VACATION -->
|
||||
<md-tab id="mailVacationTab" aria-controls="mailVacationTab-content" label:label="Vacation">
|
||||
<div role="tabpanel" aria-labelledby="mailVacationView" id="mailVacationView-content">
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.enabled"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Enable vacation auto reply"/>
|
||||
</md-checkbox>
|
||||
|
||||
|
||||
<div>
|
||||
<label><var:string label:value="Auto reply message :"/>
|
||||
<textarea const:name="autoReplyText"
|
||||
const:id="autoReplyText"
|
||||
ng-model="preferences.defaults.Vacation.autoReplyText"/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<!-- <script>
|
||||
var defaultEmailAddresses = <var:string value="defaultEmailAddresses" const:escapeHTML="NO"/>;
|
||||
</script> -->
|
||||
<label><var:string label:value="Email addresses (separated by commas) :"/></label><br/>
|
||||
<textarea const:name="autoReplyEmailAddresses"
|
||||
const:id="autoReplyEmailAddresses"
|
||||
ng-model="preferences.defaults.Vacation.autoReplyEmailAddresses"/><br/>
|
||||
<md-button>
|
||||
<var:string label:value="Add default email addresses" type="button"/>
|
||||
</md-button>
|
||||
</div>
|
||||
|
||||
<div layout="row" layout-align="space-around center">
|
||||
<div><var:string label:value="Days between responses :"/></div>
|
||||
<div>
|
||||
<md-select ng-model="preferences.defaults.Vacation.daysBetweenResponse">
|
||||
<var:foreach list="daysBetweenResponsesList" item="item">
|
||||
<md-option var:value="item">
|
||||
<var:string value="item"/>
|
||||
</md-option>
|
||||
</var:foreach>
|
||||
</md-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.ignoreLists"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Do not send responses to mailing lists" />
|
||||
</md-checkbox>
|
||||
|
||||
<div layout="row" layout-align="space-around center">
|
||||
<var:if condition="isVacationEnabled">
|
||||
<md-tab id="mailVacationTab" aria-controls="mailVacationTab-content" label:label="Vacation">
|
||||
<div role="tabpanel" aria-labelledby="mailVacationView" id="mailVacationView-content">
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.endDateEnabled"
|
||||
ng-model="preferences.defaults.Vacation.enabled"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Disable auto reply on" />
|
||||
<var:string label:value="Enable vacation auto reply"/>
|
||||
</md-checkbox>
|
||||
|
||||
<div class="value">
|
||||
<p class="PseudoField-inputLike--underline">
|
||||
<input type="date" ng-model="preferences.defaults.Vacation.endDate"/>
|
||||
</p>
|
||||
|
||||
|
||||
<div>
|
||||
<label><var:string label:value="Auto reply message :"/>
|
||||
<textarea const:name="autoReplyText"
|
||||
const:id="autoReplyText"
|
||||
ng-model="preferences.defaults.Vacation.autoReplyText"/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<!-- <script>
|
||||
var defaultEmailAddresses = <var:string value="defaultEmailAddresses" const:escapeHTML="NO"/>;
|
||||
</script> -->
|
||||
<label><var:string label:value="Email addresses (separated by commas) :"/></label><br/>
|
||||
<textarea const:name="autoReplyEmailAddresses"
|
||||
const:id="autoReplyEmailAddresses"
|
||||
ng-model="preferences.defaults.Vacation.autoReplyEmailAddresses"/><br/>
|
||||
<md-button>
|
||||
<var:string label:value="Add default email addresses" type="button"/>
|
||||
</md-button>
|
||||
</div>
|
||||
|
||||
<div layout="row" layout-align="space-around center">
|
||||
<div><var:string label:value="Days between responses :"/></div>
|
||||
<div>
|
||||
<md-select ng-model="preferences.defaults.Vacation.daysBetweenResponse">
|
||||
<var:foreach list="daysBetweenResponsesList" item="item">
|
||||
<md-option var:value="item">
|
||||
<var:string value="item"/>
|
||||
</md-option>
|
||||
</var:foreach>
|
||||
</md-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.ignoreLists"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Do not send responses to mailing lists" />
|
||||
</md-checkbox>
|
||||
|
||||
<div layout="row" layout-align="space-around center">
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.endDateEnabled"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Disable auto reply on" />
|
||||
</md-checkbox>
|
||||
|
||||
<div class="value">
|
||||
<p class="PseudoField-inputLike--underline">
|
||||
<input type="date" ng-model="preferences.defaults.Vacation.endDate"/>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.alwaysSend"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Always send vacation message response"/>
|
||||
</md-checkbox>
|
||||
|
||||
</div>
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Vacation.alwaysSend"
|
||||
ng-true-value="1"
|
||||
ng-false-value="0">
|
||||
<var:string label:value="Always send vacation message response"/>
|
||||
</md-checkbox>
|
||||
|
||||
</div>
|
||||
</md-tab>
|
||||
</md-tab>
|
||||
</var:if>
|
||||
<!-- END OF MAIL > VACATION -->
|
||||
|
||||
|
||||
<!-- MAIL > FORWARD -->
|
||||
<md-tab id="mailForwardTab" aria-controls="mailForwardTab-content" label:label="Forward">
|
||||
<div role="tabpanel" aria-labelledby="mailForwardView" id="mailForwardView-content">
|
||||
<var:if condition="isForwardEnabled">
|
||||
<var:if condition="isForwardEnabled">
|
||||
<md-tab id="mailForwardTab" aria-controls="mailForwardTab-content" label:label="Forward">
|
||||
<div role="tabpanel" aria-labelledby="mailForwardView" id="mailForwardView-content">
|
||||
<div id="forwardView" class="tab">
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Forward.enabled"
|
||||
|
@ -864,12 +873,12 @@
|
|||
|
||||
<div id="forward">
|
||||
<label><var:string label:value="Email addresses (separated by commas) :"/><br/>
|
||||
<textarea const:name="forwardAddress"
|
||||
const:id="forwardAddress"
|
||||
ng-model="preferences.defaults.Forward.forwardAddress" />
|
||||
<textarea const:name="forwardAddress"
|
||||
const:id="forwardAddress"
|
||||
ng-model="preferences.defaults.Forward.forwardAddress" />
|
||||
</label><br/>
|
||||
</div>
|
||||
|
||||
|
||||
<md-checkbox
|
||||
ng-model="preferences.defaults.Forward.keepCopy"
|
||||
ng-true-value="1"
|
||||
|
@ -882,9 +891,9 @@
|
|||
</script>
|
||||
|
||||
</div>
|
||||
</var:if>
|
||||
</div>
|
||||
</md-tab>
|
||||
</md-tab>
|
||||
</var:if>
|
||||
<!-- END OF MAIL > FORWARD -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue