Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import') (more/less context) (ignore whitespace changes)
13 files changed, 3968 insertions, 0 deletions
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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + columnSelectorCheckboxCells.push({tag:'th', valign:'top', cls:(this.mainComponent().isColumnSelected(i) ? 'selectedColumn': 'skippedColumn'), children:[ + {tag:'input', type:'checkbox', id:this.getId('columnCheckbox_' + i), value:i} + ]}) + } + + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Columns']}, + {tag:'div', id:this.getId('dataDiv'), cls:'csvImportPreview', children:[ + {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview columns', cellspacing:'0', children:[ + {tag:'thead', id:this.getId('previewData_thead'), children:[ + {tag:'tr', children:columnSelectorCheckboxCells} + ]}, + {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} + ]} + ]} + ]}); + + c = data[0].length; + for (i=0; i<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + this.getDom('columnCheckbox_' + i).checked = true; + } + } + + this.renderData(this.getElement('previewData_tbody'), data); + + checkboxes = MochiKit.DOM.getElementsByTagAndClassName('input', null, this.getDom('previewData_thead')); + c = checkboxes.length; + for (i=0; i<c; i++) { + MochiKit.Signal.connect(checkboxes[i], 'onclick', this, 'renderDataHandler'); + } +//MochiKit.Logging.logDebug("<<< CSVImportColumns.render"); + }, + + //------------------------------------------------------------------------- + + 'renderData': function(anElement, someData) { + var config; + var i,c; + +//MochiKit.Logging.logDebug(">>> 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<c; i++) { + var field; + + field = aRowData[i]; + result.children.push({tag:'td', valign:'top', cls:(this.mainComponent().isColumnSelected(i) ? 'selectedColumn': 'skippedColumn'), html:(MochiKit.Base.isNotEmpty(field) ? field.replace(/\n/g, '<br>') : ' ')}); + } + + 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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + var trimmedLabel; + + trimmedLabel = Clipperz.Base.trim(this.mainComponent().labelForColumn(i)); + fieldsHeaderCells.push({tag:'td', valign:'top', id:this.getId('fieldHeaderTD_' + i), cls:((trimmedLabel == "") ? 'missingLabelWarning' : (this.isColumnSetup(i) ? 'configuredColumn': 'unconfiguredColumn')), children:[ + {tag:'span', html:((trimmedLabel == "") ? Clipperz.PM.Strings['CSV_ImportWizard_Fields_MissingLabelWarning'] : trimmedLabel)/*, cls:((trimmedLabel == "") ? 'missingLabelWarning' : '')*/}, + {tag:'select', id:this.getId('select_' + i), name:i, children:[ + {tag:'option', value:'UNDEFINED', html:"select data type", cls:'disabledOption'}, + {tag:'option', value:'TXT', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['TXT']['shortDescription']}, + {tag:'option', value:'PWD', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['PWD']['shortDescription']}, + {tag:'option', value:'URL', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['URL']['shortDescription']}, + {tag:'option', value:'DATE', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['DATE']['shortDescription']}, + {tag:'option', value:'ADDR', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['ADDR']['shortDescription']} + ]} + ]}) + } + } + + if (notesColumnIndex != -1) { + fieldsHeaderCells.push({tag:'td', valign:'top', cls:'notes', html:this.mainComponent().labelForColumn(notesColumnIndex)}); + } + + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Fields']}, + {tag:'div', id:this.getId('dataDiv'), children:[ + {tag:'div', children:[ + ]}, + {tag:'div', cls:'csvImportPreview', children:[ + {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ + {tag:'thead', id:this.getId('previewData_thead'), children:[ + {tag:'tr', cls:'CSV_previewData_header', children:fieldsHeaderCells} + ]}, + {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} + ]} + ]} + ]} + ]}); + + for (i=0; i<c; i++) { + if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + Clipperz.DOM.selectOptionMatchingValue(this.getDom('select_' + i), this.mainComponent().typeForColumn(i)); + MochiKit.Signal.connect(this.getDom('select_' + i), 'onchange', this, 'renderDataRowsHandler'); + } + } + + this.renderDataRows(this.getElement('previewData_tbody')); +// Clipperz.NotificationCenter.register(null, 'updatedCSVImportColumnHeader', this, 'renderDataRowsHandler'); + }, + + //------------------------------------------------------------------------- + + 'isColumnSetup': function(aColumnIndex) { + return ((Clipperz.Base.trim(this.mainComponent().labelForColumn(aColumnIndex)) != "") && (this.mainComponent().typeForColumn(aColumnIndex) != 'UNDEFINED')); + }, + + //------------------------------------------------------------------------- + + 'renderDataRowsHandler': function(anEvent) { + var columnIndex; + var tdElement; + +//MochiKit.Logging.logDebug(">>> 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<c; i++) { + var rowData; + var rowConfig; + var ii, cc; + + rowData = data[i]; + + rowConfig = {tag:'tr', children:[ + {tag:'td', valign:'top', cls:'title', html:(MochiKit.Base.isNotEmpty(rowData[titleColumnIndex]) ? rowData[titleColumnIndex].replace(/\n/g, '<br>') : ' ')} + ]}; + + cc = rowData.length; + for (ii=0; ii<cc; ii++) { +// if ((ii != titleColumnIndex) && (ii != notesColumnIndex)) { + if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (this.mainComponent().isColumnSelected(ii))) { + rowConfig.children.push({ + tag:'td', + valign:'top', + cls:(this.isColumnSetup(ii) ? 'configuredColumn' : 'unconfiguredColumn'), + html:(MochiKit.Base.isNotEmpty(rowData[ii]) ? rowData[ii].replace(/\n/g, '<br>') : ' ') + }); + } + } + if (notesColumnIndex != -1) { + rowConfig.children.push({tag:'td', valign:'top', cls:'notes', html:(MochiKit.Base.isNotEmpty(rowData[notesColumnIndex]) ? rowData[notesColumnIndex].replace(/\n/g, '<br>') : ' ')}); + } + + 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<c; i++) { + if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + result = result && this.isColumnSetup(i); + } + } + + if (result) { + this.mainComponent().nextButton().enable(); + } else { + this.mainComponent().nextButton().disable(); + } + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js new file mode 100644 index 0000000..ebd243a --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js @@ -0,0 +1,240 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { +// thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:this.mainComponent().labelForColumn(i)}]}); + thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:""}]}); + } + } + + this.element().update(""); + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header']}, + {tag:'div', cls:'importStepParameters', children:[ + {tag:'input', type:'checkbox', name:'isFistRowHeader', id:this.getId('isFirstRowHeader_checkbox')}, + {tag:'span', id:this.getId('isFirstRowHeader_span'), cls:'clickableSpan', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header_Settings_firstRowHeaderLabel']} + ]}, + {tag:'div', id:this.getId('dataDiv'), children:[ + {tag:'div', cls:'csvImportPreview', children:[ + {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview header', cellspacing:'0', children:[ + {tag:'thead', children:[{tag:'tr', children:thConfigs}]}, + {tag:'tbody', id:this.getId('previewData_tbody')} + ]} + ]} + ]} + ]}); + + for (i=0; i<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + this.getElement('headerTextField_' + i).dom.value = this.mainComponent().labelForColumn(i); + } + } + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + + if (this.mainComponent().isFirstRowHeader()) { + this.getDom('isFirstRowHeader_checkbox').click(); + } + + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onchange', MochiKit.Base.partial(MochiKit.Base.method(this, 'labelFieldHandler'), i)); + MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onkeypress', MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandler'), i)); + } + } + + MochiKit.Signal.connect(this.getDom('isFirstRowHeader_checkbox'), 'onclick', this, 'toggleFirstRowHeaderCheckboxHandler'); + if (Clipperz_IEisBroken != true) { + MochiKit.Signal.connect(this.getDom('isFirstRowHeader_span'), 'onclick', this.getDom('isFirstRowHeader_checkbox'), 'click'); + } +//MochiKit.Logging.logDebug("<<< CSVImportHeader.render"); + }, + + //------------------------------------------------------------------------- + + 'renderData': function(anElement, someData) { + var trConfigs; + var data; + var i,c; + +// anElement.update(""); + MochiKit.DOM.replaceChildNodes(anElement.dom); + + if (this.mainComponent().isFirstRowHeader()) { + data = someData.slice(1); + } else { + data = someData; + } + + trConfigs = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { + var result; + var i,c; + + result = {tag:'tr', children:[]}; + c = aRowData.length; + for (i=0; i<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + result.children.push({tag:'td', valign:'top', html:(MochiKit.Base.isNotEmpty(aRowData[i]) ? aRowData[i].replace(/\n/g, '<br>') : ' ')}); + } + } + + 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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + var label; + + if (this.mainComponent().isFirstRowHeader()) { + label = firstRowData[i]; + } else { + label = null; + } + + this.mainComponent().setLabelForColumn(label, i); + } + }; + + this.updateInputFieldValues(); + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); +//MochiKit.Logging.logDebug("<<< toggleFirstRowHeaderCheckboxHandler"); + }, + + //------------------------------------------------------------------------- + + 'updateInputFieldValues': function() { + var i,c; + +//MochiKit.Logging.logDebug(">>> updateInputFieldValues"); + c = this.mainComponent().parsedValues()[0].length; + for (i=0; i<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + this.getDom('headerTextField_' + i).value = this.mainComponent().labelForColumn(i); + } + } +//console.log('[1] fieldSettings', fieldSettings); +//MochiKit.Logging.logDebug("<<< updateInputFieldValues"); + }, + + //------------------------------------------------------------------------- + + 'labelFieldHandler': function(aColumnIndex, anEvent) { + var inputField; + +//MochiKit.Logging.logDebug(">>> 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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + if ((i != titleColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + notesSelectorCheckboxCells.push({tag:'th', id:this.getId('th_' + i), valign:'top', children:[ + {tag:'input', type:'radio', id:this.getId('radio_' + i), name:'CSVImportNotesColumn', value:i}, + {tag:'span', cls:'clickableSpan', id:this.getId('columnLabel_' + i), html:this.mainComponent().labelForColumn(i)} + ]}) + } + } + + this.domHelper().append(this.element(), {tag:'div', children:[ + {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Notes']}, + {tag:'div', id:this.getId('dataDiv'), children:[ + {tag:'div', cls:'importStepParameters', children:[ + {tag:'input', id:this.getId('doNotSetNotes_radio'), type:'radio', name:'CSVImportNotesColumn', value:-1}, + {tag:'span', id:this.getId('doNotSetNotes_span'), cls:'clickableSpan', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Notes_Settings_noSelectionLabel']} + ]}, + {tag:'div', 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:notesSelectorCheckboxCells} + ]}, + {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} + ]} + ]} + ]} + ]}); + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + + if ((notesColumnIndex >= totalNumberOfColumns) || (notesColumnIndex == titleColumnIndex) || !(this.mainComponent().isColumnSelected(notesColumnIndex))) { + this.mainComponent().setNotesColumnIndex(-1); + notesColumnIndex = -1; + } + + c = totalNumberOfColumns; + for (i=0; i<c; i++) { + if ((i != titleColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + MochiKit.Signal.connect(this.getDom('radio_' + i), 'onclick', this, 'renderDataHandler'); + if (Clipperz_IEisBroken != true) { + MochiKit.Signal.connect(this.getDom('columnLabel_' + i), 'onclick', this.getDom('radio_' + i), 'click'); + } + } + } + + MochiKit.Signal.connect(this.getDom('doNotSetNotes_radio'), 'onclick', this, 'renderDataHandler'); + if (Clipperz_IEisBroken != true) { + MochiKit.Signal.connect(this.getDom('doNotSetNotes_span'), 'onclick', this.getDom('doNotSetNotes_radio'), 'click'); + } + + if (notesColumnIndex == -1) { + this.getDom('doNotSetNotes_radio').click(); + } else { + this.getDom('radio_' + notesColumnIndex).click(); + } + }, + + //------------------------------------------------------------------------- + + 'renderData': function(anElement, someData) { + var data; + var config; + var titleColumnIndex; + var notesColumnIndex; + var i,c; + +// anElement.update(""); + MochiKit.DOM.replaceChildNodes(anElement.dom); + + titleColumnIndex = this.mainComponent().titleColumnIndex(); + notesColumnIndex = this.mainComponent().notesColumnIndex(); + + if (this.mainComponent().isFirstRowHeader()) { + data = someData.slice(1); + } else { + data = someData; + } + + +// config = [{tag:'tr', cls:'CSV_previewData_header', children:[{tag:'td', valign:'top', html:header[titleColumnIndex], cls:'title'}]}]; +// c = header.length; +// for (i=0; i<c; i++) { +// if (i != titleColumnIndex) { +// config[0].children.push({tag:'td', valign:'top', html:header[i], cls:((notesColumnIndex == i) ? 'notesColumn': '')}) +// } +// } + + config = MochiKit.Base.map(MochiKit.Base.bind(function(aTitleColumnIndex, aRowData) { + var result; + var i,c; + + result = {tag:'tr', children:[{tag:'td', valign:'top', cls:'title', html:(MochiKit.Base.isNotEmpty(aRowData[aTitleColumnIndex]) ? aRowData[aTitleColumnIndex].replace(/\n/g, '<br>') : ' ')}]}; + c = aRowData.length; + for (i=0; i<c; i++) { + if ((i != titleColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + result.children.push({tag:'td', valign:'top', cls:((notesColumnIndex == i) ? 'notesColumn': ''), html:(MochiKit.Base.isNotEmpty(aRowData[i]) ? aRowData[i].replace(/\n/g, '<br>') : ' ')}); + } + } + + 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<c; i++) { + if ((i != titleColumnIndex) && (this.mainComponent().isColumnSelected(i))) { + this.getElement('th_' + i).removeClass('notesColumn'); + } + } + if (anEvent.src().value != -1) { + this.getElement('th_' + anEvent.src().value).addClass('notesColumn'); + } + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js new file mode 100644 index 0000000..9162867 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + titleSelectorCheckboxCells.push({tag:'th', valign:'top', id:this.getId('th_' + i), children:[ + {tag:'input', type:'radio', id:this.getId('radio_' + i), name:'CSVImportTitleColumn', value:i}, + {tag:'span', cls:'clickableSpan', id:this.getId('columnLabel_' + i), html:this.mainComponent().labelForColumn(i)} + ]}) + } + } + + if (titleColumnIndex >= 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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + MochiKit.Signal.connect(this.getDom('radio_' + i), 'onclick', this, 'renderDataHandler'); + if (Clipperz_IEisBroken != true) { + MochiKit.Signal.connect(this.getDom('columnLabel_' + i), 'onclick', this.getDom('radio_' + i), 'click'); + } + } + } + + if (titleColumnIndex != -1) { + this.getDom('radio_' + titleColumnIndex).click(); + } else { + this.mainComponent().nextButton().disable(); + } + + }, + + //------------------------------------------------------------------------- + + 'renderData': function(anElement, someData) { + var data; + var config; + var titleColumnIndex; + var i,c; + +// anElement.update(""); + MochiKit.DOM.replaceChildNodes(anElement.dom); + + titleColumnIndex = this.mainComponent().titleColumnIndex() + + if (this.mainComponent().isFirstRowHeader()) { + data = someData.slice(1); + } else { + data = someData; + } + + 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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + var field; + + field = aRowData[i]; + result.children.push({tag:'td', valign:'top', cls:((titleColumnIndex == i) ? 'titleColumn': ''), html:(MochiKit.Base.isNotEmpty(field) ? field.replace(/\n/g, '<br>') : ' ')}); + } + } + + 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<c; i++) { + if (this.mainComponent().isColumnSelected(i)) { + this.getElement('th_' + i).removeClass('titleColumn'); + } + } + this.getElement('th_' + anEvent.src().value).addClass('titleColumn'); + + if (anEvent.src().value != -1) { + this.mainComponent().nextButton().enable(); + } else { + this.mainComponent().nextButton().disable(); + } + + this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImportComponent.js new file mode 100644 index 0000000..707a3d2 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImportComponent.js @@ -0,0 +1,548 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + deferredResult.addCallback(MochiKit.Async.wait, 0.2); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); + deferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + var record; + var recordVersion; + var ii; + + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + record.setLabel(someData[titleColumnIndex]); + if (notesColumnIndex != -1) { + record.setNotes(someData[notesColumnIndex]); + } + recordVersion = record.currentVersion() + + for (ii in someData) { +// if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (typeof(this.fieldSettings()[ii]) != 'undefined')) { + if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (this.isColumnSelected(ii))) { + var recordField; + + recordField = new Clipperz.PM.DataModel.RecordField({ + recordVersion: recordVersion, + label: this.labelForColumn(ii), + value: someData[ii], + type: this.typeForColumn(ii) + }); + recordVersion.addField(recordField); + } + } + + someRecords.push(record); + + return someRecords; + }, this), records, someValues[i]); + } + deferredResult.addCallback(MochiKit.Async.succeed, records); + deferredResult.callback(); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'step1Component': function() { + if (this._step1Component == null) { + this._step1Component = new Clipperz.PM.Components.Import.CSVImport.CSVImportColumns(this.getElement('step_1'), {mainComponent:this}); + } + + return this._step1Component; + }, + + 'step2Component': function() { + if (this._step2Component == null) { + this._step2Component = new Clipperz.PM.Components.Import.CSVImport.CSVImportHeader(this.getElement('step_2'), {mainComponent:this}); + } + + return this._step2Component; + }, + + 'step3Component': function() { + if (this._step3Component == null) { + this._step3Component = new Clipperz.PM.Components.Import.CSVImport.CSVImportTitle(this.getElement('step_3'), {mainComponent:this}); + } + + return this._step3Component; + }, + + 'step4Component': function() { + if (this._step4Component == null) { + this._step4Component = new Clipperz.PM.Components.Import.CSVImport.CSVImportNotes(this.getElement('step_4'), {mainComponent:this}); + } + + return this._step4Component; + }, + + 'step5Component': function() { + if (this._step5Component == null) { + this._step5Component = new Clipperz.PM.Components.Import.CSVImport.CSVImportFields(this.getElement('step_5'), {mainComponent:this}); + } + + return this._step5Component; + }, + + //------------------------------------------------------------------------- + + 'isFirstRowHeader': function() { + return this._isFirstRowHeader; + }, + + 'setIsFirstRowHeader': function(aValue) { + this._isFirstRowHeader = aValue; + }, + + //------------------------------------------------------------------------- + + 'titleColumnIndex': function() { + return this._titleColumnIndex; + }, + + 'setTitleColumnIndex': function(aValue) { + this._titleColumnIndex = aValue; + }, + + //------------------------------------------------------------------------- + + 'notesColumnIndex': function() { + return this._notesColumnIndex; + }, + + 'setNotesColumnIndex': function(aValue) { + this._notesColumnIndex = aValue; + }, + + //------------------------------------------------------------------------- + + 'fieldSettings': function() { + return this._fieldSettings; + }, + + //------------------------------------------------------------------------- + + 'skippedColumns': function() { + return this._skippedColumns; + }, + + //------------------------------------------------------------------------- + + 'isColumnSelected': function(aColumnIndex) { + return !this.skippedColumns().contains("" + aColumnIndex); + }, + + //========================================================================= + + 'labelForColumn': function(aColumnIndex) { + var result; + + if ((typeof(this.fieldSettings()) != 'undefined') && (typeof(this.fieldSettings()[aColumnIndex]) != 'undefined')) { + if (this.isFirstRowHeader()) { + result = this.fieldSettings()[aColumnIndex]['_firstRowLabel']; +//MochiKit.Logging.logDebug("--- updateInputFieldValues - [" + aColumnIndex + "] _firstRowLabel: " + label); + } else { + result = this.fieldSettings()[aColumnIndex]['_emptyLabel']; +//MochiKit.Logging.logDebug("--- updateInputFieldValues - [" + aColumnIndex + "] _emptyLabel: " + label); + } + } else { + result = ""; + } + + return result; + }, + + //------------------------------------------------------------------------- + + 'setLabelForColumn': function(aLabel, aColumnIndex) { + var fieldSettings; + +//MochiKit.Logging.logDebug(">>> 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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2); + innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); + innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + var record; + var recordVersion; + +//MochiKit.Logging.logDebug("=== someData: " + Clipperz.Base.serializeJSON(someData)); + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + record.setLabel(someData['label']); + record.setShouldProcessData(true); + record.processData(someData); + + someRecords.push(record); + + return someRecords; + }, this), records, someClipperzValues[i]); + } + innerDeferredResult.addCallback(MochiKit.Async.succeed, records); + innerDeferredResult.callback(); + + return innerDeferredResult; + }, this)); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 6: " + res); return res;}); + deferredResult.callback(someData); + + return deferredResult; + }, + + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/ExcelImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/ExcelImportComponent.js new file mode 100644 index 0000000..ecdf509 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/ExcelImportComponent.js @@ -0,0 +1,134 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + var cls; + + if (this.currentStep() == i) { + if (this.currentStatus() == 'IDLE') { + cls = 'current'; + } else { + cls = 'currentProcessing'; + } + } else { + cls = ""; + } + + result.push({tag:'td', cls:cls, children:[ + {tag:'div', children:[{tag:'span', htmlString:Clipperz.PM.Strings['ImportWizard'][this.steps()[i]]}]} + ]}) + if (i < (c-1)) { + if ((this.currentStep() == i) && (this.currentStatus() == 'PROCESSING')) { + cls = 'stepSeparatorProcessing'; + } else { + cls = 'stepSeparator'; + } + + result.push({tag:'td', cls:cls, children:[ + {tag:'div', children:[{tag:'span', html:">"}]} + ]}); + } + } + + 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, '<br>') : ' ')} + ]}, + {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<c; i++) { + var currentRecord; + + currentRecord = processedValues[i]; + if (this.getDom(currentRecord.reference()).checked == true) { + selectedRecords.push(currentRecord); + } + } + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 1: " + res); return res;}); + deferredResult.addCallback(function(someRecords) { + var innerDeferredResult; + var text; + + text = Clipperz.PM.Strings['importData_importConfirmation_text']; + text = text.replace(/__numberOfRecords__/, someRecords.length); + + innerDeferredResult = new MochiKit.Async.Deferred(); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 1.1: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Async.succeed, someRecords); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 1.2: " + res); return res;}); + + Clipperz.PM.Components.MessageBox().deferredShow({ + title:Clipperz.PM.Strings['importData_importConfirmation_title'], + text:text, + width:240, + showProgressBar:false, + showCloseButton:false, + buttons:{ + 'yes':"yes", // Clipperz.PM.Strings['mainPanelDeleteRecordPanelConfirmButtonLabel'], + 'no':"no" // Clipperz.PM.Strings['mainPanelDeleteRecordPanelDenyButtonLabel'] + }, + fn:MochiKit.Base.partial(function(aDeferred, aResult) { + if (aResult == 'yes') { + aDeferred.callback(aResult); + } else { + aDeferred.errback(aResult); + } + }, innerDeferredResult) + }/*, this.getId('nextActionButton')*/); + + return innerDeferredResult; + }); + +//------------------- +// deferredResult.addCallback(MochiKit.Base.bind(function(someRecords) { +// Clipperz.PM.Components.MessageBox.showProgressPanel( +// MochiKit.Base.method(this, 'importProcessedValues_core', someRecords), +// MochiKit.Base.method(this, 'handleProcessError'), +// this.getDom('mainDiv') +// ); +// }, this)); + +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 2: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Components.MessageBox(), 'deferredShow'), + { +// title:Clipperz.PM.Strings['accountPanelDeletingAccountPanelProgressTitle'], +// text:Clipperz.PM.Strings['accountPanelDeletingAccountPanelProgressText'], + width:240, + showProgressBar:true, + showCloseButton:false + } + ); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("GenericImportComponent - 3: " + res); return res;}); + + deferredResult.addCallback(MochiKit.Base.bind(function(someRecords) { + var innerDeferredResult; + +//MochiKit.Logging.logDebug(">>> 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<c; i++) { + this.user().addRecord(someRecords[i], true); + } + + return someRecords; + }, this)); + deferredResult.addCallback(MochiKit.Async.wait, 0.5); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("importProcessedValues_core - 4: " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'recordAdded', null); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("importProcessedValues_core - 5: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(this.user(), 'saveRecords')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("importProcessedValues_core - 6: " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'selectTab', 'mainTabPanel.recordsTab'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("importProcessedValues_core - 7: " + res); return res;}); + + if (this.user().preferences().shouldShowDonationPanel()) { + deferredResult.addCallback(Clipperz.PM.showDonationSplashScreen, this.user(), 'mainDiv'); + } + + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importCompleted', null); + + deferredResult.callback(someRecords); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + + 'handleParseError': function(res) { + this.processingAborted(); + MochiKit.Logging.logError("An error occurred while parsing the values: " + res); + alert("An error occurred while parsing the values: " + res); + Clipperz.PM.Components.MessageBox().hide(); + }, + + 'handleProcessError': function(res) { + this.processingAborted(); + MochiKit.Logging.logError("An error occurred while processing the values: " + res); + alert("An error occurred while processing the values: " + res); + Clipperz.PM.Components.MessageBox().hide(); + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js new file mode 100644 index 0000000..0657520 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js @@ -0,0 +1,450 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + var fieldLabel; + + for (fieldLabel in this.parsedValues()[i]) { + availableFields.add(fieldLabel); + } + } + + c = this.definedFields().length; + for (i=0; i<c; i++) { + var definedField; + + definedField = this.definedFields()[i]; + if (availableFields.contains(definedField)) { +//MochiKit.Logging.logDebug("enabling field " + definedField); + this.getDom(definedField + '_checkbox').disabled = false; + this.getElement(definedField + '_label').removeClass('disabled'); + } else { +//MochiKit.Logging.logDebug("disabling field " + definedField); + this.getDom(definedField + '_checkbox').disabled = true; + this.getDom(definedField + '_checkbox').checked = false; // ???? + this.getElement(definedField + '_label').addClass('disabled'); + } + } +//MochiKit.Logging.logDebug("<<< KeePassImportCOmponent.showSettings"); + + return MochiKit.Async.succeed(someValues); + }, + + //------------------------------------------------------------------------- + + 'shouldImportField': function(aFieldName) { + var fieldCheckbox; + var result; + +//MochiKit.Logging.logDebug(">>> 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<c; i++) { +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.1: " + res); return res;}); + deferredResult.addCallback(MochiKit.Async.wait, 0.2); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.2: " + res); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.3: " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + var record; + var recordVersion; + var ii; + + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + record.setLabel(someData['Title']); + if (this.shouldImportField('Notes')) { + record.setNotes(someData['Notes']); + } + recordVersion = record.currentVersion() + + for (ii in someData) { + if ((ii != 'Title') && (ii != 'Notes') && (typeof(someData[ii]) != "undefined") && (this.shouldImportField(ii))) { + var recordField; + var recordFieldType; + + recordFieldType = 'TXT'; + if (ii == 'Password') { + recordFieldType = 'PWD'; + } else if (ii == 'URL') { + recordFieldType = 'URL'; + } else if ((ii == 'Creation Time') || (ii == 'Last Access') || (ii == 'Last Modification') || (ii == 'Expires')) { + recordFieldType = 'Date'; + } + + recordField = new Clipperz.PM.DataModel.RecordField({ + recordVersion: recordVersion, + label: ii, + value: someData[ii], + type: recordFieldType + }); + recordVersion.addField(recordField); + } + } + + someRecords.push(record); + + return someRecords; + }, this), records, someValues[i]); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.4: " + res); return res;}); + } +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 2: " + res); return res;}); + deferredResult.addCallback(MochiKit.Async.succeed, records); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 3: " + res); return res;}); + deferredResult.callback(); +//MochiKit.Logging.logDebug("<<< processKeePassParsedValues"); + + return deferredResult; + }, + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/MainComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/MainComponent.js new file mode 100644 index 0000000..54813bc --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/MainComponent.js @@ -0,0 +1,332 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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<c; i++) { + innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2); + innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); + innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + if (someData[0] == '0') { + var record; + var recordVersion; + var ii, cc; + + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + if (someData[1] != "") { + record.setLabel(someData[1]); + } else { + record.setLabel("imported record [" + (i+1) + "]"); + } + record.setNotes(someData[33]); + recordVersion = record.currentVersion() + + cc = 10; + for (ii=0; ii<cc; ii++) { + var currentFieldValueIndex; + var currentType; + + currentFieldValueIndex = (ii * 3) + 4; + + if (someData[currentFieldValueIndex] != "") { + var recordField; + var recordFieldType; + + recordFieldType = 'TXT'; + if (someData[currentFieldValueIndex + 1] == 1) { + recordFieldType = 'PWD'; + } else if (/^http/.test(someData[currentFieldValueIndex])) { + recordFieldType = 'URL'; + } + + recordField = new Clipperz.PM.DataModel.RecordField({ + recordVersion: recordVersion, + label: someData[currentFieldValueIndex - 1], + value: someData[currentFieldValueIndex], + type: recordFieldType + }); + recordVersion.addField(recordField); + } + } + + // this.user().addRecord(record, true); + + someRecords.push(record); + } + + return someRecords; + }, this), records, someCSVValues[i]); + } + innerDeferredResult.addCallback(MochiKit.Async.succeed, records); + innerDeferredResult.callback(); + + return innerDeferredResult; + }, this)); + deferredResult.callback(someData); + + return deferredResult; + +/* +0 Is Template +1 Title +2 Category + +3 Field 1 Label +4 Field 1 Value +5 Field 1 Hidden + +6 Field 2 Label +7 Field 2 Value +8 Field 2 Hidden + +9 Field 3 Label +10 Field 3 Value +11 Field 3 Hidden + +12 Field 4 Label +13 Field 4 Value +14 Field 4 Hidden + +15 Field 5 Label +16 Field 5 Value +17 Field 5 Hidden + +18 Field 6 Label +19 Field 6 Value +20 Field 6 Hidden + +21 Field 7 Label +22 Field 7 Value +23 Field 7 Hidden + +24 Field 8 Label +25 Field 8 Value +26 Field 8 Hidden + +27 Field 9 Label +28 Field 9 Value +29 Field 9 Hidden + +30 Field 10 Label +31 Field 10 Value +32 Field 10 Hidden + +33 Note +*/ + }, + + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js new file mode 100644 index 0000000..d35bdc6 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js @@ -0,0 +1,392 @@ +/* + +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 + <http://www.gnu.org/licenses/>. + +*/ + +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.RoboFormImportComponent = function(anElement, args) { + args = args || {}; + + Clipperz.PM.Components.Import.RoboFormImportComponent.superclass.constructor.call(this, anElement, args); + + this.render(); + + return this; +} + +//============================================================================= + +YAHOO.extendX(Clipperz.PM.Components.Import.RoboFormImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { + + 'toString': function() { + return "Clipperz.PM.Components.Import.RoboFormImportComponent component"; + }, + + //------------------------------------------------------------------------- + + 'render': function() { +//MochiKit.Logging.logDebug(">>> Import.RoboFormImportComponent.render"); + this.domHelper().append(this.element(), {tag:'div', cls:'roboFormImportWizard', children:[ + {tag:'h3', htmlString:Clipperz.PM.Strings['RoboForm_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_roboForm_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.RoboFormImportComponent.render"); + }, + + //------------------------------------------------------------------------- + + '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, 'processRoboFormValues')); + 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; + }, + + //------------------------------------------------------------------------- + + 'processRoboFormValues': function(someData) { + var result; + + if (someData.match(/^\<HTML\>\<HEAD\>\<TITLE\>RoboForm Passcards List /g)) { + result = this.processRoboFormPasscardsValues(someData); + } else if (someData.match(/\<HTML\>\<HEAD\>\<TITLE\>RoboForm Safenotes List /g)) { + result = this.processRoboFormSafenotesValues(someData); + } + + return result; + }, + + //......................................................................... + + 'processRoboFormPasscardsValues': function(someData) { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 1: "/* + res*/); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 2: "/* + res*/); return res;}); + deferredResult.addCallback(function(someData) { + var result; + var data; + + data = someData.replace(/\r?\n/g, ""); + result = data.match(/\<TABLE width\=\"100\%\"\>.*?\<\/TABLE\>/g); + + return result; + }); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3: "/* + res*/); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3.1: " + res.length); return res;}); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); + }) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 4: "/* + res*/); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(someRecordValues) { + var innerDeferredResult; + var records; + var i,c; + + innerDeferredResult = new MochiKit.Async.Deferred(); + records = []; + + c = someRecordValues.length; + for(i=0; i<c; i++) { +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 1: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 2: " + res); return res;}); + innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 3: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + var data; + var record; + var recordVersion; + var fields; + var ii, cc; + var hasNotes; + + var caption; + var subcaption; + +//MochiKit.Logging.logDebug("data: " + someData); + data = someData.replace(/\<WBR\>/g, ""); + hasNotes = false; + + /\<TD class\=caption colSpan\=3\>(.*?)\<\/TD\>/.test(data); // <TD class=caption colSpan=3>110mb</TD> + caption = RegExp.$1; +//MochiKit.Logging.logDebug("caption: " + caption); + + /\<TD class\=subcaption colSpan\=3\>(.*?)\<\/TD\>/.test(data); // <TD class=subcaption colSpan=3>110<WBR>mb.com</TD> + subcaption = RegExp.$1; +//MochiKit.Logging.logDebug("subcaption: " + subcaption); + + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + recordVersion = record.currentVersion() + + record.setLabel(caption); +// record.setNotes(subcaption); + if (subcaption != null) { + var recordField; + + recordField = new Clipperz.PM.DataModel.RecordField({ + recordVersion: recordVersion, + label: "url", + value: subcaption, + type: 'URL' + }); + recordVersion.addField(recordField); + } + + fields = data.match(/\<TR\>.*?\<\/TR\>/g) || []; + cc = fields.length; +//MochiKit.Logging.logDebug("fields.length: " + cc); + for (ii=0; ii<cc; ii++) { + var recordField; + var fieldString; + var fieldName; + var fieldValue; + +//MochiKit.Logging.logDebug("fieldString: " + fields[ii]); + fieldString = fields[ii]; +//MochiKit.Logging.logDebug("fieldString (cleaned): " + fieldString); + /\<TD class\=field vAlign\=top align\=left width\=\"40\%\"\>(.*?)\<\/TD\>/.test(fieldString); + fieldName = RegExp.$1; + + /\<TD class\=wordbreakfield vAlign\=top align\=left width\=\"55\%\"\>(.*?)\<\/TD\>/.test(fieldString); + fieldValue = RegExp.$1; + + if (fieldName == "Note$") { + record.setNotes(fieldValue); + hasNotes = true; + } else { + var fieldType; + + if (((ii == 1) && (hasNotes == false)) || ((ii == 2) && (hasNotes == true))) { + fieldType = 'PWD'; + } else { + fieldType = 'TXT'; + } + + recordField = new Clipperz.PM.DataModel.RecordField({ + recordVersion: recordVersion, + label: fieldName, + value: fieldValue, + type: fieldType + }); + recordVersion.addField(recordField); + } + } + + someRecords.push(record); + + return someRecords; + }, this), records, someRecordValues[i]); + } +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 4: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Async.succeed, records); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 5: " + res); return res;}); + innerDeferredResult.callback(); + + return innerDeferredResult; + }, this)); + deferredResult.callback(someData); + + return deferredResult; + }, + + + //......................................................................... + + 'processRoboFormSafenotesValues': function(someData) { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 1: "/* + res*/); return res;}); + deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 2: "/* + res*/); return res;}); + deferredResult.addCallback(function(someData) { + var result; + var data; + + data = someData.replace(/\r?\n/g, ""); + result = data.match(/\<TABLE width\=\"100\%\"\>.*?\<\/TABLE\>/g); + + return result; + }); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3: "/* + res*/); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3.1: " + res.length); return res;}); + deferredResult.addCallback(function(res) { + return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); + }) +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 4: "/* + res*/); return res;}); + deferredResult.addCallback(MochiKit.Base.bind(function(someRecordValues) { + var innerDeferredResult; + var records; + var i,c; + + innerDeferredResult = new MochiKit.Async.Deferred(); + records = []; + + c = someRecordValues.length; + for(i=0; i<c; i++) { +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 1: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 2: " + res); return res;}); + innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 3: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { + var data; + var record; + var recordVersion; + + var caption; + var wordbreakfield; + +//MochiKit.Logging.logDebug("data: " + someData); + data = someData.replace(/\<WBR\>/g, ""); + hasNotes = false; + + /\<TD class\=caption colSpan\=3\>(.*?)\<\/TD\>/.test(data); // <TD class=caption colSpan=3>110mb</TD> + caption = RegExp.$1; +//MochiKit.Logging.logDebug("caption: " + caption); + + /\<TD class\=wordbreakfield vAlign=top align\=left width\=\"\1\0\0\%\"\>(.*?)\<\/TD\>/.test(data); // <TD class=wordbreakfield vAlign=top align=left width="100%">7759500</TD> + wordbreakfield = RegExp.$1; +//MochiKit.Logging.logDebug("subcaption: " + subcaption); + + record = new Clipperz.PM.DataModel.Record({user:this.user()}); + recordVersion = record.currentVersion() + + record.setLabel(caption); + record.setNotes(wordbreakfield); + + someRecords.push(record); + + return someRecords; + }, this), records, someRecordValues[i]); + } +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 4: " + res); return res;}); + innerDeferredResult.addCallback(MochiKit.Async.succeed, records); +//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 5: " + res); return res;}); + innerDeferredResult.callback(); + + return innerDeferredResult; + }, this)); + deferredResult.callback(someData); + + return deferredResult; + }, + + + //------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" +}); + |