Commit 88565c87d5cb3de6e02d1f1c5774d0147970d0b6
1 parent
50d191bc
Exists in
master
and in
2 other branches
refatoring of load state and city of profile
Showing
1 changed file
with
44 additions
and
1 deletions
Show diff stats
www/js/controllers.js
... | ... | @@ -306,6 +306,49 @@ angular.module('confjuvapp.controllers', []) |
306 | 306 | }); |
307 | 307 | }; |
308 | 308 | |
309 | + //FIXME Refactor this code | |
310 | + // Load State | |
311 | + $scope.setStateAndCityOfProfile = function() { | |
312 | + $scope.loading = true; | |
313 | + | |
314 | + var path = 'states/'; | |
315 | + if($scope.profile && $scope.profile.region){ | |
316 | + path += $scope.profile.region.parent_id; | |
317 | + } | |
318 | + | |
319 | + $http.get(ConfJuvAppUtils.pathTo(path)) | |
320 | + .then(function(resp) { | |
321 | + $scope.profile.state = resp.data; | |
322 | + if($scope.profile.state){ | |
323 | + $scope.setCityOfProfile(); | |
324 | + } | |
325 | + $scope.loading = false; | |
326 | + }, function(err) { | |
327 | + $ionicPopup.alert({ title: 'Estados', template: 'Não foi possível atribuir o estado ao perfil' }); | |
328 | + $scope.loading = false; | |
329 | + }); | |
330 | + }; | |
331 | + | |
332 | + //FIXME Refactor this code | |
333 | + // Load City | |
334 | + $scope.setCityOfProfile = function() { | |
335 | + $scope.loading = true; | |
336 | + var path = 'states/'; | |
337 | + | |
338 | + if($scope.profile && $scope.profile.region){ | |
339 | + path += $scope.profile.region.parent_id + '/cities/' + $scope.profile.region.id; | |
340 | + } | |
341 | + | |
342 | + $http.get(ConfJuvAppUtils.pathTo(path)) | |
343 | + .then(function(resp) { | |
344 | + $scope.profile.city = resp.data; | |
345 | + $scope.loading = false; | |
346 | + }, function(err) { | |
347 | + $ionicPopup.alert({ title: 'Cidade', template: 'Não foi possível atribuir a cidade ao perfil' }); | |
348 | + $scope.loading = false; | |
349 | + }); | |
350 | + }; | |
351 | + | |
309 | 352 | // Load Cities |
310 | 353 | $scope.loadCitiesByState = function(state_id) { |
311 | 354 | $scope.loading = true; |
... | ... | @@ -313,7 +356,6 @@ angular.module('confjuvapp.controllers', []) |
313 | 356 | |
314 | 357 | $http.get(ConfJuvAppUtils.pathTo(path)) |
315 | 358 | .then(function(resp) { |
316 | - $scope.loading = false; | |
317 | 359 | $scope.cities = resp.data; |
318 | 360 | $scope.shouldDisplayCities = true; |
319 | 361 | $scope.loading = false; |
... | ... | @@ -1162,6 +1204,7 @@ angular.module('confjuvapp.controllers', []) |
1162 | 1204 | .then(function(resp) { |
1163 | 1205 | $scope.profile = resp.data.person; |
1164 | 1206 | $scope.loginCallback(ConfJuvAppUtils.getPrivateToken()); |
1207 | + $scope.setStateAndCityOfProfile(); | |
1165 | 1208 | $scope.loading = false; |
1166 | 1209 | }, function(err) { |
1167 | 1210 | $scope.token = ConfJuvAppUtils.setPrivateToken(null); | ... | ... |