FrankYan93/nanotwitter

View on GitHub
views/userfollowings.erb

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html>
    <head>
        <title>user followings</title>
    </head>

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


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

      <%= control_bar @user_name %>

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

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


        <% if session[:user_id]== @user[:id] %>
          <h2>"Some Users you may interest in!"</h2>

          <% for i in 0..@count_number-1  %>
              <% unless @unfollowings[i].nil? %>
              <%   @i = i %>
              <% determine_status @unfollowings[i][:id]%>
              <%   @users = @unfollowings %>
              <%= erb :singleUser %>
            <% end %>
          <% end %>
        <% end %>
    </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();
      putFollow.open("PUT", '/api/v1/users/' + '<%= session[:user_id] %>' + '/unfollow/' + this.id, true);
      putFollow.send();
      $(this).parent().parent().parent().hide();
    }else{
      following_number+=1;
      $("#following_number").html(following_number+' followings  ');
      var putFollow = new XMLHttpRequest();
      putFollow.open("PUT", '/api/v1/users/' + '<%= session[:user_id] %>' + '/follow/' + this.id, true);
      putFollow.send();
      $(this).parent().parent().parent().hide();
    }
  });

</script>
<%end%>