Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js index 6ba58a8..f77ea80 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.Header.RecordIndex.js | |||
@@ -1,408 +1,405 @@ | |||
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's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | 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 |
15 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * 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 |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | */ | 24 | */ |
28 | 25 | ||
29 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { | 26 | try { if (typeof(Clipperz.PM.DataModel.User) == 'undefined') { throw ""; }} catch (e) { |
30 | throw "Clipperz.PM.DataModel.User.Header.RecordIndex depends on Clipperz.PM.DataModel.User!"; | 27 | throw "Clipperz.PM.DataModel.User.Header.RecordIndex depends on Clipperz.PM.DataModel.User!"; |
31 | } | 28 | } |
32 | 29 | ||
33 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } | 30 | if (typeof(Clipperz.PM.DataModel.User.Header) == 'undefined') { Clipperz.PM.DataModel.User.Header = {}; } |
34 | 31 | ||
35 | Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) { | 32 | Clipperz.PM.DataModel.User.Header.RecordIndex = function(args) { |
36 | Clipperz.PM.DataModel.User.Header.RecordIndex.superclass.constructor.apply(this, arguments); | 33 | Clipperz.PM.DataModel.User.Header.RecordIndex.superclass.constructor.apply(this, arguments); |
37 | 34 | ||
38 | //console.log("NEW Clipperz.PM.DataModel.User.Header.RecordIndex", args); | 35 | //console.log("NEW Clipperz.PM.DataModel.User.Header.RecordIndex", args); |
39 | this._recordsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ | 36 | this._recordsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ |
40 | 'name':'recordsData', | 37 | 'name':'recordsData', |
41 | 'retrieveKeyFunction': args.retrieveKeyFunction, | 38 | 'retrieveKeyFunction': args.retrieveKeyFunction, |
42 | 'remoteData': { | 39 | 'remoteData': { |
43 | 'data': args.recordsData['data'], | 40 | 'data': args.recordsData['data'], |
44 | 'version': args.encryptedDataVersion, | 41 | 'version': args.encryptedDataVersion, |
45 | 'recordsStats': args.recordsStats | 42 | 'recordsStats': args.recordsStats |
46 | }//, | 43 | }//, |
47 | // 'encryptedDataKeypath': 'data', | 44 | // 'encryptedDataKeypath': 'data', |
48 | // 'encryptedVersionKeypath': 'version' | 45 | // 'encryptedVersionKeypath': 'version' |
49 | }); | 46 | }); |
50 | 47 | ||
51 | this._directLoginsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ | 48 | this._directLoginsData = new Clipperz.PM.DataModel.EncryptedRemoteObject({ |
52 | 'name':'directLoginsData', | 49 | 'name':'directLoginsData', |
53 | 'retrieveKeyFunction': args.retrieveKeyFunction, | 50 | 'retrieveKeyFunction': args.retrieveKeyFunction, |
54 | 'remoteData': { | 51 | 'remoteData': { |
55 | 'data': args.directLoginsData['data'], | 52 | 'data': args.directLoginsData['data'], |
56 | 'version': args.encryptedDataVersion | 53 | 'version': args.encryptedDataVersion |
57 | }//, | 54 | }//, |
58 | // 'encryptedDataKeypath': 'data', | 55 | // 'encryptedDataKeypath': 'data', |
59 | // 'encryptedVersionKeypath': 'version' | 56 | // 'encryptedVersionKeypath': 'version' |
60 | }); | 57 | }); |
61 | 58 | ||
62 | this._lock = new MochiKit.Async.DeferredLock(); | 59 | this._lock = new MochiKit.Async.DeferredLock(); |
63 | this._transientState = null; | 60 | this._transientState = null; |
64 | 61 | ||
65 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); | 62 | this._retrieveRecordDetailFunction = args.retrieveRecordDetailFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); |
66 | this._recordsIndex = args.recordsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter'); | 63 | this._recordsIndex = args.recordsData['index'] || Clipperz.Base.exception.raise('MandatoryParameter'); |
67 | this._directLoginsIndex = args.directLoginsData['index']|| Clipperz.Base.exception.raise('MandatoryParameter'); | 64 | this._directLoginsIndex = args.directLoginsData['index']|| Clipperz.Base.exception.raise('MandatoryParameter'); |
68 | 65 | ||
69 | this._records = null; | 66 | this._records = null; |
70 | 67 | ||
71 | return this; | 68 | return this; |
72 | } | 69 | } |
73 | 70 | ||
74 | 71 | ||
75 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, { | 72 | Clipperz.Base.extend(Clipperz.PM.DataModel.User.Header.RecordIndex, Object, { |
76 | 73 | ||
77 | 'toString': function() { | 74 | 'toString': function() { |
78 | return "Clipperz.PM.DataModel.User.Header.RecordIndex"; | 75 | return "Clipperz.PM.DataModel.User.Header.RecordIndex"; |
79 | }, | 76 | }, |
80 | 77 | ||
81 | //------------------------------------------------------------------------- | 78 | //------------------------------------------------------------------------- |
82 | 79 | ||
83 | 'retrieveRecordDetailFunction': function () { | 80 | 'retrieveRecordDetailFunction': function () { |
84 | return this._retrieveRecordDetailFunction; | 81 | return this._retrieveRecordDetailFunction; |
85 | }, | 82 | }, |
86 | 83 | ||
87 | //------------------------------------------------------------------------- | 84 | //------------------------------------------------------------------------- |
88 | 85 | ||
89 | 'recordsIndex': function () { | 86 | 'recordsIndex': function () { |
90 | return this._recordsIndex; | 87 | return this._recordsIndex; |
91 | }, | 88 | }, |
92 | 89 | ||
93 | 'recordsData': function () { | 90 | 'recordsData': function () { |
94 | return this._recordsData; | 91 | return this._recordsData; |
95 | }, | 92 | }, |
96 | 93 | ||
97 | //------------------------------------------------------------------------- | 94 | //------------------------------------------------------------------------- |
98 | 95 | ||
99 | 'directLoginsIndex': function () { | 96 | 'directLoginsIndex': function () { |
100 | return this._directLoginsIndex; | 97 | return this._directLoginsIndex; |
101 | }, | 98 | }, |
102 | 99 | ||
103 | 'directLoginsData': function () { | 100 | 'directLoginsData': function () { |
104 | return this._directLoginsData; | 101 | return this._directLoginsData; |
105 | }, | 102 | }, |
106 | 103 | ||
107 | //------------------------------------------------------------------------- | 104 | //------------------------------------------------------------------------- |
108 | 105 | ||
109 | 'lock': function () { | 106 | 'lock': function () { |
110 | return this._lock; | 107 | return this._lock; |
111 | }, | 108 | }, |
112 | 109 | ||
113 | //------------------------------------------------------------------------- | 110 | //------------------------------------------------------------------------- |
114 | 111 | ||
115 | 'transientState': function () { | 112 | 'transientState': function () { |
116 | if (this._transientState == null) { | 113 | if (this._transientState == null) { |
117 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'User.Header.RecordIndex.transientState [1]'}*/); | 114 | this._transientState = new Clipperz.KeyValueObjectStore(/*{'name':'User.Header.RecordIndex.transientState [1]'}*/); |
118 | } | 115 | } |
119 | 116 | ||
120 | return this._transientState; | 117 | return this._transientState; |
121 | }, | 118 | }, |
122 | 119 | ||
123 | 'resetTransientState': function (isCommitting) { | 120 | 'resetTransientState': function (isCommitting) { |
124 | //console.log("######## UserHeaderRecordIndex - resetTransientState", Clipperz.Base.deepClone(this._transientState)); | 121 | //console.log("######## UserHeaderRecordIndex - resetTransientState", Clipperz.Base.deepClone(this._transientState)); |
125 | if (this._transientState != null) { | 122 | if (this._transientState != null) { |
126 | this._transientState.removeAllData(); | 123 | this._transientState.removeAllData(); |
127 | } | 124 | } |
128 | 125 | ||
129 | this._transientState = null; | 126 | this._transientState = null; |
130 | }, | 127 | }, |
131 | 128 | ||
132 | //------------------------------------------------------------------------- | 129 | //------------------------------------------------------------------------- |
133 | 130 | ||
134 | 'getRecordKey': function (aRecordReference) { | 131 | 'getRecordKey': function (aRecordReference) { |
135 | return Clipperz.Async.callbacks("User.Header.RecordIndex.getRecordKey", [ | 132 | return Clipperz.Async.callbacks("User.Header.RecordIndex.getRecordKey", [ |
136 | MochiKit.Base.method(this, 'getRecordIndexData', aRecordReference), | 133 | MochiKit.Base.method(this, 'getRecordIndexData', aRecordReference), |
137 | MochiKit.Base.itemgetter('key') | 134 | MochiKit.Base.itemgetter('key') |
138 | ], {trace:false}); | 135 | ], {trace:false}); |
139 | }, | 136 | }, |
140 | 137 | ||
141 | 'setRecordKey': function (aRecordReference, aValue) { | 138 | 'setRecordKey': function (aRecordReference, aValue) { |
142 | return this.updateRecordIndexData(aRecordReference, 'key', aValue); | 139 | return this.updateRecordIndexData(aRecordReference, 'key', aValue); |
143 | }, | 140 | }, |
144 | 141 | ||
145 | //------------------------------------------------------------------------- | 142 | //------------------------------------------------------------------------- |
146 | 143 | ||
147 | 'getRecordIndexData': function (aRecordReference) { | 144 | 'getRecordIndexData': function (aRecordReference) { |
148 | return this.recordsData().getValue(this.recordsIndex()[aRecordReference]); | 145 | return this.recordsData().getValue(this.recordsIndex()[aRecordReference]); |
149 | }, | 146 | }, |
150 | 147 | ||
151 | //......................................................................... | 148 | //......................................................................... |
152 | 149 | ||
153 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { | 150 | 'updateRecordIndexData': function (aRecordReference, aKey, aValue) { |
154 | return this.recordsData().setValue(this.recordsIndex()[aRecordReference]+'.'+aKey, aValue); | 151 | return this.recordsData().setValue(this.recordsIndex()[aRecordReference]+'.'+aKey, aValue); |
155 | }, | 152 | }, |
156 | 153 | ||
157 | //------------------------------------------------------------------------- | 154 | //------------------------------------------------------------------------- |
158 | 155 | ||
159 | 'getDirectLoginIndexData': function (aDirectLoginReference) { | 156 | 'getDirectLoginIndexData': function (aDirectLoginReference) { |
160 | return this.directLoginsData().getValue(this.directLoginsIndex()[aDirectLoginReference]); | 157 | return this.directLoginsData().getValue(this.directLoginsIndex()[aDirectLoginReference]); |
161 | }, | 158 | }, |
162 | 159 | ||
163 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { | 160 | 'setDirectLoginIndexData': function (aDirectLoginReference, aKey, aValue) { |
164 | //console.log("UserHeaderRecordIndex.setDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference], aKey); | 161 | //console.log("UserHeaderRecordIndex.setDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference], aKey); |
165 | //if (MochiKit.Base.isUndefinedOrNull(this.directLoginsIndex()[aDirectLoginReference])) { | 162 | //if (MochiKit.Base.isUndefinedOrNull(this.directLoginsIndex()[aDirectLoginReference])) { |
166 | //throw "PIPPO"; | 163 | //throw "PIPPO"; |
167 | //} | 164 | //} |
168 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference] + '.' + aKey, aValue); | 165 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference] + '.' + aKey, aValue); |
169 | }, | 166 | }, |
170 | 167 | ||
171 | 'addDirectLoginIndexData': function (aDirectLoginReference) { | 168 | 'addDirectLoginIndexData': function (aDirectLoginReference) { |
172 | //console.log("UserHeaderRecordIndex.addDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference]); | 169 | //console.log("UserHeaderRecordIndex.addDirectLoginIndexData", aDirectLoginReference, this.directLoginsIndex()[aDirectLoginReference]); |
173 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference], {}); | 170 | return this.directLoginsData().setValue(this.directLoginsIndex()[aDirectLoginReference], {}); |
174 | }, | 171 | }, |
175 | 172 | ||
176 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { | 173 | 'removeDirectLoginIndexData': function (aDirectLoginReference) { |
177 | return this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLoginReference]) | 174 | return this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLoginReference]) |
178 | }, | 175 | }, |
179 | 176 | ||
180 | //------------------------------------------------------------------------- | 177 | //------------------------------------------------------------------------- |
181 | 178 | ||
182 | 'records': function () { | 179 | 'records': function () { |
183 | vardeferredResult; | 180 | vardeferredResult; |
184 | 181 | ||
185 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records", {trace:false}); | 182 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records", {trace:false}); |
186 | deferredResult.acquireLock(this.lock()); | 183 | deferredResult.acquireLock(this.lock()); |
187 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 184 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
188 | var innerDeferredResult; | 185 | var innerDeferredResult; |
189 | 186 | ||
190 | if (this._records == null) { | 187 | if (this._records == null) { |
191 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records <inner deferred>", {trace:false}); | 188 | innerDeferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.records <inner deferred>", {trace:false}); |
192 | innerDeferredResult.collectResults({ | 189 | innerDeferredResult.collectResults({ |
193 | 'records': [ | 190 | 'records': [ |
194 | // MochiKit.Base.method(this.recordsData(), 'getObjectDataStore'), | 191 | // MochiKit.Base.method(this.recordsData(), 'getObjectDataStore'), |
195 | // MochiKit.Base.methodcaller('values') | 192 | // MochiKit.Base.methodcaller('values') |
196 | MochiKit.Base.method(this.recordsData(), 'values') | 193 | MochiKit.Base.method(this.recordsData(), 'values') |
197 | ], | 194 | ], |
198 | 'recordsStats': [ | 195 | 'recordsStats': [ |
199 | MochiKit.Base.method(this.recordsData(), 'getRemoteData'), | 196 | MochiKit.Base.method(this.recordsData(), 'getRemoteData'), |
200 | MochiKit.Base.itemgetter('recordsStats') | 197 | MochiKit.Base.itemgetter('recordsStats') |
201 | ], | 198 | ], |
202 | 'directLogins': [ | 199 | 'directLogins': [ |
203 | // MochiKit.Base.method(this.directLoginsData(), 'getObjectDataStore'), | 200 | // MochiKit.Base.method(this.directLoginsData(), 'getObjectDataStore'), |
204 | // MochiKit.Base.methodcaller('values') | 201 | // MochiKit.Base.methodcaller('values') |
205 | MochiKit.Base.method(this.directLoginsData(), 'values') | 202 | MochiKit.Base.method(this.directLoginsData(), 'values') |
206 | ] | 203 | ] |
207 | }) | 204 | }) |
208 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someData) { | 205 | innerDeferredResult.addCallback(MochiKit.Base.bind(function (someData) { |
209 | var indexReference; | 206 | var indexReference; |
210 | var recordsInvertedIndex; | 207 | var recordsInvertedIndex; |
211 | var directLoginsInvertedIndex; | 208 | var directLoginsInvertedIndex; |
212 | 209 | ||
213 | recordsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.recordsIndex()); | 210 | recordsInvertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.recordsIndex()); |
214 | directLoginsInvertedIndex= Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.directLoginsIndex()); | 211 | directLoginsInvertedIndex= Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(this.directLoginsIndex()); |
215 | 212 | ||
216 | this._records = {}; | 213 | this._records = {}; |
217 | 214 | ||
218 | for (indexReference in someData['records']) { | 215 | for (indexReference in someData['records']) { |
219 | varrecord; | 216 | varrecord; |
220 | var reference; | 217 | var reference; |
221 | var updateDate; | 218 | var updateDate; |
222 | 219 | ||
223 | reference = recordsInvertedIndex[indexReference]; | 220 | reference = recordsInvertedIndex[indexReference]; |
224 | 221 | ||
225 | if (typeof(someData['recordsStats'][reference]) != 'undefined') { | 222 | if (typeof(someData['recordsStats'][reference]) != 'undefined') { |
226 | updateDate = someData['recordsStats'][reference]['updateDate']; | 223 | updateDate = someData['recordsStats'][reference]['updateDate']; |
227 | 224 | ||
228 | record = new Clipperz.PM.DataModel.Record({ | 225 | record = new Clipperz.PM.DataModel.Record({ |
229 | 'reference': reference, | 226 | 'reference': reference, |
230 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), | 227 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), |
231 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), | 228 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), |
232 | 229 | ||
233 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), | 230 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), |
234 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), | 231 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), |
235 | 'updateDate': updateDate, | 232 | 'updateDate': updateDate, |
236 | 233 | ||
237 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), | 234 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), |
238 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), | 235 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), |
239 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), | 236 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), |
240 | 237 | ||
241 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') | 238 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') |
242 | }); | 239 | }); |
243 | 240 | ||
244 | this._records[reference] = record; | 241 | this._records[reference] = record; |
245 | } else { | 242 | } else { |
246 | Clipperz.log("SKIPPING record " + reference + " as there are no stas associated - " + Clipperz.Base.serializeJSON(someData['records'][reference])); | 243 | Clipperz.log("SKIPPING record " + reference + " as there are no stas associated - " + Clipperz.Base.serializeJSON(someData['records'][reference])); |
247 | //# skip the record, as it seems it is not present in the DB | 244 | //# skip the record, as it seems it is not present in the DB |
248 | //updateDate = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 245 | //updateDate = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
249 | } | 246 | } |
250 | } | 247 | } |
251 | 248 | ||
252 | for (indexReference in someData['directLogins']) { | 249 | for (indexReference in someData['directLogins']) { |
253 | // vardirectLogin; | 250 | // vardirectLogin; |
254 | var reference; | 251 | var reference; |
255 | var record; | 252 | var record; |
256 | 253 | ||
257 | reference = directLoginsInvertedIndex[indexReference]; | 254 | reference = directLoginsInvertedIndex[indexReference]; |
258 | record = this._records[recordsInvertedIndex[someData['directLogins'][indexReference]['record']]]; | 255 | record = this._records[recordsInvertedIndex[someData['directLogins'][indexReference]['record']]]; |
259 | 256 | ||
260 | if (record != null) { | 257 | if (record != null) { |
261 | // directLogin = new Clipperz.PM.DataModel.DirectLogin({ | 258 | // directLogin = new Clipperz.PM.DataModel.DirectLogin({ |
262 | new Clipperz.PM.DataModel.DirectLogin({ | 259 | new Clipperz.PM.DataModel.DirectLogin({ |
263 | 'reference': reference, | 260 | 'reference': reference, |
264 | 'record': record | 261 | 'record': record |
265 | }); | 262 | }); |
266 | } else { | 263 | } else { |
267 | Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!"); | 264 | Clipperz.log("WARNING: DIRECT LOGIN without a matching RECORD!!"); |
268 | //console.log("direct login data", someData['directLogins']); | 265 | //console.log("direct login data", someData['directLogins']); |
269 | //console.log("current direct login data", someData['directLogins'][indexReference]) | 266 | //console.log("current direct login data", someData['directLogins'][indexReference]) |
270 | //console.log("reference", reference); | 267 | //console.log("reference", reference); |
271 | //console.log("record index", this.recordsIndex()); | 268 | //console.log("record index", this.recordsIndex()); |
272 | //console.log("record inverted index", recordsInvertedIndex); | 269 | //console.log("record inverted index", recordsInvertedIndex); |
273 | } | 270 | } |
274 | } | 271 | } |
275 | 272 | ||
276 | return this._records; | 273 | return this._records; |
277 | }, this)); | 274 | }, this)); |
278 | innerDeferredResult.callback(); | 275 | innerDeferredResult.callback(); |
279 | } else { | 276 | } else { |
280 | innerDeferredResult = MochiKit.Async.succeed(this._records); | 277 | innerDeferredResult = MochiKit.Async.succeed(this._records); |
281 | } | 278 | } |
282 | 279 | ||
283 | return innerDeferredResult; | 280 | return innerDeferredResult; |
284 | }, this)); | 281 | }, this)); |
285 | deferredResult.releaseLock(this.lock()); | 282 | deferredResult.releaseLock(this.lock()); |
286 | deferredResult.callback(); | 283 | deferredResult.callback(); |
287 | 284 | ||
288 | return deferredResult; | 285 | return deferredResult; |
289 | }, | 286 | }, |
290 | 287 | ||
291 | //------------------------------------------------------------------------- | 288 | //------------------------------------------------------------------------- |
292 | 289 | ||
293 | 'updateRecordIndexForNewRecord': function (aNewRecord) { | 290 | 'updateRecordIndexForNewRecord': function (aNewRecord) { |
294 | var newRecordIndex; | 291 | var newRecordIndex; |
295 | var recordReference; | 292 | var recordReference; |
296 | 293 | ||
297 | recordReference = aNewRecord.reference(); | 294 | recordReference = aNewRecord.reference(); |
298 | newRecordIndex = (MochiKit.Base.listMax(MochiKit.Base.map(MochiKit.Base.partial(MochiKit.Base.operator.mul, 1), MochiKit.Base.values(this.recordsIndex()))) + 1) + ''; | 295 | newRecordIndex = (MochiKit.Base.listMax(MochiKit.Base.map(MochiKit.Base.partial(MochiKit.Base.operator.mul, 1), MochiKit.Base.values(this.recordsIndex()))) + 1) + ''; |
299 | this.recordsIndex()[recordReference] = newRecordIndex; | 296 | this.recordsIndex()[recordReference] = newRecordIndex; |
300 | 297 | ||
301 | this.transientState().setValue('newlyCreatedRecordsIndex' + '.' + recordReference, newRecordIndex); | 298 | this.transientState().setValue('newlyCreatedRecordsIndex' + '.' + recordReference, newRecordIndex); |
302 | this.transientState().setValue('newlyCreatedRecordsReferences'+ '.' + recordReference, aNewRecord); | 299 | this.transientState().setValue('newlyCreatedRecordsReferences'+ '.' + recordReference, aNewRecord); |
303 | }, | 300 | }, |
304 | 301 | ||
305 | //......................................................................... | 302 | //......................................................................... |
306 | 303 | ||
307 | 'createNewRecord': function () { | 304 | 'createNewRecord': function () { |
308 | var deferredResult; | 305 | var deferredResult; |
309 | var newRecord; | 306 | var newRecord; |
310 | 307 | ||
311 | //console.log("#### new Clipperz.PM.DataModel.Record [4]"); | 308 | //console.log("#### new Clipperz.PM.DataModel.Record [4]"); |
312 | newRecord = new Clipperz.PM.DataModel.Record({ | 309 | newRecord = new Clipperz.PM.DataModel.Record({ |
313 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), | 310 | 'retrieveKeyFunction': MochiKit.Base.method(this, 'getRecordKey'), |
314 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), | 311 | 'retrieveRemoteDataFunction':this.retrieveRecordDetailFunction(), |
315 | 312 | ||
316 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), | 313 | 'retrieveIndexDataFunction':MochiKit.Base.method(this, 'getRecordIndexData'), |
317 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), | 314 | 'updateIndexDataFunction': MochiKit.Base.method(this, 'updateRecordIndexData'), |
318 | 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 315 | 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
319 | 316 | ||
320 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), | 317 | 'retrieveDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'getDirectLoginIndexData'), |
321 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), | 318 | 'setDirectLoginIndexDataFunction': MochiKit.Base.method(this, 'setDirectLoginIndexData'), |
322 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), | 319 | 'removeDirectLoginIndexDataFunction':MochiKit.Base.method(this, 'removeDirectLoginIndexData'), |
323 | 320 | ||
324 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') | 321 | 'createNewDirectLoginFunction': MochiKit.Base.method(this, 'createNewDirectLogin') |
325 | }); | 322 | }); |
326 | 323 | ||
327 | this.transientState().setValue('newRecordsReferences' + '.' + newRecord.reference(), newRecord); | 324 | this.transientState().setValue('newRecordsReferences' + '.' + newRecord.reference(), newRecord); |
328 | this.updateRecordIndexForNewRecord(newRecord); | 325 | this.updateRecordIndexForNewRecord(newRecord); |
329 | 326 | ||
330 | deferredResult = Clipperz.Async.callbacks("User.Header.RecordIndex.createNewRecord", [ | 327 | deferredResult = Clipperz.Async.callbacks("User.Header.RecordIndex.createNewRecord", [ |
331 | MochiKit.Base.method(this, 'records'), | 328 | MochiKit.Base.method(this, 'records'), |
332 | MochiKit.Base.partial(Clipperz.Async.setItemOnObject, newRecord.reference(), newRecord), | 329 | MochiKit.Base.partial(Clipperz.Async.setItemOnObject, newRecord.reference(), newRecord), |
333 | MochiKit.Base.method(this, 'setRecordKey', newRecord.reference(), Clipperz.PM.Crypto.randomKey()), | 330 | MochiKit.Base.method(this, 'setRecordKey', newRecord.reference(), Clipperz.PM.Crypto.randomKey()), |
334 | MochiKit.Base.method(newRecord, 'setLabel', ''), | 331 | MochiKit.Base.method(newRecord, 'setLabel', ''), |
335 | MochiKit.Base.partial(MochiKit.Async.succeed, newRecord) | 332 | MochiKit.Base.partial(MochiKit.Async.succeed, newRecord) |
336 | ], {trace:false}); | 333 | ], {trace:false}); |
337 | 334 | ||
338 | 335 | ||
339 | return deferredResult; | 336 | return deferredResult; |
340 | }, | 337 | }, |
341 | 338 | ||
342 | //------------------------------------------------------------------------- | 339 | //------------------------------------------------------------------------- |
343 | 340 | ||
344 | 'deleteRecord': function (aRecord) { | 341 | 'deleteRecord': function (aRecord) { |
345 | var deferredResult; | 342 | var deferredResult; |
346 | var recordReference; | 343 | var recordReference; |
347 | 344 | ||
348 | recordReference = aRecord.reference(); | 345 | recordReference = aRecord.reference(); |
349 | 346 | ||
350 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.deleteRecord", {trace:false}); | 347 | deferredResult = new Clipperz.Async.Deferred("User.Header.RecordIndex.deleteRecord", {trace:false}); |
351 | 348 | ||
352 | deferredResult.addMethod(aRecord, 'directLogins'); | 349 | deferredResult.addMethod(aRecord, 'directLogins'); |
353 | deferredResult.addCallback(MochiKit.Base.values); | 350 | deferredResult.addCallback(MochiKit.Base.values); |
354 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeDirectLogin')); | 351 | deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'removeDirectLogin')); |
355 | 352 | ||
356 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); | 353 | deferredResult.addMethod(this.recordsData(), 'removeValue', this.recordsIndex()[recordReference]); |
357 | deferredResult.addCallback(MochiKit.Base.bind(function () { | 354 | deferredResult.addCallback(MochiKit.Base.bind(function () { |
358 | this.transientState().setValue('deleteRecordsIndex' + '.' + recordReference, this.recordsIndex()[recordReference]); | 355 | this.transientState().setValue('deleteRecordsIndex' + '.' + recordReference, this.recordsIndex()[recordReference]); |
359 | delete this.recordsIndex()[recordReference]; | 356 | delete this.recordsIndex()[recordReference]; |
360 | }, this)); | 357 | }, this)); |
361 | 358 | ||
362 | deferredResult.addMethod(this, 'records'); | 359 | deferredResult.addMethod(this, 'records'); |
363 | deferredResult.addCallback(MochiKit.Base.itemgetter(recordReference)); | 360 | deferredResult.addCallback(MochiKit.Base.itemgetter(recordReference)); |
364 | deferredResult.addMethod(this.transientState(), 'setValue', 'deleteRecordsReferences' + '.' + recordReference); | 361 | deferredResult.addMethod(this.transientState(), 'setValue', 'deleteRecordsReferences' + '.' + recordReference); |
365 | 362 | ||
366 | deferredResult.addMethod(this, 'records'); | 363 | deferredResult.addMethod(this, 'records'); |
367 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { | 364 | deferredResult.addCallback(MochiKit.Base.bind(function (someRecords) { |
368 | delete someRecords[recordReference]; | 365 | delete someRecords[recordReference]; |
369 | }, this)); | 366 | }, this)); |
370 | deferredResult.callback(); | 367 | deferredResult.callback(); |
371 | 368 | ||
372 | return deferredResult; | 369 | return deferredResult; |
373 | }, | 370 | }, |
374 | 371 | ||
375 | //========================================================================= | 372 | //========================================================================= |
376 | 373 | ||
377 | 'removeDirectLogin': function (aDirectLogin) { | 374 | 'removeDirectLogin': function (aDirectLogin) { |
378 | this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLogin.reference()]); | 375 | this.directLoginsData().removeValue(this.directLoginsIndex()[aDirectLogin.reference()]); |
379 | }, | 376 | }, |
380 | 377 | ||
381 | //------------------------------------------------------------------------- | 378 | //------------------------------------------------------------------------- |
382 | 379 | ||
383 | 'createNewDirectLogin': function (aRecord) { | 380 | 'createNewDirectLogin': function (aRecord) { |
384 | var newDirectLogin; | 381 | var newDirectLogin; |
385 | varnewDirectLoginIndexValue; | 382 | varnewDirectLoginIndexValue; |
386 | 383 | ||
387 | newDirectLogin = new Clipperz.PM.DataModel.DirectLogin({record:aRecord}); | 384 | newDirectLogin = new Clipperz.PM.DataModel.DirectLogin({record:aRecord}); |
388 | newDirectLoginIndexValue = MochiKit.Base.listMax(MochiKit.Base.map(function (aValue) { return aValue * 1; }, MochiKit.Base.values(this.directLoginsIndex()))) + 1; | 385 | newDirectLoginIndexValue = MochiKit.Base.listMax(MochiKit.Base.map(function (aValue) { return aValue * 1; }, MochiKit.Base.values(this.directLoginsIndex()))) + 1; |
389 | 386 | ||
390 | this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); | 387 | this.transientState().setValue('newDirectLoginReferences' + '.' + newDirectLogin.reference(), newDirectLogin); |
391 | 388 | ||
392 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [1]", newDirectLogin.reference(), newDirectLoginIndexValue); | 389 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [1]", newDirectLogin.reference(), newDirectLoginIndexValue); |
393 | this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; | 390 | this.directLoginsIndex()[newDirectLogin.reference()] = newDirectLoginIndexValue; |
394 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [2]", newDirectLogin.reference(), this.directLoginsIndex()[newDirectLogin.reference()]); | 391 | //console.log("UserHeaderRecordIndex.createNewDirectLogin [2]", newDirectLogin.reference(), this.directLoginsIndex()[newDirectLogin.reference()]); |
395 | this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); | 392 | this.directLoginsData().setValue(this.directLoginsIndex()[newDirectLogin.reference()], {'record': this.recordsIndex()[aRecord.reference()]}); |
396 | 393 | ||
397 | return newDirectLogin; | 394 | return newDirectLogin; |
398 | }, | 395 | }, |
399 | 396 | ||
400 | //========================================================================= | 397 | //========================================================================= |
401 | 398 | ||
402 | 'deleteAllCleanTextData': function () { | 399 | 'deleteAllCleanTextData': function () { |
403 | return Clipperz.Async.callbacks("User.Header.RecordIndex.deleteAllCleanTextData", [ | 400 | return Clipperz.Async.callbacks("User.Header.RecordIndex.deleteAllCleanTextData", [ |
404 | // MochiKit.Base.method(this, 'records'), | 401 | // MochiKit.Base.method(this, 'records'), |
405 | // MochiKit.Base.values, | 402 | // MochiKit.Base.values, |
406 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), | 403 | // MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller('deleteAllCleanTextData')), |
407 | 404 | ||
408 | MochiKit.Base.method(this, 'recordsData'), | 405 | MochiKit.Base.method(this, 'recordsData'), |