From 541bb378ddece2eab135a8066a16994e94436dea Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Mon, 03 Oct 2011 16:04:12 +0000 Subject: Merge pull request #1 from gcsolaroli/master First version of the restructured repository --- (limited to 'frontend/beta/js/Clipperz/PM/Components') diff --git a/frontend/beta/js/Clipperz/PM/Components/BaseComponent.js b/frontend/beta/js/Clipperz/PM/Components/BaseComponent.js new file mode 100644 index 0000000..67e257b --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/BaseComponent.js @@ -0,0 +1,124 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } + +//############################################################################# + +var _Clipperz_PM_Components_Panels_base_id_ = 0; + +//############################################################################# + +Clipperz.PM.Components.BaseComponent = function(anElement, args) { + args = args || {}; +// MochiKit.Base.bindMethods(this); +// Clipperz.PM.Components.BaseComponent.superclass.constructor.call(this, args); + + this._element = anElement; + this._ids = {}; + + return this; +} + +//============================================================================= + +//MochiKit.Base.update(Clipperz.PM.Components.BaseComponent.prototype, { +YAHOO.extendX(Clipperz.PM.Components.BaseComponent, YAHOO.ext.util.Observable, { + + 'isClipperzPMComponent': true, + + //------------------------------------------------------------------------- + + 'toString': function () { + return "Clipperz.PM.Components.BaseComponent component"; + }, + + //------------------------------------------------------------------------- + + 'domHelper': function() { + return Clipperz.YUI.DomHelper; + }, + + //------------------------------------------------------------------------- + + 'element': function() { +//MochiKit.Logging.logDebug(">>> BaseComponent.element"); + return this._element; + }, + + 'setElement': function(aValue) { + this._element = aValue; + }, + + //----------------------------------------------------- + + 'remove': function() { +//MochiKit.Logging.logDebug(">>> BaseComponent.remove"); + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); +//MochiKit.Logging.logDebug("<<< BaseComponent.remove"); + }, + + //------------------------------------------------------------------------- + + 'getId': function(aValue) { + var result; + + result = this._ids[aValue]; + + if (typeof(result) == 'undefined') { + _Clipperz_PM_Components_Panels_base_id_ ++; + + result = "Clipperz_PM_Components_Panels_" + aValue + "_" + _Clipperz_PM_Components_Panels_base_id_; + this._ids[aValue] = result; +//MochiKit.Logging.logDebug(">>> getId(" + aValue + ") = " + result); + } else { +//MochiKit.Logging.logDebug("<<< getId(" + aValue + ") = " + result); + } + + return result; + }, + + 'getDom': function(aValue) { + return YAHOO.util.Dom.get(this.getId(aValue)); + }, + + 'getElement': function(aValue) { + return YAHOO.ext.Element.get(this.getId(aValue)); + }, + + 'getActor': function(aValue, anAnimator) { + return new YAHOO.ext.Actor(this.getDom(aValue), anAnimator); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); diff --git a/frontend/beta/js/Clipperz/PM/Components/Compact/CompactHeader.js b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactHeader.js new file mode 100644 index 0000000..e51b56f --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactHeader.js @@ -0,0 +1,86 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Compact) == 'undefined') { Clipperz.PM.Components.Compact = {}; } + +Clipperz.PM.Components.Compact.CompactHeader = function(anElement, args) { + + Clipperz.PM.Components.Compact.CompactHeader.superclass.constructor.call(this, anElement, args); + + this.render(); + + return this; +}; + +YAHOO.extendX(Clipperz.PM.Components.Compact.CompactHeader, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Compact.CompactHeader"; + }, + + //----------------------------------------------------- + + 'render': function() { + this.element().update(""); + + Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', children:[ + {tag:'img', src:'./images/logo.gif'}, + {tag:'div', id:'lockBlock', children:[ + {tag:'input', type:'checkbox', id:'autolock'}, + {tag:'span', html:'auto'}, + {tag:'a', href:'#', htmlString:Clipperz.PM.Strings['lockMenuLabel'], id:'lock'} + ]} + ]}); + + Clipperz.YUI.DomHelper.append(this.element().dom, + {tag:'div', id:'compactMiscLinks', children:[ + {tag:'a', id:'donateHeaderIconLink', target:'_blank', href:Clipperz.PM.Strings['donateHeaderLinkUrl'], children:[ + {tag:'img', id:'donateHeaderLinkIcon', src:'./images/smiles_small.gif'} + ]}, + {tag:'ul', children:[ + {tag:'li', children:[{tag:'a', id:'donateHeaderLink', html:'donate', target:'_blank'}]}, + {tag:'li', children:[{tag:'a', id:'creditsHeaderLink', html:'credits', target:'_blank'}]}, + {tag:'li', children:[{tag:'a', id:'feedbackHeaderLink', html:'feedback', target:'_blank'}]}, + {tag:'li', children:[{tag:'a', id:'helpHeaderLink', html:'help', target:'_blank'}]}, + {tag:'li', children:[{tag:'a', id:'forumHeaderLink', html:'forum', target:'_blank'}]} + ]} + ]} + ); + + YAHOO.ext.Element.get('lockBlock').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + Clipperz.NotificationCenter.notify(this, 'switchLanguage'); + }, + + //----------------------------------------------------- + __syntaxFix__: '__syntaxFix__' +}); + + diff --git a/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js new file mode 100644 index 0000000..492f815 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Compact/CompactInterface.js @@ -0,0 +1,312 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Compact) == 'undefined') { Clipperz.PM.Components.Compact = {}; } + +Clipperz.PM.Components.Compact.CompactInterface = function(anElement, args) { + + Clipperz.PM.Components.Compact.CompactInterface.superclass.constructor.call(this, anElement, args); + + this._directLoginItemTemplate = null; + this._user = args.user; + this._autoLockTimer = null; + + Clipperz.NotificationCenter.register(null, 'updatedProgressState', this, 'userNotificationHandler') + Clipperz.NotificationCenter.register(null, 'directLoginAdded', this, 'directLoginAddedHandler'); + + this.render(); + + return this; +}; + +YAHOO.extendX(Clipperz.PM.Components.Compact.CompactInterface, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Compact.CompactInterface"; + }, + + //----------------------------------------------------- + + 'render': function() { + var result; + var layout; + var registerButton; + +//MochiKit.Logging.logDebug(">>> CompactInterface.render"); + this.element().update(""); + + Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', children:[ + {tag:'div', id:this.getId('cantentPanel'), children:[ + {tag:'h4', id:this.getId('message')}, + {tag:'ul', id:'directLogins', children:[]} + ]}, + {tag:'div', id:this.getId('lockPanel'), cls:'lockPanel', children:[ + {tag:'div', htmlString:Clipperz.PM.Strings['lockDescription']}, + {tag:'form', id:'lockDialogForm', children:[ + {tag:'input', type:'password', id:this.getId('lockPassphrase')} + ]}, + {tag:'div', id:this.getId('unlock')} + ]} + ]}); + + this.getElement('lockPanel').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + + YAHOO.ext.Element.get('lockBlock').show(); + MochiKit.Signal.connect(YAHOO.ext.Element.get('lock').dom, 'onclick', this, 'doLockEventHandler'); + new YAHOO.ext.Button(this.getId('unlock'), {text:Clipperz.PM.Strings['unlockButtonLabel'], handler:this.doUnlockEventHandler, scope:this, minWidth:0}); + this.getElement('unlock').swallowEvent('click', true); + new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('lockPassphrase')); + MochiKit.Signal.connect('lockDialogForm', 'onsubmit', this, 'doUnlockEventHandler'); + + this.getElement('cantentPanel').setVisibilityMode(YAHOO.ext.Element.DISPLAY); +//MochiKit.Logging.logDebug("<<< CompactInterface.render"); + + return result; + }, + + //----------------------------------------------------- + + 'directLoginAddedHandler': function(anEvent) { + this.redrawDirectLoginItems(); + }, + + //----------------------------------------------------- + + 'compareDirectLogins': function(a, b) { + return MochiKit.Base.compare(a.label().toLowerCase(), b.label().toLowerCase()); + }, + + //----------------------------------------------------- + + 'redrawDirectLoginItems': function() { + var template; + var allDirectLogins; + + this.getElement('message').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); +//MochiKit.Logging.logDebug(">>> CompactInterface.redrawDirectLoginItems"); +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 0"); + MochiKit.Iter.forEach(YAHOO.ext.Element.get('directLogins').getChildrenByTagName('li'), function(aDirectLoginElement) { + MochiKit.Signal.disconnectAll(aDirectLoginElement.dom); +//MochiKit.Logging.logDebug("disconnecting IMG " + aDirectLoginElement.getChildrenByTagName('img')[0].dom.src); + MochiKit.Signal.disconnectAll(aDirectLoginElement.getChildrenByTagName('img')[0].dom); + }) +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 1"); + YAHOO.ext.Element.get('directLogins').update(""); +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 2"); + allDirectLogins = MochiKit.Base.values(this.user().directLoginReferences()); +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 3"); + allDirectLogins.sort(this.compareDirectLogins); + +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 4"); + template = this.directLoginItemTemplate(); +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 5"); + MochiKit.Iter.forEach(allDirectLogins, MochiKit.Base.bind(function(aDirectLogin) { + var directLoginElement; + var faviconImageElementID; + + faviconImageElementID = aDirectLogin.reference() + "_faviconIMG"; + directLoginElement = template.append('directLogins', { + elementID:faviconImageElementID, + faviconUrl:aDirectLogin.fixedFavicon(), + directLoginTitle:aDirectLogin.label(), + directLoginReference:aDirectLogin.reference() + }, true); +//MochiKit.Logging.logDebug("--- CompactInterface.redrawDirectLoginItems - 6: " + recordElement.dom); + directLoginElement.addClassOnOver("hover"); + MochiKit.Signal.connect(directLoginElement.dom, 'onclick', this, 'handleDirectLoginClick'); + + MochiKit.Signal.connect(faviconImageElementID, 'onload', this, 'handleLoadedFaviconImage'); + MochiKit.Signal.connect(faviconImageElementID, 'onerror', aDirectLogin, 'handleMissingFaviconImage'); + MochiKit.Signal.connect(faviconImageElementID, 'onabort', aDirectLogin, 'handleMissingFaviconImage'); + +// YAHOO.ext.Element.get(faviconImageElementID).dom.src = aDirectLogin.fixedFavicon(); + }, this)); + + this.resetAutoLockTimer(); +//MochiKit.Logging.logDebug("<<< CompactInterface.redrawDirectLoginItems"); + }, + + //----------------------------------------------------- + + 'directLoginItemTemplate': function() { + if (this._directLoginItemTemplate == null) { + this._directLoginItemTemplate = Clipperz.YUI.DomHelper.createTemplate({tag:'li', id:'{directLoginReference}', children:[ + {tag:'table', border:'0', cellpadding:'0', cellspacing:'0', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', width:'20', align:'center', valign:'top', children:[ + {tag:'img', id:'{elementID}', src:'{faviconUrl}'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'a', cls:'directLoginItemTitle', html:'{directLoginTitle}'} + ]} + ]} + ]} + ]} + ]}); + this._directLoginItemTemplate.compile(); + } + + return this._directLoginItemTemplate; + }, + + //------------------------------------------------------------------------- + + 'handleDirectLoginClick': function(anEvent) { + var directLoginReference; +//MochiKit.Logging.logDebug(">>> MainPanel.handleDirectLoginClick !!!"); + + directLoginReference = this.user().directLoginReferences()[anEvent.src().id]; + this.openDirectLogin(directLoginReference); + this.resetAutoLockTimer(); +//MochiKit.Logging.logDebug("<<< MainPanel.handleDirectLoginClick"); + }, + + //----------------------------------------------------- + + 'openDirectLogin': function(aDirectLoginReference) { + var deferredResult; + var newWindow; + +//MochiKit.Logging.logDebug(">>> MainPanel.openDirectLogin - " + aDirectLoginReference.label()); + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("MainPanel.openDirectLogin - 1: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(aDirectLoginReference, 'setupJumpPageWindow')); + deferredResult.addCallback(MochiKit.Base.method(aDirectLoginReference, 'deferredDirectLogin')); + deferredResult.addCallback(function(aDirectLogin) { + aDirectLogin.runDirectLogin(newWindow); + }); + + newWindow = window.open(Clipperz.PM.Strings['directLoginJumpPageUrl'], ""); +// MochiKit.Signal.connect(newWindow, 'onload', MochiKit.Base.method(deferredResult, 'callback', newWindow)) +// MochiKit.Signal.connect(newWindow, 'onload', MochiKit.Base.partial(alert, "done")); + deferredResult.callback(newWindow); +//MochiKit.Logging.logDebug("<<< MainPanel.openDirectLogin"); + }, + + //------------------------------------------------------------------------- + + 'handleLoadedFaviconImage': function(anEvent) { +//MochiKit.Logging.logDebug(">>> MainPanel.handleLoadedFaviconImage"); + MochiKit.Signal.disconnectAll(anEvent.src()) +//MochiKit.Logging.logDebug("<<< MainPanel.handleLoadedFaviconImage"); + }, + + //------------------------------------------------------------------------- + + 'doLockEventHandler': function(anEvent) { + anEvent.stop(); + this.lock(); + }, + + 'doUnlockEventHandler': function(anEvent) { + if (typeof(anEvent.stop) != 'undefined') { + anEvent.stop(); + } + this.unlock(); + }, + + //------------------------------------------------------------------------- + + 'autolock': function() { + var shouldAutoLock; + + shouldAutoLock = YAHOO.ext.Element.get('autolock').dom.checked; + + if (shouldAutoLock) { + this.lock(); + } else { + this.resetAutoLockTimer(); + } + }, + + 'lock': function() { +//MochiKit.Logging.logDebug(">>> lock"); + this.getDom('lockPassphrase').value = ""; + this.getElement('lockPanel').show(); + this.getElement('cantentPanel').hide(); + YAHOO.ext.Element.get('lockBlock').hide(); + //this.getElement('lockPassphrase').focus(); +//MochiKit.Logging.logDebug("<<< lock"); + }, + + 'unlock': function(anEvent) { +//MochiKit.Logging.logDebug(">>> unlock"); + if (this.getDom('lockPassphrase').value == this.user().passphrase()) { + this.getElement('lockPanel').hide(); + this.getElement('cantentPanel').show(); + YAHOO.ext.Element.get('lockBlock').show(); + this.resetAutoLockTimer(); + } else { + this.getDom('lockPassphrase').value = ""; + this.getElement('lockPassphrase').focus(); + } +//MochiKit.Logging.logDebug("<<< unlock"); + }, + + //------------------------------------------------------------------------- + + 'user': function() { + return this._user; + }, + + //----------------------------------------------------- + + 'autoLockTimer': function() { + if (this._autoLockTimer == null) { +//MochiKit.Logging.logDebug("--- timer started - 1"); + this._autoLockTimer = MochiKit.Async.callLater(60, MochiKit.Base.method(this, 'autolock')); +//MochiKit.Logging.logDebug("--- timer started - 2"); + } + + return this._autoLockTimer; + }, + + 'resetAutoLockTimer': function() { +//MochiKit.Logging.logDebug(">>> timer resetted"); + this.autoLockTimer().cancel(); + this._autoLockTimer = null; +//MochiKit.Logging.logDebug("--- timer resetted - 1"); + this.autoLockTimer(); +//MochiKit.Logging.logDebug("<<< timer resetted"); + }, + + //----------------------------------------------------- + + 'userNotificationHandler': function(anEvent) { + this.getElement('message').update(anEvent.parameters().text); + }, + + //----------------------------------------------------- + __syntaxFix__: '__syntaxFix__' +}); + + diff --git a/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js b/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js new file mode 100644 index 0000000..d708464 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Compact/LoginForm.js @@ -0,0 +1,189 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Compact) == 'undefined') { Clipperz.PM.Components.Compact = {}; } + +Clipperz.PM.Components.Compact.LoginForm = function(anElement, args) { + + Clipperz.PM.Components.Compact.LoginForm.superclass.constructor.call(this, anElement, args); + + this.render(); + Clipperz.NotificationCenter.register(null, 'updatedProgressState', this, 'userNotificationHandler') + + return this; +}; + +YAHOO.extendX(Clipperz.PM.Components.Compact.LoginForm, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Compact.LoginForm"; + }, + + //----------------------------------------------------- + + 'render': function() { + var result; + var layout; + + MochiKit.Signal.disconnectAllTo(this); + this.element().update(""); + + Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', id:this.getId('baseDiv'), cls:'LoginPanel', children:[ + {tag:'div', id:'compactHeader'}, + {tag:'div', id:'compactBody', children:[ + {tag:'form', id:this.getId('loginForm_form'), children:[ + {tag:'dl', children:[ + {tag:'dt', htmlString:Clipperz.PM.Strings['loginFormUsernameLabel']}, + {tag:'dd', children:[ + {tag:'input', id:this.getId('login_username'), type:'text', size:'30', name:'username'} + ]}, + {tag:'dt', htmlString:Clipperz.PM.Strings['loginFormPassphraseLabel']}, + {tag:'dd', children:[ + {tag:'input', id:this.getId('login_passphrase'), type:'password', size:'30', name:'passphrase'} + ]} + ]}, + {tag:'div', id:this.getId('login_submit')} + ]}, + {tag:'h4', id:this.getId('message')} + ]} + ]}); + + new Clipperz.PM.Components.Compact.CompactHeader(YAHOO.ext.Element.get('compactHeader')); + + MochiKit.Signal.connect(this.getId('loginForm_form'), 'onsubmit', this, 'stopFormSubmit'); + new YAHOO.ext.Button(this.getId('login_submit'), {text:Clipperz.PM.Strings['loginFormButtonLabel'], handler:this.doLogin, scope:this, minWidth:0}); + this.getElement('login_submit').swallowEvent('click', true); + + MochiKit.Signal.connect(this.getId('loginForm_form'), 'onkeydown', this, 'onkeydown'); + + new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('login_passphrase')); + this.getElement('login_username').focus(); + + return result; + }, + + //----------------------------------------------------- + + 'doLogin': function(e) { +//MochiKit.Logging.logDebug(">>> compact.LoginForm.doLogin"); + if (this.checkLoginForm()) { + this.doLoginWithUsernameAndPassphrase(this.getDom('login_username').value, this.getDom('login_passphrase').value); + } +//MochiKit.Logging.logDebug("<<< compact.LoginForm.doLogin"); + }, + + //......................................................................... + + 'doLoginWithUsernameAndPassphrase': function(anUsername, aPassphrase) { + var deferredResult; + var user; + +//MochiKit.Logging.logDebug(">>> compact.LoginForm.doLoginWithUsernameAndPassphrase"); + user = new Clipperz.PM.DataModel.User({username:anUsername, passphrase:aPassphrase}); + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(MochiKit.Base.method(user, 'connect')); + deferredResult.addCallback(MochiKit.Base.method(user, 'loadPreferences')); + deferredResult.addCallback(MochiKit.Base.method(user, 'loadRecords')); + deferredResult.addCallback(MochiKit.Base.method(user, 'loadDirectLogins')); + deferredResult.addErrback(MochiKit.Base.bind(function() { + this.getElement('loginForm_form').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show(); + this.getElement('message').update(Clipperz.PM.Strings['loginMessagePanelFailureText']); + this.getDom('login_passphrase').value = ""; + this.getElement('login_passphrase').focus(); + }, this)) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("compact.LoginForm.doLogin - 6: " + res); return res;}); + deferredResult.callback("token"); +//MochiKit.Logging.logDebug("<<< compact.LoginForm.doLoginWithUsernameAndPassphrase"); + + return deferredResult; + }, + + //......................................................................... + + 'checkLoginForm': function() { + var result; + var username + var passphrase; + +//MochiKit.Logging.logDebug(">>> checkLoginForm"); + username = this.getDom('login_username').value; + passphrase = this.getDom('login_passphrase').value; + + if ((username != "") && (passphrase != "")) { + result = true; + } else { + if (username == "") { + this.getElement('login_username').focus(); + } else if (passphrase == "") { + this.getElement('login_passphrase').focus(); + } + + result = false; + } +//MochiKit.Logging.logDebug("<<< checkLoginForm - " + result); + + return result; + }, + + //------------------------------------------------------------------------- + + 'stopFormSubmit': function(anEvent) { + anEvent.stop(); + }, + + //------------------------------------------------------------------------- + + 'onkeydown': function(anEvent) { +//MochiKit.Logging.logDebug(">>> onkeydown - " + anEvent.src().id); + if (anEvent.key().code == 13) { + this.doLogin(); + anEvent.stop(); + } + }, + + //----------------------------------------------------- + + 'userNotificationHandler': function(anEvent) { +//MochiKit.Logging.logDebug(">>> compact.LoginForm.userNotificationHandler"); +//MochiKit.Logging.logDebug("userNotificationHandler - event: " + anEvent.event()); + this.getElement('loginForm_form').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + if (this.getDom('message') != null) { + this.getElement('message').update(Clipperz.PM.Strings.messagePanelConfigurations[anEvent.parameters()]()['text']); + } +//MochiKit.Logging.logDebug("<<< compact.LoginForm.userNotificationHandler"); + }, + + //----------------------------------------------------- + __syntaxFix__: '__syntaxFix__' +}); + + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js new file mode 100644 index 0000000..18b36da --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js @@ -0,0 +1,174 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } +if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImport.CSVImportColumns = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.CSVImport.CSVImportColumns.superclass.constructor.call(this, anElement, args); + this._mainComponent = args.mainComponent; + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportColumns, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImport.CSVImportColumns component"; + }, + + //------------------------------------------------------------------------- + + 'mainComponent': function() { + return this._mainComponent; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + var i,c; + var columnSelectorCheckboxCells; + var checkboxes; + var data; + +//MochiKit.Logging.logDebug(">>> CSVImportColumns.render"); + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + this.element().update(""); + + data = this.mainComponent().parsedValues(); + columnSelectorCheckboxCells = []; + + c = data[0].length; + for (i=0; i>> CSVImportColumns.renderData"); +// anElement.update(""); + MochiKit.DOM.replaceChildNodes(anElement.dom); + + config = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { + var result; + var i,c; + + result = {tag:'tr', children:[]}; + c = aRowData.length; + for (i=0; i') : ' ')}); + } + + return result; + }, this), someData); + + MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, config); + + Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); +//MochiKit.Logging.logDebug("<<< CSVImportColumns.renderData"); + }, + + //------------------------------------------------------------------------- + + 'renderDataHandler': function(anEvent) { + var thElement; + + thElement = YAHOO.ext.Element.get(anEvent.src().parentNode); + + if (anEvent.src().checked == true) { + this.mainComponent().skippedColumns().remove(anEvent.src().value); + thElement.addClass('selectedColumn'); + thElement.removeClass('skippedColumn'); + } else { + this.mainComponent().skippedColumns().add(anEvent.src().value); + thElement.removeClass('selectedColumn'); + thElement.addClass('skippedColumn'); + } + + if (this.mainComponent().skippedColumns().allItems().length == this.mainComponent().parsedValues()[0].length) { + this.mainComponent().nextButton().disable(); + } else { + this.mainComponent().nextButton().enable(); + } + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js new file mode 100644 index 0000000..a368747 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js @@ -0,0 +1,247 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } +if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImport.CSVImportFields = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.CSVImport.CSVImportFields.superclass.constructor.call(this, anElement, args); + this._mainComponent = args.mainComponent; + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportFields, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImport.CSVImportFields component"; + }, + + //------------------------------------------------------------------------- + + 'mainComponent': function() { + return this._mainComponent; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + var fieldsHeaderCells; + var titleColumnIndex; + var notesColumnIndex; + var i,c; + + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + this.element().update(""); + + titleColumnIndex = this.mainComponent().titleColumnIndex() + notesColumnIndex = this.mainComponent().notesColumnIndex() + + fieldsHeaderCells = []; + fieldsHeaderCells.push({tag:'td', valign:'top', cls:'title', html:this.mainComponent().labelForColumn(titleColumnIndex)}); + + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i>> renderDataRowsHandler") + columnIndex = anEvent.src().name; + this.mainComponent().setTypeForColumn(anEvent.src().value, columnIndex); + + tdElement = this.getElement('fieldHeaderTD_' + columnIndex); + + if (this.isColumnSetup(columnIndex)) { + tdElement.removeClass('unconfiguredColumn'); + tdElement.addClass('configuredColumn'); + } else { + tdElement.addClass('unconfiguredColumn'); + tdElement.removeClass('configuredColumn'); + } + + this.renderDataRows(this.getElement('previewData_tbody')); + }, + + //------------------------------------------------------------------------- + + 'renderDataRows': function(anElement) { + var titleColumnIndex; + var notesColumnIndex; + var data + var i,c; + +//MochiKit.Logging.logDebug("#### >> renderDataRows"); +// anElement.update(""); + MochiKit.DOM.replaceChildNodes(anElement.dom); + + if (this.mainComponent().isFirstRowHeader()) { + data = this.mainComponent().parsedValues().slice(1); + } else { + data = this.mainComponent().parsedValues(); + } + + + titleColumnIndex = this.mainComponent().titleColumnIndex(); + notesColumnIndex = this.mainComponent().notesColumnIndex(); + + c = data.length; + for (i=0; i') : ' ')} + ]}; + + cc = rowData.length; + for (ii=0; ii') : ' ') + }); + } + } + if (notesColumnIndex != -1) { + rowConfig.children.push({tag:'td', valign:'top', cls:'notes', html:(MochiKit.Base.isNotEmpty(rowData[notesColumnIndex]) ? rowData[notesColumnIndex].replace(/\n/g, '
') : ' ')}); + } + + this.domHelper().append(anElement, rowConfig); + } + + Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); + + this.checkWetherToEnableNextButton(); +//MochiKit.Logging.logDebug("#### << renderDataRows"); + }, + + //------------------------------------------------------------------------- + + 'checkWetherToEnableNextButton': function() { + var result; + var titleColumnIndex; + var notesColumnIndex; + var i,c; + + titleColumnIndex = this.mainComponent().titleColumnIndex() + notesColumnIndex = this.mainComponent().notesColumnIndex() + + result = true; + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } +if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImport.CSVImportHeader = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.CSVImport.CSVImportHeader.superclass.constructor.call(this, anElement, args); + this._mainComponent = args.mainComponent; + + this._pendingDeferredLabelFieldHandlerEvents = 0; + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportHeader, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImport.CSVImportHeader component"; + }, + + //------------------------------------------------------------------------- + + 'mainComponent': function() { + return this._mainComponent; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + var thConfigs; + var i,c; + +//MochiKit.Logging.logDebug(">>> CSVImportHeader.render"); + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + thConfigs = []; + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i') : ' ')}); + } + } + + return result; + }, this), data); + + MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, trConfigs); + + Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); + }, + + //------------------------------------------------------------------------- + + 'toggleFirstRowHeaderCheckboxHandler': function() { + var firstRowData; + var i,c; + +//MochiKit.Logging.logDebug(">>> toggleFirstRowHeaderCheckboxHandler"); + this.mainComponent().setIsFirstRowHeader(this.getDom('isFirstRowHeader_checkbox').checked); + + firstRowData = this.mainComponent().parsedValues()[0]; + + c = firstRowData.length; + for (i=0; i>> updateInputFieldValues"); + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i>> labelFieldHandler"); + inputField = anEvent.src(); + + this.mainComponent().setLabelForColumn(inputField.value, aColumnIndex); +//MochiKit.Logging.logDebug("##### [" + anEvent.src().id + "] -> label[" + aColumnIndex + "]: '" + inputField.value + "'"); +//MochiKit.Logging.logDebug("<<< labelFieldHandler"); + }, + + 'deferredLabelFieldHandler': function(aColumnIndex, anEvent) { +//MochiKit.Logging.logDebug(">>> deferredLabelFieldHandler"); + this._pendingDeferredLabelFieldHandlerEvents ++; + MochiKit.Async.callLater(1, MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandlerCatcher'), aColumnIndex, anEvent)); +//MochiKit.Logging.logDebug("<<< deferredLabelFieldHandler"); + }, + + 'deferredLabelFieldHandlerCatcher': function(aColumnIndex, anEvent) { +//MochiKit.Logging.logDebug(">>> deferredLabelFieldHandlerCatcher"); + this._pendingDeferredLabelFieldHandlerEvents --; + if (this._pendingDeferredLabelFieldHandlerEvents == 0) { + this.labelFieldHandler(aColumnIndex, anEvent); + } +//MochiKit.Logging.logDebug("<<< deferredLabelFieldHandlerCatcher"); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportNotes.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportNotes.js new file mode 100644 index 0000000..a53c531 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportNotes.js @@ -0,0 +1,212 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } +if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImport.CSVImportNotes = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.CSVImport.CSVImportNotes.superclass.constructor.call(this, anElement, args); + this._mainComponent = args.mainComponent; + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportNotes, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImport.CSVImportNotes component"; + }, + + //------------------------------------------------------------------------- + + 'mainComponent': function() { + return this._mainComponent; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + var notesSelectorCheckboxCells; + var totalNumberOfColumns; + var titleColumnIndex; + var notesColumnIndex; + var i,c; + + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + this.element().update(""); + + titleColumnIndex = this.mainComponent().titleColumnIndex() + notesColumnIndex = this.mainComponent().notesColumnIndex() + + totalNumberOfColumns = this.mainComponent().parsedValues()[0].length; + + notesSelectorCheckboxCells = [{tag:'th', cls:'title', html:this.mainComponent().labelForColumn(titleColumnIndex)}]; + c = totalNumberOfColumns; + for (i=0; i= totalNumberOfColumns) || (notesColumnIndex == titleColumnIndex) || !(this.mainComponent().isColumnSelected(notesColumnIndex))) { + this.mainComponent().setNotesColumnIndex(-1); + notesColumnIndex = -1; + } + + c = totalNumberOfColumns; + for (i=0; i') : ' ')}]}; + c = aRowData.length; + for (i=0; i') : ' ')}); + } + } + + return result; + }, this, titleColumnIndex), data); + + MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, config); + + Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); + }, + + //------------------------------------------------------------------------- + + 'renderDataHandler': function(anEvent) { + var titleColumnIndex; + var i,c; + + this.mainComponent().setNotesColumnIndex(anEvent.src().value); + titleColumnIndex = this.mainComponent().titleColumnIndex(); + + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } +if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImport.CSVImportTitle = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.CSVImport.CSVImportTitle.superclass.constructor.call(this, anElement, args); + this._mainComponent = args.mainComponent; + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportTitle, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImport.CSVImportTitle component"; + }, + + //------------------------------------------------------------------------- + + 'mainComponent': function() { + return this._mainComponent; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + var titleSelectorCheckboxCells; + var titleColumnIndex; + var i,c; + + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + this.element().update(""); + + titleColumnIndex = this.mainComponent().titleColumnIndex() + titleSelectorCheckboxCells = []; + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i= titleSelectorCheckboxCells.length) { + this.mainComponent().setTitleColumnIndex(-1); + } + + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Title']}, + {tag:'div', id:this.getId('dataDiv'), cls:'csvImportPreview', children:[ + {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ + {tag:'thead', id:this.getId('previewData_thead'), children:[ + {tag:'tr', children:titleSelectorCheckboxCells} + ]}, + {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} + ]} + ]} + ]}); + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i') : ' ')}); + } + } + + return result; + }, this), data); + + MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, config); + + Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); + }, + + //------------------------------------------------------------------------- + + 'renderDataHandler': function(anEvent) { + var i,c; + + this.mainComponent().setTitleColumnIndex(anEvent.src().value); + + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.CSVImportComponent = function(anElement, args) { + args = args || {}; + + this._steps = this._steps || ['CSV_EDIT', 'CSV_COLUMNS', 'CSV_HEADER', 'CSV_TITLE', 'CSV_NOTES', 'CSV_FIELDS', 'PREVIEW', 'IMPORT']; + + Clipperz.PM.Components.Import.CSVImportComponent.superclass.constructor.call(this, anElement, args); + + this._step1Component = null; + this._step2Component = null; + this._step3Component = null; + this._step4Component = null; + this._step5Component = null; + + this._isFirstRowHeader = false; + this._titleColumnIndex = -1; + this._notesColumnIndex = -1; + this._fieldSettings = {}; + this._skippedColumns = new Clipperz.Set(); + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.CSVImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.CSVImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { + this.domHelper().append(this.element(), {tag:'div', cls:'csvImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Title']}, + {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, + {tag:'div', cls:'importStepBlocks', children:[ + {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ + {tag:'div', children:[ + {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_csv_description']}, + {tag:'div', cls:'importOptionsParameters', children:[ + {tag:'div', cls:'CSVImportOptionsParameters', children:[ + {tag:'ul', children:[ + {tag:'li', children:[ + {tag:'label', 'for':this.getId('CSV_inputOptions_separator'), html:"separator"}, + {tag:'select', name:this.getId('CSV_inputOptions_separator'), id:this.getId('CSV_inputOptions_separator'), children:[ + {tag:'option', name:'comma', value:',', html:"comma (,)", selected:true}, + {tag:'option', name:'tab', value:'\t', html:"tab"} + ]} + ]}, + + {tag:'li', children:[ + {tag:'label', 'for':this.getId('CSV_inputOptions_quote'), html:"quote"}, + {tag:'select', name:this.getId('CSV_inputOptions_quote'), id:this.getId('CSV_inputOptions_quote'), children:[ + {tag:'option', name:'doubleQuote', value:'\"', html:"double quote (\")", selected:true}, + {tag:'option', name:'singleQuote', value:'\'', html:"single quote (\')"} + ]} + ]}, + + {tag:'li', children:[ + {tag:'label', 'for':this.getId('CSV_inputOptions_escape'), html:"escape"}, + {tag:'select', name:this.getId('CSV_inputOptions_escape'), id:this.getId('CSV_inputOptions_escape'), children:[ + {tag:'option', name:'doubleQuote', value:'\"', html:"double quote (\")", selected:true}, + {tag:'option', name:'slash', value:'\/', html:"slash (\/)"}, + {tag:'option', name:'backslash', value:'\\', html:"backslash (\\)"} + ]} + ]} + ]} + ]} + ]}, + this.textAreaConfig() + ]} + ]}, + {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[]}, + {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[]}, + {tag:'div', cls:'step_3', id:this.getId('step_3'), children:[]}, + {tag:'div', cls:'step_4', id:this.getId('step_4'), children:[]}, + {tag:'div', cls:'step_5', id:this.getId('step_5'), children:[]}, + {tag:'div', cls:'step_6', id:this.getId('step_6'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('previewDiv'), html:"preview"} + ]} + ]}, + {tag:'div', cls:'step_7', id:this.getId('step_7'), children:[ + {tag:'div', children:[ + {tag:'h4', html:"done"} + ]} + ]} + ]}, + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]}); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.updateSteps(); + + this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() + this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_3').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_4').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_5').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_6').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_7').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + +// this.backButton().disable(); + }, + + //------------------------------------------------------------------------- + + 'nextAction': function() { + switch (this.currentStep()) { + case 0: // -> 1 + Clipperz.PM.Components.MessageBox.showProgressPanel( + MochiKit.Base.method(this, 'deferredParseValues'), + MochiKit.Base.method(this, 'handleParseError'), + this.getDom('nextActionButton') + ); + break; + case 1: // -> 2 + this.getElement('step_1').hide(); + this.step2Component().render(); + this.setCurrentStep(2); + this.getElement('step_2').show(); + break; + case 2: // -> 3 + this.getElement('step_2').hide(); + this.step3Component().render(); + this.setCurrentStep(3); + this.getElement('step_3').show(); + break; + case 3: // -> 4 + this.getElement('step_3').hide(); + this.step4Component().render(); + this.setCurrentStep(4); + this.getElement('step_4').show(); + break; + case 4: // -> 5 + this.getElement('step_4').hide(); + this.step5Component().render(); + this.setCurrentStep(5); + this.getElement('step_5').show(); + break; + case 5: // -> 6 + this.previewValues(); + break; + case 6: // -> 7 + this.importValues(); + break; + } + }, + + //------------------------------------------------------------------------- + + 'deferredParseValues': function() { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 1 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 2 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 3 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'parseCSVValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 4 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'setParsedValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 5 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this.step1Component(), 'render')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 6 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_0').hide(); + this.getElement('step_1').show(); + this.backButton().enable(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("CSVImportComponent.deferredParseValues - 7 " + res); return res;}); + deferredResult.callback(this.textAreaContent()); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'deferredPreviewValues': function() { + var deferredResult; + +//MochiKit.Logging.logDebug(">>> CSVImportComponent.deferredPreviewValues"); + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 1 " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 2 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 3 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'processCSVParsedValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 4 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 5 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 6 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_5').hide(); + this.getElement('step_6').show(); + this.backButton().enable(); + + return res; + }, this)); + deferredResult.callback(this.parsedValues()); +//MochiKit.Logging.logDebug("<<< CSVImportComponent.deferredPreviewValues"); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'csvProcessor': function() { + return new Clipperz.CSVProcessor({ + quoteChar: this.getDom('CSV_inputOptions_quote').value, + escapeChar: this.getDom('CSV_inputOptions_escape').value, + separatorChar: this.getDom('CSV_inputOptions_separator').value, + binary:true + }); + }, + + //------------------------------------------------------------------------- + + 'parseCSVValues': function(someData) { + var deferredResult; + var csvProcessor; + + csvProcessor = this.csvProcessor(); + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 1 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); + }) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 2 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.method(csvProcessor, 'deferredParse')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 3 " + res); return res;}); + deferredResult.callback(someData); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'processCSVParsedValues': function (someValues) { + var deferredResult; + var records; + var titleColumnIndex; + var notesColumnIndex; + var i,c; + + deferredResult = new MochiKit.Async.Deferred(); + records = []; + + titleColumnIndex = this.titleColumnIndex(); + notesColumnIndex = this.notesColumnIndex(); + + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {steps:(someValues.length)}); + + c = someValues.length; + if (this.isFirstRowHeader()) { + i = 1; + } else { + i = 0; + } + + for( ; i>> setLabelForColumn[" + aColumnIndex + "]: " + aLabel); + fieldSettings = this.fieldSettings(); + + if (typeof(fieldSettings[aColumnIndex]) == 'undefined') { + fieldSettings[aColumnIndex] = {} + } + + if (this.isFirstRowHeader()) { +//MochiKit.Logging.logDebug("--- setLabelForColumn -> _firstRowLabel"); + fieldSettings[aColumnIndex]['_firstRowLabel'] = aLabel; + } else { + if (typeof(fieldSettings[aColumnIndex]['_emptyLabel']) == 'undefined') { + if (aLabel == null) { +//MochiKit.Logging.logDebug("--- setLabelForColumn -> _emptyLabel = \"\""); + fieldSettings[aColumnIndex]['_emptyLabel'] = ""; + } else { + fieldSettings[aColumnIndex]['_emptyLabel'] = aLabel; + } + } else { +//MochiKit.Logging.logDebug("--- setLabelForColumn -> _emptyLabel = " + aLabel); + if (aLabel != null) { + fieldSettings[aColumnIndex]['_emptyLabel'] = aLabel; + } + } + } +//MochiKit.Logging.logDebug("<<< setLabelForColumn[" + aColumnIndex + "]: " + aLabel); + }, + + //========================================================================= + + 'typeForColumn': function(aColumnIndex) { + var result; + + if ((typeof(this.fieldSettings()) != 'undefined') && (typeof(this.fieldSettings()[aColumnIndex]) != 'undefined') && (typeof(this.fieldSettings()[aColumnIndex]['type']) != 'undefined')) { + result = this.fieldSettings()[aColumnIndex]['type']; + } else { + result = 'UNDEFINED'; + } + + return result; + }, + + //------------------------------------------------------------------------- + + 'setTypeForColumn': function(aType, aColumnIndex) { + var fieldSettings; + + fieldSettings = this.fieldSettings(); + + if (typeof(fieldSettings[aColumnIndex]) == 'undefined') { + fieldSettings[aColumnIndex] = {} + } + + fieldSettings[aColumnIndex]['type'] = aType; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js new file mode 100644 index 0000000..50dcb93 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js @@ -0,0 +1,212 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.ClipperzImportComponent = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.ClipperzImportComponent.superclass.constructor.call(this, anElement, args); + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.ClipperzImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.ClipperzImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.ClipperzImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', cls:'clipperzImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['Clipperz_ImportWizard_Title']}, + {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, + {tag:'div', cls:'importStepBlocks', children:[ + {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ + {tag:'div', children:[ + {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_clipperz_description']}, + {tag:'div', cls:'importOptionsParameters', children:[]}, + this.textAreaConfig() + ]} + ]}, + {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('previewDiv'), html:"preview"} + ]} + ]}, + {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[ + {tag:'div', children:[ + {tag:'h4', html:"done"} + ]} + ]} + ]}, + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]}); + + this.updateSteps(); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() + this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); +//MochiKit.Logging.logDebug("<<< Import.ClipperzImportComponent.render"); + }, + + //------------------------------------------------------------------------- + + 'nextAction': function() { + switch (this.currentStep()) { + case 0: // -> 1 + this.previewValues(); + break; + case 1: // -> 2 + this.importValues(); + break; + } + }, + + //------------------------------------------------------------------------- + + 'deferredPreviewValues': function() { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); + deferredResult.addCallback(MochiKit.Base.method(this, 'processClipperzValues')); + deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues')); + deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues')); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_0').hide(); + this.getElement('step_1').show(); + this.backButton().enable(); + + return res; + }, this)); +// deferredResult.addErrback(MochiKit.Base.bind(function() { +// this.processingAborted(); +// }, this)) + deferredResult.callback(this.textAreaContent()); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'processClipperzValues': function(someData) { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 1: " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 2: " + res); return res;}); + deferredResult.addCallback(Clipperz.Base.evalJSON); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 3: " + res); return res;}); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); + }) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 4: " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 5: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(someClipperzValues) { + var innerDeferredResult; + var records; + var i,c; + + innerDeferredResult = new MochiKit.Async.Deferred(); + records = []; + + c = someClipperzValues.length; + for(i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.ExcelImportComponent = function(anElement, args) { + args = args || {}; + + this._steps = ['EXCEL_EDIT', 'CSV_COLUMNS', 'CSV_HEADER', 'CSV_TITLE', 'CSV_NOTES', 'CSV_FIELDS', 'PREVIEW', 'IMPORT']; + + Clipperz.PM.Components.Import.ExcelImportComponent.superclass.constructor.call(this, anElement, args); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.ExcelImportComponent, Clipperz.PM.Components.Import.CSVImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.ExcelImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.ExcelImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', cls:'excelImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['Excel_ImportWizard_Title']}, + {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, + {tag:'div', cls:'importStepBlocks', children:[ + {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ + {tag:'div', children:[ + {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_excel_description']}, + {tag:'div', cls:'importOptionsParameters', children:[]}, + this.textAreaConfig() + ]} + ]}, + {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[]}, + {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[]}, + {tag:'div', cls:'step_3', id:this.getId('step_3'), children:[]}, + {tag:'div', cls:'step_4', id:this.getId('step_4'), children:[]}, + {tag:'div', cls:'step_5', id:this.getId('step_5'), children:[]}, + {tag:'div', cls:'step_6', id:this.getId('step_6'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('previewDiv'), html:"preview"} + ]} + ]}, + {tag:'div', cls:'step_7', id:this.getId('step_7'), children:[ + {tag:'div', children:[ + {tag:'h4', html:"done"} + ]} + ]} + ]}, + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]}); + + this.updateSteps(); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() + this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_3').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_4').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_5').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_6').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_7').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); +//MochiKit.Logging.logDebug("<<< Import.ExcelImportComponent.render"); + }, + + //------------------------------------------------------------------------- + + 'csvProcessor': function() { + return new Clipperz.CSVProcessor({ +// quoteChar: this.getDom('CSV_inputOptions_quote').value, +// escapeChar: this.getDom('CSV_inputOptions_escape').value, + separatorChar: '\t', + binary:true + }); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/GenericImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/GenericImportComponent.js new file mode 100644 index 0000000..4f6b1e4 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/GenericImportComponent.js @@ -0,0 +1,523 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.GenericImportComponent = function(anElement, args) { + args = args || {}; + + this._steps = this._steps || ['EDIT', 'PREVIEW', 'IMPORT']; + + Clipperz.PM.Components.Import.GenericImportComponent.superclass.constructor.call(this, anElement, args); + + this._user = args['user']; + + this._currentStep = 0; + this._currentStatus = 'IDLE'; // 'PROCESSING' + + this._parsedValues = null; + this._processedValues = null; + + this._backButton = null; + this._nextButton = null; + + Clipperz.NotificationCenter.register(null, 'importProcessorProgressUpdate', this, 'updateProgressDialogStatus'); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.GenericImportComponent, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.GenericImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'user': function() { + return this._user; + }, + + //------------------------------------------------------------------------- + + 'textAreaConfig': function() { + return {tag:'textarea', name:this.getId('importTextArea'), cls:'importTextArea', id:this.getId('importTextArea'), cols:60, rows:15, html:""}; + }, + + 'textAreaContent': function() { + return this.getDom('importTextArea').value + }, + + //------------------------------------------------------------------------- + + 'steps': function() { + return this._steps; + }, + + 'currentStep': function() { + return this._currentStep; + }, + + 'setCurrentStep': function(aValue) { + this._currentStep = aValue; + this.updateSteps(); + }, + + //------------------------------------------------------------------------- + + 'currentStatus': function() { + return this._currentStatus; + }, + + 'startProcessing': function() { + this._currentStatus = 'PROCESSING'; + this.updateSteps(); + }, + + 'processingDone': function() { + this._currentStatus = 'IDLE'; + this.setCurrentStep(this.currentStep() + 1); + }, + + 'processingAborted': function() { + this._currentStatus = 'IDLE'; + this.updateSteps(); + }, + + //------------------------------------------------------------------------- + + 'stepsConfig': function() { + var result; + var i,c; + + result = []; + c = this.steps().length; + for (i=0; i"}]} + ]}); + } + } + + result = [{tag:'div', cls:'importWizardStepsBox', children:[ + {tag:'div', cls:'importWizardStepsInnerBox', children:[ + {tag:'table', cls:'importWizardSteps', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:result} + ]} + ]} + ]}, + {tag:'div', cls:'importWizardStepsBoxFooter'} + ]}]; + + return result; + }, + + 'updateSteps': function() { + this.getElement('importSteps').update(""); + Clipperz.YUI.DomHelper.append(this.getDom('importSteps'), {tag:'div', children:this.stepsConfig()}); + }, + + //------------------------------------------------------------------------- + + 'backAction': function() { +//MochiKit.Logging.logDebug(">>> backAction"); + if (this.currentStep() == 0) { + Clipperz.NotificationCenter.notify(this, 'importCancelled'); + } else { + this.getElement('step_' + this.currentStep()).hide(); + this.setCurrentStep(this.currentStep() - 1); + this.getElement('step_' + this.currentStep()).show(); + + this.nextButton().enable(); + } +//MochiKit.Logging.logDebug("<<< backAction"); + }, + + //------------------------------------------------------------------------- + + 'backButton': function() { + return this._backButton; + }, + + 'setBackButton': function(aValue) { + this._backButton = aValue; + }, + + 'nextButton': function() { + return this._nextButton; + }, + + 'setNextButton': function(aValue) { + this._nextButton = aValue; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.GenericImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'h2', html:this.toString()} + ]}); +//MochiKit.Logging.logDebug("<<< Import.GenericImportComponent.render"); + }, + + //------------------------------------------------------------------------- + + 'previewValues': function() { + Clipperz.PM.Components.MessageBox.showProgressPanel( + MochiKit.Base.method(this, 'deferredPreviewValues'), + MochiKit.Base.method(this, 'handlePreviewError'), + this.getDom('nextActionButton') + ); + }, + + 'deferredPreviewValues': function() { + throw Clipperz.Base.exception.AbstractMethod; + }, + + 'handlePreviewError': function(anError) { +console.log("anError", anError); + MochiKit.Logging.logError("An error occurred while previewing the data: " + anError); + alert("An error occurred while previewing the data"); + Clipperz.PM.Components.MessageBox().hide(); + }, + + //------------------------------------------------------------------------- + + 'previewRecordValues': function(someProcessedRecords) { +//MochiKit.Logging.logDebug(">>> previewRecordValues"); + this.getElement('previewDiv').update(""); +//MochiKit.Logging.logDebug("--- previewRecordValues - 1"); + this.domHelper().append(this.getElement('previewDiv'), {tag:'div', cls:'importPreviewDiv', children:[{tag:'table', id:'importPreview', cellspacing:'0', children:[ + {tag:'tbody', children: + MochiKit.Base.map(MochiKit.Base.bind(function(aRecord) { + var result; +//MochiKit.Logging.logDebug("--- previewRecordValues - 1.1"); +//console.log("fields", aRecord.currentVersion().fields()); + result = {tag:'tr', children:[{tag:'td', children:[ + {tag:'table', cls:'importPreview_record', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', rowspan:'2', valign:'top', children:[ + {tag:'input', type:'checkbox', id:this.getId(aRecord.reference()), value:"aRecord.reference()", checked:true} + ]}, + {tag:'td', colspan:'2', children:[ + {tag:'span', cls:'importPreview_title', html:aRecord.label()} + ]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'span', cls:'importPreview_notes', html:(MochiKit.Base.isNotEmpty(aRecord.notes()) ? aRecord.notes().replace(/\n/g, '
') : ' ')} + ]}, + {tag:'td', valign:'top', cls:'importPreview_fieds', children:[ + {tag:'table', cls:'importPreview_fields', children:[ + {tag:'tbody', children:MochiKit.Base.map(function(aField) { + var result; +//MochiKit.Logging.logDebug("--- previewRecordValues - 1.1.1"); + result = {tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'span', cls:'importPreview_fields_label', html:aField.label()} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'span', cls:'importPreview_fields_value', html:aField.value()} + ]} + ]}; +//MochiKit.Logging.logDebug("--- previewRecordValues - 1.1.2"); + return result; + }, MochiKit.Base.values(aRecord.currentVersion().fields()))} + ]} + ]} + ]} + ]} + ]} + ]}]}; +//MochiKit.Logging.logDebug("--- previewRecordValues - 1.2"); + return result; + }, this), someProcessedRecords) + } + ]}]}); +//MochiKit.Logging.logDebug("--- previewRecordValues - 2"); + + MochiKit.Base.map(MochiKit.Base.bind(function(aRecord) { + this.getElement(aRecord.reference()).dom.value = aRecord.reference(); + }, this), someProcessedRecords); + + Clipperz.Style.applyZebraStylesToTable('importPreview'); +//MochiKit.Logging.logDebug("<<< previewRecordValues"); + }, + + //------------------------------------------------------------------------- + + 'updateProgressDialogStatus': function(anEvent) { + Clipperz.PM.Components.MessageBox().update({step:anEvent.parameters().progress}); + }, + + //------------------------------------------------------------------------- + + 'parsedValues': function() { + return this._parsedValues; + }, + + 'setParsedValues': function(aValue) { + this._parsedValues = aValue; + + return this._parsedValues; + }, + + //------------------------------------------------------------------------- + + 'processedValues': function() { + return this._processedValues; + }, + + 'setProcessedValues': function(aValue) { + this._processedValues = aValue; + return this._processedValues; + }, + + //------------------------------------------------------------------------- + + 'importValues': function() { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); + + deferredResult.addCallback(MochiKit.Base.bind(function() { + this.nextButton().disable(); + this.startProcessing(); + },this)); + deferredResult.addCallback(MochiKit.Base.method(this, 'importProcessedValues')); + deferredResult.addCallback(MochiKit.Base.method(this, 'processingDone')); + deferredResult.addErrback (MochiKit.Base.method(this, 'processingAborted')); + deferredResult.callback(); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'importProcessedValues': function() { + var deferredResult; + var processedValues; + var selectedRecords; + var i,c; + +//MochiKit.Logging.logDebug(">>> GenericImportComponent.importProcessedValues"); + processedValues = this.processedValues(); + selectedRecords = []; + + c = processedValues.length; + for (i=0; i>> inner deferred"); + innerDeferredResult = new MochiKit.Async.Deferred(); + +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 3.1: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Base.method(this, 'importProcessedValues_core', someRecords)); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 3.2: " + res); return res;}); + innerDeferredResult.addErrback(MochiKit.Base.method(this, 'handleProcessError')); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 3.3: " + res); return res;}); + innerDeferredResult.callback(someRecords); +//MochiKit.Logging.logDebug("<<< inner deferred"); + + return innerDeferredResult; + }, this), selectedRecords); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 4: " + res); return res;}); + + deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Components.MessageBox(), 'hide'), 'mainDiv'); + + deferredResult.addErrback(MochiKit.Base.bind(function() { + this.nextButton().enable(); + this.setCurrentStep(this.currentStep() -1); + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 5: " + res); return res;}); + + deferredResult.callback(selectedRecords); +//MochiKit.Logging.logDebug("<<< GenericImportComponent.importProcessedValues"); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'importProcessedValues_core': function(someRecords) { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); + + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'processingImportData'); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {steps:(someRecords.length + 6 + 1)}); + deferredResult.addCallback(MochiKit.Async.wait, 0.5); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("importProcessedValues_core - 3: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(someRecords) { + var i,c; + + c = someRecords.length; + for (i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.KeePassImportComponent = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.KeePassImportComponent.superclass.constructor.call(this, anElement, args); + + this._steps = ['EDIT', 'KEEPASS_SETTINGS', 'PREVIEW', 'IMPORT']; + this._definedFields = ['Group', 'Group Tree', 'UserName', 'URL', 'Password', 'Notes', 'UUID', 'Icon', 'Creation Time', 'Last Access', 'Last Modification', 'Expires', 'Attachment Description', 'Attachment']; + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.KeePassImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.KeePassImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.KeePassImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', cls:'keePassImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['KeePass_ImportWizard_Title']}, + {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, + {tag:'div', cls:'importStepBlocks', children:[ + {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ + {tag:'div', children:[ + {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_keePass_description']}, + {tag:'div', cls:'importOptionsParameters', children:[]}, + this.textAreaConfig() + ]} + ]}, + {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('settingsDiv'), children:[ + {tag:'table', id:'KeePassSettings', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', width:'50%', valign:'top', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Group_checkbox'), name:'Group'/*, checked:true*/}]}, + {tag:'td', width:'150', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Group_label'), html:"Group"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Group Tree_checkbox'), name:'Group Tree'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Group Tree_label'), html:"Group Tree"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('UserName_checkbox'), name:'UserName', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('UserName_label'), html:"UserName"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('URL_checkbox'), name:'URL', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('URL_label'), html:"URL"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Password_checkbox'), name:'Password', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Password_label'), html:"Password"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Notes_checkbox'), name:'Notes', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Notes_label'), html:"Notes"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('UUID_checkbox'), name:'UUID'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('UUID_label'), html:"UUID"}]} + ]} + ]} + ]} + ]}, + {tag:'td', width:'50%', valign:'top', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Icon_checkbox'), name:'Icon'/*, checked:true*/}]}, + {tag:'td', width:'150', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Icon_label'), html:"Icon"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Creation Time_checkbox'), name:'Creation Time'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Creation Time_label'), html:"Creation Time"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Last Access_checkbox'), name:'Last Access'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Last Access_label'), html:"Last Access"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Last Modification_checkbox'), name:'Last Modification'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Last Modification_label'), html:"Last Modification"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Expires_checkbox'), name:'Expires'/*, checked:true*/}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Expires_label'), html:"Expires"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Attachment Description_checkbox'), name:'Attachment Description', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Attachment Description_label'), html:"Attachment Description"}]} + ]}, + {tag:'tr', children:[ + {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Attachment_checkbox'), name:'Attachment', checked:true}]}, + {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Attachment_label'), html:"Attachment"}]} + ]} + ]} + ]} + ]} + ]} + ]} + ]} + ]} + ]} + ]}, + {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('previewDiv'), html:"preview"} + ]} + ]}, + {tag:'div', cls:'step_3', id:this.getId('step_3'), children:[ + {tag:'div', children:[ + {tag:'h4', html:"done"} + ]} + ]} + ]}, + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]}); + + this.updateSteps(); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() + this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_3').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); +//MochiKit.Logging.logDebug("<<< Import.KeePassImportComponent.render"); + }, + + //------------------------------------------------------------------------- + + 'nextAction': function() { + switch (this.currentStep()) { + case 0: // -> 1 + Clipperz.PM.Components.MessageBox.showProgressPanel( + MochiKit.Base.method(this, 'deferredParseValues'), + MochiKit.Base.method(this, 'handleParseError'), + this.getDom('nextActionButton') + ); + break; + case 1: // -> 2 + this.previewValues(); + break; + case 2: // -> 3 + this.importValues(); + break; + } + }, + + //------------------------------------------------------------------------- + + 'deferredParseValues': function() { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 1 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 2 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 3 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'parseKeePassValues')); // processPasswordPlusValues +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 4 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'setParsedValues')); // setProcessedValues +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 5 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'showSettings')); // previewRecordValues +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 6 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_0').hide(); + this.getElement('step_1').show(); + this.backButton().enable(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 7 " + res); return res;}); + deferredResult.callback(this.textAreaContent()); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'deferredPreviewValues': function() { + var deferredResult; + +//MochiKit.Logging.logDebug(">>> KeePassImportComonent.deferredPreviewValues"); + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 1 " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 2 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 3 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'processKeePassParsedValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 4 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 5 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 6 " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_1').hide(); + this.getElement('step_2').show(); + this.backButton().enable(); + + return res; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 7 " + res); return res;}); +// deferredResult.addErrback(MochiKit.Base.bind(function() { +// this.processingAborted(); +// }, this)) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 8 " + res); return res;}); + deferredResult.callback(this.parsedValues()); +//MochiKit.Logging.logDebug("<<< KeePassImportComonent.deferredPreviewValues"); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'definedFields': function() { + return this._definedFields; + }, + + //------------------------------------------------------------------------- + + 'parseKeePassValues': function(someData) { + var deferredResult; + var keePassProcessor; + + keePassProcessor = new Clipperz.KeePassExportProcessor(); + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 1 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); + }) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 2 " + res.substring(0,50)); return res;}); + deferredResult.addCallback(MochiKit.Base.method(keePassProcessor, 'deferredParse')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 3 " + res); return res;}); + deferredResult.callback(someData); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'showSettings': function(someValues) { + var availableFields; + var i,c; + +//MochiKit.Logging.logDebug(">>> KeePassImportCOmponent.showSettings"); + availableFields = new Clipperz.Set(); + c = this.parsedValues().length; + for (i=0; i>> shouldImportField: " + aFieldName); +// fieldCheckbox = this.getDom(aFieldName + '_checkbox'); + fieldCheckbox = MochiKit.DOM.getElement(this.getId(aFieldName + '_checkbox')); + if (fieldCheckbox != null) { + result = fieldCheckbox.checked; + } else { + result = false; + } +//MochiKit.Logging.logDebug("<<< shouldImportField: " + result); + + return result; + }, + + //------------------------------------------------------------------------- + + 'processKeePassParsedValues': function(someValues) { + var deferredResult; + var records; + var i,c; + +//MochiKit.Logging.logDebug(">>> processKeePassParsedValues"); + deferredResult = new MochiKit.Async.Deferred(); + records = []; + +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 1: " + res); return res;}); + c = someValues.length; + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:c}, res); + }) + for(i=0; i. + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.MainComponent = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.MainComponent.superclass.constructor.call(this, anElement, args); + + this._user = args.user; + this._wizardComponent = null; + + this._backButton = null; + this._nextButton = null; + + this._selectedComponent = null; + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.MainComponent, Clipperz.PM.Components.BaseComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.MainComponent component"; + }, + + //------------------------------------------------------------------------- + + 'user': function() { + return this._user; + }, + + //------------------------------------------------------------------------- + + 'wizardComponent': function() { + return this._wizardComponent; + }, + + 'setWizardComponent': function(aValue) { + if (this._wizardComponent != null) { + this._wizardComponent.remove(); + } + + if (aValue != null) { + this.getElement('importCover').hide(); + this.getElement('importWizard').show(); + } + this._wizardComponent = aValue; + }, + + 'resetImportComponent': function() { +//MochiKit.Logging.logDebug(">>> resetImportComponent"); + this.setWizardComponent(null); + this.getElement('wizardComponent').update(""); + + this.getElement('importCover').show(); + this.getElement('importWizard').hide(); +//MochiKit.Logging.logDebug("<<< resetImportComponent"); + }, + + //------------------------------------------------------------------------- + + 'backButton': function() { + return this._backButton; + }, + + 'setBackButton': function(aValue) { + this._backButton = aValue; + }, + + 'nextButton': function() { + return this._nextButton; + }, + + 'setNextButton': function(aValue) { + this._nextButton = aValue; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.MainComponent.render"); + Clipperz.NotificationCenter.unregister(this); + MochiKit.Signal.disconnectAllTo(this); + + this.element().update(""); + this.domHelper().append(this.element(), {tag:'div', id:this.getId('mainDiv'), children:[ + {tag:'div', id:this.getId('importCover'), children:[ + {tag:'h5', htmlString:Clipperz.PM.Strings['importTabTitle']}, + {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['importTabDescription']}, + {tag:'div', cls:'importFormats', children:[ + {tag:'ul', cls:'radioList', children:[ + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('CSV_radio'), type:'radio', name:'importFormat', value:'CSV'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('CSV_title'), htmlString:Clipperz.PM.Strings['importFormats']['CSV']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['CSV']['description']} + ]} + ]}]}]} + ]}, + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('Excel_radio'), type:'radio', name:'importFormat', value:'EXCEL'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('Excel_title'), htmlString:Clipperz.PM.Strings['importFormats']['Excel']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['Excel']['description']} + ]} + ]}]}]} + ]}, + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('KeePass_radio'), type:'radio', name:'importFormat', value:'KEEPASS'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('KeePass_title'), htmlString:Clipperz.PM.Strings['importFormats']['KeePass']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['KeePass']['description']} + ]} + ]}]}]} + ]}, + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('Roboform_radio'), type:'radio', name:'importFormat', value:'ROBOFORM'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('Roboform_title'), htmlString:Clipperz.PM.Strings['importFormats']['Roboform']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['Roboform']['description']} + ]} + ]}]}]} + ]}, + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('PasswordPlus_radio'), type:'radio', name:'importFormat', value:'PASSWORD_PLUS'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('PasswordPlus_title'), htmlString:Clipperz.PM.Strings['importFormats']['PasswordPlus']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['PasswordPlus']['description']} + ]} + ]}]}]} + ]}, + {tag:'li', children:[ + {tag:'table', children:[{tag:'tbody', children:[{tag:'tr', children:[ + {tag:'td', valign:'top', children:[ + {tag:'input', id:this.getId('ClipperzExport_radio'), type:'radio', name:'importFormat', value:'CLIPPERZ_EXPORT'} + ]}, + {tag:'td', valign:'top', children:[ + {tag:'h4', id:this.getId('ClipperzExport_title'), htmlString:Clipperz.PM.Strings['importFormats']['ClipperzExport']['label']}, + {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['importFormats']['ClipperzExport']['description']} + ]} + ]}]}]} + ]} + ]}, + + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]} + ]}, + {tag:'div', id:this.getId('importWizard'), children:[ + {tag:'form', id:this.getId('importWizardForm'), children:[ + {tag:'div', cls:'wizardComponent', id:this.getId('wizardComponent'), children:[]} + ]} + ]} + ]}); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.backButton().disable(); + this.nextButton().disable(); + + this.getElement('importCover').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show(); + this.getElement('importWizard').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + + if (Clipperz.PM.Proxy.defaultProxy.isReadOnly()) { + this.getElement('mainDiv').addClass('read-only'); + + this.getDom('ClipperzExport_radio').disabled = true; + this.getDom('CSV_radio').disabled = true; + this.getDom('Excel_radio').disabled = true; + this.getDom('PasswordPlus_radio').disabled = true; + this.getDom('Roboform_radio').disabled = true; + this.getDom('KeePass_radio').disabled = true; + } else { + MochiKit.Signal.connect(this.getId('ClipperzExport_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + MochiKit.Signal.connect(this.getId('CSV_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + MochiKit.Signal.connect(this.getId('Excel_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + MochiKit.Signal.connect(this.getId('PasswordPlus_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + MochiKit.Signal.connect(this.getId('Roboform_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + MochiKit.Signal.connect(this.getId('KeePass_radio'), 'onclick', MochiKit.Base.method(this, 'selectComponent')); + + if (Clipperz_IEisBroken != true) { + MochiKit.Signal.connect(this.getId('ClipperzExport_title'), 'onclick', this.getDom('ClipperzExport_radio'), 'click'); + MochiKit.Signal.connect(this.getId('CSV_title'), 'onclick', this.getDom('CSV_radio'), 'click'); + MochiKit.Signal.connect(this.getId('Excel_title'), 'onclick', this.getDom('Excel_radio'), 'click'); + MochiKit.Signal.connect(this.getId('PasswordPlus_title'), 'onclick', this.getDom('PasswordPlus_radio'), 'click'); + MochiKit.Signal.connect(this.getId('Roboform_title'), 'onclick', this.getDom('Roboform_radio'), 'click'); + MochiKit.Signal.connect(this.getId('KeePass_title'), 'onclick', this.getDom('KeePass_radio'), 'click'); + } + + Clipperz.NotificationCenter.register(null, 'importCompleted', this, 'resetImportComponent'); + Clipperz.NotificationCenter.register(null, 'importCancelled', this, 'resetImportComponent'); + } + +//MochiKit.Logging.logDebug("<<< Import.MainComponent.render"); + }, + + //------------------------------------------------------------------------- +/* + 'selectedFormat': function() { + return this.getDom('importSelectionOptions').value; + }, +*/ + //------------------------------------------------------------------------- + + 'updateSelectedImportWizardComponent': function(aComponent) { + var newWizardComponent; + +//MochiKit.Logging.logDebug(">>> Import.MainComponent.updateSelectedImportWizardComponent"); + this.getElement('wizardComponent').update(""); + + switch(aComponent) { + case 'CLIPPERZ_EXPORT': + newWizardComponent = new Clipperz.PM.Components.Import.ClipperzImportComponent(this.getElement('wizardComponent'), {user:this.user()}); + break; + case 'CSV': + newWizardComponent = new Clipperz.PM.Components.Import.CSVImportComponent(this.getElement('wizardComponent'), {user:this.user()}); + break; + case 'EXCEL': + newWizardComponent = new Clipperz.PM.Components.Import.ExcelImportComponent(this.getElement('wizardComponent'), {user:this.user()}); + break; + case 'PASSWORD_PLUS': + newWizardComponent = new Clipperz.PM.Components.Import.PasswordPlusImportComponent(this.getElement('wizardComponent'), {user:this.user()}); + break; + case 'ROBOFORM': + newWizardComponent = new Clipperz.PM.Components.Import.RoboFormImportComponent(this.getElement('wizardComponent'), {user:this.user()});; + break; + case 'KEEPASS': + newWizardComponent = new Clipperz.PM.Components.Import.KeePassImportComponent(this.getElement('wizardComponent'), {user:this.user()}); + break; + } + + this.setWizardComponent(newWizardComponent); +//MochiKit.Logging.logDebug("<<< Import.MainComponent.updateSelectedWizardComponent"); + }, + + //------------------------------------------------------------------------- + + 'selectComponent': function(anEvent) { + this.setSelectedComponent(anEvent.src().value); + this.nextButton().enable(); + }, + + 'selectedComponent': function() { + return this._selectedComponent; + }, + + 'setSelectedComponent': function(aValue) { + this._selectedComponent = aValue; + }, + + //------------------------------------------------------------------------- + + 'backAction': function() { + }, + + //------------------------------------------------------------------------- + + 'nextAction': function() { + this.updateSelectedImportWizardComponent(this.selectedComponent()); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/PasswordPlusImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/PasswordPlusImportComponent.js new file mode 100644 index 0000000..f476ac2 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/PasswordPlusImportComponent.js @@ -0,0 +1,315 @@ +/* + +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. +For further information about its features and functionalities please +refer to http://www.clipperz.com + +* Javascript Crypto Library 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 + 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 + . + +*/ + +if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } +if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } +if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } +if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } + +//############################################################################# + +Clipperz.PM.Components.Import.PasswordPlusImportComponent = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.PasswordPlusImportComponent.superclass.constructor.call(this, anElement, args); + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.PasswordPlusImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.PasswordPlusImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.PasswordPlusImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', cls:'passwordPlusImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['PasswordPlus_ImportWizard_Title']}, + {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, + {tag:'div', cls:'importStepBlocks', children:[ + {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ + {tag:'div', children:[ + {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_passwordPlus_description']}, + {tag:'div', cls:'importOptionsParameters', children:[]}, + this.textAreaConfig() + ]} + ]}, + {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[ + {tag:'div', children:[ + {tag:'div', id:this.getId('previewDiv'), html:"preview"} + ]} + ]}, + {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[ + {tag:'div', children:[ + {tag:'h4', html:"done"} + ]} + ]} + ]}, + {tag:'div', cls:'importOptionsButtons', children:[ + {tag:'table', children:[ + {tag:'tbody', children:[ + {tag:'tr', children:[ + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('backActionButton')} + ]}, + {tag:'td', html:' '}, + {tag:'td', children:[ + {tag:'div', id:this.getId('nextActionButton')} + ]}, + {tag:'td', html:' '} + ]} + ]} + ]} + ]} + ]}); + + this.updateSteps(); + + this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); + this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); + + this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() + this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); + this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); +//MochiKit.Logging.logDebug("<<< Import.PasswordPlusImportComponent.render"); + }, + + //------------------------------------------------------------------------- +/* + 'backAction': function() { + switch (this.currentStep()) { + case 1: // -> 0 + this.backButton().disable(); + this.getElement('step_1').hide(); + this.setCurrentStep(0); + this.getElement('step_0').show(); + break; + } + }, +*/ + //------------------------------------------------------------------------- + + 'nextAction': function() { + switch (this.currentStep()) { + case 0: // -> 1 + this.previewValues(); + break; + case 1: // -> 2 + this.importValues(); + break; + } + }, + + //------------------------------------------------------------------------- + + 'deferredPreviewValues': function() { + var deferredResult; + +// this.setFormValues(MochiKit.DOM.formContents(this.getDom('dataForm'))); + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.startProcessing(); + + return res; + }, this)); + deferredResult.addCallback(MochiKit.Base.method(this, 'processPasswordPlusValues')); + deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues')); + deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues')); + deferredResult.addCallback(MochiKit.Base.bind(function(res) { + this.processingDone(); + this.getElement('step_0').hide(); + this.getElement('step_1').show(); + this.backButton().enable(); + + return res; + }, this)); +// deferredResult.addErrback(MochiKit.Base.bind(function() { +// this.processingAborted(); +// }, this)) + deferredResult.callback(this.textAreaContent()); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'processPasswordPlusValues': function(someData) { + var deferredResult; + var csvProcessor; + + csvProcessor = new Clipperz.CSVProcessor({binary:true}); + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length * 2)}, res); + }) + deferredResult.addCallback(MochiKit.Base.method(csvProcessor, 'deferredParse')); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData'); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length * 2), step:res.length}, res); + }) + deferredResult.addCallback(MochiKit.Base.bind(function(someCSVValues) { + var innerDeferredResult; + var records; + var i,c; + + innerDeferredResult = new MochiKit.Async.Deferred(); + records = []; + + c = someCSVValues.length; + i=0; + i++; // Dataviz Passwords Plus Export, Version,1, Minimum Version To Read,1 + i++; // Is Template,Title,Category,Field 1 Label,Field 1 Value,Field 1 Hidden,Field 2 Label,Field 2 Value,Field 2 Hidden,Field 3 Label,Field 3 Value,Field 3 Hidden,Field 4 Label,Field 4 Value,Field 4 Hidden,Field 5 Label,Field 5 Value,Field 5 Hidden,Field 6 Label,Field 6 Value,Field 6 Hidden,Field 7 Label,Field 7 Value,Field 7 Hidden,Field 8 Label,Field 8 Value,Field 8 Hidden,Field 9 Label,Field 9 Value,Field 9 Hidden,Field 10 Label,Field 10 Value,Field 10 Hidden,Note + + for( ; i