summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js b/frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js
index aee5703..c0cfa3c 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/DirectLogin.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.DirectLogin = function(args) { 31Clipperz.PM.DataModel.DirectLogin = function(args) {
34//MochiKit.Logging.logDebug(">>> new Clipperz.PM.DataModel.DirectLogin"); 32//MochiKit.Logging.logDebug(">>> new Clipperz.PM.DataModel.DirectLogin");
35//console.log(">>> new Clipperz.PM.DataModel.DirectLogin - args: %o", args); 33//console.log(">>> new Clipperz.PM.DataModel.DirectLogin - args: %o", args);
36//console.log("--- formData: %s", Clipperz.Base.serializeJSON(args.formData)); 34//console.log("--- formData: %s", Clipperz.Base.serializeJSON(args.formData));
37 args = args || {}; 35 args = args || {};
38 36
39//MochiKit.Logging.logDebug("--- new Clipperz.PM.DataModel.DirectLogin - args: " + Clipperz.Base.serializeJSON(MochiKit.Base.keys(args))); 37//MochiKit.Logging.logDebug("--- new Clipperz.PM.DataModel.DirectLogin - args: " + Clipperz.Base.serializeJSON(MochiKit.Base.keys(args)));
40 this._record = args.record || null; 38 this._record = args.record || null;
41 this._label = args.label || "unnamed record" 39 this._label = args.label || "unnamed record"
42 this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); 40 this._reference = args.reference || Clipperz.PM.Crypto.randomKey();
43 this._favicon = args.favicon || null; 41 this._favicon = args.favicon || null;
44 this._bookmarkletVersion = args.bookmarkletVersion || "0.1"; 42 this._bookmarkletVersion = args.bookmarkletVersion || "0.1";
45 43
46 this._directLoginInputs = null; 44 this._directLoginInputs = null;
47 45
48 this._formValues = args.formValues || {}; 46 this._formValues = args.formValues || {};
49 this.setFormData(args.formData || null); 47 this.setFormData(args.formData || null);
50//console.log("=== formData: %o", this.formData()); 48//console.log("=== formData: %o", this.formData());
51 49
52 if (args.legacyBindingData == null) { 50 if (args.legacyBindingData == null) {
53 this.setBindingData(args.bindingData || null); 51 this.setBindingData(args.bindingData || null);
54 } else { 52 } else {
55 this.setLegacyBindingData(args.legacyBindingData); 53 this.setLegacyBindingData(args.legacyBindingData);
56 } 54 }
57 55
58 this._fixedFavicon = null; 56 this._fixedFavicon = null;
59 57
60 //this._formValues = args.formValues || (this.hasValuesToSet() ? {} : null); 58 //this._formValues = args.formValues || (this.hasValuesToSet() ? {} : null);
61//MochiKit.Logging.logDebug("<<< new Clipperz.PM.DataModel.DirectLogin"); 59//MochiKit.Logging.logDebug("<<< new Clipperz.PM.DataModel.DirectLogin");
62 60
63 return this; 61 return this;
64} 62}
65 63
66Clipperz.PM.DataModel.DirectLogin.prototype = MochiKit.Base.update(null, { 64Clipperz.PM.DataModel.DirectLogin.prototype = MochiKit.Base.update(null, {
67 65
68 'remove': function() { 66 'remove': function() {
69 this.record().removeDirectLogin(this); 67 this.record().removeDirectLogin(this);
70 }, 68 },
71 69
72 //------------------------------------------------------------------------- 70 //-------------------------------------------------------------------------
73 71
74 'record': function() { 72 'record': function() {
75 return this._record; 73 return this._record;
76 }, 74 },
77 75
78 //------------------------------------------------------------------------- 76 //-------------------------------------------------------------------------
79 77
80 'user': function() { 78 'user': function() {
81 return this.record().user(); 79 return this.record().user();
82 }, 80 },
83 81
84 //------------------------------------------------------------------------- 82 //-------------------------------------------------------------------------
85 83
86 'reference': function() { 84 'reference': function() {
87 return this._reference; 85 return this._reference;
88 }, 86 },
89 87
90 //------------------------------------------------------------------------- 88 //-------------------------------------------------------------------------
91 89
92 'label': function() { 90 'label': function() {
93 return this._label; 91 return this._label;
94 }, 92 },
95 93
96 'setLabel': function(aValue) { 94 'setLabel': function(aValue) {
97 this._label = aValue; 95 this._label = aValue;
98 }, 96 },
99 97
100 //------------------------------------------------------------------------- 98 //-------------------------------------------------------------------------
101 99
102 'favicon': function() { 100 'favicon': function() {
103 if (this._favicon == null) { 101 if (this._favicon == null) {
104 varactionUrl; 102 varactionUrl;
105 var hostname; 103 var hostname;
106 104
107 actionUrl = this.formData()['attributes']['action']; 105 actionUrl = this.formData()['attributes']['action'];
108 hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1'); 106 hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1');
109 this._favicon = "http://" + hostname + "/favicon.ico"; 107 this._favicon = "http://" + hostname + "/favicon.ico";
110 } 108 }
111 109
112 return this._favicon; 110 return this._favicon;
113 }, 111 },
114 112
115 //------------------------------------------------------------------------- 113 //-------------------------------------------------------------------------
116 114
117 'fixedFavicon': function() { 115 'fixedFavicon': function() {
118 var result; 116 var result;
119 117
120 if (this._fixedFavicon == null) { 118 if (this._fixedFavicon == null) {
121 result = this.favicon(); 119 result = this.favicon();
122 120
123 if (Clipperz_IEisBroken) { 121 if (Clipperz_IEisBroken) {
124 if (this.user().preferences().disableUnsecureFaviconLoadingForIE()) { 122 if (this.user().preferences().disableUnsecureFaviconLoadingForIE()) {
125 if (result.indexOf('https://') != 0) { 123 if (result.indexOf('https://') != 0) {
126 result = Clipperz.PM.Strings['defaultFaviconUrl_IE']; 124 result = Clipperz.PM.Strings['defaultFaviconUrl_IE'];
127 this.setFixedFavicon(result); 125 this.setFixedFavicon(result);
128 } 126 }
129 } 127 }
130 } 128 }
131 } else { 129 } else {
132 result = this._fixedFavicon; 130 result = this._fixedFavicon;
133 } 131 }
134 132
135 return result; 133 return result;
136 }, 134 },
137 135
138 'setFixedFavicon': function(aValue) { 136 'setFixedFavicon': function(aValue) {
139 this._fixedFavicon = aValue; 137 this._fixedFavicon = aValue;
140 }, 138 },
141 139
142 //------------------------------------------------------------------------- 140 //-------------------------------------------------------------------------
143 141
144 'bookmarkletVersion': function() { 142 'bookmarkletVersion': function() {
145 return this._bookmarkletVersion; 143 return this._bookmarkletVersion;
146 }, 144 },
147 145
148 'setBookmarkletVersion': function(aValue) { 146 'setBookmarkletVersion': function(aValue) {
149 this._bookmarkletVersion = aValue; 147 this._bookmarkletVersion = aValue;
150 }, 148 },
151 149
152 //------------------------------------------------------------------------- 150 //-------------------------------------------------------------------------
153 151
154 'formData': function() { 152 'formData': function() {
155 return this._formData; 153 return this._formData;
156 }, 154 },
157 155
158 'setFormData': function(aValue) { 156 'setFormData': function(aValue) {
159 var formData; 157 var formData;
160 158
161//MochiKit.Logging.logDebug(">>> DirectLogin.setFormData - " + Clipperz.Base.serializeJSON(aValue)); 159//MochiKit.Logging.logDebug(">>> DirectLogin.setFormData - " + Clipperz.Base.serializeJSON(aValue));
162 switch (this.bookmarkletVersion()) { 160 switch (this.bookmarkletVersion()) {
163 case "0.2": 161 case "0.2":
164 formData = aValue; 162 formData = aValue;
165 break; 163 break;
166 case "0.1": 164 case "0.1":
167//MochiKit.Logging.logDebug("--- DirectLogin.setFormData - fixing form data from bookmarklet version 0.1"); 165//MochiKit.Logging.logDebug("--- DirectLogin.setFormData - fixing form data from bookmarklet version 0.1");
168 formData = this.fixFormDataFromBookmarkletVersion_0_1(aValue); 166 formData = this.fixFormDataFromBookmarkletVersion_0_1(aValue);
169 break; 167 break;
170 } 168 }
171 169
172 this._formData = aValue; 170 this._formData = aValue;
173 this.setBookmarkletVersion("0.2"); 171 this.setBookmarkletVersion("0.2");
174 172
175//MochiKit.Logging.logDebug("--- DirectLogin.setFormData - formData: " + Clipperz.Base.serializeJSON(formData)); 173//MochiKit.Logging.logDebug("--- DirectLogin.setFormData - formData: " + Clipperz.Base.serializeJSON(formData));
176 if (formData != null) { 174 if (formData != null) {
177 var i,c; 175 var i,c;
178 176
179 this._directLoginInputs = []; 177 this._directLoginInputs = [];
180 c = formData['inputs'].length; 178 c = formData['inputs'].length;
181 for (i=0; i<c; i++) { 179 for (i=0; i<c; i++) {
182 var directLoginInput; 180 var directLoginInput;
183 181
184 directLoginInput = new Clipperz.PM.DataModel.DirectLoginInput(this, formData['inputs'][i]); 182 directLoginInput = new Clipperz.PM.DataModel.DirectLoginInput(this, formData['inputs'][i]);
185 this._directLoginInputs.push(directLoginInput); 183 this._directLoginInputs.push(directLoginInput);
186 } 184 }
187 } 185 }
188//MochiKit.Logging.logDebug("<<< DirectLogin.setFormData"); 186//MochiKit.Logging.logDebug("<<< DirectLogin.setFormData");
189 }, 187 },
190 188
191 'fixFormDataFromBookmarkletVersion_0_1': function(aValue) { 189 'fixFormDataFromBookmarkletVersion_0_1': function(aValue) {
192//{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true } 190//{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true }
193 // || 191 // ||
194 // \ / 192 // \ /
195 // \/ 193 // \/
196//{"name":"dominio", "type":"radio", "options":[{"value":"@alice.it", "checked":true}, {"value":"@tin.it", "checked":false}, {"value":"@virgilio.it", "checked":false}, {"value":"@tim.it", "checked":false}]} 194//{"name":"dominio", "type":"radio", "options":[{"value":"@alice.it", "checked":true}, {"value":"@tin.it", "checked":false}, {"value":"@virgilio.it", "checked":false}, {"value":"@tim.it", "checked":false}]}
197 var result; 195 var result;
198 var inputs; 196 var inputs;
199 var updatedInputs; 197 var updatedInputs;
200 var radios; 198 var radios;
201 199
202//MochiKit.Logging.logDebug(">>> DirectLogin.fixFormDataFromBookmarkletVersion_0_1"); 200//MochiKit.Logging.logDebug(">>> DirectLogin.fixFormDataFromBookmarkletVersion_0_1");
203 result = aValue; 201 result = aValue;
204 inputs = aValue['inputs']; 202 inputs = aValue['inputs'];
205 203
206 updatedInputs = MochiKit.Base.filter(function(anInput) { 204 updatedInputs = MochiKit.Base.filter(function(anInput) {
207 varresult; 205 varresult;
208 var type; 206 var type;
209 207
210 type = anInput['type'] || 'text'; 208 type = anInput['type'] || 'text';
211 result = type.toLowerCase() != 'radio'; 209 result = type.toLowerCase() != 'radio';
212 210
213 return result; 211 return result;
214 }, inputs); 212 }, inputs);