author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-06-16 07:22:01 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-06-16 07:22:01 (UTC) |
commit | 9ae34bd825e9390eedb1a8c9842b2515699dac99 (patch) (unidiff) | |
tree | f2efea0a967f890ce9235871fd26a96515596bc4 | |
parent | 36ff1deefcbbd24aceca97eb39a13f9da4af8ff5 (diff) | |
parent | 36b3236415b856ddd0ad2804e82e410b5240ff4f (diff) | |
download | clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.zip clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.tar.gz clipperz-9ae34bd825e9390eedb1a8c9842b2515699dac99.tar.bz2 |
Merge pull request #40 from jokajak/issue37
fix the cancel button for editing cards
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Record.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js index ffb45de..9e496de 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js | |||
@@ -1,680 +1,686 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 29 | ||
30 | 30 | ||
31 | //############################################################################# | 31 | //############################################################################# |
32 | 32 | ||
33 | Clipperz.PM.DataModel.Record = function(args) { | 33 | Clipperz.PM.DataModel.Record = function(args) { |
34 | args = args || {}; | 34 | args = args || {}; |
35 | 35 | ||
36 | this._user = args['user'] || null; | 36 | this._user = args['user'] || null; |
37 | this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); | 37 | this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); |
38 | this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 38 | this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
39 | this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); | 39 | this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); |
40 | 40 | ||
41 | this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); | 41 | this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); |
42 | 42 | ||
43 | this.setHeaderNotes(args['headerNotes'] || null); | 43 | this.setHeaderNotes(args['headerNotes'] || null); |
44 | this.setNotes(args['notes'] || args['headerNotes'] || ""); | 44 | this.setNotes(args['notes'] || args['headerNotes'] || ""); |
45 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); | 45 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); |
46 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); | 46 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); |
47 | //this._notes = args.notes || ""; | 47 | //this._notes = args.notes || ""; |
48 | 48 | ||
49 | this._versions = {}; | 49 | this._versions = {}; |
50 | this._directLogins = {}; | 50 | this._directLogins = {}; |
51 | this._removedDirectLogins = []; | 51 | this._removedDirectLogins = []; |
52 | 52 | ||
53 | this.setIsBrandNew(args['reference'] == null); | 53 | this.setIsBrandNew(args['reference'] == null); |
54 | 54 | ||
55 | this.setShouldLoadData(this.isBrandNew() ? false: true); | 55 | this.setShouldLoadData(this.isBrandNew() ? false: true); |
56 | this.setShouldDecryptData(this.isBrandNew() ? false: true); | 56 | this.setShouldDecryptData(this.isBrandNew() ? false: true); |
57 | this.setShouldProcessData(this.isBrandNew() ? false: true); | 57 | this.setShouldProcessData(this.isBrandNew() ? false: true); |
58 | 58 | ||
59 | this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); | 59 | this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); |
60 | this.setCurrentVersionKey(null); | 60 | this.setCurrentVersionKey(null); |
61 | 61 | ||
62 | this._serverData = null; | 62 | this._serverData = null; |
63 | this._decryptedData = null; | 63 | this._decryptedData = null; |
64 | this._cachedData = null; | 64 | this._cachedData = null; |
65 | 65 | ||
66 | return this; | 66 | return this; |
67 | } | 67 | } |
68 | 68 | ||
69 | Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { | 69 | Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { |
70 | 70 | ||
71 | 'toString': function() { | 71 | 'toString': function() { |
72 | return "Record (" + this.label() + ")"; | 72 | return "Record (" + this.label() + ")"; |
73 | }, | 73 | }, |
74 | 74 | ||
75 | //------------------------------------------------------------------------- | 75 | //------------------------------------------------------------------------- |
76 | 76 | ||
77 | 'isBrandNew': function() { | 77 | 'isBrandNew': function() { |
78 | return this._isBrandNew; | 78 | return this._isBrandNew; |
79 | }, | 79 | }, |
80 | 80 | ||
81 | 'setIsBrandNew': function(aValue) { | 81 | 'setIsBrandNew': function(aValue) { |
82 | this._isBrandNew = aValue; | 82 | this._isBrandNew = aValue; |
83 | }, | 83 | }, |
84 | 84 | ||
85 | //------------------------------------------------------------------------- | 85 | //------------------------------------------------------------------------- |
86 | /* | 86 | /* |
87 | 'shouldRunTheRecordCreationWizard': function() { | 87 | 'shouldRunTheRecordCreationWizard': function() { |
88 | return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); | 88 | return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); |
89 | }, | 89 | }, |
90 | */ | 90 | */ |
91 | //------------------------------------------------------------------------- | 91 | //------------------------------------------------------------------------- |
92 | 92 | ||
93 | 'user': function() { | 93 | 'user': function() { |
94 | return this._user; | 94 | return this._user; |
95 | }, | 95 | }, |
96 | 96 | ||
97 | //------------------------------------------------------------------------- | 97 | //------------------------------------------------------------------------- |
98 | 98 | ||
99 | 'reference': function() { | 99 | 'reference': function() { |
100 | return this._reference; | 100 | return this._reference; |
101 | }, | 101 | }, |
102 | 102 | ||
103 | //------------------------------------------------------------------------- | 103 | //------------------------------------------------------------------------- |
104 | 104 | ||
105 | 'key': function() { | 105 | 'key': function() { |
106 | return this._key; | 106 | return this._key; |
107 | }, | 107 | }, |
108 | 108 | ||
109 | 'updateKey': function() { | 109 | 'updateKey': function() { |
110 | this._key = Clipperz.PM.Crypto.randomKey(); | 110 | this._key = Clipperz.PM.Crypto.randomKey(); |
111 | }, | 111 | }, |
112 | 112 | ||
113 | //------------------------------------------------------------------------- | 113 | //------------------------------------------------------------------------- |
114 | 114 | ||
115 | 'label': function() { | 115 | 'label': function() { |
116 | return this._label; | 116 | return this._label; |
117 | }, | 117 | }, |
118 | 118 | ||
119 | 'setLabel': function(aValue) { | 119 | 'setLabel': function(aValue) { |
120 | this._label = aValue; | 120 | this._label = aValue; |
121 | }, | 121 | }, |
122 | 122 | ||
123 | 'lowerCaseLabel': function() { | 123 | 'lowerCaseLabel': function() { |
124 | return this.label().toLowerCase(); | 124 | return this.label().toLowerCase(); |
125 | }, | 125 | }, |
126 | 126 | ||
127 | //------------------------------------------------------------------------- | 127 | //------------------------------------------------------------------------- |
128 | 128 | ||
129 | 'versions': function() { | 129 | 'versions': function() { |
130 | return this._versions; | 130 | return this._versions; |
131 | }, | 131 | }, |
132 | 132 | ||
133 | //------------------------------------------------------------------------- | 133 | //------------------------------------------------------------------------- |
134 | 134 | ||
135 | 'currentVersion': function() { | 135 | 'currentVersion': function() { |
136 | return this._currentVersion; | 136 | return this._currentVersion; |
137 | }, | 137 | }, |
138 | 138 | ||
139 | 'setCurrentVersion': function(aValue) { | 139 | 'setCurrentVersion': function(aValue) { |
140 | this._currentVersion = aValue; | 140 | this._currentVersion = aValue; |
141 | }, | 141 | }, |
142 | 142 | ||
143 | //------------------------------------------------------------------------- | 143 | //------------------------------------------------------------------------- |
144 | 144 | ||
145 | 'currentVersionKey': function() { | 145 | 'currentVersionKey': function() { |
146 | return this._currentVersionKey; | 146 | return this._currentVersionKey; |
147 | }, | 147 | }, |
148 | 148 | ||
149 | 'setCurrentVersionKey': function(aValue) { | 149 | 'setCurrentVersionKey': function(aValue) { |
150 | this._currentVersionKey = aValue; | 150 | this._currentVersionKey = aValue; |
151 | }, | 151 | }, |
152 | 152 | ||
153 | //------------------------------------------------------------------------- | 153 | //------------------------------------------------------------------------- |
154 | 154 | ||
155 | 'deferredData': function() { | 155 | 'deferredData': function() { |
156 | vardeferredResult; | 156 | vardeferredResult; |
157 | 157 | ||
158 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); | 158 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); |
159 | deferredResult = new MochiKit.Async.Deferred(); | 159 | deferredResult = new MochiKit.Async.Deferred(); |
160 | deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); | 160 | deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); |
161 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); | 161 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); |
162 | deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); | 162 | deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); |
163 | deferredResult.addCallback(function(aRecord) { | 163 | deferredResult.addCallback(function(aRecord) { |
164 | return aRecord.currentVersion().deferredData(); | 164 | return aRecord.currentVersion().deferredData(); |
165 | }); | 165 | }); |
166 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); | 166 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); |
167 | deferredResult.addCallback(MochiKit.Async.succeed, this); | 167 | deferredResult.addCallback(MochiKit.Async.succeed, this); |
168 | deferredResult.callback(); | 168 | deferredResult.callback(); |
169 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); | 169 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); |
170 | 170 | ||
171 | return deferredResult; | 171 | return deferredResult; |
172 | }, | 172 | }, |
173 | 173 | ||
174 | //------------------------------------------------------------------------- | 174 | //------------------------------------------------------------------------- |
175 | 175 | ||
176 | 'exportedData': function() { | 176 | 'exportedData': function() { |
177 | var result; | 177 | var result; |
178 | 178 | ||
179 | result = {}; | 179 | result = {}; |
180 | result['label'] = this.label(); | 180 | result['label'] = this.label(); |
181 | result['data'] = this.serializedData(); | 181 | result['data'] = this.serializedData(); |
182 | result['currentVersion'] = this.currentVersion().serializedData(); | 182 | result['currentVersion'] = this.currentVersion().serializedData(); |
183 | result['currentVersion']['reference'] = this.currentVersion().reference(); | 183 | result['currentVersion']['reference'] = this.currentVersion().reference(); |
184 | // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); | 184 | // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); |
185 | 185 | ||
186 | return Clipperz.Base.serializeJSON(result); | 186 | return Clipperz.Base.serializeJSON(result); |
187 | }, | 187 | }, |
188 | 188 | ||
189 | //------------------------------------------------------------------------- | 189 | //------------------------------------------------------------------------- |
190 | 190 | ||
191 | 'shouldLoadData': function() { | 191 | 'shouldLoadData': function() { |
192 | return this._shouldLoadData; | 192 | return this._shouldLoadData; |
193 | }, | 193 | }, |
194 | 194 | ||
195 | 'setShouldLoadData': function(aValue) { | 195 | 'setShouldLoadData': function(aValue) { |
196 | this._shouldLoadData = aValue; | 196 | this._shouldLoadData = aValue; |
197 | }, | 197 | }, |
198 | 198 | ||
199 | //------------------------------------------------------------------------- | 199 | //------------------------------------------------------------------------- |
200 | 200 | ||
201 | 'shouldDecryptData': function() { | 201 | 'shouldDecryptData': function() { |
202 | return this._shouldDecryptData; | 202 | return this._shouldDecryptData; |
203 | }, | 203 | }, |
204 | 204 | ||
205 | 'setShouldDecryptData': function(aValue) { | 205 | 'setShouldDecryptData': function(aValue) { |
206 | this._shouldDecryptData = aValue; | 206 | this._shouldDecryptData = aValue; |
207 | }, | 207 | }, |
208 | 208 | ||
209 | //------------------------------------------------------------------------- | 209 | //------------------------------------------------------------------------- |
210 | 210 | ||
211 | 'shouldProcessData': function() { | 211 | 'shouldProcessData': function() { |
212 | return this._shouldProcessData; | 212 | return this._shouldProcessData; |
213 | }, | 213 | }, |
214 | 214 | ||
215 | 'setShouldProcessData': function(aValue) { | 215 | 'setShouldProcessData': function(aValue) { |
216 | this._shouldProcessData = aValue; | 216 | this._shouldProcessData = aValue; |
217 | }, | 217 | }, |
218 | 218 | ||
219 | //------------------------------------------------------------------------- | 219 | //------------------------------------------------------------------------- |
220 | 220 | ||
221 | 'loadData': function() { | 221 | 'loadData': function() { |
222 | var result; | 222 | var result; |
223 | 223 | ||
224 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); | 224 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); |
225 | if (this.shouldLoadData()) { | 225 | if (this.shouldLoadData()) { |
226 | var deferredResult; | 226 | var deferredResult; |
227 | 227 | ||
228 | deferredResult = new MochiKit.Async.Deferred(); | 228 | deferredResult = new MochiKit.Async.Deferred(); |
229 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); | 229 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); |
230 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); | 230 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); |
231 | deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); | 231 | deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); |
232 | deferredResult.callback(); | 232 | deferredResult.callback(); |
233 | result = deferredResult; | 233 | result = deferredResult; |
234 | } else { | 234 | } else { |
235 | result = MochiKit.Async.succeed(this.serverData()); | 235 | result = MochiKit.Async.succeed(this.serverData()); |
236 | } | 236 | } |
237 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); | 237 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); |
238 | 238 | ||
239 | return result; | 239 | return result; |
240 | }, | 240 | }, |
241 | 241 | ||
242 | //------------------------------------------------------------------------- | 242 | //------------------------------------------------------------------------- |
243 | 243 | ||
244 | 'decryptData': function(anEncryptedData) { | 244 | 'decryptData': function(anEncryptedData) { |
245 | var result; | 245 | var result; |
246 | 246 | ||
247 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); | 247 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); |
248 | if (this.shouldDecryptData()) { | 248 | if (this.shouldDecryptData()) { |
249 | var deferredResult; | 249 | var deferredResult; |
250 | 250 | ||
251 | deferredResult = new MochiKit.Async.Deferred(); | 251 | deferredResult = new MochiKit.Async.Deferred(); |
252 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); | 252 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); |
253 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); | 253 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); |
254 | deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { | 254 | deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { |
255 | varresult; | 255 | varresult; |
256 | 256 | ||
257 | result = anEncryptedData; | 257 | result = anEncryptedData; |
258 | result['data'] = someDecryptedValues; | 258 | result['data'] = someDecryptedValues; |
259 | 259 | ||
260 | return result; | 260 | return result; |
261 | }, anEncryptedData); | 261 | }, anEncryptedData); |
262 | deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); | 262 | deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); |
263 | deferredResult.callback(); | 263 | deferredResult.callback(); |
264 | 264 | ||
265 | result = deferredResult; | 265 | result = deferredResult; |
266 | } else { | 266 | } else { |
267 | result = MochiKit.Async.succeed(this.decryptedData()); | 267 | result = MochiKit.Async.succeed(this.decryptedData()); |
268 | } | 268 | } |
269 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); | 269 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); |
270 | 270 | ||
271 | return result; | 271 | return result; |
272 | }, | 272 | }, |
273 | 273 | ||
274 | //------------------------------------------------------------------------- | 274 | //------------------------------------------------------------------------- |
275 | 275 | ||
276 | 'processData': function(someValues) { | 276 | 'processData': function(someValues) { |
277 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); | 277 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); |
278 | //MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); | 278 | //MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); |
279 | if (this.shouldProcessData()) { | 279 | if (this.shouldProcessData()) { |
280 | var currentVersionParameters; | 280 | var currentVersionParameters; |
281 | 281 | ||
282 | console.log("Record.processData", someValues); | 282 | console.log("Record.processData", someValues); |
283 | this.processDataToExtractLegacyValues(someValues['data']); | 283 | this.processDataToExtractLegacyValues(someValues['data']); |
284 | 284 | ||
285 | if (typeof(someValues['data']['notes']) != 'undefined') { | 285 | if (typeof(someValues['data']['notes']) != 'undefined') { |
286 | this.setNotes(someValues['data']['notes']); | 286 | this.setNotes(someValues['data']['notes']); |
287 | } | 287 | } |
288 | 288 | ||
289 | if (someValues['data']['currentVersionKey'] != null) { | 289 | if (someValues['data']['currentVersionKey'] != null) { |
290 | this.setCurrentVersionKey(someValues['data']['currentVersionKey']); | 290 | this.setCurrentVersionKey(someValues['data']['currentVersionKey']); |
291 | } else { | 291 | } else { |
292 | this.setCurrentVersionKey(this.key()); | 292 | this.setCurrentVersionKey(this.key()); |
293 | } | 293 | } |
294 | 294 | ||
295 | // currentVersionParameters = someValues['currentVersion']; | 295 | // community edition doesn't currently pass version |
296 | currentVersionParameters = someValues['versions'][someValues['currentVersion']]; | 296 | // information |
297 | if (someValues['versions'] == null) { | ||
298 | currentVersionParameters = someValues['currentVersion']; | ||
299 | } else { | ||
300 | currentVersionParameters = someValues['versions'][someValues['currentVersion']]; | ||
301 | } | ||
302 | |||
297 | console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey()); | 303 | console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey()); |
298 | console.log("Record.processData - currentVersionParameters", currentVersionParameters); | 304 | console.log("Record.processData - currentVersionParameters", currentVersionParameters); |
299 | currentVersionParameters['key'] = this.currentVersionKey(); | 305 | currentVersionParameters['key'] = this.currentVersionKey(); |
300 | this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); | 306 | this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); |
301 | 307 | ||
302 | if (someValues['data']['directLogins'] != null) { | 308 | if (someValues['data']['directLogins'] != null) { |
303 | vardirectLoginReference; | 309 | vardirectLoginReference; |
304 | 310 | ||
305 | for (directLoginReference in someValues['data']['directLogins']) { | 311 | for (directLoginReference in someValues['data']['directLogins']) { |
306 | var directLogin; | 312 | var directLogin; |
307 | var directLoginParameters; | 313 | var directLoginParameters; |
308 | 314 | ||
309 | directLoginParameters = someValues['data']['directLogins'][directLoginReference]; | 315 | directLoginParameters = someValues['data']['directLogins'][directLoginReference]; |
310 | directLoginParameters.record = this; | 316 | directLoginParameters.record = this; |
311 | directLoginParameters.reference = directLoginReference; | 317 | directLoginParameters.reference = directLoginReference; |
312 | 318 | ||
313 | directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); | 319 | directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); |
314 | this.addDirectLogin(directLogin, true); | 320 | this.addDirectLogin(directLogin, true); |
315 | } | 321 | } |
316 | } | 322 | } |
317 | this.setShouldProcessData(false); | 323 | this.setShouldProcessData(false); |
318 | } | 324 | } |
319 | 325 | ||
320 | Clipperz.NotificationCenter.notify(this, 'recordDataReady'); | 326 | Clipperz.NotificationCenter.notify(this, 'recordDataReady'); |
321 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); | 327 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); |
322 | //MochiKit.Logging.logDebug("<<< Record.processData"); | 328 | //MochiKit.Logging.logDebug("<<< Record.processData"); |
323 | 329 | ||
324 | return this; | 330 | return this; |
325 | }, | 331 | }, |
326 | 332 | ||
327 | //------------------------------------------------------------------------- | 333 | //------------------------------------------------------------------------- |
328 | 334 | ||
329 | 'processDataToExtractLegacyValues': function(someValues) { | 335 | 'processDataToExtractLegacyValues': function(someValues) { |
330 | //MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); | 336 | //MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); |
331 | if (someValues['data'] != null) { | 337 | if (someValues['data'] != null) { |
332 | this.setNotes(someValues['data']); | 338 | this.setNotes(someValues['data']); |
333 | } | 339 | } |
334 | 340 | ||
335 | if ( | 341 | if ( |
336 | (typeof(someValues['loginFormData']) != "undefined") | 342 | (typeof(someValues['loginFormData']) != "undefined") |
337 | &&(typeof(someValues['loginBindings'] != "undefined")) | 343 | &&(typeof(someValues['loginBindings'] != "undefined")) |
338 | &&(someValues['loginFormData'] != "") | 344 | &&(someValues['loginFormData'] != "") |
339 | &&(someValues['loginBindings'] != "") | 345 | &&(someValues['loginBindings'] != "") |
340 | ) { | 346 | ) { |
341 | vardirectLogin; | 347 | vardirectLogin; |
342 | 348 | ||
343 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ | 349 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ |
344 | record:this, | 350 | record:this, |
345 | label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], | 351 | label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], |
346 | reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + | 352 | reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + |
347 | someValues['loginFormData'] + | 353 | someValues['loginFormData'] + |
348 | someValues['loginBindings'])).toHexString().substring(2), | 354 | someValues['loginBindings'])).toHexString().substring(2), |
349 | formData:Clipperz.Base.evalJSON(someValues['loginFormData']), | 355 | formData:Clipperz.Base.evalJSON(someValues['loginFormData']), |
350 | legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), | 356 | legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), |
351 | bookmarkletVersion:'0.1' | 357 | bookmarkletVersion:'0.1' |
352 | }); | 358 | }); |
353 | this.addDirectLogin(directLogin, true); | 359 | this.addDirectLogin(directLogin, true); |
354 | } | 360 | } |
355 | //MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); | 361 | //MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); |
356 | }, | 362 | }, |
357 | 363 | ||
358 | //------------------------------------------------------------------------- | 364 | //------------------------------------------------------------------------- |
359 | 365 | ||
360 | 'getReadyBeforeUpdatingVersionValues': function() { | 366 | 'getReadyBeforeUpdatingVersionValues': function() { |
361 | }, | 367 | }, |
362 | 368 | ||
363 | //------------------------------------------------------------------------- | 369 | //------------------------------------------------------------------------- |
364 | 370 | ||
365 | 'addNewField': function() { | 371 | 'addNewField': function() { |
366 | varnewField; | 372 | varnewField; |
367 | 373 | ||
368 | //MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); | 374 | //MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); |
369 | this.getReadyBeforeUpdatingVersionValues(); | 375 | this.getReadyBeforeUpdatingVersionValues(); |
370 | newField = this.currentVersion().addNewField(); | 376 | newField = this.currentVersion().addNewField(); |
371 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); | 377 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); |
372 | //MochiKit.Logging.logDebug("<<< Record.addNewField"); | 378 | //MochiKit.Logging.logDebug("<<< Record.addNewField"); |
373 | 379 | ||
374 | return newField; | 380 | return newField; |
375 | }, | 381 | }, |
376 | 382 | ||
377 | //------------------------------------------------------------------------- | 383 | //------------------------------------------------------------------------- |
378 | 384 | ||
379 | 'removeField': function(aField) { | 385 | 'removeField': function(aField) { |
380 | this.getReadyBeforeUpdatingVersionValues(); | 386 | this.getReadyBeforeUpdatingVersionValues(); |
381 | this.currentVersion().removeField(aField); | 387 | this.currentVersion().removeField(aField); |
382 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); | 388 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); |
383 | }, | 389 | }, |
384 | 390 | ||
385 | 'removeEmptyFields': function() { | 391 | 'removeEmptyFields': function() { |
386 | MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { | 392 | MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { |
387 | if (aField.isEmpty()) { | 393 | if (aField.isEmpty()) { |
388 | this.removeField(aField); | 394 | this.removeField(aField); |
389 | // this.currentVersion().removeField(aField); | 395 | // this.currentVersion().removeField(aField); |
390 | } | 396 | } |
391 | }, this)); | 397 | }, this)); |
392 | }, | 398 | }, |
393 | 399 | ||
394 | //------------------------------------------------------------------------- | 400 | //------------------------------------------------------------------------- |
395 | 401 | ||
396 | 'notes': function() { | 402 | 'notes': function() { |
397 | return this._notes; | 403 | return this._notes; |
398 | }, | 404 | }, |
399 | 405 | ||
400 | 'setNotes': function(aValue) { | 406 | 'setNotes': function(aValue) { |
401 | this._notes = aValue; | 407 | this._notes = aValue; |
402 | this.setHeaderNotes(null); | 408 | this.setHeaderNotes(null); |
403 | }, | 409 | }, |
404 | 410 | ||
405 | //------------------------------------------------------------------------- | 411 | //------------------------------------------------------------------------- |
406 | 412 | ||
407 | 'headerNotes': function() { | 413 | 'headerNotes': function() { |
408 | return this._headerNotes; | 414 | return this._headerNotes; |
409 | }, | 415 | }, |
410 | 416 | ||
411 | 'setHeaderNotes': function(aValue) { | 417 | 'setHeaderNotes': function(aValue) { |
412 | this._headerNotes = aValue; | 418 | this._headerNotes = aValue; |
413 | }, | 419 | }, |
414 | 420 | ||
415 | //------------------------------------------------------------------------- | 421 | //------------------------------------------------------------------------- |
416 | 422 | ||
417 | 'remove': function() { | 423 | 'remove': function() { |
418 | //MochiKit.Logging.logDebug(">>> Record.remove - " + this); | 424 | //MochiKit.Logging.logDebug(">>> Record.remove - " + this); |
419 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), MochiKit.Base.method(this, 'removeDirectLogin')); | 425 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), MochiKit.Base.method(this, 'removeDirectLogin')); |
420 | 426 | ||
421 | this.syncDirectLoginReferenceValues(); | 427 | this.syncDirectLoginReferenceValues(); |
422 | this.user().removeRecord(this); | 428 | this.user().removeRecord(this); |
423 | //MochiKit.Logging.logDebug("<<< Record.remove"); | 429 | //MochiKit.Logging.logDebug("<<< Record.remove"); |
424 | }, | 430 | }, |
425 | 431 | ||
426 | //------------------------------------------------------------------------- | 432 | //------------------------------------------------------------------------- |
427 | 433 | ||
428 | 'directLogins': function() { | 434 | 'directLogins': function() { |
429 | return this._directLogins; | 435 | return this._directLogins; |
430 | }, | 436 | }, |
431 | 437 | ||
432 | 'addDirectLogin': function(aDirectLogin, shouldUpdateUser) { | 438 | 'addDirectLogin': function(aDirectLogin, shouldUpdateUser) { |
433 | this.directLogins()[aDirectLogin.reference()] = aDirectLogin; | 439 | this.directLogins()[aDirectLogin.reference()] = aDirectLogin; |
434 | if (shouldUpdateUser == true) { | 440 | if (shouldUpdateUser == true) { |
435 | this.user().addDirectLogin(aDirectLogin); | 441 | this.user().addDirectLogin(aDirectLogin); |
436 | } | 442 | } |
437 | }, | 443 | }, |
438 | 444 | ||
439 | 'removeDirectLogin': function(aDirectLogin) { | 445 | 'removeDirectLogin': function(aDirectLogin) { |
440 | this.removedDirectLogins().push(aDirectLogin); | 446 | this.removedDirectLogins().push(aDirectLogin); |
441 | delete this.directLogins()[aDirectLogin.reference()]; | 447 | delete this.directLogins()[aDirectLogin.reference()]; |
442 | // this.user().removeDirectLogin(aDirectLogin); | 448 | // this.user().removeDirectLogin(aDirectLogin); |
443 | }, | 449 | }, |
444 | 450 | ||
445 | 'resetDirectLogins': function() { | 451 | 'resetDirectLogins': function() { |
446 | this._directLogins = {}; | 452 | this._directLogins = {}; |
447 | }, | 453 | }, |
448 | 454 | ||
449 | 'removedDirectLogins': function() { | 455 | 'removedDirectLogins': function() { |
450 | return this._removedDirectLogins; | 456 | return this._removedDirectLogins; |
451 | }, | 457 | }, |
452 | 458 | ||
453 | 'resetRemovedDirectLogins': function() { | 459 | 'resetRemovedDirectLogins': function() { |
454 | this._removedDirectLogins = []; | 460 | this._removedDirectLogins = []; |
455 | }, | 461 | }, |
456 | 462 | ||
457 | //------------------------------------------------------------------------- | 463 | //------------------------------------------------------------------------- |
458 | 464 | ||
459 | 'serverData': function() { | 465 | 'serverData': function() { |
460 | return this._serverData; | 466 | return this._serverData; |
461 | }, | 467 | }, |
462 | 468 | ||
463 | 'setServerData': function(aValue) { | 469 | 'setServerData': function(aValue) { |
464 | this._serverData = aValue; | 470 | this._serverData = aValue; |
465 | this.setShouldLoadData(false); | 471 | this.setShouldLoadData(false); |
466 | return aValue; | 472 | return aValue; |
467 | }, | 473 | }, |
468 | 474 | ||
469 | //------------------------------------------------------------------------- | 475 | //------------------------------------------------------------------------- |
470 | 476 | ||
471 | 'decryptedData': function() { | 477 | 'decryptedData': function() { |
472 | return this._decryptedData; | 478 | return this._decryptedData; |
473 | }, | 479 | }, |
474 | 480 | ||
475 | 'setDecryptedData': function(aValue) { | 481 | 'setDecryptedData': function(aValue) { |
476 | this._decryptedData = aValue; | 482 | this._decryptedData = aValue; |
477 | this.setShouldDecryptData(false); | 483 | this.setShouldDecryptData(false); |
478 | return aValue; | 484 | return aValue; |
479 | }, | 485 | }, |
480 | 486 | ||
481 | //------------------------------------------------------------------------- | 487 | //------------------------------------------------------------------------- |
482 | 488 | ||
483 | 'cachedData': function() { | 489 | 'cachedData': function() { |
484 | return this._cachedData; | 490 | return this._cachedData; |
485 | }, | 491 | }, |
486 | 492 | ||
487 | 'setCachedData': function(aValue) { | 493 | 'setCachedData': function(aValue) { |
488 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); | 494 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); |
489 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); | 495 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); |
490 | this._cachedData = aValue; | 496 | this._cachedData = aValue; |
491 | this.setShouldProcessData(false); | 497 | this.setShouldProcessData(false); |
492 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); | 498 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); |
493 | 499 | ||
494 | return aValue; | 500 | return aValue; |
495 | }, | 501 | }, |
496 | 502 | ||
497 | //------------------------------------------------------------------------- | 503 | //------------------------------------------------------------------------- |
498 | 504 | ||
499 | 'hasPendingChanges': function() { | 505 | 'hasPendingChanges': function() { |
500 | var result; | 506 | var result; |
501 | 507 | ||
502 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 508 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
503 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); | 509 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); |
504 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); | 510 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); |
505 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); | 511 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); |
506 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); | 512 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); |
507 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); | 513 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); |
508 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); | 514 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); |
509 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); | 515 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); |
510 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); | 516 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); |
511 | 517 | ||
512 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { | 518 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { |
513 | result = true; | 519 | result = true; |
514 | } | 520 | } |
515 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 521 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
516 | 522 | ||
517 | return result; | 523 | return result; |
518 | }, | 524 | }, |
519 | 525 | ||
520 | //------------------------------------------------------------------------- | 526 | //------------------------------------------------------------------------- |
521 | 527 | ||
522 | 'currentDataSnapshot': function() { | 528 | 'currentDataSnapshot': function() { |
523 | varresult; | 529 | varresult; |
524 | 530 | ||
525 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 531 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
526 | result = { | 532 | result = { |
527 | 'label': this.label(), | 533 | 'label': this.label(), |
528 | 'data': this.serializedData(), | 534 | 'data': this.serializedData(), |
529 | 'currentVersion': this.currentVersion().currentDataSnapshot() | 535 | 'currentVersion': this.currentVersion().currentDataSnapshot() |
530 | }; | 536 | }; |
531 | 537 | ||
532 | // result['data']['data'] = this.notes(); | 538 | // result['data']['data'] = this.notes(); |
533 | result = Clipperz.Base.serializeJSON(result); | 539 | result = Clipperz.Base.serializeJSON(result); |
534 | 540 | ||
535 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 541 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
536 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); | 542 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); |
537 | 543 | ||
538 | return result; | 544 | return result; |
539 | }, | 545 | }, |
540 | 546 | ||
541 | //......................................................................... | 547 | //......................................................................... |
542 | 548 | ||
543 | 'takeSnapshotOfCurrentData': function() { | 549 | 'takeSnapshotOfCurrentData': function() { |
544 | this.setCachedData(this.currentDataSnapshot()); | 550 | this.setCachedData(this.currentDataSnapshot()); |
545 | }, | 551 | }, |
546 | 552 | ||
547 | //------------------------------------------------------------------------- | 553 | //------------------------------------------------------------------------- |
548 | 554 | ||
549 | 'headerData': function() { | 555 | 'headerData': function() { |
550 | var result; | 556 | var result; |
551 | 557 | ||
552 | result = { | 558 | result = { |
553 | 'label': this.label(), | 559 | 'label': this.label(), |
554 | 'key': this.key() | 560 | 'key': this.key() |
555 | }; | 561 | }; |
556 | 562 | ||
557 | if (this.headerNotes() != null) { | 563 | if (this.headerNotes() != null) { |
558 | result['headerNotes'] = this.headerNotes(); | 564 | result['headerNotes'] = this.headerNotes(); |
559 | } | 565 | } |
560 | 566 | ||
561 | return result; | 567 | return result; |
562 | }, | 568 | }, |
563 | 569 | ||
564 | //------------------------------------------------------------------------- | 570 | //------------------------------------------------------------------------- |
565 | 571 | ||
566 | 'serializedData': function() { | 572 | 'serializedData': function() { |
567 | var result; | 573 | var result; |
568 | var directLoginReference; | 574 | var directLoginReference; |
569 | 575 | ||
570 | result = {}; | 576 | result = {}; |
571 | result['currentVersionKey'] = this.currentVersion().key(); | 577 | result['currentVersionKey'] = this.currentVersion().key(); |
572 | 578 | ||
573 | result['directLogins'] = {}; | 579 | result['directLogins'] = {}; |
574 | for (directLoginReference in this.directLogins()) { | 580 | for (directLoginReference in this.directLogins()) { |
575 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); | 581 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); |
576 | } | 582 | } |
577 | result['notes'] = this.notes(); | 583 | result['notes'] = this.notes(); |
578 | 584 | ||
579 | return result; | 585 | return result; |
580 | }, | 586 | }, |
581 | 587 | ||
582 | //------------------------------------------------------------------------- | 588 | //------------------------------------------------------------------------- |
583 | 589 | ||
584 | 'encryptedData': function() { | 590 | 'encryptedData': function() { |
585 | var deferredResult; | 591 | var deferredResult; |
586 | varresult; | 592 | varresult; |
587 | 593 | ||
588 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); | 594 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); |
589 | result = {} | 595 | result = {} |
590 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); | 596 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); |
591 | deferredResult = new MochiKit.Async.Deferred(); | 597 | deferredResult = new MochiKit.Async.Deferred(); |
592 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); | 598 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); |
593 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); | 599 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); |
594 | deferredResult.addCallback(function(aResult, aRecord) { | 600 | deferredResult.addCallback(function(aResult, aRecord) { |
595 | aResult['reference'] = aRecord.reference(); | 601 | aResult['reference'] = aRecord.reference(); |
596 | return aResult; | 602 | return aResult; |
597 | }, result, this); | 603 | }, result, this); |
598 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); | 604 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); |
599 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); | 605 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); |
600 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); | 606 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); |
601 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); | 607 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); |
602 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); | 608 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); |
603 | deferredResult.addCallback(function(aResult, res) { | 609 | deferredResult.addCallback(function(aResult, res) { |
604 | aResult['data'] = res; | 610 | aResult['data'] = res; |
605 | return aResult; | 611 | return aResult; |
606 | }, result); | 612 | }, result); |
607 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); | 613 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); |
608 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); | 614 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); |
609 | deferredResult.addCallback(function(aResult) { | 615 | deferredResult.addCallback(function(aResult) { |
610 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 616 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
611 | return aResult; | 617 | return aResult; |
612 | }, result); | 618 | }, result); |
613 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); | 619 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); |
614 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); | 620 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); |
615 | deferredResult.callback(); | 621 | deferredResult.callback(); |
616 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); | 622 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); |
617 | 623 | ||
618 | return deferredResult; | 624 | return deferredResult; |
619 | }, | 625 | }, |
620 | 626 | ||
621 | //------------------------------------------------------------------------- | 627 | //------------------------------------------------------------------------- |
622 | 628 | ||
623 | 'syncDirectLoginReferenceValues': function() { | 629 | 'syncDirectLoginReferenceValues': function() { |
624 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); | 630 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); |
625 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { | 631 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { |
626 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); | 632 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); |
627 | }); | 633 | }); |
628 | 634 | ||
629 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { | 635 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { |
630 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); | 636 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); |
631 | }); | 637 | }); |
632 | 638 | ||
633 | this.resetRemovedDirectLogins(); | 639 | this.resetRemovedDirectLogins(); |
634 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); | 640 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); |
635 | }, | 641 | }, |
636 | 642 | ||
637 | //------------------------------------------------------------------------- | 643 | //------------------------------------------------------------------------- |
638 | 644 | ||
639 | 'saveChanges': function() { | 645 | 'saveChanges': function() { |
640 | var result; | 646 | var result; |
641 | 647 | ||
642 | if (this.isBrandNew() == false) { | 648 | if (this.isBrandNew() == false) { |
643 | result = this.user().saveRecords([this], 'updateData'); | 649 | result = this.user().saveRecords([this], 'updateData'); |
644 | } else { | 650 | } else { |
645 | result = this.user().saveRecords([this], 'addNewRecords'); | 651 | result = this.user().saveRecords([this], 'addNewRecords'); |
646 | } | 652 | } |
647 | 653 | ||
648 | return result; | 654 | return result; |
649 | }, | 655 | }, |
650 | 656 | ||
651 | /* | 657 | /* |
652 | 'saveChanges': function() { | 658 | 'saveChanges': function() { |
653 | var deferredResult; | 659 | var deferredResult; |
654 | varresult; | 660 | varresult; |
655 | 661 | ||
656 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); | 662 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); |
657 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); | 663 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); |
658 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); | 664 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); |
659 | if (this.headerNotes() != null) { | 665 | if (this.headerNotes() != null) { |
660 | this.setNotes(this.headerNotes()); | 666 | this.setNotes(this.headerNotes()); |
661 | } | 667 | } |
662 | this.syncDirectLoginReferenceValues(); | 668 | this.syncDirectLoginReferenceValues(); |
663 | this.currentVersion().createNewVersion(); | 669 | this.currentVersion().createNewVersion(); |
664 | 670 | ||
665 | result = {'records': [{}]}; | 671 | result = {'records': [{}]}; |
666 | 672 | ||
667 | deferredResult = new MochiKit.Async.Deferred(); | 673 | deferredResult = new MochiKit.Async.Deferred(); |
668 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); | 674 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); |
669 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); | 675 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); |
670 | 676 | ||
671 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); | 677 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); |
672 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 678 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
673 | deferredResult.addCallback(function(aResult, res) { | 679 | deferredResult.addCallback(function(aResult, res) { |
674 | aResult['user'] = res; | 680 | aResult['user'] = res; |
675 | return aResult; | 681 | return aResult; |
676 | }, result); | 682 | }, result); |
677 | 683 | ||
678 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); | 684 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); |
679 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 685 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
680 | deferredResult.addCallback(function(aResult, res) { | 686 | deferredResult.addCallback(function(aResult, res) { |