Fix node-webkit download file
This commit is contained in:
parent
44f4f204c0
commit
b58a26a2f1
2 changed files with 26 additions and 6 deletions
|
|
@ -496,6 +496,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ng-if="!index.isCordova" class="m20t text-center">
|
<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();">
|
<a class="text-gray" ng-click="index.csvHistory();">
|
||||||
<i class="fi-page-export-csv"></i>
|
<i class="fi-page-export-csv"></i>
|
||||||
<span translate>Download CSV file</span>
|
<span translate>Download CSV file</span>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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;
|
var self = this;
|
||||||
self.isCordova = isCordova;
|
self.isCordova = isCordova;
|
||||||
self.onGoingProcess = {};
|
self.onGoingProcess = {};
|
||||||
|
|
@ -537,6 +537,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
|
|
||||||
this.csvHistory = function() {
|
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) {
|
function formatDate(date) {
|
||||||
var dateObj = new Date(date);
|
var dateObj = new Date(date);
|
||||||
if (!dateObj) {
|
if (!dateObj) {
|
||||||
|
|
@ -597,11 +611,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
csvContent += index < data.length ? dataString + "\n" : dataString;
|
csvContent += index < data.length ? dataString + "\n" : dataString;
|
||||||
});
|
});
|
||||||
|
|
||||||
var encodedUri = encodeURI(csvContent);
|
if (nodeWebkit.isDefined()) {
|
||||||
var link = document.createElement("a");
|
saveFile('#export_file',csvContent);
|
||||||
link.setAttribute("href", encodedUri);
|
}
|
||||||
link.setAttribute("download", filename);
|
else {
|
||||||
link.click();
|
var encodedUri = encodeURI(csvContent);
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.setAttribute("href", encodedUri);
|
||||||
|
link.setAttribute("download", filename);
|
||||||
|
link.click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue