| Line 116: |
Line 116: |
| | button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } ); | | button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } ); |
| | | | |
| − | button_import.on( 'change', function () { | + | button_import.on( 'change', function (event) { |
| | | | |
| | if (window.webkitURL != null) { | | if (window.webkitURL != null) { |
| Line 124: |
Line 124: |
| | } | | } |
| | | | |
| | + | console.log( event ); |
| | + | var input_object = event; |
| | + | readFileContent( input_object ).then( function(content) { |
| | + | var data = WikibaseProcessor.rxjson(content); |
| | + | indexedDBobject.EnqueuePDIO('import record', data); |
| | + | }); |
| | }); | | }); |
| | | | |
| Line 136: |
Line 142: |
| | var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now() + '.json'; | | var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now() + '.json'; |
| | | | |
| − | result.id = ''; | + | delete result.id; |
| − | result.name.user = ''; | + | delete result.name.user; |
| | | | |
| | var export_to_text = JSON.stringify(result); | | var export_to_text = JSON.stringify(result); |
| Line 166: |
Line 172: |
| | }); | | }); |
| | | | |
| − | mw.notify( $( button_import.$element ), { autoHide: false } ); | + | mw.notify( $( button_import.$element ), { autoHide: false } ); |
| − | mw.notify( $( button_export.$element ), { autoHide: false } ); | + | mw.notify( $( button_export.$element ), { autoHide: false } ); |
| | }); | | }); |
| | + | } |
| | + | |
| | + | function readFileContent(file) { |
| | + | const reader = new FileReader() |
| | + | return new Promise((resolve, reject) => { |
| | + | reader.onload = event => resolve(event.target.result) |
| | + | reader.onerror = error => reject(error) |
| | + | reader.readAsText(file) |
| | + | }) |
| | } | | } |
| | | | |
| | } | | } |