angular.module('starter.controllers', []) .controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile,$ionicLoading,$state,$filter,$ionicModal) { $scope.preis=""; $scope.name=""; $scope.freitext=""; $scope.items=[]; $scope.item=[]; $scope.backgroundpic = "1"; $scope.backgrounds = [ { id: "1", name : "Hintergrund 1", backvalue : "1", beschreibung: "Herzen nit Tieren", image: "http://api.raataar.de/rosen/bg/bg_1.png"}, { id: "2", name : "Hintergrund 2", backvalue : "2", beschreibung: "EngelHerz", image: "http://api.raataar.de/rosen/bg/bg_2.png"}, { id: "3", name : "Hintergrund 3", backvalue : "3", beschreibung: "Herzenmuster", image: "http://api.raataar.de/rosen/bg/bg_3.png"}, { id: "4", name : "Hintergrund 4", backvalue : "4", beschreibung: "Herzpflanzen", image: "http://api.raataar.de/rosen/bg/bg_4.png"}, { id: "5", name : "Hintergrund 5", backvalue : "5", beschreibung: "Neutral dunkel", image: "http://api.raataar.de/rosen/bg/bg_5.png"}, { id: "6", name : "Hintergrund 6", backvalue : "6", beschreibung: "Springendes Paar", image: "http://api.raataar.de/rosen/bg/bg_6.png"}, { id: "7", name : "Hintergrund 7", backvalue : "7", beschreibung: "Herzen mit Verzierung", image: "http://api.raataar.de/rosen/bg/bg_7.png"}, { id: "8", name : "Hintergrund 8", backvalue : "8", beschreibung: "Hand in Hand", image: "http://api.raataar.de/rosen/bg/bg_8.png"}, { id: "9", name : "Hintergrund 9", backvalue : "9", beschreibung: "Stoffmuster", image: "http://api.raataar.de/rosen/bg/bg_9.png"}, { id: "10", name : "Hintergrund 10", backvalue : "10", beschreibung: "Ballons mit Herzen", image: "http://api.raataar.de/rosen/bg/bg_10.png"}, ]; $scope.producitems=[]; $scope.rosen1titel=""; $scope.rosen1preis=""; $scope.rosen1beschreibung=""; $scope.rosen1preiscurrency=""; $scope.rosen1preistag=""; $scope.rosen3titel=""; $scope.rosen3preis=""; $scope.rosen3beschreibung=""; $scope.rosen3preiscurrency=""; $scope.rosen3preistag=""; $scope.rosen9titel=""; $scope.rosen9preis=""; $scope.rosen9beschreibung=""; $scope.rosen9preiscurrency=""; $scope.rosen9preistag=""; $scope.flateraterosentitel=""; $scope.flateraterosenpreis=""; $scope.flateraterosenbeschreibung=""; $scope.flateraterosenpreiscurrency=""; $scope.flateraterosenpreistag=""; $scope.showrosen = false; $scope.showflatrate = true; $scope.zitat=''; $scope.show = function() { $ionicLoading.show({ template: '

Kauf wird abgeschlossen.

' }); }; $scope.hide = function(){ $ionicLoading.hide(); }; $scope.validate = function() { var link = 'http://api.raataar.de/rosen/vorschau.php'; $http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis, bg: $scope.backgroundpic}).then(function (res){ $scope.response = res.data; //window.open($scope.response, '_system', 'location=yes'); //return false; $scope.showVorschauImages($scope.response); return false; }); }; /* * Vorschau-Modal */ $scope.showVorschauImages = function(imagesrc) { //Bild im dialog anzeigen $scope.imagesrc=imagesrc; $scope.showVorschauModal('templates/image-vorschau-popover.html'); } $scope.showVorschauModal = function(templateUrl) { $ionicModal.fromTemplateUrl(templateUrl, { scope: $scope, animation: 'slide-in-up' }).then(function(modal) { $scope.modal = modal; $scope.modal.show(); }); } // Close the modal $scope.closeVorschauModal = function() { $scope.modal.hide(); $scope.modal.remove() }; /* * Vorschau-Modal ENDE */ //Getter für Selectbox $scope.getBackgroundOpt = function(newValuea, oldValue){ $scope.backgroundpic=newValuea.backvalue; // return newValuea.backvalue; }; //Flatrate resetten DEBUGGING $scope.resetflat = function() { inappbilling.consumePurchase(function(result) {}, function(result) {}, 'rosenflatrate'); $rootScope.flatrate=0; $scope.showflatrate = true; $timeout(getProducts, 1000); }; /* * Zitat in Text-Box laden */ $scope.loadzitat = function() { $http({ url: 'http://api.raataar.de/sapientia-web/sapientia-zitationic/67557103d3658523fa63ff3dcd46d8ec/zitat', dataType: 'json', method: 'GET', headers: { "Content-Type": "application/json" } }) .success(function(response) { $scope.zitat = response; $scope.freitext='"' + response.zitat_text + '"'; }) .error(function(response) { alert("Fehler! Besteht eine Verbindung zum Internet?"); }); }; /* * Produkt-Details abrufen START */ function getProducts(){ inappbilling.getProductDetails(successProducts, errorProducts,["rosenflatrate","9xrose","3xrose","1xrose"]); } function successProducts (result) { //alert(JSON.stringify(result)); $scope.showrosen = false; $scope.producitems = [ angular.fromJson(result[0]), angular.fromJson(result[1]), angular.fromJson(result[2]), angular.fromJson(result[3]) ]; $scope.producitems[0].title=$scope.producitems[0].title.replace("(Wolle Rosen kaufen)", ""); $scope.producitems[1].title=$scope.producitems[1].title.replace("(Wolle Rosen kaufen)", ""); $scope.producitems[2].title=$scope.producitems[2].title.replace("(Wolle Rosen kaufen)", ""); $scope.producitems[3].title=$scope.producitems[3].title.replace("(Wolle Rosen kaufen)", ""); $scope.rosen1titel=$scope.producitems[2].title; $scope.rosen1preis=$scope.producitems[2].price; $scope.rosen1beschreibung=$scope.producitems[2].description; $scope.rosen1preiscurrency=$scope.producitems[2].price_currency_code; $scope.rosen1preistag="Preis: " + $scope.rosen1preis + " " + $scope.rosen1preiscurrency + " (inkl. MwSt.)"; $scope.rosen3titel=$scope.producitems[1].title; $scope.rosen3preis=$scope.producitems[1].price; $scope.rosen3beschreibung=$scope.producitems[1].description; $scope.rosen3preiscurrency=$scope.producitems[2].price_currency_code; $scope.rosen3preistag="Preis: " + $scope.rosen3preis + " " + $scope.rosen3preiscurrency + " (inkl. MwSt.)"; $scope.rosen9titel=$scope.producitems[0].title; $scope.rosen9preis=$scope.producitems[0].price; $scope.rosen9beschreibung=$scope.producitems[0].description; $scope.rosen9preiscurrency=$scope.producitems[2].price_currency_code; $scope.rosen9preistag="Preis: " + $scope.rosen9preis + " " + $scope.rosen9preiscurrency + " (inkl. MwSt.)"; $scope.flateraterosentitel=$scope.producitems[3].title; $scope.flateraterosenpreis=$scope.producitems[3].price; $scope.flateraterosenbeschreibung=$scope.producitems[3].description; $scope.flateraterosenpreiscurrency=$scope.producitems[2].price_currency_code; $scope.flateraterosenpreistag="Preis: " + $scope.flateraterosenpreis + " " + $scope.flateraterosenpreiscurrency + " (inkl. MwSt.)"; if($rootScope.flatrate==1) { $scope.showflatrate = false; $scope.rosen1preistag="kostenlos - Flatrate"; $scope.rosen3preistag="kostenlos - Flatrate"; $scope.rosen9preistag="kostenlos - Flatrate"; } $scope.showrosen = true; $timeout(function(){ $scope.showrosen = true; }, 400); } function errorProducts (result) { /* var strResult = ""; if(typeof result === 'object') { strResult = JSON.stringify(result); } else { strResult = result; } alert(strResult); */ } $timeout(getProducts, 2000); /* * Produkt-Details abrufen ENDE */ /* * Rosen kaufen START */ $scope.buyRose = function() { if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") { if ($rootScope.storeinit==1){ if ($rootScope.flatrate==1){ $timeout(successConsumeHandler, 200); } else{ if ($scope.preis=='rosenflatrate'){ inappbilling.buy(successBuyOnceHandler, errorBuyHandler, $scope.preis); } else{ 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'); }); } } } function errorBuyHandler (error) { /* var strResult = ""; var returnBool=false; if(typeof error === 'object') { strResult = JSON.stringify(error); } else { strResult = error; } */ /* * Prüfen ob Kauf schonmal durchgeführt wurde, aber noch nicht konsumiert */ returnBool=strResult.indexOf("Item Already Owned") != -1; if (returnBool==true){ //Rose wurde schon gekauft, jetzt konsumieren $timeout(consumesuccessHandler, 500); } else{ //Ein anderer Fehler ist auf getreten Kauf wird abgebrochen 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 successBuyHandler (result) { if ($rootScope.flatrate==1){ //Kein Konsum auslösem direkt zum Download $timeout(successConsumeHandler, 200); } else{ //Kein Konsum auslösem $timeout(consumesuccessHandler, 500); } } function successBuyOnceHandler (result) { $rootScope.flatrate=1; $scope.showflatrate = false; $scope.rosen1preistag="kostenlos - Flatrate"; $scope.rosen3preistag="kostenlos - Flatrate"; $scope.rosen9preistag="kostenlos - Flatrate"; $timeout(getProducts, 300); } /* * Rosen kaufen ENDE */ /* * Rosen konsuieren START */ 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, bg: $scope.backgroundpic}).then(function (res){ $scope.filetodownload = res.data; // File for download var url = "http://api.raataar.de/rosen/" + $scope.filetodownload; // File name only var filename = url.split("/").pop(); var Kaufdatum=''; // Save location //var targetPath = cordova.file.externalRootDirectory + filename; var targetPath = cordova.file.applicationStorageDirectory + filename; var targetpublicPath = cordova.file.externalRootDirectory + "/WolleRosenKaufen/" + filename; $scope.targetPath=''; $scope.targetPath=targetPath; $scope.targetpublicPath=targetpublicPath; $scope.filename=filename; $cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) { $scope.item={name: $scope.name, bild: $scope.targetpublicPath}; $scope.items.push($scope.item); Kaufdatum = $filter('date')(new Date(),'dd.MM.yyyy - H:mm:ss'); //itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath $database.setBuys($scope.name,$scope.filename,$scope.freitext, Kaufdatum,'', $scope.targetpublicPath); //Ordner erstellen auf SD-Karte $cordovaFile.createDir(cordova.file.externalRootDirectory, "WolleRosenKaufen", false) .then(function (success) { // success }, function (error) { // error }); $cordovaFile.copyFile(cordova.file.applicationStorageDirectory, $scope.filename, cordova.file.externalRootDirectory + "/WolleRosenKaufen", $scope.filename) .then(function (success) { // success }, function (error) { // error }); $scope.hide($ionicLoading); $state.go('tab.buys'); }, function (error) { console.log('Error'); }, function (progress) { // PROGRESS HANDLING GOES HERE }); return false; }); } 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); } /* * Rosen konsumieren ENDE */ }) .controller('BuysCtrl', function($scope, $database,$location,$ionicModal,$ionicLoading,$timeout,$cordovaFile,$ionicPopup) { $scope.$on( "$ionicView.enter", function( scopes, states ) { $scope.show($ionicLoading); $timeout(fill_list, 1000); }); function fill_list(){ $scope.items=[]; $database.getAllBuys().then(function (result) { if(result.length>0){ for(i=0;iLade...

' }); }; $scope.hide = function(){ $ionicLoading.hide(); }; $scope.deleteBuy = function(id,imagefile) { $ionicPopup.confirm({ title: 'System-Hinweis', template: 'Möchten Sie das Bild wirklich löschen?' }) .then(function(res) { if (res) { //Dateien Löschen im Programmpfad $cordovaFile.removeFile(cordova.file.applicationStorageDirectory, imagefile) .then(function (success) { // success }, function (error) { // error }); //Dateien Löschen im Public-Programmpfad $cordovaFile.removeFile(cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile) .then(function (success) { // success }, function (error) { // error }); //Datenbank-eintrag löschen $database.deleteBuy(id); $scope.show($ionicLoading); $timeout(fill_list, 300); } }); } $scope.showImages = function(imagesrc,imagefile) { //Sicherstellen, das Bild im Publicfolder vorhanden ist $cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile) .then(function (success) { // success }, function (error) { // error }); //Bild im dialog anzeigen $scope.imagesrc=imagesrc; $scope.showModal('templates/image-popover.html'); } $scope.shareimage = function(imagesrc,imagefile) { //Sicherstellen, das Bild im Publicfolder vorhanden ist $cordovaFile.copyFile(cordova.file.applicationStorageDirectory, imagefile, cordova.file.externalRootDirectory + "/WolleRosenKaufen", imagefile) .then(function (success) { // success }, function (error) { // error }); //Bild im dialog anzeigen $scope.imagesrc=imagesrc; window.plugins.socialsharing.share(null, null, $scope.imagesrc, null); } $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() }; }) .controller('Dummy', function($scope) { });