Commit a0c2586b78e7d7607eaad57ab87cd6a7d6b25c04

Authored by Evandro Junior
2 parents 3bfc5777 acf792af

Merge branch 'master' of https://gitlab.com/participa/proposal-app

Conflicts:
	js/main.js
Showing 2 changed files with 137 additions and 73 deletions   Show diff stats
index.html
... ... @@ -311,7 +311,7 @@
311 311  
312 312 <div class="talk-proposal-container col-sm-12">
313 313 <section class="talk-proposal box box-propostas">
314   - <div class="container-title box-title">Hangout com ministras e ministros</div>
  314 + <div class="container-title box-title">Bate-papo virtual com ministras e ministros</div>
315 315 <div class="calendar-container"></div>
316 316 </section>
317 317 </div>
... ... @@ -429,11 +429,11 @@
429 429 <div class="row">
430 430 <div class="password col-sm-6">
431 431 <label for="signup-user_password" class="label">Senha:</label>
432   - <input id="signup-user_password" name="password" type="password" placeholder="Senha">
  432 + <input id="signup-user_password" name="password" required type="password" placeholder="Senha">
433 433 </div>
434 434 <div class="password-confirmation col-sm-6">
435 435 <label for="user_password_confirmation" class="label">Confirme a senha:</label>
436   - <input id="user_password_confirmation" name="password_confirmation" type="password" placeholder="Confirme a senha">
  436 + <input id="user_password_confirmation" name="password_confirmation" required type="password" placeholder="Confirme a senha">
437 437 </div>
438 438 <div class="oauth-providers">
439 439 <input id="user_oauth_providers" name="oauth_providers" type="hidden">
... ... @@ -448,9 +448,8 @@
448 448 </div>
449 449 <div id="terms-of-use-box" class="col-sm-12">
450 450 <div class="checkbox">
451   - <input id="user_terms_accepted" name="user[terms_accepted]" value="0" type="hidden" />
452   - <label>
453   - <input name="user[terms_accepted]" value="0" type="checkbox" />
  451 + <label for="user_terms_accepted">
  452 + <input id="user_terms_accepted" name="user_terms_accepted" value="0" required type="checkbox" />
454 453 Eu aceito os <a href="#/artigo/107880" target="_blank">termos de uso</a>
455 454 </label>
456 455 </div>
... ...
js/main.js
... ... @@ -251,12 +251,10 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
251 251 var loginContainer = requireLoginContainer.find('.login-container');
252 252 loginContainer.show();
253 253 loginContainer.find('.new-user').click();
254   - var signupForm = loginContainer.find('#signup-form');
255   - signupForm.find('#user_email').val(user.email);
256   - signupForm.find('#user_name').val(user.login);
257   - signupForm.find('#user_oauth_providers').val(user.oauth_providers);
258   - //signupForm.find(".password").hide();
259   - //signupForm.find(".password-confirmation").hide();
  254 + var $signupForm = loginContainer.find('#signup-form');
  255 + $signupForm.find('#user_email').val(user.email);
  256 + $signupForm.find('#user_name').val(user.login);
  257 + $signupForm.find('#user_oauth_providers').val(user.oauth_providers);
