FrankYan93/nanotwitter

View on GitHub
views/userfollowers.erb

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html>
    <head>
        <title>
            <%= @user_name %>'s followers</title>
    </head>

    <body>

        <div class="container theme-showcase" role="main">

        <h1>Follwers of  <%= @user_name %></h1>

        <%= control_bar @user_name %>

        <% for i in 0+@n*10..9+@n*10  %>
        <% unless @followers[i].nil? %>
        <% determine_status @followers[i][:id]%>
        <% @i = i %>
        <% @users = @followers %>
        <%= erb :singleUser %>
        <% end %>
        <% end %>

        <% @link ="/#{@user_name}/followers?" %>
        <%= erb :control_pages%>

        </div>

    </body>
</html>

<%if @status != "unable to follow"%>
<script type="text/javascript">
var following_number=<%= @user.following_number %>;
var follower_number=<%= @user.follower_number %>;
$(".status").hover(function(){
  if(this.innerHTML==="  Following  "){
    $(this).html("  Unfollow  ");
  }else{
    $(this).html("   Follow   ");
  }
},function(){
  if(this.innerHTML==="  Unfollow  "){
    $(this).html("  Following  ");
  }else{
    $(this).html("Not following");
  }
});
  $(".status").click(function(){
    var st=this.innerHTML;
    if(st === "  Unfollow  "){
      following_number-=1;
      $("#following_number").html(following_number+' followings  ');
      var putFollow = new XMLHttpRequest();
      $(this).html("   Follow   ");
      putFollow.open("PUT", '/api/v1/users/' + '<%= session[:user_id] %>' + '/unfollow/' + this.id, true);
      putFollow.send();
    }else{
      following_number+=1;
      $("#following_number").html(following_number+' followings  ');
      var putFollow = new XMLHttpRequest();
      $(this).html("  Unfollow  ");
      putFollow.open("PUT", '/api/v1/users/' + '<%= session[:user_id] %>' + '/follow/' + this.id, true);
      putFollow.send();
    }
  });
</script>
<%end%>