summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js b/frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js
index fc4a45c..69a7d91 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/RecordVersion.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 25if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
28if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } 26if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
29 27
30 28
31//############################################################################# 29//#############################################################################
32 30
33Clipperz.PM.DataModel.RecordVersion = function(aRecord, args) { 31Clipperz.PM.DataModel.RecordVersion = function(aRecord, args) {
34 args = args || {}; 32 args = args || {};
35 33
36 this._record = aRecord; 34 this._record = aRecord;
37 35
38 this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); 36 this._reference = args.reference || Clipperz.PM.Crypto.randomKey();
39 this._version = args.version || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; 37 this._version = args.version || Clipperz.PM.Crypto.encryptingFunctions.currentVersion;
40 this._key = args.key || Clipperz.PM.Crypto.randomKey();; 38 this._key = args.key || Clipperz.PM.Crypto.randomKey();;
41 39
42 this._previousVersion = args.previousVersion || null; 40 this._previousVersion = args.previousVersion || null;
43 this._previousVersionKey = args.previousVersionKey || null; 41 this._previousVersionKey = args.previousVersionKey || null;
44 42
45 this.setIsBrandNew(args.reference == null); 43 this.setIsBrandNew(args.reference == null);
46 44
47 if (this.isBrandNew()) { 45 if (this.isBrandNew()) {
48 this._fields = {}; 46 this._fields = {};
49 47
50 this.setShouldLoadData(false); 48 this.setShouldLoadData(false);
51 this.setShouldDecryptData(false); 49 this.setShouldDecryptData(false);
52 this.setShouldProcessData(false); 50 this.setShouldProcessData(false);
53 } else { 51 } else {
54 if (typeof(args.fields) != 'undefined') { 52 if (typeof(args.fields) != 'undefined') {
55 this.processFieldData(args.fields); 53 this.processFieldData(args.fields);
56 54
57 this.setShouldLoadData(false); 55 this.setShouldLoadData(false);
58 this.setShouldDecryptData(false); 56 this.setShouldDecryptData(false);
59 this.setShouldProcessData(false); 57 this.setShouldProcessData(false);
60 } else { 58 } else {
61 if (typeof(args.data) != 'undefined') { 59 if (typeof(args.data) != 'undefined') {
62 this.setShouldLoadData(false); 60 this.setShouldLoadData(false);
63 } else { 61 } else {
64 this.setShouldLoadData(true); 62 this.setShouldLoadData(true);
65 } 63 }
66 this.setShouldDecryptData(true); 64 this.setShouldDecryptData(true);
67 this.setShouldProcessData(true); 65 this.setShouldProcessData(true);
68 } 66 }
69 } 67 }
70 68
71 this._serverData = args.data; 69 this._serverData = args.data;
72 this._decryptedData = null; 70 this._decryptedData = null;
73 71
74 return this; 72 return this;
75} 73}
76 74
77Clipperz.PM.DataModel.RecordVersion.prototype = MochiKit.Base.update(null, { 75Clipperz.PM.DataModel.RecordVersion.prototype = MochiKit.Base.update(null, {
78 76
79 'toString': function() { 77 'toString': function() {
80 return "RecordVersion"; 78 return "RecordVersion";
81 }, 79 },
82 80
83 //------------------------------------------------------------------------- 81 //-------------------------------------------------------------------------
84 82
85 'record': function() { 83 'record': function() {
86 return this._record; 84 return this._record;
87 }, 85 },
88 86
89 //------------------------------------------------------------------------- 87 //-------------------------------------------------------------------------
90 88
91 'reference': function() { 89 'reference': function() {
92 return this._reference; 90 return this._reference;
93 }, 91 },
94 92
95 'setReference': function(aValue) { 93 'setReference': function(aValue) {
96 this._reference = aValue; 94 this._reference = aValue;
97 }, 95 },
98 96
99 //------------------------------------------------------------------------- 97 //-------------------------------------------------------------------------
100 98
101 'key': function() { 99 'key': function() {
102//MochiKit.Logging.logDebug(">>> RecordVersion.key"); 100//MochiKit.Logging.logDebug(">>> RecordVersion.key");
103//MochiKit.Logging.logDebug("--- RecordVersion.key - " + this._key); 101//MochiKit.Logging.logDebug("--- RecordVersion.key - " + this._key);
104 return this._key; 102 return this._key;
105 }, 103 },
106 104
107 'setKey': function(aValue) { 105 'setKey': function(aValue) {
108 this._key = aValue; 106 this._key = aValue;
109 }, 107 },
110 108
111 //------------------------------------------------------------------------- 109 //-------------------------------------------------------------------------
112 110
113 'serverData': function() { 111 'serverData': function() {
114 return this._serverData; 112 return this._serverData;
115 }, 113 },
116 114
117 'setServerData': function(aValue) { 115 'setServerData': function(aValue) {
118 this._serverData = aValue; 116 this._serverData = aValue;
119 this.setShouldLoadData(false); 117 this.setShouldLoadData(false);
120 return aValue; 118 return aValue;
121 }, 119 },
122 120
123 //------------------------------------------------------------------------- 121 //-------------------------------------------------------------------------
124 122
125 'decryptedData': function() { 123 'decryptedData': function() {
126//MochiKit.Logging.logDebug(">>> RecordVersion.decryptedData: " + (this._decryptedData ? Clipperz.Base.serializeJSON(aValue) : "null")); 124//MochiKit.Logging.logDebug(">>> RecordVersion.decryptedData: " + (this._decryptedData ? Clipperz.Base.serializeJSON(aValue) : "null"));
127 return this._decryptedData; 125 return this._decryptedData;
128 }, 126 },
129 127
130 'setDecryptedData': function(aValue) { 128 'setDecryptedData': function(aValue) {
131//MochiKit.Logging.logDebug(">>> RecordVersion.setDecryptedData: " + Clipperz.Base.serializeJSON(aValue)); 129//MochiKit.Logging.logDebug(">>> RecordVersion.setDecryptedData: " + Clipperz.Base.serializeJSON(aValue));
132 this._decryptedData = aValue; 130 this._decryptedData = aValue;
133 this.setShouldDecryptData(false); 131 this.setShouldDecryptData(false);
134 return aValue; 132 return aValue;
135 }, 133 },
136 134
137 //------------------------------------------------------------------------- 135 //-------------------------------------------------------------------------
138 136
139 'version': function() { 137 'version': function() {
140 return this._version; 138 return this._version;
141 }, 139 },
142 140
143 //------------------------------------------------------------------------- 141 //-------------------------------------------------------------------------
144 142
145 'isBrandNew': function() { 143 'isBrandNew': function() {
146 return this._isBrandNew; 144 return this._isBrandNew;
147 }, 145 },
148 146
149 'setIsBrandNew': function(aValue) { 147 'setIsBrandNew': function(aValue) {
150 this._isBrandNew = aValue; 148 this._isBrandNew = aValue;
151 }, 149 },
152 150
153 //------------------------------------------------------------------------- 151 //-------------------------------------------------------------------------
154 152
155 'fields': function() { 153 'fields': function() {
156 return this._fields; 154 return this._fields;
157 }, 155 },
158 156
159 'addField': function(aField) { 157 'addField': function(aField) {
160 this.fields()[aField.key()] = aField; 158 this.fields()[aField.key()] = aField;
161 }, 159 },
162 160
163 'addNewField': function() { 161 'addNewField': function() {
164 varnewRecordField; 162 varnewRecordField;
165 163
166 newRecordField = new Clipperz.PM.DataModel.RecordField({recordVersion:this}); 164 newRecordField = new Clipperz.PM.DataModel.RecordField({recordVersion:this});
167 this.addField(newRecordField); 165 this.addField(newRecordField);
168 166
169 return newRecordField; 167 return newRecordField;
170 }, 168 },
171 169
172 'fieldWithName': function(aValue) { 170 'fieldWithName': function(aValue) {
173 varresult; 171 varresult;
174 var fieldValues; 172 var fieldValues;
175 var i,c; 173 var i,c;
176 174
177 result = null; 175 result = null;
178 fieldValues = MochiKit.Base.values(this.fields()); 176 fieldValues = MochiKit.Base.values(this.fields());
179 c = fieldValues.length; 177 c = fieldValues.length;
180 for (i=0; (i<c) && (result == null); i++) { 178 for (i=0; (i<c) && (result == null); i++) {
181 varcurrentField; 179 varcurrentField;
182 180
183 currentField = fieldValues[i]; 181 currentField = fieldValues[i];
184 if (currentField.label() == aValue) { 182 if (currentField.label() == aValue) {
185 result = currentField; 183 result = currentField;
186 } 184 }
187 } 185 }
188 186
189 return result; 187 return result;
190 }, 188 },
191 189
192 //------------------------------------------------------------------------- 190 //-------------------------------------------------------------------------
193 191
194 'shouldLoadData': function() { 192 'shouldLoadData': function() {
195 return this._shouldLoadData; 193 return this._shouldLoadData;
196 }, 194 },
197 195
198 'setShouldLoadData': function(aValue) { 196 'setShouldLoadData': function(aValue) {
199 this._shouldLoadData = aValue; 197 this._shouldLoadData = aValue;
200 }, 198 },
201 199
202 //------------------------------------------------------------------------- 200 //-------------------------------------------------------------------------
203 201
204 'shouldDecryptData': function() { 202 'shouldDecryptData': function() {
205 return this._shouldDecryptData; 203 return this._shouldDecryptData;
206 }, 204 },
207 205
208 'setShouldDecryptData': function(aValue) { 206 'setShouldDecryptData': function(aValue) {
209 this._shouldDecryptData = aValue; 207 this._shouldDecryptData = aValue;
210 }, 208 },
211 209
212 //------------------------------------------------------------------------- 210 //-------------------------------------------------------------------------
213 211
214 'shouldProcessData': function() { 212 'shouldProcessData': function() {