<div class="box admin-list-container users-list-container">
  <table class="table table-hover users-list-table">
  <thead class="thead-light">
    <tr>
      <th width="9%">序号</th>
      <th width="15%">作者</th>
      <th width="32%" class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">标题</th>
      <th width="18%">发布时间<i class="fa fa-long-arrow-down %> color-light-green ml5"></i></th>
      <th>回复数</th>
      <th width="18%">操作</th>
    </tr>
  </thead>
  <tbody>
     <% @memos.each_with_index do |memo,index| %>
    <tr id="apply_destroy_memo_<%= memo.id %>">
      <td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
      <td>
        <%= link_to(memo.try(:author).try(:show_real_name), "/users/#{memo.author.login}", target: "_blank") %>
      </td>
      <td class="edu-txt-left" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
        <%= link_to(memo.subject, "/forums/#{memo.id}/detail", target: "_blank") %>
      </td>
      <td><%= format_time(memo.created_at) %></td>
      <td>
        <%= link_to(memo.replies_count, "/forums/#{memo.id}/detail", target: "_blank") %>
      </td>
      <td>
      <%= link_to '拒绝', confirm_apply_destroy_admins_apply_destroy_index_path(id: memo.id, confirm: "reject"), method: :post, remote: true, data: {confirm: "拒绝删除该帖子吗？"} %>
      <%= link_to '同意', confirm_apply_destroy_admins_apply_destroy_index_path(id: memo.id, confirm: "delete"), method: :post, remote: true, data: {confirm: "确认删除该帖子吗？"} %>
      </td>
    </tr>
    <% end %>
  </tbody>
</table>
</div>

<%= render partial: 'admins/shared/paginate', locals: { objects: @memos } %>
<script>
  $(".magic-checkbox").on("click", function() {
    var $link = $(this);

    var id = $link.data('id');
    var url = $link.data('url');
    var checked = $link.is(':checked');

    $.ajax({
      url: url,
      type: 'post',
      data: {
        id: id,
        checked: checked
      },
      dataType: 'json',
      success: function(data) {
        if ($link.data('type') === 'hidden') {
          console.log('#home_show_' + id, !checked);
          $('#home_show_' + id).attr('disabled', !checked);
          if (checked) {
            $('.delete-link-' + id).hide();
          } else {
            $('.delete-link-' + id).show();
          }
        }
      },
      error: function() {
        notice_box('操作失败');
        $link.attr('checked', !checked);
      }
    })
  });
</script>