Google-Store Kauf funktionstuechtig, Dialoge geadded.

This commit is contained in:
2016-01-21 22:37:56 +01:00
parent 7c683d7450
commit 3333e9eb4a
174 changed files with 3896 additions and 263 deletions

View File

@@ -5,21 +5,55 @@
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
var db;
.run(function($ionicPlatform, $ionicPopup) {
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform, $window, $ionicHistory, $database, $ionicPopup, $state, $localstorage, $rootScope) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
$ionicPlatform.registerBackButtonAction(function(event) {
// Handle Android back button to avoid the application exits accidentaly
if ($state.current.name=="tab.dash") {
$ionicPopup.confirm({
title: 'System-Hinweis',
template: 'Möchten Sie die App beenden?'
}).then(function(res) {
if (res) {
ionic.Platform.exitApp();
}
});
} else {
$ionicHistory.clearCache();
$ionicHistory.nextViewOptions({
historyRoot: true
});
$state.go('tab.dash');
}
}, 100);
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
// Mandatory for InAppBrowser plugin
if(window.cordova){
window.open = cordova.InAppBrowser.open;
}
// Copy the populated database to mobile device destination
//if (window.sqlitePlugin && window.cordova) {
if (window.sqlitePlugin && window.cordova) {
window.plugins.sqlDB.copy("raataar_wrk.db", function (e) {
console.log(e);
});
}
function successHandler (result) {
var strResult = "";
@@ -39,7 +73,16 @@ angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
inappbilling.init(successHandler, errorHandler, {showLog:true});
}
// Initialize database through $database service
db = $database.initDB();
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})

View File

@@ -1,38 +1,56 @@
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup) {
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout) {
$scope.preis="";
$scope.name="";
$scope.freitext="";
var showAlert=0;
$scope.items=[];
$scope.item=[];
//db = Database.getDb();
//$scope.items=$localstorage.getObject('items');
$scope.validate = function() {
showAlert=0;
if ($scope.name.length < 1){
showAlert=1;
}
if ($scope.freitext.length < 1){
showAlert=1;
}
if (showAlert==1){
$scope.showAlert();
}
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.showAlert = function() {
var alertPopup = $ionicPopup.alert({
title: 'Uuuupppsssiii',
template: 'Bitte prüfe deine Eingaben.'
});
alertPopup.then(function(res) {
console.log('Thank you for not eating my delicious ice cream cone');
});
};
function successHandler (result) {
$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);
@@ -40,42 +58,68 @@ angular.module('starter.controllers', [])
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
}
$timeout(buysuccessHandler, 1000);
}
function errorHandler (error) {
function successConsumeHandler (result) {
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
alert("SUCCESS: \r\n"+strResult );
}
function errorBuyHandler (error) {
alert("ERROR: \r\n"+error );
}
}
$scope.buyAdFree = function() {
function errorConsumeHandler (error) {
alert("ERROR: \r\n"+error );
}
function buysuccessHandler (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() {
//alert($scope.preis);
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
alert($scope.preis);
inappbilling.buy(successHandler, errorHandler,"3xrose");
inappbilling.consumePurchase(successHandler, errorHandler, "3xrose");
inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis);
}
}
})
.controller('BuysCtrl', function($scope) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//
//$scope.$on('$ionicView.enter', function(e) {
//});
.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=[];
}
});
}
});
})

File diff suppressed because one or more lines are too long

View File

@@ -1,50 +1,94 @@
angular.module('starter.services', [])
.factory('Chats', function() {
// Might use a resource here that returns a JSON array
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
setObject: function(key, value) {
$window.localStorage[key] = angular.toJson(value);
},
getObject: function(key) {
return JSON.parse($window.localStorage[key] || '[]');
},
destroy: function(key) {
$window.localStorage.removeItem(key);
},
log: function(key, defaultValue) {
console.log($window.localStorage[key] || defaultValue);
},
logObject: function(key) {
console.log(JSON.stringify($window.localStorage[key] || '{}'));
}
};
}])
// Some fake testing data
var chats = [{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];
.factory('$database',['$cordovaSQLite', function($cordovaSQLite) {
var self = this;
self.db = null;
var query;
//this updateTable function is for ilustrative use here, it can be changed to manage all queries indeed.
updateTable=function (table, column, value, condition) {
if(!condition){
query = "UPDATE " + table + " SET " + column + " = " + value;
} else{
query = "UPDATE " + table + " SET " + column + " = " + value + " WHERE " + condition;
}
return $cordovaSQLite.execute(self.db,query,[]).
then(function(result) {
console.log(query);
query=null;
return result;
},function(error) {
console.error(error);
query=null;
return error;
});
};
return {
all: function() {
return chats;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
},
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
initDB: function() {
if(window.cordova){
//self.db = sqlitePlugin.openDatabase({name: "data.db", location: 2, createFromLocation: 1});
self.db = $cordovaSQLite.openDB("raataar_wrk.db");
} else {
self.db = window.openDatabase('raataar_wrk.db','1','my',800*1024); // only available when WebSQL is available in Browser
}
console.log('Database opened');
return self.db;
},
setBuys: function(itemName,itemBild) {
query="INSERT INTO buys (Name, Bild) VALUES (?,?);";
return $cordovaSQLite.execute(self.db,query,[itemName,itemBild]).
then(function(result) {
console.log("Gespeichert");
query=null;
}, function(error) {
console.error(error);
});
},
getAllBuys: function(){
var ArrayQ=[];
query="SELECT * FROM buys order by id ASC";
return $cordovaSQLite.execute(self.db,query).
then(function(result) {
for(j=0;j<result.rows.length;j++){
var List={};
//console.log(result.rows.item(j));
List.name=result.rows.item(j).Name;
List.bild=result.rows.item(j).Bild;
ArrayQ.push(List);
}
//console.log(ArrayQ);
return ArrayQ;
},function(e){
console.error(error);
return error;
});
}
return null;
}
};
});
};
}]);