Guest User

Untitled

a guest
Jan 21st, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. app.run(function($ionicPlatform, $rootScope, $cordovaSQLite, $cordovaNetwork, $cordovaAppVersion, $cordovaFileTransfer, $localStorage, _, DatabaseService, BackgroundService, ConnectionService) {$ionicPlatform.ready(function() {
  2. // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
  3. // for form inputs)
  4. if (window.cordova && window.cordova.plugins.Keyboard) {
  5. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
  6. cordova.plugins.Keyboard.disableScroll(true);
  7. }
  8.  
  9. if (window.StatusBar) {
  10. // org.apache.cordova.statusbar required
  11. StatusBar.styleDefault();
  12. }
  13.  
  14. });
  15.  
  16. $scope.login = function() {
  17. console.log('Login Function:');
  18.  
  19. $scope.loginStarted = true;
  20. $scope.loginFailed = false;
  21.  
  22. console.log($scope.loginData.username);
  23.  
  24. if (!angular.isDefined($scope.loginData.username) || !angular.isDefined($scope.loginData.password)) {
  25. $scope.loginStarted = false;
  26. $scope.loginFailed = true;
  27. $scope.failureMessage = 'Please enter both your Login Number and Password.';
  28. } else {
  29. var user = {
  30. login_number: $scope.loginData.username,
  31. password: $scope.loginData.password
  32. };
  33.  
  34.  
  35.  
  36. ConnectionService.getConnection()
  37. .then(function(conn) {
  38. if (conn === 'online') {
  39. console.log('ONLINE');
  40. $scope.loginStarted = false;
  41. } else {
  42. console.log('OFFLINE');
  43. $scope.loginStarted = false;
  44. }
  45. });
  46.  
  47.  
  48. }
  49. };
  50. app.service('ConnectionService', function($http, $q, $cordovaNetwork, $rootScope) {
  51. var service = {};
  52.  
  53. service.getConnection = function() {
  54. var deferred = $q.defer();
  55.  
  56. var isOnline;
  57.  
  58. var network = $cordovaNetwork.getNetwork();
  59. isOnline = $cordovaNetwork.isOnline();
  60. isOffline = $cordovaNetwork.isOffline();
  61.  
  62. switch(isOnline) {
  63. case true:
  64. console.log('ISONLINE IS ONLINE.');
  65. deferred.resolve('online');
  66. break;
  67. case false:
  68. console.log('ISONLINE IS OFFLINE.');
  69. deferred.resolve('offline');
  70. break;
  71. default:
  72. console.log('DEFAULT TRIGGERED');
  73. deferred.resolve('offline');
  74. break;
  75. }
  76.  
  77. return deferred.promise;
  78. };
  79.  
  80. return service;});
Add Comment
Please, Sign In to add comment