mirror of https://github.com/BTCPrivate/copay.git
Fix node-webkit download file
This commit is contained in:
parent
44f4f204c0
commit
b58a26a2f1
|
@ -496,6 +496,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div ng-if="!index.isCordova" class="m20t text-center">
|
||||
<input id="export_file" type="file" nwsaveas="copay_history.csv" accept=".csv" style="display:none" nwworkingdir=""/>
|
||||
<a class="text-gray" ng-click="index.csvHistory();">
|
||||
<i class="fi-page-export-csv"></i>
|
||||
<span translate>Download CSV file</span>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment) {
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit) {
|
||||
var self = this;
|
||||
self.isCordova = isCordova;
|
||||
self.onGoingProcess = {};
|
||||
|
@ -537,6 +537,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
|
||||
this.csvHistory = function() {
|
||||
|
||||
function saveFile(name,data) {
|
||||
var chooser = document.querySelector(name);
|
||||
chooser.addEventListener("change", function(evt) {
|
||||
console.log(this.value); // get your file name
|
||||
var fs = require('fs'); // save it now
|
||||
fs.writeFile(this.value, data, function(err) {
|
||||
if(err) {
|
||||
alert("error"+err);
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
chooser.click();
|
||||
}
|
||||
|
||||
function formatDate(date) {
|
||||
var dateObj = new Date(date);
|
||||
if (!dateObj) {
|
||||
|
@ -597,11 +611,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
csvContent += index < data.length ? dataString + "\n" : dataString;
|
||||
});
|
||||
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
link.setAttribute("download", filename);
|
||||
link.click();
|
||||
if (nodeWebkit.isDefined()) {
|
||||
saveFile('#export_file',csvContent);
|
||||
}
|
||||
else {
|
||||
var encodedUri = encodeURI(csvContent);
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
link.setAttribute("download", filename);
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
$rootScope.$apply();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue