Debug-Infos entfernt, vollstaendige Kaufabwicklung hinzugefügt

This commit is contained in:
2016-01-29 00:56:13 +01:00
parent 6dbbc77c30
commit 38583577f6
6 changed files with 105 additions and 45 deletions

View File

@@ -121,6 +121,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
}
})
.state('tab.buys', {
url: '/buys',
views: {

View File

@@ -1,6 +1,6 @@
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile) {
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile,$ionicLoading,$state) {
$scope.preis="";
$scope.name="";
@@ -9,6 +9,17 @@ angular.module('starter.controllers', [])
$scope.item=[];
$scope.show = function() {
$ionicLoading.show({
template: '<p>Kauf wird abgeschlossen.</p><ion-spinner></ion-spinner>'
});
};
$scope.hide = function(){
$ionicLoading.hide();
};
$scope.validate = function() {
var link = 'http://api.raataar.de/rosen/vorschau.php';
@@ -22,38 +33,12 @@ angular.module('starter.controllers', [])
};
$scope.loaddata = function() {
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
alert("daten da");
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
alert(i);
}
} else {
$scope.items=[];
}
});
};
$scope.savedata = function() {
$scope.item={name: $scope.name, bild: "test"};
$scope.items.push($scope.item);
$database.setBuys($scope.name,"test");
};
function successBuyHandler (result) {
$timeout(consumesuccessHandler, 1000);
}
function successConsumeHandler (result) {
$scope.show($ionicLoading);
var link = 'http://api.raataar.de/rosen/kauf.php';
$http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis}).then(function (res){
@@ -98,14 +83,15 @@ angular.module('starter.controllers', [])
// error
});
$scope.hide($ionicLoading);
$state.go('tab.buys');
}, function (error) {
console.log('Error');
}, function (progress) {
// PROGRESS HANDLING GOES HERE
});
return false;
});
@@ -158,8 +144,8 @@ angular.module('starter.controllers', [])
if ($rootScope.storeinit==1){
//Wegenbug ausgehebelt
//inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
successConsumeHandler();
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
//successConsumeHandler();
}
else{
var alertPopup = $ionicPopup.alert({
@@ -178,12 +164,21 @@ angular.module('starter.controllers', [])
})
.controller('BuysCtrl', function($scope, $database,$location) {
$scope.items=[];
//$scope.items=$localstorage.getObject('items');
.controller('BuysCtrl', function($scope, $database,$location,$ionicModal,$ionicLoading) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if ($location.path() == "/tab/buys") {
if ($location.path() == "/tab/buys") {
$scope.show($ionicLoading);
fill_list();
$scope.hide($ionicLoading);
}
});
function fill_list(){
$scope.items=[];
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
@@ -192,10 +187,42 @@ angular.module('starter.controllers', [])
} else {
$scope.items=[];
}
});
}
});
}
$scope.show = function() {
$ionicLoading.show({
template: '<p>Lade...</p><ion-spinner></ion-spinner>'
});
};
$scope.hide = function(){
$ionicLoading.hide();
};
$scope.showImages = function(imagesrc) {
$scope.imagesrc=imagesrc;
$scope.showModal('templates/image-popover.html');
}
$scope.showModal = function(templateUrl) {
$ionicModal.fromTemplateUrl(templateUrl, {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show();
});
}
// Close the modal
$scope.closeModal = function() {
$scope.modal.hide();
$scope.modal.remove()
};
});
})