Last active
August 29, 2015 14:16
-
-
Save dvidsilva/b213ed0ec07ae74b5c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("orientationchange", handleOrientation, true); | |
function handleOrientation(){ | |
if (Math.abs(window.orientation) == 90) { | |
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-landscape.png"); | |
angular.element(document.querySelector('#imagen-Background')).css("width","35%"); | |
} else { | |
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-portrait.png"); | |
angular.element(document.querySelector('#imagen-Background')).css("width","45%"); | |
} | |
} | |
document.addEventListener("deviceready", function() { | |
if (Math.abs(window.orientation) == 90) { | |
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-landscape.png"); | |
angular.element(document.querySelector('#imagen-Background')).css("width","35%"); | |
} else { | |
angular.element(document.querySelector('#imagenBackground')).attr("src","img/background-portrait.png"); | |
angular.element(document.querySelector('#imagen-Background')).css("width","45%"); | |
} | |
angular.bootstrap(document, ['starter']); | |
}, false); | |
//ng-app="starter" | |
var starter = angular.module('starter', ['ionic']); | |
// create a config object | |
starter.value('Config', { | |
url : "http://104.236.24.67" | |
}); | |
//Controlador principal | |
starter.controller("principal", ["$scope","$timeout","$http", function ($scope, $timeout, $http, Config){ | |
//Esta el div de cargado visible y oculta el div que dice "malo el internet" | |
$scope.visibleLoading = false; | |
//Llama el controlador del internet del dispositivo | |
$scope.networkState = navigator.connection.type; | |
//Verifica que tipo de conexion es, si es none connected es falso | |
if($scope.networkState == "none"){ | |
$scope.connected = false; | |
}else{ | |
$scope.connected = true; | |
} | |
$scope.server = undefined; | |
//Hace un get cualquiera al servidor, haber si hay conexion con el servidor | |
$http.get(Config.url + '/public/api/v1/check/2f1767dc31e7a8dc68b2c21bf07984ff').success(function(data, status, headers, config){ | |
if(data.success == true){ | |
$scope.server = true; | |
}else{ | |
$scope.server = false; | |
} | |
}).error(function(data, status, headers, config){ | |
$scope.server = false; | |
}); | |
var promise = $timeout(function(){ | |
if($scope.connected && $scope.server){ | |
window.location="resources/login/login.html"; | |
}else if(!$scope.connected){ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unable to detect internet<br>connectivity, please check your network<br>settings and try again.</b>"); | |
}else if(!$scope.server){ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unable to contact login servers<br>please try again later.</b>"); | |
}else{ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unknown error.</b>"); | |
} | |
}, 3000); | |
$scope.onRetry = function(){ | |
//Esta el div de cargado visible y oculta el div que dice malo el internet | |
$scope.visibleLoading = false; | |
//Llama el controlador del internet del dispositivo | |
$scope.networkState = navigator.connection.type; | |
//Verifica que tipo de conexion es, si es none connected es falso | |
if($scope.networkState == "none"){ | |
$scope.connected = false; | |
}else{ | |
$scope.connected = true; | |
} | |
$scope.server = undefined; | |
//Hace un get cualquiera al servidor, haber si hay conexion con el servidor | |
$http.get(Config.url + '/public/api/v1/check/2f1767dc31e7a8dc68b2c21bf07984ff').success(function(data, status, headers, config){ | |
if(data.success == true){ | |
$scope.server = true; | |
}else{ | |
$scope.server = false; | |
} | |
}).error(function(data, status, headers, config){ | |
$scope.server = false; | |
}); | |
var promise = $timeout(function(){ | |
if($scope.connected && $scope.server){ | |
window.location="resources/login/login.html"; | |
}else if(!$scope.connected){ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unable to detect internet<br>connectivity, please check your network<br>settings and try again.</b>"); | |
}else if(!$scope.server){ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unable to contact login servers<br>please try again later.</b>"); | |
}else{ | |
$scope.visibleLoading = true; | |
angular.element(document.querySelector('#problemText')).html("<b>Unknown error.</b>"); | |
} | |
}, 3000); | |
} | |
//Funcion para salir de la aplicacion | |
$scope.onExit = function(){ | |
exitFromApp(); | |
} | |
}]); | |
function exitFromApp(){ | |
if (navigator.app) { | |
navigator.app.exitApp(); | |
} | |
else if (navigator.device) { | |
navigator.device.exitApp(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment