Fix node-webkit download file

This commit is contained in:
Gustavo Maximiliano Cortez 2015-07-07 13:24:18 -03:00
parent 44f4f204c0
commit b58a26a2f1
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
2 changed files with 26 additions and 6 deletions

View File

@ -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>

View File

@ -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();
});