summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/Record.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/Record.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
index 85dd06b..b816f80 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.js
@@ -1,216 +1,213 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2011 Clipperz Srl
4 4
5This file is part of Clipperz's Javascript Crypto Library. 5This file is part of Clipperz Community Edition.
6Javascript Crypto Library provides web developers with an extensive 6Clipperz Community Edition is an online password manager.
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please 7For further information about its features and functionalities please
11refer to http://www.clipperz.com 8refer 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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } 28if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
32 29
33 30
34Clipperz.PM.DataModel.Record = function(args) { 31Clipperz.PM.DataModel.Record = function(args) {
35//console.log(">>> new Clipperz.PM.DataModel.Record", args); 32//console.log(">>> new Clipperz.PM.DataModel.Record", args);
36 Clipperz.PM.DataModel.Record.superclass.constructor.apply(this, arguments); 33 Clipperz.PM.DataModel.Record.superclass.constructor.apply(this, arguments);
37 34
38 this._updateDate = (args.updateDate ? Clipperz.PM.Date.parse(args.updateDate) : Clipperz.Base.exception.raise('MandatoryParameter')); 35 this._updateDate = (args.updateDate ? Clipperz.PM.Date.parse(args.updateDate) : Clipperz.Base.exception.raise('MandatoryParameter'));
39 36
40 this._retrieveIndexDataFunction = args.retrieveIndexDataFunction|| Clipperz.Base.exception.raise('MandatoryParameter'); 37 this._retrieveIndexDataFunction = args.retrieveIndexDataFunction|| Clipperz.Base.exception.raise('MandatoryParameter');
41 this._updateIndexDataFunction = args.updateIndexDataFunction || Clipperz.Base.exception.raise('MandatoryParameter'); 38 this._updateIndexDataFunction = args.updateIndexDataFunction || Clipperz.Base.exception.raise('MandatoryParameter');
42 39
43 this._retrieveDirectLoginIndexDataFunction = args.retrieveDirectLoginIndexDataFunction|| null; 40 this._retrieveDirectLoginIndexDataFunction = args.retrieveDirectLoginIndexDataFunction|| null;
44 this._setDirectLoginIndexDataFunction = args.setDirectLoginIndexDataFunction || null; 41 this._setDirectLoginIndexDataFunction = args.setDirectLoginIndexDataFunction || null;
45 this._removeDirectLoginIndexDataFunction = args.removeDirectLoginIndexDataFunction|| null; 42 this._removeDirectLoginIndexDataFunction = args.removeDirectLoginIndexDataFunction|| null;
46 43
47 this._createNewDirectLoginFunction = args.createNewDirectLoginFunction || null; 44 this._createNewDirectLoginFunction = args.createNewDirectLoginFunction || null;
48 45
49 this._directLogins = {}; 46 this._directLogins = {};
50 47
51 this._versions = {}; 48 this._versions = {};
52 49
53 this._currentRecordVersion = null; 50 this._currentRecordVersion = null;
54 if (this.isBrandNew()) { 51 if (this.isBrandNew()) {
55 var newVersion; 52 var newVersion;
56 53
57 this.setNotes(''); 54 this.setNotes('');
58 newVersion = new Clipperz.PM.DataModel.Record.Version({ 55 newVersion = new Clipperz.PM.DataModel.Record.Version({
59 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'), 56 'retrieveKeyFunction':MochiKit.Base.method(this, 'getVersionKey'),
60 'getVersion': MochiKit.Base.method(this, 'getVersion') 57 'getVersion': MochiKit.Base.method(this, 'getVersion')
61 58
62 }); 59 });
63 this._versions[newVersion.reference()] = newVersion; 60 this._versions[newVersion.reference()] = newVersion;
64 this._currentVersionReference = newVersion.reference(); 61 this._currentVersionReference = newVersion.reference();
65 // this.setLabel(''); 62 // this.setLabel('');
66 } 63 }
67 64
68//console.log("<<< new Clipperz.PM.DataModel.Record", args); 65//console.log("<<< new Clipperz.PM.DataModel.Record", args);
69 66
70 return this; 67 return this;
71} 68}
72 69
73 70
74Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.EncryptedRemoteObject, { 71Clipperz.Base.extend(Clipperz.PM.DataModel.Record, Clipperz.PM.DataModel.EncryptedRemoteObject, {
75 72
76 'toString': function() { 73 'toString': function() {
77 return "Record (" + this.reference() + ")"; 74 return "Record (" + this.reference() + ")";
78 }, 75 },
79 76
80 //------------------------------------------------------------------------- 77 //-------------------------------------------------------------------------
81 78
82 'reference': function () { 79 'reference': function () {
83 return this._reference; 80 return this._reference;
84 }, 81 },
85 82
86 //========================================================================= 83 //=========================================================================
87 84
88 'getIndexData': function () { 85 'getIndexData': function () {
89 return this._retrieveIndexDataFunction(this.reference()); 86 return this._retrieveIndexDataFunction(this.reference());
90 }, 87 },
91 88
92 //......................................................................... 89 //.........................................................................
93 90
94 'getIndexDataForKey': function (aKey) { 91 'getIndexDataForKey': function (aKey) {
95 return Clipperz.Async.callbacks("Record.getIndexDataForKey", [ 92 return Clipperz.Async.callbacks("Record.getIndexDataForKey", [
96 MochiKit.Base.method(this, 'getIndexData'), 93 MochiKit.Base.method(this, 'getIndexData'),
97 MochiKit.Base.itemgetter(aKey) 94 MochiKit.Base.itemgetter(aKey)
98 ], {trace:false}); 95 ], {trace:false});
99 }, 96 },
100 97
101 //------------------------------------------------------------------------- 98 //-------------------------------------------------------------------------
102 99
103 'setIndexDataForKey': function (aKey, aValue) { 100 'setIndexDataForKey': function (aKey, aValue) {
104 // return this._updateIndexDataFunction(this.reference(), aKey, aValue); 101 // return this._updateIndexDataFunction(this.reference(), aKey, aValue);
105 102
106 var deferredResult; 103 var deferredResult;
107 104
108 deferredResult = new Clipperz.Async.Deferred("Record.setIndexDataForKey", {trace:false}); 105 deferredResult = new Clipperz.Async.Deferred("Record.setIndexDataForKey", {trace:false});
109 deferredResult.addMethod(this, 'getIndexDataForKey', aKey); 106 deferredResult.addMethod(this, 'getIndexDataForKey', aKey);
110 deferredResult.addCallback(MochiKit.Base.bind(function (aCurrentValue) { 107 deferredResult.addCallback(MochiKit.Base.bind(function (aCurrentValue) {
111 var result; 108 var result;
112 var originalValue; 109 var originalValue;
113 110
114 originalValue = this.transientState().getValue('originalValues.indexData.' + aKey); 111 originalValue = this.transientState().getValue('originalValues.indexData.' + aKey);
115 if (originalValue == null) { 112 if (originalValue == null) {
116 originalValue = this.transientState().setValue('originalValues.indexData.' + aKey, aCurrentValue); 113 originalValue = this.transientState().setValue('originalValues.indexData.' + aKey, aCurrentValue);
117 } 114 }
118 115
119 if (aCurrentValue != aValue) { 116 if (aCurrentValue != aValue) {
120 if (originalValue != aValue) { 117 if (originalValue != aValue) {
121 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, true); 118 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, true);
122 } else { 119 } else {
123 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, false); 120 this.transientState().setValue('hasPendingChanges.indexData.' + aKey, false);
124 } 121 }
125 122
126 result = this._updateIndexDataFunction(this.reference(), aKey, aValue); 123 result = this._updateIndexDataFunction(this.reference(), aKey, aValue);
127 } else { 124 } else {
128 result = MochiKit.Async.succeed(aValue); 125 result = MochiKit.Async.succeed(aValue);
129 } 126 }
130 127
131 return result; 128 return result;
132 }, this)); 129 }, this));
133 130
134 deferredResult.callback(); 131 deferredResult.callback();
135 132
136 return deferredResult; 133 return deferredResult;
137 }, 134 },
138 135
139 //========================================================================= 136 //=========================================================================
140/* 137/*
141 'key': function () { 138 'key': function () {
142 return this.getIndexDataForKey('key'); 139 return this.getIndexDataForKey('key');
143 }, 140 },
144*/ 141*/
145 //========================================================================= 142 //=========================================================================
146 143
147 'label': function () { 144 'label': function () {
148 return this.getIndexDataForKey('label'); 145 return this.getIndexDataForKey('label');
149 }, 146 },
150 147
151 //......................................................................... 148 //.........................................................................
152 149
153 'setLabel': function (aValue) { 150 'setLabel': function (aValue) {
154 return this.setIndexDataForKey('label', aValue); 151 return this.setIndexDataForKey('label', aValue);
155 }, 152 },
156 153
157 //========================================================================= 154 //=========================================================================
158 155
159 'headerNotes': function () { 156 'headerNotes': function () {
160 return this.getIndexDataForKey('notes'); 157 return this.getIndexDataForKey('notes');
161 }, 158 },
162 159
163 //------------------------------------------------------------------------- 160 //-------------------------------------------------------------------------
164 161
165 'notes': function () { 162 'notes': function () {
166 return Clipperz.Async.callbacks("Record.notes", [ 163 return Clipperz.Async.callbacks("Record.notes", [
167 MochiKit.Base.method(this, 'headerNotes'), 164 MochiKit.Base.method(this, 'headerNotes'),
168 MochiKit.Base.bind(function (someHeaderNotes) { 165 MochiKit.Base.bind(function (someHeaderNotes) {
169 var result; 166 var result;
170 167
171 if ((someHeaderNotes == null) || (typeof(someHeaderNotes) == 'undefined')) { 168 if ((someHeaderNotes == null) || (typeof(someHeaderNotes) == 'undefined')) {
172 result = this.getValue('notes'); 169 result = this.getValue('notes');
173 } else { 170 } else {
174 result = MochiKit.Async.succeed(someHeaderNotes); 171 result = MochiKit.Async.succeed(someHeaderNotes);
175 } 172 }
176 173
177 return result; 174 return result;
178 }, this) 175 }, this)
179 ], {trace:false}); 176 ], {trace:false});
180 }, 177 },
181 178
182 //......................................................................... 179 //.........................................................................
183 180
184 'setNotes': function (aValue) { 181 'setNotes': function (aValue) {
185 return this.setValue('notes', aValue); 182 return this.setValue('notes', aValue);
186 }, 183 },
187 184
188 //========================================================================= 185 //=========================================================================
189 186
190 'updateDate': function () { 187 'updateDate': function () {
191 return MochiKit.Async.succeed(this._updateDate); 188 return MochiKit.Async.succeed(this._updateDate);
192 }, 189 },
193 190
194 //========================================================================= 191 //=========================================================================
195 192
196 'favicon': function () { 193 'favicon': function () {
197 var result; 194 var result;
198 var directLogins; 195 var directLogins;
199 196
200 directLogins = MochiKit.Base.values(this.directLogins()); 197 directLogins = MochiKit.Base.values(this.directLogins());
201 if (directLogins.length > 0) { 198 if (directLogins.length > 0) {
202 result = directLogins[0].favicon(); 199 result = directLogins[0].favicon();
203 // } else if (/* is there an URL to use for searching a favicon */){ 200 // } else if (/* is there an URL to use for searching a favicon */){
204 } else { 201 } else {
205 result = null; //MochiKit.Async.succeed(Clipperz.PM.Strings['defaultFaviconUrl']); 202 result = null; //MochiKit.Async.succeed(Clipperz.PM.Strings['defaultFaviconUrl']);
206 } 203 }
207 204
208 return result; 205 return result;
209 }, 206 },
210 207
211 //------------------------------------------------------------------------- 208 //-------------------------------------------------------------------------
212 209
213 'searchableContent': function () { 210 'searchableContent': function () {
214 var deferredResult; 211 var deferredResult;
215 212
216//console.log(">>> searchableContent"); 213//console.log(">>> searchableContent");