Changes

Jump to navigation Jump to search
m
no edit summary
Line 37: Line 37:  
// Get concerns relation :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it  
 
// Get concerns relation :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it  
   −
var concern_origin = WikibaseProcessor.checkentity( { this_concerns: [ WBEStructure['concernsRelation'], WBEStructure['IDPropLoc'], WBEStructure['IDName'] ] } )['this_concerns'][0];
+
var concern_origin = WikibaseProcessor.checkentity( { this_concerns: [ WBEStructure['concernsRelation'], WBEStructure['IDPropLoc'], WBEStructure['qIDPropName'] ] } )['this_concerns'][0];
    
// Get defval for entity :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it  
 
// Get defval for entity :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it  
Line 109: Line 109:  
 
 
function notify_porting() {
 
function notify_porting() {
  −
var button_import = new OO.ui.ButtonWidget( { label: "Import Personal Data", classes: [ 'pduimark' ] } ),
  −
button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } );
     −
button_import.on( 'click', function () {
+
mw.loader.using( 'oojs-ui-core' ).done( function () {
   −
}
+
var button_import = new OO.ui.SelectFileWidget( { label: "Import Personal Data", classes: [ 'pduimark' ] } ),
   −
button_export.on( 'click', function () {
+
button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } );
   −
var get_record = indexedDBobject.EnqueuePDIO('update record');
+
button_import.on( 'change', function (event) {
   −
get_record.then( function(result) {
+
if (window.webkitURL != null) {
var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now();
+
console.log("loading file on webkit")
result.id = '';
+
} else {
result.name.user = '';
+
console.log("loading file non webkit")
var export_to_text = JSON.stringify(result);
+
}
var textFileAsBlob = new Blob([export_to_text], {type:'text/plain'});
+
 
var downloadLink = document.createElement("a");
+
console.log( event );
downloadLink.download = filename_tosaveas;
+
var input_object = event;
if (window.webkitURL != null)
+
readFileContent( input_object ).then( function(content) {
{
+
var data = WikibaseProcessor.rxjson(content);
// Chrome allows the link to be clicked
+
indexedDBobject.EnqueuePDIO('import record', data);
// without actually adding it to the DOM.
+
});
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
+
});
}
+
 
else
+
button_export.on( 'click', function () {
{
+
 
// Firefox requires the link to be added to the DOM
+
var get_record = indexedDBobject.EnqueuePDIO('get record');
// before it can be clicked.
+
 
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
+
get_record.then( function(result) {
downloadLink.style.display = "none";
+
console.log("happening");
document.body.appendChild(downloadLink);
+
if ( result === undefined ) { window.alert("No local data to export") } else {
}
+
 
 +
var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now() + '.json';
 +
 +
delete result.id;
 +
delete result.name.user;
 +
 +
var export_to_text = JSON.stringify(result);
 +
var textFileAsBlob = new Blob([export_to_text], {type:'text/plain'});
 +
var downloadLink = document.createElement("a");
 +
downloadLink.download = filename_tosaveas;
 +
if (window.webkitURL != null)
 +
{
 +
// Chrome allows the link to be clicked
 +
// without actually adding it to the DOM.
 +
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
 +
}
 +
else
 +
{
 +
// Firefox requires the link to be added to the DOM
 +
// before it can be clicked.
 +
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
 +
downloadLink.style.display = "none";
 +
document.body.appendChild(downloadLink);
 +
}
   −
downloadLink.click();
+
downloadLink.click();
   −
});
+
}
   −
}
+
});
   −
mw.notify( $( button_import.$element + '<br>' + button_export.$element ) );
+
});
    +
mw.notify( $( button_import.$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)
 +
})
 
}
 
}
    
}
 
}
530

edits

Navigation menu