Filedownload added

This commit is contained in:
2016-01-22 00:34:27 +01:00
parent 3333e9eb4a
commit d22c3ce5b1
27 changed files with 238 additions and 212 deletions

View File

@@ -1,6 +1,6 @@
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope) {
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer) {
$scope.preis="";
$scope.name="";
@@ -74,6 +74,45 @@ angular.module('starter.controllers', [])
}
alert("SUCCESS: \r\n"+strResult );
*/
var link = 'http://api.raataar.de/rosen/kauf.php';
$http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis}).then(function (res){
$scope.filetodownload = res.data;
// File for download
var url = "http://api.raataar.de/rosen/" + $scope.filetodownload;
alert(url);
// File name only
var filename = url.split("/").pop();
alert(filename);
// Save location
//var targetPath = cordova.file.externalRootDirectory + filename;
var targetPath = cordova.file.applicationStorageDirectory + filename;
alert(targetPath);
$scope.targetPath='';
$scope.targetPath=targetPath;
$cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) {
$scope.item={name: $scope.name, bild: $scope.targetPath};
$scope.items.push($scope.item);
alert ($scope.targetPath);
$database.setBuys($scope.name,$scope.targetPath);
}, function (error) {
console.log('Error');
}, function (progress) {
// PROGRESS HANDLING GOES HERE
});
return false;
});
}
function errorBuyHandler (error) {