2015-05-14 18:55:18 +02:00
|
|
|
/*
|
|
|
|
|
2018-11-25 17:31:43 +01:00
|
|
|
Copyright 2008-2018 Clipperz Srl
|
2015-05-14 18:55:18 +02:00
|
|
|
|
|
|
|
This file is part of Clipperz, the online password manager.
|
|
|
|
For further information about its features and functionalities please
|
|
|
|
refer to http://www.clipperz.com.
|
|
|
|
|
|
|
|
* Clipperz 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.
|
|
|
|
|
|
|
|
* Clipperz 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 Clipperz. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
Clipperz.Base.module('Clipperz.PM.UI.Components.ExtraFeatures.DataImport');
|
|
|
|
|
|
|
|
Clipperz.PM.UI.Components.ExtraFeatures.DataImport.PreviewClass = React.createClass({
|
|
|
|
|
2016-03-29 11:45:50 +02:00
|
|
|
displayName: 'Clipperz.PM.UI.Components.ExtraFeatures.DataImport.Preview',
|
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
getInitialState: function() {
|
2015-06-27 19:08:20 +02:00
|
|
|
var recordsToImport;
|
2015-07-20 10:27:28 +02:00
|
|
|
|
2015-06-27 19:08:20 +02:00
|
|
|
recordsToImport = MochiKit.Iter.reduce(
|
|
|
|
function (acc, item) { acc[item['reference']] = item; return acc; },
|
|
|
|
MochiKit.Base.filter(
|
|
|
|
function (aRecord) { return !Clipperz.PM.DataModel.Record.labelContainsArchiveTag(aRecord['label']); },
|
|
|
|
this.props.importContext.state('recordsToImport')
|
|
|
|
),
|
|
|
|
{}
|
|
|
|
);
|
2015-05-21 14:32:51 +02:00
|
|
|
|
2015-06-27 19:08:20 +02:00
|
|
|
this.props.importContext.setState('recordsToImport', MochiKit.Base.values(recordsToImport));
|
2015-05-21 14:32:51 +02:00
|
|
|
|
2015-06-27 19:08:20 +02:00
|
|
|
return {
|
|
|
|
'recordsToImport': recordsToImport
|
|
|
|
};
|
2015-05-21 14:32:51 +02:00
|
|
|
},
|
2015-06-27 19:08:20 +02:00
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
//=========================================================================
|
2015-06-27 19:08:20 +02:00
|
|
|
|
2015-07-20 10:27:28 +02:00
|
|
|
selectRecordsToImport: function(records) {
|
|
|
|
var newRecordsToImport;
|
|
|
|
var i;
|
|
|
|
|
|
|
|
newRecordsToImport = {};
|
|
|
|
for (i in records) {
|
|
|
|
newRecordsToImport[records[i]['reference']] = records[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({'recordsToImport': newRecordsToImport});
|
|
|
|
this.props.importContext.setState('recordsToImport', MochiKit.Base.values(newRecordsToImport));
|
|
|
|
},
|
|
|
|
|
|
|
|
selectAll: function() {
|
|
|
|
this.selectRecordsToImport(this.props.importContext.state('jsonData'));
|
|
|
|
},
|
|
|
|
|
|
|
|
selectNone: function() {
|
|
|
|
this.selectRecordsToImport({});
|
|
|
|
},
|
|
|
|
|
|
|
|
selectNotArchived: function() {
|
|
|
|
this.selectRecordsToImport(MochiKit.Base.filter(function (aRecord) {
|
|
|
|
return !Clipperz.PM.DataModel.Record.labelContainsArchiveTag(aRecord['label']);
|
|
|
|
}, this.props.importContext.state('jsonData')));
|
|
|
|
},
|
|
|
|
|
|
|
|
selectArchived: function() {
|
|
|
|
this.selectRecordsToImport(MochiKit.Base.filter(function (aRecord) {
|
|
|
|
return Clipperz.PM.DataModel.Record.labelContainsArchiveTag(aRecord['label']);
|
|
|
|
}, this.props.importContext.state('jsonData')));
|
|
|
|
},
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
handleImportTagTextChange: function() {
|
2016-03-29 11:45:50 +02:00
|
|
|
var newTag = this.refs['importTagText'].value;
|
2015-07-20 10:27:28 +02:00
|
|
|
|
|
|
|
this.props.importContext.setState('importTag', newTag);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleImportTagCheckboxChange: function() {
|
|
|
|
this.props.importContext.setState('useImportTag', ! this.props.importContext.state('useImportTag'));
|
|
|
|
},
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
toggleRecordToImport: function(record) {
|
|
|
|
var newRecordsToImport;
|
|
|
|
var recordPosition;
|
|
|
|
|
|
|
|
newRecordsToImport = this.state.recordsToImport;
|
2015-06-27 19:08:20 +02:00
|
|
|
|
|
|
|
if (this.isRecordToImport(record)) {
|
|
|
|
delete newRecordsToImport[record['reference']];
|
2015-05-21 14:32:51 +02:00
|
|
|
} else {
|
2015-06-27 19:08:20 +02:00
|
|
|
newRecordsToImport[record['reference']] = record;
|
2015-05-21 14:32:51 +02:00
|
|
|
}
|
2015-06-27 19:08:20 +02:00
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
this.setState({'recordsToImport': newRecordsToImport});
|
2015-06-27 19:08:20 +02:00
|
|
|
this.props.importContext.setState('recordsToImport', MochiKit.Base.values(newRecordsToImport));
|
2015-05-21 14:32:51 +02:00
|
|
|
},
|
2015-06-27 19:08:20 +02:00
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
isRecordToImport: function(record) {
|
2015-06-27 19:08:20 +02:00
|
|
|
return (MochiKit.Base.keys(this.state.recordsToImport).indexOf(record['reference']) != -1) ? true : false;
|
2015-05-21 14:32:51 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getTags: function (aTitle) {
|
|
|
|
var result;
|
|
|
|
var tagList;
|
|
|
|
|
|
|
|
var tagObject = Clipperz.PM.DataModel.Record.extractTagsFromFullLabel(aTitle);
|
2015-06-27 19:08:20 +02:00
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
tagList = MochiKit.Base.keys(tagObject);
|
2015-06-27 19:08:20 +02:00
|
|
|
tagList = MochiKit.Base.filter(function(aTag) { return !Clipperz.PM.DataModel.Record.isSpecialTag(aTag); }, tagList);
|
|
|
|
|
2015-07-20 10:27:28 +02:00
|
|
|
if (this.props.importContext.state('useImportTag') && this.props.importContext.state('importTag')) {
|
|
|
|
tagList.push(this.props.importContext.state('importTag'));
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:32:51 +02:00
|
|
|
if (tagList.length > 0) {
|
|
|
|
result = React.DOM.ul({'className': 'tagList'},
|
|
|
|
MochiKit.Base.map(function(aTag){
|
|
|
|
return React.DOM.li({}, aTag);
|
|
|
|
}, tagList)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
2015-05-14 18:55:18 +02:00
|
|
|
|
2015-06-27 19:08:20 +02:00
|
|
|
renderCardFields: function (someFields) {
|
|
|
|
return MochiKit.Base.map(function (key) {
|
2015-05-14 18:55:18 +02:00
|
|
|
var field = someFields[key];
|
|
|
|
return [
|
2015-06-27 19:08:20 +02:00
|
|
|
React.DOM.dt({}, field['label']),
|
|
|
|
React.DOM.dd({'className': field['actionType'] + (field['hidden'] ? ' password' : '')}, field['value']),
|
2015-05-14 18:55:18 +02:00
|
|
|
];
|
2015-06-27 19:08:20 +02:00
|
|
|
}, MochiKit.Base.keys(someFields));
|
2015-05-14 18:55:18 +02:00
|
|
|
},
|
2015-06-27 19:08:20 +02:00
|
|
|
|
|
|
|
renderCard: function (aCard) {
|
|
|
|
var classes;
|
|
|
|
|
|
|
|
classes = {
|
|
|
|
'card': true,
|
|
|
|
'archived': Clipperz.PM.DataModel.Record.labelContainsArchiveTag(aCard['label'])
|
|
|
|
}
|
|
|
|
|
|
|
|
return React.DOM.li({'className':Clipperz.PM.UI.Components.classNames(classes)}, [
|
2015-05-14 18:55:18 +02:00
|
|
|
React.DOM.input({
|
|
|
|
'type': 'checkbox',
|
2015-05-21 14:32:51 +02:00
|
|
|
'checked': this.isRecordToImport(aCard),
|
2015-06-27 19:08:20 +02:00
|
|
|
'onChange': MochiKit.Base.partial(this.toggleRecordToImport, aCard)
|
2015-05-14 18:55:18 +02:00
|
|
|
}),
|
2015-06-27 19:08:20 +02:00
|
|
|
React.DOM.div({'className': 'cardContent'}, [
|
|
|
|
React.DOM.h3({}, Clipperz.PM.DataModel.Record.extractLabelFromFullLabel(aCard['label'])),
|
|
|
|
this.getTags(aCard['label']),
|
|
|
|
React.DOM.dl({'className': 'fields'}, this.renderCardFields(aCard['currentVersion']['fields'])),
|
|
|
|
(aCard['data']['notes']) ? React.DOM.p({'className': 'notes'}, aCard['data']['notes']) : null
|
|
|
|
])
|
2015-05-14 18:55:18 +02:00
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-07-20 10:27:28 +02:00
|
|
|
var inputFormat = this.props.importContext.inputFormat();
|
|
|
|
|
2015-06-27 19:08:20 +02:00
|
|
|
return React.DOM.div({'className': 'preview'},
|
2015-07-20 10:27:28 +02:00
|
|
|
React.DOM.div({'className': 'selectButtons'},
|
|
|
|
React.DOM.span({}, "Select:"),
|
|
|
|
React.DOM.a({'onClick': this.selectAll}, "All"),
|
|
|
|
React.DOM.a({'onClick': this.selectNone}, "None"),
|
|
|
|
(inputFormat == 'JSON') ? React.DOM.a({'onClick': this.selectNotArchived}, "Not Archived") : null,
|
|
|
|
(inputFormat == 'JSON') ? React.DOM.a({'onClick': this.selectArchived}, "Archived") : null
|
|
|
|
),
|
|
|
|
React.DOM.div({'className': 'tagButtons'},
|
|
|
|
React.DOM.input({
|
|
|
|
'type': 'checkbox',
|
|
|
|
'id': 'tagCheckbox',
|
|
|
|
'checked': this.props.importContext.state('useImportTag'),
|
|
|
|
'onChange': this.handleImportTagCheckboxChange
|
|
|
|
}),
|
|
|
|
React.DOM.label({'htmlFor': 'tagCheckbox'}, "Apply the following tag to imported cards:"),
|
|
|
|
React.DOM.input({
|
|
|
|
'ref': 'importTagText',
|
|
|
|
'type': 'text',
|
|
|
|
'value': this.props.importContext.state('importTag'),
|
|
|
|
'disabled': ! this.props.importContext.state('useImportTag'),
|
|
|
|
'onChange': this.handleImportTagTextChange
|
|
|
|
})
|
|
|
|
),
|
2015-06-27 19:08:20 +02:00
|
|
|
React.DOM.ul({}, MochiKit.Base.map(MochiKit.Base.method(this, 'renderCard'), this.props.importContext.state('jsonData')))
|
|
|
|
);
|
|
|
|
},
|
2015-05-14 18:55:18 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Clipperz.PM.UI.Components.ExtraFeatures.DataImport.Preview = React.createFactory(Clipperz.PM.UI.Components.ExtraFeatures.DataImport.PreviewClass);
|