Advertisement
Guest User

controller.js

a guest
May 4th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. angular.module('starter.controllers', [])
  2.  
  3. .controller('AppCtrl', function($scope, $ionicModal, $timeout, $ionicLoading, $http) {
  4.  
  5. // With the new view caching in Ionic, Controllers are only called
  6. // when they are recreated or on app start, instead of every page change.
  7. // To listen for when this page is active (for example, to refresh data),
  8. // listen for the $ionicView.enter event:
  9. //$scope.$on('$ionicView.enter', function(e) {
  10. //});
  11.  
  12. // Form data for the login modal
  13. $scope.loginData = {};
  14.  
  15. // Create the login modal that we will use later
  16. $ionicModal.fromTemplateUrl('templates/login.html', {
  17. scope: $scope
  18. }).then(function(modal) {
  19. $scope.modal = modal;
  20. });
  21.  
  22. // Triggered in the login modal to close it
  23. $scope.closeLogin = function() {
  24. $scope.modal.hide();
  25. };
  26.  
  27. // Open the login modal
  28. $scope.login = function() {
  29. $scope.modal.show();
  30. };
  31.  
  32. // Perform the login action when the user submits the login form
  33. $scope.doLogin = function() {
  34. console.log('Doing login', $scope.loginData);
  35.  
  36. // Simulate a login delay. Remove this and replace with your login
  37. // code if using a login system
  38. $timeout(function() {
  39. $scope.closeLogin();
  40. }, 1000);
  41. };
  42.  
  43. $scope.saveConn = function() {
  44. // $scope.config = {};
  45. // $scope.username = this.config.username;
  46. // $scope.password = this.config.password;
  47.  
  48. $ionicLoading.show({
  49. template: 'Checking server connection...',
  50. showBackdrop: true
  51. });
  52.  
  53. // var somplak = {
  54. // method: 'POST',
  55. // url: 'http://mobiloutlet.id/panel/Api/Login',
  56. // headers: {
  57. // 'Content-Type': 'application/json'
  58. // },
  59. // timeout: 5000,
  60. // data: $scope.config,
  61. // };
  62. $http({
  63. url: 'http://mobiloutlet.id/panel/Api/Login',
  64. method: 'POST',
  65. headers: { 'Content-Type': 'application/json' },
  66. data: {username:this.username,password:this.password}
  67. }).
  68. then(function(response) {
  69. // $ionicLoading.hide();
  70. if (response.Success == 'true') {
  71. $location.path("/home");
  72. } else {
  73. $ionicLoading.show({
  74. template: 'Username and Password Missmatch',
  75. showBackdrop: true
  76. });
  77. }
  78. });
  79. }
  80. })
  81.  
  82. .controller('HomeCtrl', function($scope, $ionicSideMenuDelegate, $http, $ionicLoading, $location, $timeout, $cordovaFileTransfer, $cordovaCamera, $cordovaFile, $cordovaDevice, $ionicPopup, $cordovaActionSheet) {
  83.  
  84. $ionicSideMenuDelegate.canDragContent(false);
  85. $http.get('http://mobiloutlet.id/panel/Api/getVehicleBrands').then(function(result){
  86. $scope.items = result.data.content;
  87. console.log(result.data.content);
  88. });
  89.  
  90. $http.get('http://mobiloutlet.id/panel/Api/getVehicleCategory').then(function(result){
  91. $scope.category = result.data.content;
  92. console.log(result.data.content);
  93. });
  94.  
  95. $scope.saveProspect = function(config) {
  96.  
  97. $scope.config = {};
  98. $scope.config.VehicleProspectBrandId = config.VehicleProspectBrandId;
  99. $scope.config.VehicleProspectCategoryId = config.VehicleProspectCategoryId;
  100. $scope.config.VehicleProspectName = config.VehicleProspectName;
  101. $scope.config.VehicleProspectModels = config.VehicleProspectModels;
  102. $scope.config.VehicleProspectColor = config.VehicleProspectColor;
  103. $scope.config.VehicleProspectTransmision = config.VehicleProspectTransmision;
  104. $scope.config.VehicleProspectBuildYear = config.VehicleProspectBuildYear;
  105. $scope.config.VehicleProspectLastKm = config.VehicleProspectLastKm;
  106. $scope.config.VehicleProspectPrice = config.VehicleProspectPrice;
  107. $scope.config.VehicleProspectOfferPrice = config.VehicleProspectOfferPrice;
  108. $scope.config.VehicleProspectSalesName = config.VehicleProspectSalesName;
  109. $scope.config.VehicleProspectSalesPhone = config.VehicleProspectSalesPhone;
  110. $scope.config.VehicleProspectSalesDealer = config.VehicleProspectSalesDealer;
  111. $scope.config.VehicleProspectCreateDate = config.VehicleProspectCreateDate;
  112. $scope.config.VehicleProspectUserId = '30';
  113. $scope.config.VehiclePhotoProspectPhotoPath = config.file;
  114.  
  115. $ionicLoading.show({
  116. template: 'Menyimpan...',
  117. showBackdrop: true
  118. });
  119. var somplak = {
  120. method: 'POST',
  121. url: 'http://mobiloutlet.id/panel/Api/saveProspect',
  122. headers: {
  123. 'Content-Type': 'application/json'
  124. },
  125. timeout: 5000,
  126. data: $scope.config,
  127. };
  128. console.log($scope.config);
  129. $http(somplak).
  130. then(function(response) {
  131. if (response.data.Success == true) {
  132. $ionicLoading.show({
  133. template: 'Data Tersimpan',
  134. showBackdrop: true
  135. });
  136. $location.path("app/data");
  137. $ionicLoading.hide();
  138. } else {
  139. console.log(response.data.Success);
  140. $ionicLoading.show({
  141. template: 'Error Menyimpan Data',
  142. showBackdrop: true
  143. });
  144. $location.path("app/home");
  145. }
  146. });
  147. }
  148.  
  149. })
  150.  
  151. .controller('PlaylistsCtrl', function($scope) {
  152. $scope.playlists = [
  153. { title: 'Reggae', id: 1 },
  154. { title: 'Chill', id: 2 },
  155. { title: 'Dubstep', id: 3 },
  156. { title: 'Indie', id: 4 },
  157. { title: 'Rap', id: 5 },
  158. { title: 'Cowbell', id: 6 }
  159. ];
  160. })
  161.  
  162. .controller('PlaylistCtrl', function($scope, $stateParams) {
  163. })
  164.  
  165. .controller('LoginCtrl', function($scope, $ionicModal, $timeout, $ionicLoading, $http, $location) {
  166. event.preventDefault();
  167. $scope.saveConn = function(config) {
  168.  
  169. $scope.config = {};
  170.  
  171. $ionicLoading.show({
  172. template: 'Checking server connection...',
  173. showBackdrop: true
  174. });
  175.  
  176. console.log($scope.config);
  177. $http({
  178. url: 'http://mobiloutlet.id/panel/Api/Login',
  179. method: 'POST',
  180. headers: { 'Content-Type': 'application/json' },
  181. timeout: 5000,
  182. data: {username:config.username,password:config.password}
  183. }).
  184. then(function(response) {
  185.  
  186. if (response.data.hasil == 'benar') {
  187. $ionicLoading.hide();
  188. $location.path("app/home");
  189. } else {
  190. // $ionicLoading.hide();
  191. console.log(response.data.Success);
  192. $ionicLoading.show({
  193. template: 'Username atau Password Salah',
  194. showBackdrop: true
  195. });
  196. // $location.path("app/home");
  197. }
  198. // }
  199. });
  200. }
  201. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement