<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg',"init_activity_KindEditor",'blog' %>
<script>
    $(function() {
        init_activity_KindEditor_data(<%= @document.id%>,null,"85%");
        showNormalImage('message_description_<%= @document.id %>');
    });
</script>
<div class="resources mt10" id="organization_document_<%= @document.id %>">
  <div class="homepagePostBrief">
    <div class="homepagePostPortrait">
      <%= link_to image_tag(url_to_avatar(User.find(@document.creator_id)), :width => 45, :heigth => 45), user_path(@document.creator_id) %>
    </div>
    <div class="homepagePostDes">
      <div class="homepagePostTo">
        <%= link_to User.find(@document.creator_id), user_path(@document.creator.id), :class => "newsBlue mr15" %>
        TO&nbsp;&nbsp;<%= link_to @document.organization.name, organization_path(@document.organization), :class => "newsBlue" %>
        |
        <% if @document.organization.home_id == @document.id %>
            <span style="color:#269ac9;">首页</span>
        <% else %>
            <span style="color:#269ac9;">组织文章</span>
        <% end %>
      </div>
      <div class="homepagePostTitle postGrey"><%= link_to @document.title, org_document_comment_path(:id => @document.id, :organization_id => @document.organization.id) %></div>
      <div class="homepagePostDate">
        发布时间：<%= format_activity_day(@document.created_at) %> <%= format_time(@document.created_at, false) %></div>
      <% unless @document.content.blank? %>
          <div class="homepagePostIntro">
            <%= @document.content.html_safe %>
          </div>
      <% end %>
      <!--    <%# if defined?(home_id) %>
        <div style="float:right;">最后编辑：<%#= User.find() %></div>
    <%# end %>-->
      <% if User.current.admin? || User.current.admin_of_org?(Organization.find(@document.organization_id) || User.current.id == @document.creator_id) %>
          <div class="homepagePostSetting">
            <ul>
              <li class="homepagePostSettingIcon">
                <ul class="homepagePostSettiongText">
                  <li>
                    <%= form_for('new_form', :url => {:controller => 'organizations', :action => 'set_homepage', :id => @document.organization_id, :home_id => @document.id}, :method => "put", :remote => true) do |f| %>
                        <a href="javascript:void(0);" class="postOptionLink" onclick="$(this).parent().submit();">设为首页</a>
                    <% end %>
                  </li>
                  <li>
                    <%= link_to "编辑文章", edit_org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id, :flag => 1), :class => "postOptionLink" %>
                  </li>
                  <li>
                    <%= link_to "删除文章", org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id), :method => 'delete',
                                :data => {:confirm => l(:text_are_you_sure)},
                                :remote => true, :class => 'postOptionLink' %>
                  </li>
                </ul>
              </li>
            </ul>
          </div>
          <div class="cl"></div>
      <% end %>
    </div>
  </div>
  <% comments_for_doc = @document.children.reorder("created_at desc") %>
  <% count = @document.children.count() %>

  <div class="homepagePostReply fl" style="background-color: #f1f1f1;" id="<%= @document.id %>">
    <% if count > 0 %>
        <div class="homepagePostReplyBanner">
          <div class="homepagePostReplyBannerCount">回复（<%= count %>）</div>
        </div>
        <div class="" id="reply_div_<%=  @document.id %>">
          <% comments_for_doc.each_with_index  do |reply,i| %>
              <script type="text/javascript">
                  $(function(){
                      showNormalImage('reply_message_description_<%= reply.id %>');
                  });
              </script>
              <% user = User.find(reply.creator_id) %>
              <div class="homepagePostReplyContainer" onmouseover="$('#reply_edit_menu_<%= reply.id%>').show();" onmouseout="$('#reply_edit_menu_<%= reply.id %>').hide();">
                <div class="homepagePostReplyPortrait">
                  <%= link_to image_tag(url_to_avatar(user), :width => 33,:height => 33), user_path(user) %>
                </div>
                <div class="homepagePostReplyDes">
                  <%= link_to User.find(reply.creator_id).realname, user_path(reply.creator_id), :class => "newsBlue mr10 f14" %>
                  <div class="homepagePostReplyContent upload_img break_word" id="reply_message_description_<%= reply.id %>">
                    <%= reply.content.html_safe unless reply.content.nil? %>
                  </div>
                  <div style="margin-top: -7px; margin-bottom: 5px">
                    <%= format_time(reply.created_at) %>
                    <div class="fr" id="reply_edit_menu_<%= reply.id%>" style="display: none">
                      <%= link_to(
                                  l(:button_reply),
                                  {:controller => 'org_document_comments',:action => 'quote',:user_id=>reply.creator_id, :id => reply.id},
                                  :remote => true,
                                  :method => 'get',
                                  :class => 'fr newsBlue',
                                  :title => l(:button_reply)) if User.current.logged? %>
                      <%= link_to(
                                  l(:button_delete),
                                  {:controller => 'org_document_comments',:action => 'delete_reply', :id => reply.id},
                                  :method => :delete,
                                  :class => 'fr newsGrey mr10',
                                  :data => {:confirm => l(:text_are_you_sure)},
                                  :title => l(:button_delete)
                          ) if reply.creator_id == User.current.id %>
                    </div>
                  </div>
                  <p id="reply_message_<%= reply.id %>"></p>
                </div>
                <div class="cl"></div>
              </div>
          <% end %>
        </div>
        <div class="cl"></div>
    <% end %>
    <% if User.current.logged?%>
        <div class="talkWrapMsg" nhname="about_talk_reply">
          <em class="talkWrapArrow"></em>
          <div class="cl"></div>
          <div class="talkConIpt ml5 mb10" id="reply<%= @document.id %>">
            <%= form_for :org_comment, :url => {:action => 'add_reply_in_doc',:controller => 'org_document_comments', :id => @document.id}, :html => {:multipart => true, :id => 'message_form'} do |f| %>
               <%= f.kindeditor :org_content,:width=>'99%',:height => '100px;',:editor_id=>'message_content_editor' %>
                <%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'message_content_editor.html("");', :class => " grey_btn fr c_white mt10 mr5" %>
                <%= link_to l(:button_reply), "javascript:void(0)", :onclick => "message_content_editor.sync();$('#message_form').submit();", :class => "blue_btn fr c_white mt10 mb10", :style => "margin-right: 5px;" %>
            <% end %>
            <div class="cl"></div>
          </div>
        </div>
    <% end %>
  </div>
</div>

<script type="text/javascript">
    function expand_reply(container, btnid) {
        var target = $(container);
        var btn = $(btnid);
        if (btn.data('init') == '0') {
            btn.data('init', 1);
            btn.html('收起回复');
            target.show();
        } else {
            btn.data('init', 0);
            btn.html('展开更多');
            target.hide();
            target.eq(0).show();
            target.eq(1).show();
            target.eq(2).show();
        }
    }
</script>