summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js288
1 files changed, 288 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
new file mode 100644
index 0000000..4dfdd8e
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
@@ -0,0 +1,288 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
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
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 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
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31//if (typeof(Clipperz.PM.BookmarkletProcessor) == 'undefined') { Clipperz.PM.BookmarkletProcessor = {}; }
32//if (typeof(Clipperz.PM.BookmarkletProcessor.versions) == 'undefined') { Clipperz.PM.BookmarkletProcessor.versions = {}; }
33
34/*
35Clipperz.PM.BookmarkletProcessor.versions['abstract'] = function(anUser, aConfiguration) {
36 this._user = anUser;
37 this._configuration = aConfiguration;
38
39 this._recordTitle = null;
40 this._record = null;
41 this._editableFields = null;
42
43 return this;
44}
45
46
47Clipperz.PM.BookmarkletProcessor.versions['abstract'].prototype = MochiKit.Base.update(null, {
48
49 'toString': function() {
50 return "BookmarkletProcessor - " + this.user();
51 },
52
53 //-------------------------------------------------------------------------
54
55 'user': function() {
56 return this._user;
57 },
58
59 //-------------------------------------------------------------------------
60
61 'configuration': function() {
62 return this._configuration;
63 },
64
65 //-------------------------------------------------------------------------
66
67 'record': function() {
68 throw Clipperz.Base.exception.AbstractMethod;
69 },
70
71 //-------------------------------------------------------------------------
72 __syntaxFix__: "syntax fix"
73});
74*/
75
76Clipperz.PM.BookmarkletProcessor = function(anUser, aConfiguration) {
77 this._user = anUser;
78 this._configuration = aConfiguration;
79
80 this._recordTitle = null;
81 this._record = null;
82 this._editableFields = null;
83 this._favicon = null;
84
85 return this;
86}
87
88Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, {
89
90 'toString': function() {
91 return "BookmarkletProcessor - " + this.user();
92 },
93
94 //-------------------------------------------------------------------------
95
96 'user': function() {
97 return this._user;
98 },
99
100 //-------------------------------------------------------------------------
101
102 'configuration': function() {
103 return this._configuration;
104 },
105
106 //-------------------------------------------------------------------------
107
108 'recordTitle': function() {
109 if (this._recordTitle == null) {
110 this._recordTitle = this.configuration().page.title;
111 }
112
113 return this._recordTitle;
114 },
115
116 //-------------------------------------------------------------------------
117
118 'fields': function() {
119 return this.configuration().form.inputs;
120 },
121
122 //-------------------------------------------------------------------------
123
124 'editableFields': function() {
125 if (this._editableFields == null) {
126 this._editableFields = MochiKit.Base.filter(function(aField) {
127 var result;
128 var type;
129
130 type = aField['type'].toLowerCase();
131 result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select'));
132
133 return result;
134 }, this.fields())
135 }
136
137 return this._editableFields;
138 },
139
140 //-------------------------------------------------------------------------
141
142 'hostname': function() {
143 if (this._hostname == null) {
144 var actionUrl;
145
146 actionUrl = this.configuration()['form']['attributes']['action'];
147//MochiKit.Logging.logDebug("+++ actionUrl: " + actionUrl);
148 this._hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1');
149 }
150
151 return this._hostname;
152 },
153
154 'favicon': function() {
155 if (this._favicon == null) {
156 this._favicon = "http://" + this.hostname() + "/favicon.ico";
157//MochiKit.Logging.logDebug("+++ favicon: " + this._favicon);
158 }
159
160 return this._favicon;
161 },
162
163 //-------------------------------------------------------------------------
164
165 'record': function() {
166 if (this._record == null) {
167 var record;
168 var recordVersion;
169 var directLogin;
170 var bindings;
171 var i,c;
172
173 record = new Clipperz.PM.DataModel.Record({
174 label:this.recordTitle(),
175 notes:"",
176 user:this.user()
177 });
178 recordVersion = new Clipperz.PM.DataModel.RecordVersion(record, {})
179 record.setCurrentVersion(recordVersion);
180
181 bindings = {};
182
183 c = this.editableFields().length;
184 for (i=0; i<c; i++) {
185 var formField;
186 var recordField;
187
188//MochiKit.Logging.logDebug(">>> adding a field");
189 formField = this.editableFields()[i];
190 recordField = new Clipperz.PM.DataModel.RecordField({
191 recordVersion:recordVersion,
192 label:formField['name'],
193 value:formField['value'],
194 type:Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']],
195 hidden:false
196 });
197 recordVersion.addField(recordField);
198
199 bindings[formField['name']] = recordField.key();
200//MochiKit.Logging.logDebug("<<< adding a field");
201 }
202
203 directLogin = new Clipperz.PM.DataModel.DirectLogin({
204 record:record,
205 label:this.recordTitle() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'],
206 // bookmarkletVersion:this.version(),
207 bookmarkletVersion:'0.2',
208 favicon:this.favicon(),
209 formData:this.configuration()['form'],
210 bindingData:bindings
211 });
212 record.addDirectLogin(directLogin);
213
214 this.user().addRecord(record);
215
216 this._record = record;
217 }
218
219 return this._record;
220 },
221
222 //-------------------------------------------------------------------------
223 __syntaxFix__: "syntax fix"
224});
225
226//#############################################################################
227
228Clipperz.PM.BookmarkletProcessor.createRecordFromBookmarkletConfiguration = function(anUser, aConfiguration) {
229 var processor;
230
231 processor = new Clipperz.PM.BookmarkletProcessor(anUser, aConfiguration);
232
233 return processor.record();
234};
235
236//-----------------------------------------------------------------------------
237
238Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration = function(aConfiguration) {
239 var result;
240
241 //throw "XSS Bookmarklet attempt";
242
243 result = aConfiguration;
244
245 return result;
246};
247
248//-----------------------------------------------------------------------------
249
250Clipperz.PM.BookmarkletProcessor.checkBookmarkletConfiguration = function(aConfiguration, aButton, aCallback) {
251 var result;
252
253 try {
254 result = Clipperz.Base.evalJSON(aConfiguration);
255 result = Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration(result);
256
257 if (result['version'] != '0.2.3') {
258 throw "WrongBookmarkletVersion";
259 }
260 } catch (exception) {
261 var title;
262 var message;
263
264 if (exception == "WrongBookmarkletVersion") {
265 title = Clipperz.PM.Strings['newRecordPanelWrongBookmarkletVersionExceptionTitle'];
266 message = Clipperz.PM.Strings['newRecordPanelWrongBookmarkletVersionExceptionMessage'];
267 } else {
268 title = Clipperz.PM.Strings['newRecordPanelGeneralExceptionTitle'];
269 message = Clipperz.PM.Strings['newRecordPanelGeneralExceptionMessage'];
270 }
271 Clipperz.PM.Components.MessageBox().show({
272 title:title,
273 text:message,
274 width:240,
275 fn:aCallback,
276 closable:false,
277 showProgressBar:false,
278 showCloseButton:false,
279 buttons:{'ok':Clipperz.PM.Strings['newRecordPanelExceptionPanelCloseButtonLabel']}
280 }, aButton);
281
282 throw exception;
283 }
284
285 return result;
286};
287
288//-----------------------------------------------------------------------------