Skip to content

Commit

Permalink
Switch the Sign in/Account menu from server to client side
Browse files Browse the repository at this point in the history
This means pages that don't show favourit data and do not
change can be cached forever, next step is to do the same for
favourit data.
  • Loading branch information
ranguard committed May 21, 2015
1 parent f156b05 commit 85d7018
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
27 changes: 27 additions & 0 deletions root/static/js/cpan.js
Expand Up @@ -71,6 +71,8 @@ function toggleTOC() {
}

$(document).ready(function() {
processUserData();

$(".ttip").tooltip();

$('#signin-button').mouseenter(function() {
Expand Down Expand Up @@ -398,6 +400,31 @@ function logInPAUSE(a) {
return false;
}

function processUserData () {
// TODO: use localstorage for cacheing
getFavDataFromServer();
}

function showUserData(fav_data) {
// User is logged in, so show it
$('.logged_in').css('display', 'inline');
}

function getFavDataFromServer() {
$.ajax({
type: 'GET',
url: '/account/favorite/list_as_json',
success: function(databack) {
showUserData(databack);
},
error: function() {
// Can't be logged in
$('.logged_out').show();
}
});
return true;
}

function favDistribution(form) {
form = $(form);
var data = form.serialize();
Expand Down
8 changes: 2 additions & 6 deletions root/wrapper.html
Expand Up @@ -114,9 +114,8 @@
<%- END %>
</ul>
<ul class="nav navbar-nav navbar-right">
<%- IF user_exists %>
<form action="<% c.uri_for("/account/logout") %>" method="POST" id="logout"></form>
<li class="dropdown">
<li class="dropdown logged_in" style="display: none;">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account
<b class="caret"></b>
Expand All @@ -130,8 +129,7 @@
</li>
</ul>
</li>
<% ELSE %>
<li class="dropdown">
<li class="dropdown logged_out" style="display: none;">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Sign in
<b class="caret"></b>
Expand All @@ -153,7 +151,6 @@
</li>
</ul>
</li>
<% END %>
</ul>
</div>
</nav>
Expand Down Expand Up @@ -250,4 +247,3 @@ <h4 class="modal-title">Keyboard Shortcuts</h4>
</div>
</body>
</html>

0 comments on commit 85d7018

Please sign in to comment.