Storage list in Buys

This commit is contained in:
2016-01-08 01:23:49 +01:00
parent 17c376632d
commit 5b6397ea1a
101 changed files with 2635 additions and 218 deletions

View File

@@ -1,25 +1,16 @@
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope,$ionicPopup,$http) {
.controller('DashCtrl', function($scope,$ionicPopup,$http, $localstorage) {
$scope.preis="";
$scope.name="";
$scope.freitext="";
var showAlert=0;
$scope.items=[];
$scope.item=[];
$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();
return;
}
var link = 'http://api.raataar.de/rosen/vorschau.php';
@@ -31,21 +22,19 @@ angular.module('starter.controllers', [])
};
$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');
});
};
$scope.loaddata = function() {
$scope.items=$localstorage.getObject('items');
alert(JSON.stringify($scope.items));
};
function buysuccessHandler (result) {
inappbilling.consumePurchase(successHandler, errorHandler, "3xrose");
}
$scope.savedata = function() {
$scope.item={name: $scope.name, freitext: $scope.freitext, rosen: $scope.preis, bild: "test"};
alert(JSON.stringify($scope.item));
$scope.items.push($scope.item);
$localstorage.setObject('items',$scope.items);
};
function successHandler (result) {
function successBuyHandler (result) {
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
@@ -55,33 +44,50 @@ angular.module('starter.controllers', [])
alert("SUCCESS: \r\n"+strResult );
}
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 );
}
alert($scope.preis);
function buysuccessHandler (result) {
inappbilling.consumePurchase(successConsumeHandler, errorConsumeHandler, $scope.preis);
}
$scope.buyRose = function() {
//alert($scope.preis);
if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") {
inappbilling.buy(buysuccessHandler, 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, $localstorage,$location) {
$scope.items=[];
$scope.items=$localstorage.getObject('items');
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if ($location.path() == "/tab/buys") {
$scope.items=$localstorage.getObject('items');
}
});
})

View File

@@ -1,50 +1,19 @@
angular.module('starter.services', [])
.factory('Chats', function() {
// Might use a resource here that returns a JSON array
// 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('$localstorage', ['$window', function($window) {
return {
all: function() {
return chats;
set: function(key, value) {
$window.localStorage[key] = value;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
}
}
return null;
setObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key) {
return JSON.parse($window.localStorage[key] || '{}');
}
};
});
}
}]);