summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js197
1 files changed, 197 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js b/frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js
new file mode 100644
index 0000000..dc73ce1
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/DataModel/UserPreferences.js
@@ -0,0 +1,197 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
32
33
34//#############################################################################
35
36Clipperz.PM.DataModel.UserPreferences = function(args) {
37 args = args || {};
38
39 this._user = args['user']; delete args['user'];
40 this._config = args;
41
42 return this;
43}
44
45Clipperz.PM.DataModel.UserPreferences.prototype = MochiKit.Base.update(null, {
46
47 //-------------------------------------------------------------------------
48
49 'config': function() {
50 return this._config;
51 },
52
53 //-------------------------------------------------------------------------
54
55 'user': function() {
56 return this._user;
57 },
58
59 //-------------------------------------------------------------------------
60
61 'updateWithData': function(someValues) {
62 var currentLanguage;
63
64//MochiKit.Logging.logDebug(">>> Clipperz.PM.DataModel.UserPreferences.updateWithData: " + Clipperz.Base.serializeJSON(someValues));
65 currentLanguage = this.preferredLanguage();
66
67 MochiKit.Base.update(this._config, someValues);
68
69 if (this.preferredLanguage() != currentLanguage) {
70 Clipperz.PM.Strings.Languages.setSelectedLanguage(this.preferredLanguage());
71 } else {
72//MochiKit.Logging.logDebug("### keepping the browser selected language: " + Clipperz.PM.Strings.selectedLanguage);
73 }
74
75 return this;
76 },
77
78 //-------------------------------------------------------------------------
79
80 'configValue': function(aConfigName, aDefaultValue) {
81 var result;
82
83//MochiKit.Logging.logDebug(">>> UserPreferences.configValue - config: " + Clipperz.Base.serializeJSON(this.config()));
84 if (typeof(this.config()[aConfigName]) == 'undefined') {
85 result = aDefaultValue;
86 } else {
87 result = this.config()[aConfigName];
88 }
89//MochiKit.Logging.logDebug("<<< UserPreferences.configValue");
90
91 return result;
92 },
93
94 'setConfigValue': function(aConfigName, aValue) {
95 var result;
96
97 if (aValue != this.configValue(aConfigName)) {
98 if (aValue == null) {
99 delete this.config()[aConfigName]
100 } else {
101 this.config()[aConfigName] = aValue;
102 }
103
104 Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'preferences', true);
105
106 result = true;
107 } else {
108 result = false;
109 }
110
111 return result;
112 },
113
114 //-------------------------------------------------------------------------
115
116 'useSafeEditMode': function() {
117 return this.configValue('useSafeEditMode', true);
118 },
119
120 'setUseSafeEditMode': function(aValue) {
121 this.setConfigValue('useSafeEditMode', aValue);
122 },
123
124 //-------------------------------------------------------------------------
125
126 'preferredLanguage': function() {
127 return this.configValue('preferredLanguage', null);
128 },
129
130 'setPreferredLanguage': function(aValue) {
131 if (this.setConfigValue('preferredLanguage', aValue)) {
132 Clipperz.PM.Strings.Languages.setSelectedLanguage(this.preferredLanguage());
133 }
134 },
135
136 //-------------------------------------------------------------------------
137
138 'shouldShowDonationPanel': function() {
139 return this.configValue('shouldShowDonationPanel', true);
140 },
141
142 'setShouldShowDonationPanel': function(aValue) {
143 this.setConfigValue('shouldShowDonationPanel', aValue);
144 },
145
146 //-------------------------------------------------------------------------
147
148 'disableUnsecureFaviconLoadingForIE': function() {
149 return this.configValue('disableUnsecureFaviconLoadingForIE', false);
150 },
151
152 'setDisableUnsecureFaviconLoadingForIE': function(aValue) {
153 this.setConfigValue('disableUnsecureFaviconLoadingForIE', aValue);
154 },
155
156 //-------------------------------------------------------------------------
157
158 'serializedData': function() {
159 return this.config();
160 },
161
162 //-------------------------------------------------------------------------
163
164 'saveChanges': function(aReferenceElement) {
165 vardeferredResult;
166
167 deferredResult = new MochiKit.Async.Deferred();
168
169 deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Components.MessageBox(), 'deferredShow'),
170 {
171 title:"", //Clipperz.PM.Strings['accountPreferencesSavingPanelTitle_Step1'],
172 text:"", //Clipperz.PM.Strings['accountPreferencesSavingPanelText_Step1'],
173 width:240,
174 showProgressBar:true,
175 showCloseButton:false
176 },
177 aReferenceElement
178 );
179 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'account_savingPreferences_1');
180 deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData'));
181 deferredResult.addCallback(function(res) {
182 return {user:res};
183 })
184 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'account_savingPreferences_2');
185 deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData');
186 deferredResult.addCallback(Clipperz.PM.Components.MessageBox().hide, YAHOO.ext.Element.get('main'));
187 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedPreferences', null);
188
189 deferredResult.callback();
190
191 return deferredResult;
192 },
193
194 //-------------------------------------------------------------------------
195 __syntaxFix__: "syntax fix"
196});
197