
<%= content_for(:header_tags) do %>
    <%= import_ke(enable_at:  true, prettify: false, init_activity: true) %>
    <%= javascript_include_tag 'blog' %>
<% end %>

<script type="text/javascript">
    $(function(){
        $("#RSide").removeAttr("id");
        $("#Container").css("width","1000px");
    });
</script>
<script>
    function expand_reply(container,btnid){
        var target = $(container).children();
        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();
        }
    }
    $(function() {
        //init_activity_KindEditor_data(<%= @article.id%>,null,"87%", "<%=@article.class.to_s%>");
        sd_create_editor_from_data(<%= @article.id%>,null,"100%", "<%=@article.class.to_s%>");
        showNormalImage('message_description_<%= @article.id %>');
    });
</script>
<div class="postRightContainer ml10" >
  <div class="postThemeContainer">
    <div class="postDetailPortrait">
      <%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %>
    </div>
    <div class="postThemeWrap">
      <% if User.current &&  @article.author.id == User.current.id%>
          <div class="homepagePostSetting" id="message_setting_<%= @article.id%>" >
            <ul>
              <li class="homepagePostSettingIcon">
                <ul class="homepagePostSettiongText">
                  <li>
                    <a class="postOptionLink " onclick="course_outline('<%= @course.id%>','Y')" >重设大纲</a>
                  </li>
                  <li>
                    <%= link_to(
                                '取消大纲',
                                {:controller => 'blog_comments',:action => 'destroy',:user_id=>BlogComment.find(@course.outline).author_id,:blog_id=>BlogComment.find(@course.outline).blog_id, :id => @course.outline,:course_id=>@course.id},
                                :method => :delete,
                                :data => {:confirm => '您确定要取消么？'},
                                :class => 'postOptionLink'
                        ) if User.current && User.current.id == @article.author.id %>
                  </li>
                </ul>
              </li>
            </ul>
          </div>
          <!--<div class="homepagePostSetting" id="message_setting_<%#= @article.id%>" >-->
            <!--<ul>-->
              <!--<li class="syllabusSettingIcon"  >-->
              <!--</li>-->
            <!--</ul>-->
          <!--</div>-->
          <!--<a class="syllabusSettingIcon fr" style="width: 100px" onclick="course_outline('<%= @course.id%>')" ><span class="f14 fontGrey2" style="padding-left: 20px">[设置大纲]</span>-->
          <!--</a>-->
      <%end%>
      <div class="postDetailTitle fl" style="width: 550px !important;">
        <a href="javascript:void(0);" class="f14 linkGrey4 fb"  style="overflow:hidden;">主题: <%= @article.title%></a>
      </div>
      <div class="cl"></div>

      <div class="postDetailCreater">
        <% if @article.try(:author).try(:realname) == ' ' %>
            <%= link_to @article.try(:author), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %>
        <% else %>
            <%= link_to @article.try(:author).try(:realname), user_path(@article.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %>
        <% end %>
      </div>
      <div class="postDetailDate mb5"><%= format_time( @article.created_on)%></div>
      <div class="cl"></div>
      <div class="homepagePostIntro memo-content upload_img break_word" id="message_description_<%= @article.id %>" style="word-break: break-all; word-wrap:break-word;margin-bottom: 0px !important;" >
        <%= @article.content.html_safe%>
      </div>
      <div class="cl"></div>
      <div class=" fl" style="width: 600px">
        <%#= link_to_attachments_course @topic, :author => false %>
        <% if @article.attachments.any?%>
            <% options = {:author => true, :deletable => false} %>
            <%= render :partial => 'blog_comments/attachments_links', :locals => {:attachments => @article.attachments, :options => options, :is_float => true} %>
        <% end %>
      </div>
    </div>
    <div class="cl"></div>
  </div>
  <div class="cl"></div>
  <% count=0 %>
  <% if @article.parent %>
      <% count=@article.parent.children.count%>
  <% else %>
      <% count=@article.children.count%>
  <% end %>
  <div class="homepagePostReply">
    <% unless count == 0  %>
        <div class="homepagePostReplyBanner">
          <div class="homepagePostReplyBannerCount">回复（<%=count %>）</div>
          <div class="homepagePostReplyBannerTime"></div>
          <!-- <div class="homepagePostReplyBannerMore">
        <%# if @reply_count > 2%>
           <a href="javascript:void(0);" class="replyGrey"  id="reply_btn_<%#= @topic.id%>" onclick="expand_reply('#reply_div_<%#= @topic.id %>','#reply_btn_<%#= @topic.id%>')" data-count="<%#= @reply_count %>" data-init="0" >点击展开更多回复</a>
        <%# end %>
      </div>-->
        </div>
        <div class="" id="reply_div_<%=  @article.id %>">
          <%@article.children.reorder('created_on desc').each_with_index  do |reply,i| %>
              <script type="text/javascript">
                  $(function(){
                      showNormalImage('reply_message_description_<%= reply.id %>');
                      autoUrl('reply_message_description_<%= reply.id %>');
                  });
              </script>
              <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(reply.author), :width => 33,:height => 33), user_path(reply.author) %>
                </div>
                <div class="homepagePostReplyDes">
                  <div class="homepagePostReplyPublisher">
                    <% if reply.try(:author).try(:realname) == ' ' %>
                        <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
                    <% else %>
                        <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %>
                    <% end %>
                  </div>
                  <div class="homepagePostReplyContent upload_img break_word" id="reply_message_description_<%= reply.id %>">
                    <%= reply.content.html_safe%>
                  </div>
                  <div style="margin-top: -7px; margin-bottom: 5px">
                    <%= format_time(reply.created_on) %>
                    <div class="fr" id="reply_edit_menu_<%= reply.id%>" style="display: none">
                      <%= link_to(
                                  l(:button_reply),
                                  {:controller => 'blog_comments',:action => 'quote',:user_id=>reply.author_id,:blog_id=>reply.blog_id, :id => reply.id,:course_id=>@course.id},
                                  :remote => true,
                                  :method => 'get',
                                  :class => 'fr newsBlue',
                                  :title => l(:button_reply)) if !@article.locked? && User.current.logged?  %>
                      <%= link_to(
                                  l(:button_delete),
                                  {:controller => 'blog_comments',:action => 'destroy',:user_id=>reply.author_id,:blog_id=>reply.blog_id, :id => reply.id,:course_id=>@course.id},
                                  :method => :delete,
                                  :class => 'fr newsGrey mr10',
                                  :data => {:confirm => l(:text_are_you_sure)},
                                  :title => l(:button_delete)
                          ) if reply.author.id == User.current.id %>
                    </div>
                  </div>
                  <p id="reply_message_<%= reply.id%>"></p>
                </div>
                <div class="cl"></div>
              </div>
          <% end %>
        </div>

    <% end %>
    <div class="cl"></div>
    <% if !@article.locked? && 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<%#= @article.id %>">-->
            <!--<%#= form_for :blog_comment, :url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id}, :html => {:multipart => true, :id => 'message_form'} do |f| %>-->
                <!--<input type="hidden" name="course_id" value="<%#= @course.id%>">-->
                <!--<%#= render :partial => 'blog_comments/reply_form', :locals => {:f => f,:user=>@user,:article=>@article} %>-->
                <!--<%#= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'canel_message_replay();', :class => " grey_btn fr c_white mt10 mr5" %>-->
                <!--<%#= link_to l(:button_submit), "javascript:void(0)", :onclick => 'submit_message_replay();', :class => "blue_btn fr c_white mt10", :style => "margin-right: 5px;" %>-->
            <!--<%# end %>-->
            <!--<div class="cl"></div>-->
          <!--</div>-->
        <!--</div>-->
        <div class="homepagePostReplyContainer borderBottomNone minHeight48">
          <div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= @article.id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@article.author_id), :alt => "用户头像" %></div>
          <div class="homepagePostReplyInputContainer" style="margin-top: 8px">
            <div nhname='new_message_<%= @article.id%>' style="display:none;">
              <%= form_for 'blog_comment',:url =>  {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id},:method => "post",:html => {:multipart => true, :id => 'message_form'} do |f|%>
                  <input type="hidden" name="course_id" value="<%= @course.id%>">
                <input type="hidden" name="blog_comment[title]" value="RE:<%= @article.title%>">
                  <input type="hidden" name="blog_comment[sticky]" value="0">
                  <input type="hidden" name="quote[quote]" value="">
                  <input type="hidden" name="blog_comment[locked]" value="0">
                  <div nhname='toolbar_container_<%= @article.id%>'></div>
                  <textarea placeholder="有问题或有建议，请直接给我留言吧！" style="display: none" nhname='new_message_textarea_<%= @article.id%>' name="blog_comment[content]"></textarea>
                  <a id="new_message_submit_btn_<%= @article.id%>" href="javascript:void(0)"  onclick="this.style.display='none'" class="blue_n_btn fr" style="display:none;margin-top:2px;">发送</a>
                  <div class="cl"></div>
                  <p nhname='contentmsg_<%= @article.id%>'></p>
              <% end%>
            </div>
            <div class="cl"></div>
          </div>
          <div class="cl"></div>
        </div>
    <% end %>
  </div>
</div>
<script type="text/javascript">
    $(function(){
        $("#message_description_<%= @article.id %> p,#message_description_<%= @article.id %> span,#message_description_<%= @article.id %> em").each(function(){
            var postContent = $(this).html();
            postContent = postContent.replace(/&nbsp;/g," ");
            postContent= postContent.replace(/ {2}/g,"&nbsp; ");
            postContent=postContent.replace(/&nbsp; &nbsp;/g,"&nbsp;&nbsp;&nbsp;");
            postContent=postContent.replace(/&nbsp;  /g,"&nbsp;&nbsp; ");
            $(this).html(postContent);
        });
        autoUrl('message_description_<%= @article.id %>');
    });
</script>