<% content_for :header_tags do %>
  <%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c"  %>
  <%= javascript_include_tag 'homework','baiduTemplate' %>
  <%= stylesheet_link_tag "/assets/codemirror/codemirror" %>
<% end %>
<script type="text/javascript">
    $(function(){
        $("#RSide").removeAttr("id");
        $("#Container").css("width","1000px");
    });
</script>
<!-- 模板1开始，可以使用script（type设置为text/html）来存放模板片段，并且用id标示 -->

<script id="t:result-list" type="text/html">
    <! if((tseq == tcount) ||(status == 2)||(status == -2)){ !>
        <div class="ProResultTop">
          <p class="c_blue fl">第<!=index!>次测试</p><span class="fr c_grey"><!= time !></span>
          <div class="cl"></div>
        </div>
    <!}!>

    <! if(status == -2){!>
      <div class="ProResultCon "><pre style="white-space: pre-wrap;"><!= error_msg !></pre></div>
    <!}else{!>
      <div class="ProResultTable  ">
        <ul class="ProResultUl " >
            <li ><span class="w60 T_C">测试<!=tseq!></span>
            <! if(results["status"]!=0){ !>
                <! if(results["status"]==2){!>
                    <span class="w60 c_red">超时！</span>
                <!}else{!>
                    <span class="w60 c_red">测试错误！</span>
                <!}!>
                <span class="w60">您的输出：</span>
                <span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><!=results["result"]!> </pre></span>
                <span class="w60">正确输出：</span>
                <span  class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><!=results["output"]!></pre></span>
                <!--<! if(results["status"]==2){!>-->
                    <span class="w50">　耗时：</span>
                    <span class="w80"><pre><!=results["time_used"]==0?1:results["time_used"]!>毫秒</pre></span>
                <!--<!}!>-->
                <div class="cl"></div>
            </li>
            <!}else{!>
                <span class="w60 c_green">测试正确！</span>
                <span style="width:480px;">&nbsp;</span>
                <span class="w50">　耗时：</span>
                <span class="w80"><pre ><!=results["time_used"]==0?1:results["time_used"]!>毫秒</pre></span>

                <div class="cl"></div>
            </li>
            <!}!>
        </ul>
      </div>
    <! } !>
</script>
<!-- 模板1结束 -->

 <div class="ProgramHomework ml10">

      <div class="homepageRightBanner mb10">
      <div class="NewsBannerName"><%= @is_test ? '模拟答题' : '提交作品' %></div>
      </div>
      <div class="cl"></div>

      <div class="HomeWork">
        <div class="HomeWorkBox">
          <div class="">
              <div class="homepagePostTitle fl">
                <%= @homework.name %>
              </div>
            <span class="fr c_grey">
              截止时间：<%= @homework.end_time %>
            </span>
            <div class="cl"></div>
            <a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
            <p class="HomeWorkP">
              <%= @homework.description.html_safe %>
            </p>
            </div>
            <!--p class="c_grey mt15">注：迟交扣<span class="c_red">2</span>分，缺评一个作品扣<span class="c_red">2</span>分</p-->
        </div><!---HomeWorkBox end  -->
        <div class="HomeWorkCon">
        <%= form_for(@student_work,
                   :html => { :multipart => true },
                   :url => {:controller => 'users',
                            :action => 'user_commit_homework',
                            :student_work_id => @student_work.id,
                            :homework => @homework.id
                   },
                   :method => :post) do |f|%>
          <input type="hidden" name="is_test" value="<%=@is_test%>">
          <div class="mt15">
            <span>请使用 <%= @homework.language_name %> 语言编写</span>
            <% if @homework.language.to_i == 1 %>
                <span class = "fr">编译器信息：gcc version "4.4.7" 20120313 (Red Hat 4.4.7-11) (GCC)</span>
            <% elsif @homework.language.to_i == 2 %>
                <span class = "fr">编译器信息：gcc version "4.4.7" 20120313 (Red Hat 4.4.7-11) (GCC)</span>
            <% elsif @homework.language.to_i == 3 %>
                <span class = "fr">编译器信息：Python version "2.6.6"</span>
            <% elsif @homework.language.to_i == 4 %>
                <span class = "fr">编译器信息：java version "1.7.0_85" OpenJDK Runtime Environment</span>
            <% end %>
            <span data-language=<%=@homework.language%> style="display-hidden" id="data-language"></span>
            </div>
            <div class="mt10">
              <%= f.text_area :name, id: 'program-title', class:"InputBox  W700", placeholder:"请概括你的代码的功能", value:"#{@homework.name}的作品提交" %>
            </div>
            <div class="mt10">
            <%= f.text_area :description, id: 'program-src', class:"InputBox W700 H150", placeholder:"请贴入你的代码", rows: 10 %>
              <script>
                  var text = document.getElementById("program-src");
                  autoTextarea(text);// 调用
              </script>
            </div>
            <div class="mt10">
              <a href="javascript:void(0);" class="BlueCirBtn fl" data-homework-id="<%=@homework.id%>" data-student-work-id="<%=@student_work.id%>" id="test-program-btn">测试代码</a>
              <% if @is_test %>
                <%=link_to '返  回',homework_common_index_path(:course => @course.id),:class=>'fr mt6',:style =>'line-height:30px;' %>
              <% else @is_test %>
                <a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a>
              <% end %>
                <div class="cl"></div>
            </div>
        <% end %>
        </div><!----HomeWorkCon end-->
      </div><!----HomeWork end-->

      <div class="cl"></div>
      <div class="ProResult mt10">

        <% @student_work.student_work_tests.each_with_index do |test, index| %>
          <div class="ProResultTop">
             <p class="c_blue fl">
               第<%= @student_work.student_work_tests.count - index%>次测试
             </p>
            <span class="fr c_grey"><%= format_time(test.created_at).to_s%></span>
               <div class="cl"></div>
          </div>
          <% if test.status.to_i == -2 %>
            <div class="ProResultCon"><pre><%= test.results.first %></pre></div>
          <% else %>
            <div class="ProResultTable " >
              <ul class="ProResultUl " >
              <% test.results.reverse.each_with_index do |x, i| %>
                <% unless x.nil? %>
                  <li ><span class="w60 T_C">测试<%=test.results.size-i%></span>
                  <% if x["status"].to_i != 0 %>
                    <% if x["status"].to_i == 2 %>
                        <span class="w60 c_red">超时！</span>
                    <% else %>
                      <span class="w60 c_red">测试错误！</span>
                    <% end %>
                    <span class="w60">您的输出：</span>
                    <span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["result"].force_encoding("UTF-8")%> </pre></span>
                    <span class="w60">正确输出：</span>
                    <span  class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%= x["output"].force_encoding("UTF-8") %></pre></span>

                        <span class="w50">　耗时：</span>
                        <span class="w80"><pre><%=x["time_used"]==0?1:x["time_used"]%>毫秒</pre></span>

                    <div class="cl"></div>
                  </li>
                  <% else %>
                    <span class="w60 c_green">测试正确！</span>
                     <span style="width:480px;">&nbsp;</span>
                     <span class="w50">　耗时：</span>
                     <span class="w80"><pre><%=x["time_used"]==0?1:x["time_used"]%>毫秒</pre></span>
                    <div class="cl"></div>
                  </li>
                  <% end %>
                <% end %>
              <% end %>
             </ul>
            </div>
          <% end %>
        <% end %>
      </div><!----ProResult end-->
    </div><!--homepageRight end-->