summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/Record.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/Record.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/Record.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js
index f89f79c..7b06f29 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.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.Record = function(args) { 31Clipperz.PM.DataModel.Record = function(args) {
34 args = args || {}; 32 args = args || {};
35 33
36 this._user = args['user'] || null; 34 this._user = args['user'] || null;
37 this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); 35 this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey();
38 this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; 36 this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion;
39 this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); 37 this._key = args['key'] || Clipperz.PM.Crypto.randomKey();
40 38
41 this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); 39 this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']);
42 40
43 this.setHeaderNotes(args['headerNotes'] || null); 41 this.setHeaderNotes(args['headerNotes'] || null);
44 this.setNotes(args['notes'] || args['headerNotes'] || ""); 42 this.setNotes(args['notes'] || args['headerNotes'] || "");
45//MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); 43//MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'");
46//MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); 44//MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'");
47 //this._notes = args.notes || ""; 45 //this._notes = args.notes || "";
48 46
49 this._versions = {}; 47 this._versions = {};
50 this._directLogins = {}; 48 this._directLogins = {};
51 this._removedDirectLogins = []; 49 this._removedDirectLogins = [];
52 50
53 this.setIsBrandNew(args['reference'] == null); 51 this.setIsBrandNew(args['reference'] == null);
54 52
55 this.setShouldLoadData(this.isBrandNew() ? false: true); 53 this.setShouldLoadData(this.isBrandNew() ? false: true);
56 this.setShouldDecryptData(this.isBrandNew() ? false: true); 54 this.setShouldDecryptData(this.isBrandNew() ? false: true);
57 this.setShouldProcessData(this.isBrandNew() ? false: true); 55 this.setShouldProcessData(this.isBrandNew() ? false: true);
58 56
59 this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); 57 this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null);
60 this.setCurrentVersionKey(null); 58 this.setCurrentVersionKey(null);
61 59
62 this._serverData = null; 60 this._serverData = null;
63 this._decryptedData = null; 61 this._decryptedData = null;
64 this._cachedData = null; 62 this._cachedData = null;
65 63
66 return this; 64 return this;
67} 65}
68 66
69Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { 67Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, {
70 68
71 'toString': function() { 69 'toString': function() {
72 return "Record (" + this.label() + ")"; 70 return "Record (" + this.label() + ")";
73 }, 71 },
74 72
75 //------------------------------------------------------------------------- 73 //-------------------------------------------------------------------------
76 74
77 'isBrandNew': function() { 75 'isBrandNew': function() {
78 return this._isBrandNew; 76 return this._isBrandNew;
79 }, 77 },
80 78
81 'setIsBrandNew': function(aValue) { 79 'setIsBrandNew': function(aValue) {
82 this._isBrandNew = aValue; 80 this._isBrandNew = aValue;
83 }, 81 },
84 82
85 //------------------------------------------------------------------------- 83 //-------------------------------------------------------------------------
86/* 84/*
87 'shouldRunTheRecordCreationWizard': function() { 85 'shouldRunTheRecordCreationWizard': function() {
88 return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); 86 return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0));
89 }, 87 },
90 */ 88 */
91 //------------------------------------------------------------------------- 89 //-------------------------------------------------------------------------
92 90
93 'user': function() { 91 'user': function() {
94 return this._user; 92 return this._user;
95 }, 93 },
96 94
97 //------------------------------------------------------------------------- 95 //-------------------------------------------------------------------------
98 96
99 'reference': function() { 97 'reference': function() {
100 return this._reference; 98 return this._reference;
101 }, 99 },
102 100
103 //------------------------------------------------------------------------- 101 //-------------------------------------------------------------------------
104 102
105 'key': function() { 103 'key': function() {
106 return this._key; 104 return this._key;
107 }, 105 },
108 106
109 'updateKey': function() { 107 'updateKey': function() {
110 this._key = Clipperz.PM.Crypto.randomKey(); 108 this._key = Clipperz.PM.Crypto.randomKey();
111 }, 109 },
112 110
113 //------------------------------------------------------------------------- 111 //-------------------------------------------------------------------------
114 112
115 'label': function() { 113 'label': function() {
116 return this._label; 114 return this._label;
117 }, 115 },
118 116
119 'setLabel': function(aValue) { 117 'setLabel': function(aValue) {
120 this._label = aValue; 118 this._label = aValue;
121 }, 119 },
122 120
123 'lowerCaseLabel': function() { 121 'lowerCaseLabel': function() {
124 return this.label().toLowerCase(); 122 return this.label().toLowerCase();
125 }, 123 },
126 124
127 //------------------------------------------------------------------------- 125 //-------------------------------------------------------------------------
128 126
129 'versions': function() { 127 'versions': function() {
130 return this._versions; 128 return this._versions;
131 }, 129 },
132 130
133 //------------------------------------------------------------------------- 131 //-------------------------------------------------------------------------
134 132
135 'currentVersion': function() { 133 'currentVersion': function() {
136 return this._currentVersion; 134 return this._currentVersion;
137 }, 135 },
138 136
139 'setCurrentVersion': function(aValue) { 137 'setCurrentVersion': function(aValue) {
140 this._currentVersion = aValue; 138 this._currentVersion = aValue;
141 }, 139 },
142 140
143 //------------------------------------------------------------------------- 141 //-------------------------------------------------------------------------
144 142
145 'currentVersionKey': function() { 143 'currentVersionKey': function() {
146 return this._currentVersionKey; 144 return this._currentVersionKey;
147 }, 145 },
148 146
149 'setCurrentVersionKey': function(aValue) { 147 'setCurrentVersionKey': function(aValue) {
150 this._currentVersionKey = aValue; 148 this._currentVersionKey = aValue;
151 }, 149 },
152 150
153 //------------------------------------------------------------------------- 151 //-------------------------------------------------------------------------
154 152
155 'deferredData': function() { 153 'deferredData': function() {
156 vardeferredResult; 154 vardeferredResult;
157 155
158//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); 156//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this);
159 deferredResult = new MochiKit.Async.Deferred(); 157 deferredResult = new MochiKit.Async.Deferred();
160 deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); 158 deferredResult.addCallback(MochiKit.Base.method(this, 'loadData'));
161 deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); 159 deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData'));
162 deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); 160 deferredResult.addCallback(MochiKit.Base.method(this, 'processData'));
163 deferredResult.addCallback(function(aRecord) { 161 deferredResult.addCallback(function(aRecord) {
164 return aRecord.currentVersion().deferredData(); 162 return aRecord.currentVersion().deferredData();
165 }); 163 });
166 deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); 164 deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData'));
167 deferredResult.addCallback(MochiKit.Async.succeed, this); 165 deferredResult.addCallback(MochiKit.Async.succeed, this);
168 deferredResult.callback(); 166 deferredResult.callback();
169//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); 167//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData");
170 168
171 return deferredResult; 169 return deferredResult;
172 }, 170 },
173 171
174 //------------------------------------------------------------------------- 172 //-------------------------------------------------------------------------
175 173
176 'exportedData': function() { 174 'exportedData': function() {
177 var result; 175 var result;
178 176
179 result = {}; 177 result = {};
180 result['label'] = this.label(); 178 result['label'] = this.label();
181 result['data'] = this.serializedData(); 179 result['data'] = this.serializedData();
182 result['currentVersion'] = this.currentVersion().serializedData(); 180 result['currentVersion'] = this.currentVersion().serializedData();
183 result['currentVersion']['reference'] = this.currentVersion().reference(); 181 result['currentVersion']['reference'] = this.currentVersion().reference();
184 // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); 182 // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions()));
185 183
186 return Clipperz.Base.serializeJSON(result); 184 return Clipperz.Base.serializeJSON(result);
187 }, 185 },
188 186
189 //------------------------------------------------------------------------- 187 //-------------------------------------------------------------------------
190 188
191 'shouldLoadData': function() { 189 'shouldLoadData': function() {
192 return this._shouldLoadData; 190 return this._shouldLoadData;
193 }, 191 },
194 192
195 'setShouldLoadData': function(aValue) { 193 'setShouldLoadData': function(aValue) {
196 this._shouldLoadData = aValue; 194 this._shouldLoadData = aValue;
197 }, 195 },
198 196
199 //------------------------------------------------------------------------- 197 //-------------------------------------------------------------------------
200 198
201 'shouldDecryptData': function() { 199 'shouldDecryptData': function() {
202 return this._shouldDecryptData; 200 return this._shouldDecryptData;
203 }, 201 },
204 202
205 'setShouldDecryptData': function(aValue) { 203 'setShouldDecryptData': function(aValue) {
206 this._shouldDecryptData = aValue; 204 this._shouldDecryptData = aValue;
207 }, 205 },
208 206
209 //------------------------------------------------------------------------- 207 //-------------------------------------------------------------------------
210 208
211 'shouldProcessData': function() { 209 'shouldProcessData': function() {
212 return this._shouldProcessData; 210 return this._shouldProcessData;
213 }, 211 },
214 212