PageRenderTime 28ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/app/views/user/notes/_question_with_answer.erb

https://github.com/lifang/gankao
Ruby HTML | 147 lines | 137 code | 5 blank | 5 comment | 36 complexity | dac05fce8f350d86cb7e59cf4fdf99ee MD5 | raw file
  1. <div class="part_div">
  2. <div class="part_question">
  3. <% unless question_with_answer[1].elements['title'].nil? or question_with_answer[1].elements['title'].text.nil? or question_with_answer[1].elements['title'].text == "" %>
  4. <% if question_with_answer[1].elements['title'].text.length > 250 %>
  5. <div class="chank_yw"><a href="javascript:void(0);" onclick="openwindow(<%= question_with_answer[0].attributes["id"] %>);">查看全文</a></div>
  6. <% end %>
  7. <div class="part_q_text part_q_sl">
  8. <% title = question_with_answer[1].elements["title"].text
  9. if title.length > 250 %>
  10. <div class="question_text_div">
  11. <% if title =~ /<mp3>/ %>
  12. <%= truncate_u(title.split("<mp3>")[0].to_s.html_safe.gsub(/<[^{><}]*>/, ""), 180, "......").to_s.html_safe %>
  13. <% else %>
  14. <%= truncate_u(title.to_s.html_safe.gsub(/<[^{><}]*>/, ""), 180, "......").to_s.html_safe %>
  15. <% end %>
  16. </div>
  17. <% else
  18. if title =~ /<mp3>/ %>
  19. <div class="question_text_div" style="word-wrap:break-word; word-break:break-all;">
  20. <%= title.split("<mp3>")[0].to_s.html_safe %>
  21. </div>
  22. <div id="mp3_<%= question_with_answer[0].attributes["id"] %>">
  23. <input type="hidden" id="mp3_value_<%= question_with_answer[0].attributes["id"] %>"
  24. value="<%= Constant::BACK_SERVER_PATH %><%= title.split("<mp3>")[1] %>" />
  25. </div>
  26. <% else %>
  27. <div class="question_text_div" style="word-wrap:break-word; word-break:break-all;">
  28. <%= title.to_s.html_safe %>
  29. </div>
  30. <% end
  31. end %>
  32. <div style="display:none;" id="title_<%= question_with_answer[0].attributes["id"] %>">
  33. <%= question_with_answer[1].elements["title"].text.to_s.html_safe %>
  34. </div>
  35. <%= render :partial=>"/common/more_blanks", :object=> question_with_answer[1] %>
  36. </div>
  37. <% end %>
  38. <!--题目内容-->
  39. <% attrs_str = question_with_answer[0].elements["questionattrs"].text
  40. attrs_array = attrs_str.split(";-;") unless attrs_str.nil?
  41. correct_type = question_with_answer[0].attributes["correct_type"]
  42. answer = question_with_answer[0].elements["answer"]
  43. answers = []
  44. answer.text.split(";|;").collect { |item| answers << item.strip } unless answer.nil? or answer.text.nil?
  45. user_answer = question_with_answer[0].elements["user_answer"]
  46. user_answers = []
  47. user_answer.text.split(";|;").collect {|item| user_answers << item.strip } unless user_answer.nil? or user_answer.text.nil?
  48. is_right = false
  49. all_answer = answers | user_answers
  50. is_right = true if all_answer == answers and answers - user_answers == [] %>
  51. <div class="p_question_list <% if is_right %>question_yes<% else %>question_no<% end %>">
  52. <!--[if IE 6]><table><tr><td valign="top"><![endif]-->
  53. <div class="p_q_l_left"></div>
  54. <!--[if IE 6]></td><td><![endif]-->
  55. <div class="p_q_l_right_s">
  56. <% unless question_with_answer[0].elements["description"].nil? or question_with_answer[0].elements['description'].text.nil? or
  57. question_with_answer[0].elements['description'].text == "" %>
  58. <% if correct_type.to_i == Problem::QUESTION_TYPE[:MORE_BLANKS] %>
  59. <div class="q_drag_con" style="word-wrap:break-word; word-break:break-all;">
  60. <p><%= question_with_answer[0].elements["description"].text.to_s.html_safe.
  61. gsub("problem_x_dropplace", "problem_#{question_with_answer[0].attributes["id"]}_dropplace") %>
  62. </p>
  63. <script type="text/javascript">
  64. droppable_result('<%= answers.join(",") %>', '<%= user_answers.join(",") %>', <%= question_with_answer[0].attributes["id"] %>);
  65. </script>
  66. </div>
  67. <% else %>
  68. <div class="question_title" style="word-wrap:break-word; word-break:break-all;">
  69. <%= question_with_answer[0].elements["description"].text.to_s.html_safe %>
  70. </div>
  71. <% end %>
  72. <% end %>
  73. <% if (correct_type.to_i == Problem::QUESTION_TYPE[:MORE_CHOSE] or
  74. correct_type.to_i == Problem::QUESTION_TYPE[:SINGLE_CHOSE]) %>
  75. <ul class="chooseQuestion">
  76. <% (0..attrs_array.length-1).each do |i|
  77. is_answer = answers.include?(attrs_array[i].strip)
  78. is_user_answer=user_answers.include?(attrs_array[i].strip) %>
  79. <li <% if is_answer %> class="correctRight_bg" <% end %>>
  80. <% if correct_type.to_i == Problem::QUESTION_TYPE[:MORE_CHOSE] %>
  81. <input type="checkbox" disabled name="question_attr_<%= question_with_answer[0].attributes["id"].to_i %>"
  82. id="question_attr_<%= i %>" <% if is_user_answer %>checked="true"<% end %> />
  83. <% elsif correct_type.to_i == Problem::QUESTION_TYPE[:SINGLE_CHOSE] %>
  84. <input type="radio" disabled name="question_attr_<%= question_with_answer[0].attributes["id"].to_i %>"
  85. id="question_attr_<%= i %>" <% if is_user_answer %>checked="true"<% end %> />
  86. <% end %>
  87. &nbsp;&nbsp;<%= attrs_array[i] %>
  88. </li>
  89. <% end if attrs_array and attrs_array.any? %>
  90. </ul>
  91. <% elsif correct_type.to_i == Problem::QUESTION_TYPE[:JUDGE] %>
  92. <ul class="chooseQuestion">
  93. <li <% if answers[0].to_i==1 %>class="correctRight_bg"<% end %>>
  94. <input type="radio"<% if user_answer==1.to_s %> checked="true"<% end %> disabled /><label></label>
  95. </li>
  96. <li <% if answers[0].to_i==0 %>class="correctRight_bg"<% end %>>
  97. <input type="radio" <% if user_answer==0.to_s %> checked="true"<% end %> disabled /><label></label>
  98. </li>
  99. </ul>
  100. <% elsif correct_type.to_i == Problem::QUESTION_TYPE[:SINGLE_CALK] %>
  101. <div class="answer_text">
  102. <% height = "22px"
  103. width = "110px"
  104. if user_answers[0].to_s.length > 20 and user_answers[0].to_s.length <= 28
  105. width = (user_answers[0].to_s.length * 10).to_s + "px"
  106. elsif user_answers[0].to_s.length > 28
  107. width = "95%"
  108. if user_answers[0].to_s.length > 30
  109. height = (22 * (user_answers[0].to_s.length/30 + 1)).to_s + "px"
  110. end
  111. end
  112. %>
  113. <textarea disabled cols="" rows=""
  114. style="width:<%= width %>; height:<%= height %>;"><%= user_answers[0].to_s %></textarea>
  115. </div>
  116. <% elsif correct_type.to_i == Problem::QUESTION_TYPE[:CHARACTER] %>
  117. <div class="answer_textarea">
  118. <textarea disabled cols="" rows=""><%= user_answers[0].to_s %></textarea>
  119. </div>
  120. <% elsif correct_type.to_i == Problem::QUESTION_TYPE[:MORE_BLANKS] %>
  121. <div class="answer_text">
  122. <textarea disabled cols="" rows="" style="width:50%;height:24px;"><%= user_answers[0].to_s %></textarea>
  123. </div>
  124. <% end %>
  125. </div>
  126. <!--[if IE 6]> </td></tr></table><![endif]-->
  127. <div class="clear"></div>
  128. </div>
  129. </div>
  130. </div>
  131. <div style="display:none;"
  132. id="user_answers_<%= question_with_answer[0].attributes["id"] %>"><%= user_answers.join(",") %></div>
  133. <!--答案-->
  134. <div class="nb_r_daan">
  135. <h3><%= correct_type.to_i == Problem::QUESTION_TYPE[:CHARACTER] ? "参考答案:" : "正确答案:" %>
  136. <span id="answer_<%= question_with_answer[0].attributes["id"] %>"><%= answers.join("<br/>").to_s.html_safe %></span>
  137. </h3>
  138. <% analysis = question_with_answer[0].elements["analysis"] %>
  139. <% unless analysis.nil? or analysis.text.nil? or analysis.text == "" %>
  140. <p>解析<%= analysis.text.to_s.html_safe %></p>
  141. <% end %>
  142. </div>