Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/Header.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Header.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Header.js b/frontend/beta/js/Clipperz/PM/DataModel/Header.js index c780855..908d9f4 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Header.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Header.js | |||
@@ -1,150 +1,148 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.Header = function(args) { | 31 | Clipperz.PM.DataModel.Header = function(args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | this._user = args.user; | 34 | this._user = args.user; |
37 | 35 | ||
38 | this._serverData = null; | 36 | this._serverData = null; |
39 | this._serverDataVersion = null; | 37 | this._serverDataVersion = null; |
40 | this._jsonEvaledServerData = null; | 38 | this._jsonEvaledServerData = null; |
41 | 39 | ||
42 | this._decryptedLegacyServerData = null; | 40 | this._decryptedLegacyServerData = null; |
43 | this._isDecryptingLegacyServerData = false; | 41 | this._isDecryptingLegacyServerData = false; |
44 | this._decryptingLegacyServerDataPendingQueue = []; | 42 | this._decryptingLegacyServerDataPendingQueue = []; |
45 | 43 | ||
46 | this.resetUpdatedSections(); | 44 | this.resetUpdatedSections(); |
47 | 45 | ||
48 | this._shouldLoadSections = {}; | 46 | this._shouldLoadSections = {}; |
49 | 47 | ||
50 | Clipperz.NotificationCenter.register(this.user(), 'updatedSection', this, 'updatedSectionHandler'); | 48 | Clipperz.NotificationCenter.register(this.user(), 'updatedSection', this, 'updatedSectionHandler'); |
51 | 49 | ||
52 | return this; | 50 | return this; |
53 | } | 51 | } |
54 | 52 | ||
55 | Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { | 53 | Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { |
56 | 54 | ||
57 | //------------------------------------------------------------------------- | 55 | //------------------------------------------------------------------------- |
58 | 56 | ||
59 | 'user': function() { | 57 | 'user': function() { |
60 | return this._user; | 58 | return this._user; |
61 | }, | 59 | }, |
62 | 60 | ||
63 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
64 | //------------------------------------------------------------------------- | 62 | //------------------------------------------------------------------------- |
65 | //------------------------------------------------------------------------- | 63 | //------------------------------------------------------------------------- |
66 | //------------------------------------------------------------------------- | 64 | //------------------------------------------------------------------------- |
67 | //------------------------------------------------------------------------- | 65 | //------------------------------------------------------------------------- |
68 | //------------------------------------------------------------------------- | 66 | //------------------------------------------------------------------------- |
69 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
70 | //------------------------------------------------------------------------- | 68 | //------------------------------------------------------------------------- |
71 | //------------------------------------------------------------------------- | 69 | //------------------------------------------------------------------------- |
72 | 70 | ||
73 | 'updatedSections': function() { | 71 | 'updatedSections': function() { |
74 | return this._updatedSections; | 72 | return this._updatedSections; |
75 | }, | 73 | }, |
76 | 74 | ||
77 | 'markSectionAsUpdated': function(aSectionName) { | 75 | 'markSectionAsUpdated': function(aSectionName) { |
78 | this.updatedSections().push(aSectionName); | 76 | this.updatedSections().push(aSectionName); |
79 | }, | 77 | }, |
80 | 78 | ||
81 | 'resetUpdatedSections': function() { | 79 | 'resetUpdatedSections': function() { |
82 | this._updatedSections = [] | 80 | this._updatedSections = [] |
83 | }, | 81 | }, |
84 | 82 | ||
85 | 'hasSectionBeenUpdated': function(aSectionName) { | 83 | 'hasSectionBeenUpdated': function(aSectionName) { |
86 | return (this.updatedSections().join().indexOf(aSectionName) != -1); | 84 | return (this.updatedSections().join().indexOf(aSectionName) != -1); |
87 | }, | 85 | }, |
88 | 86 | ||
89 | 'cachedServerDataSection': function(aSectionName) { | 87 | 'cachedServerDataSection': function(aSectionName) { |
90 | return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; | 88 | return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; |
91 | }, | 89 | }, |
92 | 90 | ||
93 | 'updateAllSections': function() { | 91 | 'updateAllSections': function() { |
94 | this.resetUpdatedSections(); | 92 | this.resetUpdatedSections(); |
95 | this.markSectionAsUpdated('records'); | 93 | this.markSectionAsUpdated('records'); |
96 | this.markSectionAsUpdated('directLogins'); | 94 | this.markSectionAsUpdated('directLogins'); |
97 | this.markSectionAsUpdated('preferences'); | 95 | this.markSectionAsUpdated('preferences'); |
98 | this.markSectionAsUpdated('oneTimePasswords'); | 96 | this.markSectionAsUpdated('oneTimePasswords'); |
99 | 97 | ||
100 | return MochiKit.Async.succeed(this); | 98 | return MochiKit.Async.succeed(this); |
101 | }, | 99 | }, |
102 | 100 | ||
103 | 'updatedSectionHandler': function(anEvent) { | 101 | 'updatedSectionHandler': function(anEvent) { |
104 | this.markSectionAsUpdated(anEvent.parameters()); | 102 | this.markSectionAsUpdated(anEvent.parameters()); |
105 | }, | 103 | }, |
106 | 104 | ||
107 | //------------------------------------------------------------------------- | 105 | //------------------------------------------------------------------------- |
108 | 106 | ||
109 | 'getObjectKeyIndex': function(anObject) { | 107 | 'getObjectKeyIndex': function(anObject) { |
110 | var result; | 108 | var result; |
111 | varitemReference; | 109 | varitemReference; |
112 | var index; | 110 | var index; |
113 | 111 | ||
114 | result = {}; | 112 | result = {}; |
115 | index = 0; | 113 | index = 0; |
116 | 114 | ||
117 | for (itemReference in anObject) { | 115 | for (itemReference in anObject) { |
118 | result[itemReference] = index.toString(); | 116 | result[itemReference] = index.toString(); |
119 | index ++; | 117 | index ++; |
120 | } | 118 | } |
121 | 119 | ||
122 | return result; | 120 | return result; |
123 | }, | 121 | }, |
124 | 122 | ||
125 | //------------------------------------------------------------------------- | 123 | //------------------------------------------------------------------------- |
126 | 124 | ||
127 | 'serializedDataWithRecordAndDirectLoginIndexes': function(aRecordIndexes, aDirectLoginIndexs) { | 125 | 'serializedDataWithRecordAndDirectLoginIndexes': function(aRecordIndexes, aDirectLoginIndexs) { |
128 | var result; | 126 | var result; |
129 | var records; | 127 | var records; |
130 | var recordReference; | 128 | var recordReference; |
131 | 129 | ||
132 | //MochiKit.Logging.logDebug(">>> Header.serializedData"); | 130 | //MochiKit.Logging.logDebug(">>> Header.serializedData"); |
133 | result = { | 131 | result = { |
134 | 'records': {}, | 132 | 'records': {}, |
135 | 'directLogins': {} | 133 | 'directLogins': {} |
136 | }; | 134 | }; |
137 | 135 | ||
138 | records = this.user().records(); | 136 | records = this.user().records(); |
139 | for (recordReference in records) { | 137 | for (recordReference in records) { |
140 | result['records'][aRecordIndexes[recordReference]] = this.user().records()[recordReference].headerData(); | 138 | result['records'][aRecordIndexes[recordReference]] = this.user().records()[recordReference].headerData(); |
141 | } | 139 | } |
142 | 140 | ||
143 | for (directLoginReference in this.user().directLoginReferences()) { | 141 | for (directLoginReference in this.user().directLoginReferences()) { |
144 | var currentDirectLogin; | 142 | var currentDirectLogin; |
145 | vardirectLoginData; | 143 | vardirectLoginData; |
146 | 144 | ||
147 | currentDirectLogin = this.user().directLoginReferences()[directLoginReference]; | 145 | currentDirectLogin = this.user().directLoginReferences()[directLoginReference]; |
148 | if (aRecordIndexes[currentDirectLogin.recordReference()] != null) { | 146 | if (aRecordIndexes[currentDirectLogin.recordReference()] != null) { |
149 | directLoginData = { | 147 | directLoginData = { |
150 | // reference: currentDirectLogin.reference(), | 148 | // reference: currentDirectLogin.reference(), |