<%
  @filter = params[:filter]
  new_filter = params[:new_filter]
  
  if @filter && params[:clear]
    @filter.delete(params[:type])
  elsif @filter && new_filter
    if @filter.has_key?(new_filter[:type]) && @filter[new_filter[:type]].include?(new_filter[:id].to_s)
      @filter[new_filter[:type]].delete(new_filter[:id].to_s)
    elsif @filter.has_key?(new_filter[:type])
      @filter[new_filter[:type]] << new_filter[:id].to_s
    else
      @filter.merge!({new_filter[:type] => [new_filter[:id].to_s]})
    end
  elsif new_filter
    @filter = {new_filter[:type] => [new_filter[:id].to_s]}
  end


  @writing_books = WritingBook.where(:create_user_id => @user.id).page(params[:page]).per(10)


%>

<table class="table main-list">
	<thead>
		<tr>
			<th class="span1"><%= t('writing_book.year') %></th>
			<th class="span3"><%= t('writing_book.title') %></th>
		</tr>
	</thead>
	<tbody id="tbody_writing_books" class="sort-holder">
		
		
	<% @writing_books.each do |writing_book| %>	
			
	<tr id="<%= dom_id writing_book %>" class="with_action">
		<td><%= writing_book.year %></td>
		<td>
		<%= link_to writing_book.create_link, panel_personal_book_front_end_writing_book_path(writing_book) %>
		</td>
	</tr>		
		
	<% end %>	
		
		
	</tbody>
</table>

<div class="form-actions form-fixed pagination-right">
	<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('announcement.add_new'), new_panel_personal_book_plugin_writing_book_path, :class => 'btn btn-primary pull-right' %>
	<div id="writing_book_pagination" class="paginationFixed">
	<%= paginate @writing_books, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>
	</div>
</div>
