From 96d2a4cea8b40255b86905ad8188a3b8bd7042fd Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sat, 21 Mar 2015 15:34:18 -0400 Subject: [PATCH] Preferences saving support --- SoObjects/SOGo/SOGoDefaultsSource.h | 4 +-- SoObjects/SOGo/SOGoDefaultsSource.m | 4 +-- SoObjects/SOGo/SOGoUserDefaults.m | 2 +- UI/PreferencesUI/UIxPreferences.h | 4 +-- UI/PreferencesUI/UIxPreferences.m | 27 ++++++++++++------- .../js/Preferences/preferences-model.js | 17 +++++++----- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/SoObjects/SOGo/SOGoDefaultsSource.h b/SoObjects/SOGo/SOGoDefaultsSource.h index 741293950..d887efd12 100644 --- a/SoObjects/SOGo/SOGoDefaultsSource.h +++ b/SoObjects/SOGo/SOGoDefaultsSource.h @@ -1,8 +1,6 @@ /* SOGoDefaultsSource.h - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2009-2015 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 diff --git a/SoObjects/SOGo/SOGoDefaultsSource.m b/SoObjects/SOGo/SOGoDefaultsSource.m index 15ce69b67..6074ea420 100644 --- a/SoObjects/SOGo/SOGoDefaultsSource.m +++ b/SoObjects/SOGo/SOGoDefaultsSource.m @@ -1,8 +1,6 @@ /* SOGoDefaultsSource.m - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2009-2015 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 diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 9cc4b38e2..c0062ac18 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -1,6 +1,6 @@ /* SOGoUserDefaults.m - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2015 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 diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 51607c9a1..f46680482 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -1,6 +1,6 @@ /* UIxPreferences.h - this file is part of SOGo * - * Copyright (C) 2007-2013 Inverse inc. + * Copyright (C) 2007-2015 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 @@ -61,7 +61,7 @@ } -- (NSString *) userLongDateFormat; +//- (NSString *) userLongDateFormat; - (BOOL) isSieveServerAvailable; - (id) sieveClient; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index fc24b198c..7a6ccc341 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -58,14 +58,6 @@ #import "UIxPreferences.h" -#warning this class is not finished -/* remaining: - default event length - default snooze length - refresh calendar every X minutes - workweek = from -> to - identities */ - static NSArray *reminderItems = nil; static NSArray *reminderValues = nil; @@ -1889,7 +1881,24 @@ static NSArray *reminderValues = nil; - (id ) saveAction { - //return [self responseWithStatus: 200 andJSONRepresentation: data]; + SOGoUser *user; + id o, v; + + o = [[[context request] contentAsString] objectFromJSONString]; + user = [[self context] activeUser]; + + if ((v = [o objectForKey: @"defaults"])) + { + [[[user userDefaults] source] setValues: v]; + [[user userDefaults] synchronize]; + } + + if ((v = [o objectForKey: @"settings"])) + { + [[[user userSettings] source] setValues: v]; + [[user userSettings] synchronize]; + } + return [self responseWithStatus: 200]; } diff --git a/UI/WebServerResources/js/Preferences/preferences-model.js b/UI/WebServerResources/js/Preferences/preferences-model.js index 8f888bcba..6ff38a2b4 100644 --- a/UI/WebServerResources/js/Preferences/preferences-model.js +++ b/UI/WebServerResources/js/Preferences/preferences-model.js @@ -88,18 +88,23 @@ Preferences.prototype.$omit = function(deep) { var preferences = {}; angular.forEach(this, function(value, key) { - if (key == 'refs') { - preferences.refs = _.map(value, function(o) { - return o.$omit(deep); - }); - } - else if (key != 'constructor' && key[0] != '$') { + if (key != 'constructor' && key[0] != '$') { if (deep) preferences[key] = angular.copy(value); else preferences[key] = value; } }); + + // We swap _$key -> $key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266) + var labels = _.object(_.map(preferences.defaults.SOGoMailLabelsColors, function(value, key) { + if (key.charAt(0) == '_' && key.charAt(1) == '$') + return [key.substring(1), value]; + return [key, value]; + })); + + preferences.defaults.SOGoMailLabelsColors = labels; + return preferences; };