Wolle-Rosen-Kaufen/www/js/controllers.js

157 lines
3.7 KiB
JavaScript

angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope) {
$scope.preis="";
$scope.name="";
$scope.freitext="";
$scope.items=[];
$scope.item=[];
//db = Database.getDb();
//$scope.items=$localstorage.getObject('items');
$scope.validate = function() {
var link = 'http://api.raataar.de/rosen/vorschau.php';
$http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis}).then(function (res){
$scope.response = res.data;
window.open($scope.response, '_system', 'location=yes');
return false;
});
};
$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) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
*/
$timeout(consumesuccessHandler, 1000);
}
function successConsumeHandler (result) {
/*
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
*/
}
function errorBuyHandler (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) {
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 consumesuccessHandler (result) {
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
}
$scope.buyRose = function() {
//alert($scope.preis);
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
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');
});
}
}
}
})
.controller('BuysCtrl', function($scope, $database,$location) {
$scope.items=[];
//$scope.items=$localstorage.getObject('items');
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if ($location.path() == "/tab/buys") {
$database.getAllBuys().then(function (result) {
if(result.length>0){
for(i=0;i<result.length;i++){
$scope.items.push(result[i]);
}
} else {
$scope.items=[];
}
});
}
});
})
.controller('Dummy', function($scope) {
});