summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js
Side-by-side diff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js
index 1d38509..8f8696d 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/DirectLogin.js
@@ -1,408 +1,405 @@
/*
Copyright 2008-2011 Clipperz Srl
-This file is part of Clipperz's Javascript Crypto Library.
-Javascript Crypto Library provides web developers with an extensive
-and efficient set of cryptographic functions. The library aims to
-obtain maximum execution speed while preserving modularity and
-reusability.
+This file is part of Clipperz Community Edition.
+Clipperz Community Edition is an online password manager.
For further information about its features and functionalities please
-refer to http://www.clipperz.com
+refer to http://www.clipperz.com.
-* Javascript Crypto Library is free software: you can redistribute
+* Clipperz Community Edition is free software: you can redistribute
it and/or modify it under the terms of the GNU Affero General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.
-* Javascript Crypto Library is distributed in the hope that it will
+* Clipperz Community Edition is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
- License along with Javascript Crypto Library. If not, see
+ License along with Clipperz Community Edition. If not, see
<http://www.gnu.org/licenses/>.
*/
Clipperz.Base.module('Clipperz.PM.DataModel');
Clipperz.PM.DataModel.DirectLogin = function(args) {
args = args || {};
Clipperz.PM.DataModel.DirectLogin.superclass.constructor.apply(this, arguments);
this._reference = args.reference
|| Clipperz.PM.Crypto.randomKey();
this._record = args.record
|| Clipperz.Base.exception.raise('MandatoryParameter');
this._retrieveIndexDataFunction = args.retrieveIndexDataFunction
|| this.record().retrieveDirectLoginIndexDataFunction()
|| Clipperz.Base.exception.raise('MandatoryParameter');
this._setIndexDataFunction = args.setIndexDataFunction
|| this.record().setDirectLoginIndexDataFunction()
|| Clipperz.Base.exception.raise('MandatoryParameter');
this._removeIndexDataFunction = args.removeIndexDataFunction
|| this.record().removeDirectLoginIndexDataFunction()
|| Clipperz.Base.exception.raise('MandatoryParameter');
this._inputs = null;
this._bindings = null;
this._formValues = null;
// this._inputsDeferredLock = new MochiKit.Async.DeferredLock();
// this._bindingsDeferredLock = new MochiKit.Async.DeferredLock();
// this._formValuesDeferredLock = new MochiKit.Async.DeferredLock();
this._transientState = null;
this._isBrandNew = MochiKit.Base.isUndefinedOrNull(args.reference);
this.record().addDirectLogin(this);
return this;
}
Clipperz.Base.extend(Clipperz.PM.DataModel.DirectLogin, Object, {
'toString': function() {
return "DirectLogin (" + this.reference() + ")";
},
//=========================================================================
'reference': function () {
return this._reference;
},
//-------------------------------------------------------------------------
'record': function () {
return this._record;
},
//=========================================================================
'isBrandNew': function () {
return this._isBrandNew;
},
//=========================================================================
'removeIndexDataFunction': function () {
return this._removeIndexDataFunction;
},
'remove': function () {
return Clipperz.Async.callbacks("DirectLogin.remove", [
MochiKit.Base.partial(this.removeIndexDataFunction(), this.reference()),
MochiKit.Base.method(this.record(), 'removeDirectLogin', this)
], {trace:false});
},
//=========================================================================
/*
'inputsDeferredLock': function () {
return this._inputsDeferredLock;
},
'bindingsDeferredLock': function () {
return this._bindingsDeferredLock;
},
'formValuesDeferredLock': function () {
return this._formValuesDeferredLock;
},
*/
//=========================================================================
'label': function () {
return this.getIndexDataForKey('label');
},
'setLabelKeepingBackwardCompatibilityWithBeta': function (aValue) {
return Clipperz.Async.callbacks("DirectLogin.setLabelKeepingBackwardCompatibilityWithBeta", [
MochiKit.Base.method(this, 'setIndexDataForKey', 'label', aValue),
MochiKit.Base.method(this, 'setValue', 'label', aValue)
], {trace:false});
},
'setLabel': function (aValue) {
return this.setLabelKeepingBackwardCompatibilityWithBeta(aValue);
// return this.setIndexDataForKey('label', aValue);
},
//=========================================================================
'favicon': function () {
return this.getIndexDataForKey('favicon');
},
'setFavicon': function (aValue) {
return this.setIndexDataForKey('favicon', aValue);
},
'faviconUrlWithBookmarkletConfiguration': function (aBookmarkletConfiguration) {
var result;
if (! MochiKit.Base.isUndefinedOrNull(aBookmarkletConfiguration['page']['favicon'])) {
result = aBookmarkletConfiguration['page']['favicon'];
} else if (! MochiKit.Base.isUndefinedOrNull(aBookmarkletConfiguration['form']['attributes']['action'])) {
var actionUrl;
var hostname;
actionUrl = aBookmarkletConfiguration['form']['attributes']['action'];
hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1');
result = "http://" + hostname + "/favicon.ico";
} else {
result = null;
}
return result;
},
//-------------------------------------------------------------------------
/*
'faviconData': function () {
var regexp = new RegExp('^data\:\/\/.*', 'i');
return Clipperz.Async.callbacks("DirectLogin.favicon", [
MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon'),
MochiKit.Base.method(regexp, 'test'),
Clipperz.Async.deferredIf("is data URL", [
MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon')
], [
MochiKit.Base.method(this, 'transientState'),
MochiKit.Base.itemgetter('faviconData'),
Clipperz.Async.deferredIf('has a chaced value for the favicon data', [
MochiKit.Base.operator.identity
], [
MochiKit.Base.method(this, 'getIndexDataForKey', 'favicon'),
MochiKit.Base.method(this, 'loadFaviconDataFromURL')
])
])
], {trace:false});
},
//-------------------------------------------------------------------------
'loadFaviconDataFromURL': function (anURL) {
var deferredResult;
var image;
deferredResult = new Clipperz.Async.Deferred("DirectLogin.loadFaviconDataFromURL", {trace:false});
deferredResult.addCallback(function (anEvent) {
var image = anEvent.src();
var canvas = document.createElement("canvas");
var result;
canvas.width = image.width;
canvas.height = image.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0);
result = canvas.toDataURL(/*"image/png"* /);
return result;
});
deferredResult.addErrback(MochiKit.Async.succeed, Clipperz.PM.Strings.getValue('defaultFaviconUrl'));
deferredResult.addBoth(MochiKit.Base.bind(function (aDataUrl) {
this.transientState()['faviconData'] = aDataUrl;
return aDataUrl;
}, this));
image = new Image();
MochiKit.Signal.connect(image, 'onload', MochiKit.Base.method(deferredResult, 'callback'));
MochiKit.Signal.connect(image, 'onerror', MochiKit.Base.method(deferredResult, 'errback'));
MochiKit.Signal.connect(image, 'onabort', MochiKit.Base.method(deferredResult, 'errback'));
image.src = anURL;
return deferredResult;
},
*/
//=========================================================================
'type': function () {
return this.getValue('formData.attributes.type')
},
//=========================================================================
'serializedData': function () {
return Clipperz.Async.collectResults("DirectLogin.serializedData", {
'bookmarkletVersion': MochiKit.Base.method(this, 'getValue', 'bookmarkletVersion'),
'formData': MochiKit.Base.method(this, 'getValue', 'formData'),
'formValues': MochiKit.Base.method(this, 'getValue', 'formValues'),
'bindingData': [
MochiKit.Base.method(this, 'bindings'),
function (someBindings) {
var result;
var bindingKey;
result = {}
for (bindingKey in someBindings) {
result[bindingKey] = someBindings[bindingKey].serializedData();
}
return result;
}
]
}, {trace:false})()
},
//=========================================================================
/*
'fixFormDataFromBookmarkletVersion_0_1': function(aValue) {
//{"type":"radio", "name":"action", "value":"new-user", "checked":false }, { "type":"radio", "name":"action", "value":"sign-in", "checked":true }
// ||
// \ /
// \/
//{"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}]}
var result;
var inputs;
var updatedInputs;
var radios;
result = aValue;
inputs = aValue['inputs'];
updatedInputs = MochiKit.Base.filter(function(anInput) {
var result;
var type;
type = anInput['type'] || 'text';
result = type.toLowerCase() != 'radio';
return result;
}, inputs);
radios = MochiKit.Base.filter(function(anInput) {
var result;
var type;
type = anInput['type'] || 'text';
result = type.toLowerCase() == 'radio';
return result;
}, inputs);
if (radios.length > 0) {
var updatedRadios;
updatedRadios = {};
MochiKit.Iter.forEach(radios, MochiKit.Base.bind(function(aRadio) {
var radioConfiguration;
radioConfiguration = updatedRadios[aRadio['name']];
if (radioConfiguration == null) {
radioConfiguration = {type:'radio', name:aRadio['name'], options:[]};
updatedRadios[aRadio['name']] = radioConfiguration;
}
// TODO: remove the value: field and replace it with element.dom.value = <some value>
radioConfiguration.options.push({value:aRadio['value'], checked:aRadio['checked']});
// TODO: shoud remove the 'formValues' call, as it is now deferred
// if ((aRadio['checked'] == true) && (this.formValues()[aRadio['name']] == null)) {
// this.formValues()[aRadio['name']] = aRadio['value'];
// }
}, this))
updatedInputs = MochiKit.Base.concat(updatedInputs, MochiKit.Base.values(updatedRadios));
}
delete result.inputs;
result.inputs = updatedInputs;
return result;
},
'_fixConfiguration': function (aConfiguration) {
var fixedConfiguration;
// var inputs;
// var bindings;
// var i,c;
fixedConfiguration = Clipperz.Base.deepClone(aConfiguration);
//console.log("PROCESS CONFIGURATION", aConfiguration);
switch (aConfiguration['bookmarkletVersion']) {
case '0.1':
fixedConfiguration['formData'] = this.fixFormDataFromBookmarkletVersion_0_1(aConfiguration['formData']);
break;
case '0.2':
fixedConfiguration['formData'] = aConfiguration['formData'];
break;
}
/ *
aConfiguration['_inputs'] = [];
c = formData['inputs'].length;
for (i=0; i<c; i++) {
aConfiguration['_inputs'].push(new Clipperz.PM.DataModel.DirectLoginInput(formData['inputs'][i]));
}
* /
/ *
aConfiguration['_bindings'] = {};
if (aConfiguration['legacyBindingData'] == null) {
if (aConfiguration['bindingData'] != null) {
var bindingKey;
for (bindingKey in aConfiguration['bindingData']) {
var newBinding;
newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldKey:aConfiguration['bindingData'][bindingKey]});
aConfiguration['_bindings'][newBinding.key()] = newBinding;
}
} else {
var editableFields;
editableFields = MochiKit.Base.filter(function(aField) {
var result;
var type;
type = aField['type'].toLowerCase();
result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select'));
return result;
}, aConfiguration['_inputs']);
MochiKit.Iter.forEach(editableFields, MochiKit.Base.bind(function(anEditableField) {
var newBinding;
newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(anEditableField['name']);
aConfiguration['_bindings'][newBinding.key()] = newBinding;
}, this));
}
} else {
var bindingKey;
for (bindingKey in aConfiguration['legacyBindingData']) {
var newBinding;
newBinding = new Clipperz.PM.DataModel.DirectLoginBinding(bindingKey, {fieldName:aConfiguration['legacyBindingData'][bindingKey]});
aConfiguration['_bindings'][newBinding.key()] = newBinding;
}
}
* /
return fixedConfiguration;
},
//-------------------------------------------------------------------------
'getObjectDataStore': function () {
var deferredResult;
deferredResult = new Clipperz.Async.Deferred("DirectLogin.getObjectDataStore", {trace:false});
deferredResult.acquireLock(this.objectDataStoreDeferredLock());
deferredResult.addCallback(MochiKit.Base.bind(function () {
var innerDeferredResult;