260 258 } else {
261 259 requireLoginContainer.find('.require-login').hide();
262 260 requireLoginContainer.find('.login-container').show();
... ... @@ -1026,16 +1024,16 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1026 1024 var proposal_id = this.id.split('-').pop();
1027 1025 var form = this;
1028 1026 var $form = $(this);
1029   - var message = $(form).find('.message');
1030   - message.hide();
1031   - message.text('');
  1027 + var $message = $form.find('.message');
  1028 + $message.hide();
  1029 + $message.text('');
1032 1030 $.ajax({
1033 1031 type: 'post',
1034 1032 url: host + $form.attr('action'),
1035   - data: $('#'+this.id).serialize() + '&private_token=' + Main.private_token + '&fields=id&article[name]=article_' + Main.guid()
  1033 + data: $form.serialize() + '&private_token=' + Main.private_token + '&fields=id&article[name]=article_' + Main.guid()
1036 1034 })
1037 1035 .done(function( /*data*/ ) {
1038   - form.reset();
  1036 + $form.reset();
1039 1037 $form.hide();
1040 1038 $form.siblings('.success-sent').show();
1041 1039 $form.siblings('.subtitle').hide();
... ... @@ -1044,15 +1042,15 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1044 1042 })
1045 1043 .fail(function( jqxhr, textStatus, error ) {
1046 1044 var err = textStatus + ', ' + error;
1047   - console.log( 'Request Failed: ' + err );
1048   - message.show();
1049   - message.text('Não foi possível enviar.');
  1045 + // console.log( 'Request Failed: ' + err );
  1046 + $message.show();
  1047 + $message.text('Não foi possível enviar.');
1050 1048 });
1051 1049 });
1052 1050 })
1053 1051 .fail(function( jqxhr, textStatus, error ) {
1054 1052 var err = textStatus + ', ' + error;
1055   - console.log( 'Request Failed: ' + err );
  1053 + // console.log( 'Request Failed: ' + err );
1056 1054 });
1057 1055  
1058 1056 $(document).ready(function($) {
... ... @@ -1088,7 +1086,6 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1088 1086  
1089 1087 $(document).on('click', '.login-action', function(e) {
1090 1088 e.preventDefault();
1091   - // console.log('obj', obj);
1092 1089  
1093 1090 var $this = $(this); // button
1094 1091 var $form = $this.closest('#login-form');
... ... @@ -1148,7 +1145,6 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1148 1145 var loginForm = $(this).parents('#login-form');
1149 1146 var signupForm = loginForm.siblings('#signup-form');
1150 1147 window.signupForm = signupForm;
1151   - // console.log("novo usuário");
1152 1148 loginForm.hide();
1153 1149 signupForm.show();
1154 1150 signupForm.find(".password").show();
... ... @@ -1171,60 +1167,136 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1171 1167 });
1172 1168  
1173 1169 $(document).on('click', '.confirm-signup', function(e) {
  1170 +
  1171 + var $button = $(this);
  1172 + var $signupForm = $(this).parents('form.signup');
  1173 + var $inputEmail = $signupForm.find('#signup-user_email');
  1174 + var $inputUsername = $signupForm.find('#signup-user_name');
  1175 + var $inputPassword = $signupForm.find('#signup-user_password');
  1176 + var $inputPasswordConfirmation = $signupForm.find('#user_password_confirmation');
  1177 + var $inputAcceptation = $signupForm.find('#user_terms_accepted');
  1178 + var $inputCaptcha = $signupForm.find('#recaptcha_response_field');
  1179 +
  1180 + // clear messages
1174 1181 var message = $('.signup .message');
1175 1182 message.hide();
1176 1183 message.text('');
1177 1184  
1178   - var signup = $(this).parents('form.signup');
1179   - var $loading = $('.login-container .loading');
1180   - $loading.show();
1181   - signup.hide();
1182   - signup.removeClass('hide');
1183   - var button = $(this);
  1185 + // Validate form
  1186 + var hasEmail = $inputEmail && $inputEmail.val().length > 0;
  1187 + var hasUsername = $inputUsername && $inputUsername.val().length > 0;
  1188 + var hasPassword = $inputPassword && $inputPassword.val().length > 0;
  1189 + var hasPasswordConfirmation = $inputPasswordConfirmation && $inputPasswordConfirmation.val().length > 0;
  1190 + var hasPasswordEquals = $inputPassword.val() == $inputPasswordConfirmation.val();
  1191 + var hasAcceptation = $inputAcceptation.val();
  1192 + var hasCaptcha = $inputCaptcha.val().length > 0;
  1193 + var hasError = (!hasEmail || !hasUsername || !hasPassword || !hasPasswordConfirmation || !hasPasswordEquals || !hasAcceptation || !hasCaptcha);
1184 1194  
1185   - $.ajax({
1186   - type: 'post',
1187   - url: host + '/api/v1/register',
1188   - data: $(this).parents('.signup').serialize(),
1189   - }).done(function(data) {
  1195 + if(hasError){
1190 1196  
1191   - var $sectionContent = button.closest('.section-content');
1192   - if($sectionContent && $sectionContent.length > 0){
1193   - Main.displaySuccess($sectionContent, 'Cadastro efetuado com sucesso', 1000, 'icon-user-created');
  1197 + if ($signupForm[0].checkValidity()) { // force check of HTML5 validation
  1198 + e.preventDefault();
  1199 +
  1200 + var messageErrors = [];
  1201 +
  1202 + messageErrors.push('<ul>'); // start a HTML list
  1203 +
  1204 + if (!hasEmail){
  1205 + messageErrors.push('<li>O e-mail é um campo obrigatório.</li>');
  1206 + }
  1207 +
  1208 + if (!hasUsername){
  1209 + messageErrors.push('<li>O nome de usuário é um campo obrigatório.</li>');
  1210 + }
  1211 +
  1212 + if (!hasPassword){
  1213 + messageErrors.push('<li>A senha é um campo obrigatório.</li>');
  1214 + }
  1215 +
  1216 + if (!hasPasswordConfirmation){
  1217 + messageErrors.push('<li>A confirmação da senha é um campo obrigatório.</li>');
  1218 + }
  1219 +
  1220 + if (!hasPasswordEquals){
  1221 + messageErrors.push('<li>A senha e confirmação da senha devem ser iguais.</li>');
  1222 + }
  1223 +
  1224 + if (!hasAcceptation){
  1225 + messageErrors.push('<li>Você deve ler e aceitar os termos de uso.</li>');
  1226 + }
  1227 +
  1228 + if (!hasCaptcha){
  1229 + messageErrors.push('<li>O ReCaptcha é um campo obrigatório.</li>');
  1230 + }
  1231 +
  1232 + messageErrors.push('</ul>'); // close the paragraph
  1233 +
  1234 + messageErrors = messageErrors.join('<br/>');
  1235 + message.html($(messageErrors));
  1236 + message.show();
1194 1237 }
  1238 + } else {
  1239 + e.preventDefault();
1195 1240  
1196   - $(document).trigger('login:success', data);
1197   - }).fail(function(data) {
1198   - var msg = "";
1199   - // Reload captcha here
1200   - if(window.lastCaptcha)
1201   - window.lastCaptcha.recarregar();
1202   - try{
1203   - msg = Main.responseToText(data.responseJSON.message);
1204   - }catch(ex){
1205   - var ptBR = {};
1206   - // (Invalid request) email can't be saved
1207   - ptBR['(Invalid request) email can\'t be saved'] = 'E-mail inválido.';
1208   - // (Invalid request) login can't be saved
1209   - ptBR['(Invalid request) login can\'t be saved'] = 'Nome de usuário inválido.';
1210   - ptBR['Please solve the test in order to register.'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.';
1211   - msg = ptBR[data.responseJSON.message] || data.responseJSON.message;
  1241 + // show loading
  1242 + var $loading = $('.login-container .loading');
  1243 + $loading.show();
  1244 +
  1245 + $.ajax({
  1246 + type: 'post',
  1247 + url: host + '/api/v1/register',
  1248 + data: $signupForm.serialize(),
  1249 + })
  1250 + .done(handleDone)
  1251 + .fail(handleFail)
  1252 + .always(handleAlways);
  1253 +
  1254 + function handleDone(data){
  1255 + $signupForm.hide();
  1256 + $signupForm.removeClass('hide');
  1257 +
  1258 + var $sectionContent = $button.closest('.section-content');
  1259 + if($sectionContent && $sectionContent.length > 0){
  1260 + Main.displaySuccess($sectionContent, 'Cadastro efetuado com sucesso', 1000, 'icon-user-created');
  1261 + }
  1262 + $(document).trigger('login:success', data);
1212 1263 }
1213 1264  
1214   - message.show();
1215   - message.html('Não foi possível efetuar o cadastro: <br/><br/>' + msg);
  1265 + function handleFail(data, var2) {
  1266 + var msg = "";
  1267 + // Reload captcha here
  1268 + if(window.lastCaptcha)
  1269 + window.lastCaptcha.recarregar();
  1270 +
  1271 + if(data.responseJSON){
  1272 + try{
  1273 + msg = Main.responseToText(data.responseJSON.message);
  1274 + }catch(ex){
  1275 + var ptBR = {};
  1276 + // (Invalid request) email can't be saved
  1277 + ptBR['(Invalid request) email can\'t be saved'] = 'E-mail inválido.';
  1278 + // (Invalid request) login can't be saved
  1279 + ptBR['(Invalid request) login can\'t be saved'] = 'Nome de usuário inválido.';
  1280 + ptBR['Please solve the test in order to register.'] = 'Por favor, digite os caracteres da imagem na caixa abaixo dela.';
  1281 + msg = '<br/><br/>';
  1282 + msg += ptBR[data.responseJSON.message] || data.responseJSON.message;
  1283 + }
  1284 + }else{
  1285 + msg = '<br/><br/>';
  1286 + msg += 'Erro na comunicação com o servidor.';
  1287 + }
  1288 +
  1289 + message.html('<p>Não foi possível efetuar o cadastro:' + msg + '</p>');
  1290 + message.show();
1216 1291  
1217   - $(document).trigger('login:fail', data);
1218   - }).always(function() {
1219   - $loading.hide();
1220   - signup.show();
  1292 + $(document).trigger('login:fail', data);
  1293 + }
1221 1294  
1222   - // var $loginPanel = $loading.closest('#login-panel');
1223   - // if($loginPanel && $loginPanel.length > 0){
1224   - // $loginPanel.hide();
1225   - // }
1226   - });
1227   - e.preventDefault();
  1295 + function handleAlways() {
  1296 + $loading.hide();
  1297 + $signupForm.show();
  1298 + }
  1299 + }
1228 1300 });
1229 1301  
1230 1302 // var popupCenter = function(url, title, w, h) {
... ... @@ -1274,8 +1346,6 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1274 1346 var url = $iframe.attr('src');
1275 1347 var c = '?';
1276 1348  
1277   - // console.log('url', url);
1278   - // console.log('url.indexOf("youtube")', url.indexOf("youtube"));
1279 1349 if(url.indexOf("youtube") === -1){
1280 1350 // is not a iframe of youtube
1281 1351 // console.debug('is not a iframe of youtube');
... ... @@ -1299,11 +1369,6 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1299 1369 setTimeout(checkIframes, 500);
1300 1370 }
1301 1371 checkIframes();
1302   - // $(document).bind('DOMSubtreeModified', function(e){
1303   - // console.log('this', this);
1304   - // console.log('e', e);
1305   -
1306   - // });
1307 1372  
1308 1373 });
1309 1374  
... ... @@ -1319,7 +1384,7 @@ define([&#39;jquery&#39;, &#39;handlebars&#39;, &#39;fastclick&#39;, &#39;handlebars_helpers&#39;, &#39;piwik&#39;], fun
1319 1384 Main.locationHashChanged.apply(Main);
1320 1385 }
1321 1386 }else{
1322   - console.log('The browser not supports the hashchange event!');
  1387 + // console.log('The browser not supports the hashchange event!');
1323 1388 }
1324 1389  
1325 1390 // Handle resize event
... ...