Commit 5fb9be745eb84907e1672da971eac05a45bc5888

Authored by Caio Almeida
1 parent 4a23d376

adding state and cities selection

ConfJuvApp/www/html/_login.html
... ... @@ -73,6 +73,7 @@
73 73  
74 74 <label class="item item-input"><input type="text" placeholder="E-mail" ng-model="data.email" required></label>
75 75 <label class="item item-input"><input type="text" placeholder="Nome de usuário" ng-model="data.login" required></label>
  76 + <ng-include src="'html/_select_state.html'"></ng-include>
76 77 <label class="item item-input"><input type="password" placeholder="Senha" ng-model="data.password" required></label>
77 78 <label class="item item-input"><input type="password" placeholder="Confirmar senha" ng-model="data.password_confirmation" required></label>
78 79  
... ...
ConfJuvApp/www/html/_select_city.html 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<div class="list" ng-show="shouldDisplayCities">
  2 +
  3 + <label class="item item-input item-select">
  4 + <div class="input-label">
  5 + Cidade
  6 + </div>
  7 + <select ng-model="cityChoosed" ng-options="city.name for city in cities">
  8 + <option value="">Selecione uma cidade...</option>
  9 + </select>
  10 + </label>
  11 +
  12 +</div>
... ...
ConfJuvApp/www/html/_select_state.html 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<div class="list">
  2 +
  3 + <label class="item item-input item-select">
  4 + <div class="input-label">
  5 + Estado
  6 + </div>
  7 + <select ng-model="stateChoosed" ng-change="loadCitiesByState(stateChoosed.id)" ng-options="state.name for state in states">
  8 + <option value="">Selecione um estado...</option>
  9 + </select>
  10 + </label>
  11 +
  12 +</div>
  13 +
  14 +<ng-include src="'html/_select_city.html'"></ng-include>
  15 +
... ...
ConfJuvApp/www/js/controllers.js
... ... @@ -115,13 +115,17 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
115 115 $scope.registerFormDisplayed = false;
116 116  
117 117 $scope.displayRegisterForm = function() {
  118 + $scope.loadStates();
118 119 $scope.registerFormDisplayed = true;
119 120 $scope.loginFormDisplayed = false;
  121 + $scope.loading = false;
120 122 };
121 123  
122 124 // Function to register
123 125 $scope.Register = function(data) {
  126 +alert('no registro')
124 127 if (!data || !data.login || !data.email || !data.password || !data.password_confirmation) {
  128 +alert('teste');
125 129 $ionicPopup.alert({ title: 'Registrar', template: 'Por favor preencha todos os campos' });
126 130 return;
127 131 }
... ... @@ -168,6 +172,53 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
168 172 };
169 173  
170 174 /******************************************************************************
  175 + States > Cities
  176 + ******************************************************************************/
  177 +
  178 + $scope.states = [];
  179 + $scope.stateChoosed = null;
  180 + $scope.cities = [];
  181 + $scope.cityChoosed = null;
  182 + $scope.shouldDisplayCities = false;
  183 +
  184 + // Load States
  185 + $scope.loadStates = function() {
  186 + $scope.loading = true;
  187 + $scope.shouldDisplayCities = false;
  188 + $scope.stateChoosed = null;
  189 + $scope.cityChoosed = null;
  190 +
  191 + var path = 'states';
  192 +
  193 + $http.get(ConfJuvAppUtils.pathTo(path))
  194 + .then(function(resp) {
  195 + $scope.states = resp.data;
  196 + $scope.loading = false;
  197 + }, function(err) {
  198 + $ionicPopup.alert({ title: 'Estados', template: 'Não foi possível carregar os estados' });
  199 + $scope.loading = false;
  200 + });
  201 + };
  202 +
  203 + // Load Cities
  204 + $scope.loadCitiesByState = function(state) {
  205 + $scope.loading = true;
  206 +
  207 + var path = 'states/' + state + '/cities';
  208 +
  209 + $http.get(ConfJuvAppUtils.pathTo(path))
  210 + .then(function(resp) {
  211 + $scope.loading = false;
  212 + $scope.cities = resp.data;
  213 + $scope.shouldDisplayCities = true;
  214 + $scope.loading = false;
  215 + }, function(err) {
  216 + $ionicPopup.alert({ title: 'Estados', template: 'Não foi possível carregar as cidades' });
  217 + $scope.loading = false;
  218 + });
  219 + };
  220 +
  221 + /******************************************************************************
171 222 D I S C U S S I O N S > T O P I C S > P R O P O S A L S
172 223 ******************************************************************************/
173 224  
... ...