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

@@ -14,6 +14,10 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
$rootScope.storeinit=99;
$ionicPlatform.registerBackButtonAction(function(event) {
// Handle Android back button to avoid the application exits accidentaly
@@ -56,6 +60,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
function successHandler (result) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
@@ -63,10 +68,13 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
*/
$rootScope.storeinit=1;
}
function errorHandler (error) {
alert("ERROR: \r\n"+error );
//alert("ERROR: \r\n"+error );
$rootScope.storeinit=0;
}

View File

@@ -1,6 +1,6 @@
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout) {
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer) {
$scope.preis="";
$scope.name="";
@@ -25,6 +25,7 @@ angular.module('starter.controllers', [])
};
$scope.loaddata = function() {
$scope.items=[];
$database.getAllBuys().then(function (result) {
@@ -51,6 +52,7 @@ angular.module('starter.controllers', [])
};
function successBuyHandler (result) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
@@ -58,10 +60,12 @@ angular.module('starter.controllers', [])
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
$timeout(buysuccessHandler, 1000);
*/
$timeout(consumesuccessHandler, 1000);
}
function successConsumeHandler (result) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
@@ -69,26 +73,73 @@ angular.module('starter.controllers', [])
strResult = result;
}
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) {
alert("ERROR: \r\n"+error );
var alertPopup = $ionicPopup.alert({
title: 'Oh Nein',
template: 'Der Kauf konnte nicht durchgeführt werden.'
});
alertPopup.then(function(res) {
console.log('Der Kauf konnte nicht durchgeführt werden');
});
}
function errorConsumeHandler (error) {
alert("ERROR: \r\n"+error );
var alertPopup = $ionicPopup.alert({
title: 'Oh Nein',
template: 'Der Kauf wurde durchgeführt, aber deine Rosen konnten freigeschaltet werden.'
});
alertPopup.then(function(res) {
console.log('Der Kauf wurde durchgeführt, aber deine Rosen konnten freigeschaltet werden');
});
}
function buysuccessHandler (result) {
function consumesuccessHandler (result) {
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
}
$scope.buyRose = function() {
@@ -96,7 +147,22 @@ angular.module('starter.controllers', [])
//alert($scope.preis);
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
if ($rootScope.storeinit==1){
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
}
else{
var alertPopup = $ionicPopup.alert({
title: 'Achtung',
template: 'Der Google-Store konnte nicht initialisiert werden.'
});
alertPopup.then(function(res) {
console.log('Store steht nicht zur Verfuegung');
});
}
}
}

View File

@@ -7,7 +7,7 @@
<div class="item item-divider oleo">Hier können Sie Ihre gekauften Rosen ansehen oder nochmals versenden!</div>
<a class="item item-thumbnail-left item-button-right" href="#" ng-repeat="i in items" ng-model="items">
<img src="img/rose1.png">
<img ng-src="{{i.bild}}>
<h1>{{i.name}}</h1>
<p>{{i.freitext}} </p>
<div class="buttons" style="margin-top:30px;">