summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
index 83cbfe2..2295d3f 100644
--- a/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js
+++ b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.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 = {}; }
28//if (typeof(Clipperz.PM.BookmarkletProcessor) == 'undefined') { Clipperz.PM.BookmarkletProcessor = {}; } 26//if (typeof(Clipperz.PM.BookmarkletProcessor) == 'undefined') { Clipperz.PM.BookmarkletProcessor = {}; }
29//if (typeof(Clipperz.PM.BookmarkletProcessor.versions) == 'undefined') { Clipperz.PM.BookmarkletProcessor.versions = {}; } 27//if (typeof(Clipperz.PM.BookmarkletProcessor.versions) == 'undefined') { Clipperz.PM.BookmarkletProcessor.versions = {}; }
30 28
31/* 29/*
32Clipperz.PM.BookmarkletProcessor.versions['abstract'] = function(anUser, aConfiguration) { 30Clipperz.PM.BookmarkletProcessor.versions['abstract'] = function(anUser, aConfiguration) {
33 this._user = anUser; 31 this._user = anUser;
34 this._configuration = aConfiguration; 32 this._configuration = aConfiguration;
35 33
36 this._recordTitle = null; 34 this._recordTitle = null;
37 this._record = null; 35 this._record = null;
38 this._editableFields = null; 36 this._editableFields = null;
39 37
40 return this; 38 return this;
41} 39}
42 40
43 41
44Clipperz.PM.BookmarkletProcessor.versions['abstract'].prototype = MochiKit.Base.update(null, { 42Clipperz.PM.BookmarkletProcessor.versions['abstract'].prototype = MochiKit.Base.update(null, {
45 43
46 'toString': function() { 44 'toString': function() {
47 return "BookmarkletProcessor - " + this.user(); 45 return "BookmarkletProcessor - " + this.user();
48 }, 46 },
49 47
50 //------------------------------------------------------------------------- 48 //-------------------------------------------------------------------------
51 49
52 'user': function() { 50 'user': function() {
53 return this._user; 51 return this._user;
54 }, 52 },
55 53
56 //------------------------------------------------------------------------- 54 //-------------------------------------------------------------------------
57 55
58 'configuration': function() { 56 'configuration': function() {
59 return this._configuration; 57 return this._configuration;
60 }, 58 },
61 59
62 //------------------------------------------------------------------------- 60 //-------------------------------------------------------------------------
63 61
64 'record': function() { 62 'record': function() {
65 throw Clipperz.Base.exception.AbstractMethod; 63 throw Clipperz.Base.exception.AbstractMethod;
66 }, 64 },
67 65
68 //------------------------------------------------------------------------- 66 //-------------------------------------------------------------------------
69 __syntaxFix__: "syntax fix" 67 __syntaxFix__: "syntax fix"
70}); 68});
71*/ 69*/
72 70
73Clipperz.PM.BookmarkletProcessor = function(anUser, aConfiguration) { 71Clipperz.PM.BookmarkletProcessor = function(anUser, aConfiguration) {
74 this._user = anUser; 72 this._user = anUser;
75 this._configuration = aConfiguration; 73 this._configuration = aConfiguration;
76 74
77 this._recordTitle = null; 75 this._recordTitle = null;
78 this._record = null; 76 this._record = null;
79 this._editableFields = null; 77 this._editableFields = null;
80 this._favicon = null; 78 this._favicon = null;
81 79
82 return this; 80 return this;
83} 81}
84 82
85Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, { 83Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, {
86 84
87 'toString': function() { 85 'toString': function() {
88 return "BookmarkletProcessor - " + this.user(); 86 return "BookmarkletProcessor - " + this.user();
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 'configuration': function() { 97 'configuration': function() {
100 return this._configuration; 98 return this._configuration;
101 }, 99 },
102 100
103 //------------------------------------------------------------------------- 101 //-------------------------------------------------------------------------
104 102
105 'recordTitle': function() { 103 'recordTitle': function() {
106 if (this._recordTitle == null) { 104 if (this._recordTitle == null) {
107 this._recordTitle = this.configuration().page.title; 105 this._recordTitle = this.configuration().page.title;
108 } 106 }
109 107
110 return this._recordTitle; 108 return this._recordTitle;
111 }, 109 },
112 110
113 //------------------------------------------------------------------------- 111 //-------------------------------------------------------------------------
114 112
115 'fields': function() { 113 'fields': function() {
116 return this.configuration().form.inputs; 114 return this.configuration().form.inputs;
117 }, 115 },
118 116
119 //------------------------------------------------------------------------- 117 //-------------------------------------------------------------------------
120 118
121 'editableFields': function() { 119 'editableFields': function() {
122 if (this._editableFields == null) { 120 if (this._editableFields == null) {
123 this._editableFields = MochiKit.Base.filter(function(aField) { 121 this._editableFields = MochiKit.Base.filter(function(aField) {
124 var result; 122 var result;
125 var type; 123 var type;
126 124
127 type = aField['type'].toLowerCase(); 125 type = aField['type'].toLowerCase();
128 result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); 126 result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select'));
129 127
130 return result; 128 return result;
131 }, this.fields()) 129 }, this.fields())
132 } 130 }
133 131
134 return this._editableFields; 132 return this._editableFields;
135 }, 133 },
136 134
137 //------------------------------------------------------------------------- 135 //-------------------------------------------------------------------------
138 136
139 'hostname': function() { 137 'hostname': function() {
140 if (this._hostname == null) { 138 if (this._hostname == null) {
141 var actionUrl; 139 var actionUrl;
142 140
143 actionUrl = this.configuration()['form']['attributes']['action']; 141 actionUrl = this.configuration()['form']['attributes']['action'];
144//MochiKit.Logging.logDebug("+++ actionUrl: " + actionUrl); 142//MochiKit.Logging.logDebug("+++ actionUrl: " + actionUrl);
145 this._hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1'); 143 this._hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1');
146 } 144 }
147 145
148 return this._hostname; 146 return this._hostname;
149 }, 147 },
150 148
151 'favicon': function() { 149 'favicon': function() {
152 if (this._favicon == null) { 150 if (this._favicon == null) {
153 this._favicon = "http://" + this.hostname() + "/favicon.ico"; 151 this._favicon = "http://" + this.hostname() + "/favicon.ico";
154//MochiKit.Logging.logDebug("+++ favicon: " + this._favicon); 152//MochiKit.Logging.logDebug("+++ favicon: " + this._favicon);
155 } 153 }
156 154
157 return this._favicon; 155 return this._favicon;
158 }, 156 },
159 157
160 //------------------------------------------------------------------------- 158 //-------------------------------------------------------------------------
161 159
162 'record': function() { 160 'record': function() {
163 if (this._record == null) { 161 if (this._record == null) {
164 var record; 162 var record;
165 var recordVersion; 163 var recordVersion;
166 var directLogin; 164 var directLogin;
167 var bindings; 165 var bindings;
168 var i,c; 166 var i,c;
169 167
170 record = new Clipperz.PM.DataModel.Record({ 168 record = new Clipperz.PM.DataModel.Record({
171 label:this.recordTitle(), 169 label:this.recordTitle(),
172 notes:"", 170 notes:"",
173 user:this.user() 171 user:this.user()
174 }); 172 });
175 recordVersion = new Clipperz.PM.DataModel.RecordVersion(record, {}) 173 recordVersion = new Clipperz.PM.DataModel.RecordVersion(record, {})
176 record.setCurrentVersion(recordVersion); 174 record.setCurrentVersion(recordVersion);
177 175
178 bindings = {}; 176 bindings = {};
179 177
180 c = this.editableFields().length; 178 c = this.editableFields().length;
181 for (i=0; i<c; i++) { 179 for (i=0; i<c; i++) {
182 var formField; 180 var formField;
183 var recordField; 181 var recordField;
184 182
185//MochiKit.Logging.logDebug(">>> adding a field"); 183//MochiKit.Logging.logDebug(">>> adding a field");
186 formField = this.editableFields()[i]; 184 formField = this.editableFields()[i];
187 recordField = new Clipperz.PM.DataModel.RecordField({ 185 recordField = new Clipperz.PM.DataModel.RecordField({
188 recordVersion:recordVersion, 186 recordVersion:recordVersion,
189 label:formField['name'], 187 label:formField['name'],
190 value:formField['value'], 188 value:formField['value'],
191 type:Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']], 189 type:Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']],
192 hidden:false 190 hidden:false
193 }); 191 });
194 recordVersion.addField(recordField); 192 recordVersion.addField(recordField);
195 193
196 bindings[formField['name']] = recordField.key(); 194 bindings[formField['name']] = recordField.key();
197//MochiKit.Logging.logDebug("<<< adding a field"); 195//MochiKit.Logging.logDebug("<<< adding a field");
198 } 196 }
199 197
200 directLogin = new Clipperz.PM.DataModel.DirectLogin({ 198 directLogin = new Clipperz.PM.DataModel.DirectLogin({
201 record:record, 199 record:record,
202 label:this.recordTitle() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], 200 label:this.recordTitle() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'],
203 // bookmarkletVersion:this.version(), 201 // bookmarkletVersion:this.version(),
204 bookmarkletVersion:'0.2', 202 bookmarkletVersion:'0.2',
205 favicon:this.favicon(), 203 favicon:this.favicon(),
206 formData:this.configuration()['form'], 204 formData:this.configuration()['form'],
207 bindingData:bindings 205 bindingData:bindings
208 }); 206 });
209 record.addDirectLogin(directLogin); 207 record.addDirectLogin(directLogin);
210 208
211 this.user().addRecord(record); 209 this.user().addRecord(record);
212 210
213 this._record = record; 211 this._record = record;
214 } 212 }