Line 109: |
Line 109: |
| | | |
| function notify_porting() { | | function notify_porting() { |
− |
| |
− | var button_import = new OO.ui.SelectFileInputWidget ( {
| |
− | label: "Import Personal Data",
| |
− | useInputTag: true,
| |
− | classes: [ 'pduimark' ]
| |
− | }),
| |
| | | |
− | button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } );
| + | mw.loader.using( 'oojs-ui-core' ).done( function () { |
| | | |
− | button_import.on( 'click', function () {
| + | var button_import = new OO.ui.SelectFileWidget ( { |
| + | label: "Import Personal Data", |
| + | classes: [ 'pduimark' ] |
| + | }), |
| | | |
| + | button_export = new OO.ui.ButtonWidget( { label: "Export Personal Data", classes: [ 'pduimark' ] } ); |
| | | |
| + | button_import.on( 'click', function () { |
| | | |
− | if (window.webkitURL != null) {
| |
| | | |
− | } else {
| |
| | | |
− | }
| + | if (window.webkitURL != null) { |
| | | |
| + | } else { |
| | | |
| + | } |
| + | |
| + | |
| + | |
| + | }); |
| | | |
− | });
| + | button_export.on( 'click', function () { |
| | | |
− | button_export.on( 'click', function () {
| + | var get_record = indexedDBobject.EnqueuePDIO('get record'); |
| | | |
− | var get_record = indexedDBobject.EnqueuePDIO('get record');
| + | get_record.then( function(result) { |
| + | if ( result === undefined ) { alert("No data to export") }; |
| | | |
− | get_record.then( function(result) {
| + | var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now() + '.json'; |
− | if ( result === undefined ) { alert("No data to export") };
| + | |
| + | result.id = ''; |
| + | 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); |
| + | } |
| | | |
− | var filename_tosaveas = "pdiolocalexport_" + result.name.user + "_" + Date.now() + '.json';
| + | downloadLink.click(); |
− |
| |
− | result.id = '';
| |
− | 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(); | + | }); |
| | | |
| }); | | }); |
| | | |
| + | mw.notify( $( button_import.$element ), { autoHide: false } ); |
| + | mw.notify( $( button_export.$element ), { autoHide: false } ); |
| }); | | }); |
− |
| |
− | mw.notify( $( button_import.$element ), { autoHide: false } );
| |
− | mw.notify( $( button_export.$element ), { autoHide: false } );
| |
− |
| |
| } | | } |
| | | |
| } | | } |