Commit 22a7e56fa18f457066f25e21dd4fadc8f161ce6f
1 parent
366359fc
Exists in
master
and in
5 other branches
Small improvments on login/logout button (header)
Showing
2 changed files
with
35 additions
and
8 deletions
Show diff stats
js/main.js
| ... | ... | @@ -206,7 +206,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 206 | 206 | var requireLoginContainer = loginButton.closest('.require-login-container'); |
| 207 | 207 | |
| 208 | 208 | if(logged_in) { |
| 209 | - $('.logout').show(); | |
| 209 | + Main.showLogout(); | |
| 210 | 210 | if(token){ |
| 211 | 211 | Main.private_token = token; |
| 212 | 212 | } |
| ... | ... | @@ -228,7 +228,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 228 | 228 | } else { |
| 229 | 229 | requireLoginContainer.find('.require-login').hide(); |
| 230 | 230 | requireLoginContainer.find('.login-container').show(); |
| 231 | - $('.logout').hide(); | |
| 231 | + Main.showLogin(); | |
| 232 | 232 | } |
| 233 | 233 | }, |
| 234 | 234 | guid: function() { |
| ... | ... | @@ -577,6 +577,25 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 577 | 577 | successPanel.remove(); |
| 578 | 578 | }, timeout); |
| 579 | 579 | }, |
| 580 | + setUser: function(user){ | |
| 581 | + this.user = user; | |
| 582 | + }, | |
| 583 | + getUser: function(){ | |
| 584 | + return this.user; | |
| 585 | + }, | |
| 586 | + showLogin: function(){ | |
| 587 | + $('.entrar').show(); | |
| 588 | + $('.logout').hide(); | |
| 589 | + }, | |
| 590 | + showLogout: function(){ | |
| 591 | + $('.entrar').hide(); | |
| 592 | + var name = ''; | |
| 593 | + if(this.user){ | |
| 594 | + name = this.user.person.name + ' | '; | |
| 595 | + } | |
| 596 | + $('.logout').text(name + 'Sair'); | |
| 597 | + $('.logout').show(); | |
| 598 | + }, | |
| 580 | 599 | responseToText: function(responseJSONmessage){ |
| 581 | 600 | var o = JSON.parse(responseJSONmessage); |
| 582 | 601 | var msg = ""; |
| ... | ... | @@ -786,10 +805,14 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 786 | 805 | |
| 787 | 806 | if($.cookie('_dialoga_session')) { |
| 788 | 807 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); |
| 789 | - $.getJSON(url).done(function( /*data*/ ) { | |
| 808 | + $.getJSON(url).done(function( data ) { | |
| 790 | 809 | logged_in = true; |
| 791 | 810 | Main.private_token = $.cookie('_dialoga_session'); |
| 792 | - setTimeout(function(){ $('.logout').show(); }, 2000); | |
| 811 | + | |
| 812 | + if(data && data.user){ | |
| 813 | + Main.setUser(data.user); | |
| 814 | + Main.showLogout(); | |
| 815 | + } | |
| 793 | 816 | }); |
| 794 | 817 | } |
| 795 | 818 | |
| ... | ... | @@ -909,8 +932,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F |
| 909 | 932 | $.removeCookie('votedProposals'); |
| 910 | 933 | $.removeCookie('*'); |
| 911 | 934 | logged_in = false; |
| 912 | - $('.logout').hide(); | |
| 913 | - $('.entrar').show(); | |
| 935 | + Main.showLogin(); | |
| 914 | 936 | location.reload(); |
| 915 | 937 | e.preventDefault(); |
| 916 | 938 | }); | ... | ... |
sass/style.sass
| ... | ... | @@ -645,8 +645,13 @@ h1 |
| 645 | 645 | padding: 2px 10px |
| 646 | 646 | .entrar |
| 647 | 647 | background: url(images/icons/icon-user.png) no-repeat 20px 50% |
| 648 | - border-left: 1px solid #bcbcbc | |
| 649 | - margin-left: 20px | |
| 648 | + // border-left: 1px solid #bcbcbc | |
| 649 | + // margin-left: 20px | |
| 650 | + padding-left: 40px | |
| 651 | + .logout | |
| 652 | + background: url(images/icons/icon-user.png) no-repeat 20px 50% | |
| 653 | + // border-left: 1px solid #bcbcbc | |
| 654 | + // margin-left: 20px | |
| 650 | 655 | padding-left: 40px |
| 651 | 656 | .login,.signup |
| 652 | 657 | text-align: left | ... | ... |