dev_local
cxt 6 years ago
parent 4f5bbbd86d
commit 1846687675

@ -149,11 +149,14 @@ class ExerciseController < ApplicationController
end
@shixuns = Shixun.where("status = 2 and challenges_count = 1 and id not in (#{none_shixun_ids.join(",")})").
where("name like ?", "%#{search}%").select{|shixun| shixun.challenges.where(:st => 1).count == 0}
@limit = 8
@limit = 10
@total_pages = (@shixuns.count / 10.0).ceil
@shixuns = paginateHelper @shixuns, @limit
respond_to do |format|
format.js
render json: exercise_shixun_json_data(@shixuns)
format.json {
render json: exercise_shixun_json_data(@shixuns)
}
end
end

@ -5,11 +5,13 @@ module ExerciseHelper
shixun_owner = shixun.owner.try(:show_name)
shixun_path = shixun_path(shixun)
shixun_level = shixun.shixun_level
owner_path = user_path(shixun.owner)
shixun.attributes.dup.except("gpid", "identifier", "major_id", "webssh", "homepage_show", "fork_from", "git_url",
"mirror_script_id", "repo_name", "pod_life").merge({
shixun_owner: shixun_owner,
shixun_level: shixun_level,
shixun_path: shixun_path
shixun_path: shixun_path,
owner_path: owner_path
})
end
end

@ -4,19 +4,19 @@
<tr>
<th>实训名称</th>
<th>创建者</th>
<th>学员数</th>
<th>级别</th>
</tr>
</thead>
<tbody class="selecshixun" onscroll="contentViewScroll">
<tbody class="over260" id="shixun_list_block">
<% @shixuns.each do |shixun| %>
<tr>
<td class="clearfix" style="padding-left: 20px">
<input name="shixun_exercise" type="checkbox" class="magic-checkbox" id="shixun_input_<%= shixun.id %>" value="<%= shixun.id %>">
<label style="top:2px" for="shixun_input_<%= shixun.id %>"></label>
<input name="shixun_exercise[]" type="checkbox" class="magic-checkbox" id="shixun_input_<%= shixun.id %>" value="<%= shixun.id %>">
<label style="top:2px" for="shixun_input_<%= shixun.id %>"></label>
<%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide mt3 ml20",:style=> "text-align:left", :target => "_blank" %>
</td>
<td><%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "edu-txt-w140 mt3 task-hide" %></td>
<td><%= shixun.myshixuns.count %></td>
<td><%= shixun.shixun_level %></td>
</tr>
<% end %>
</tbody>
@ -36,6 +36,55 @@
<!-- </div>-->
</div>
<script>
var i = 1; //设置当前页数
var msg_list_loading = false;
$(function() {
var totalpage = <%= @total_pages.to_i %>; //总页数,防止超过总页数继续滚动
var winH = $(window).height(); //页面可视区域高度
$("#shixun_list_block").scroll(function() {
if (i < totalpage) { // 当滚动的页数小于总页数的时候,继续加载
var pageH = $(document.body).height();
var scrollT = $(window).scrollTop(); //滚动条top
var aa = (pageH - winH - scrollT) / winH;
if ( ! msg_list_loading ){
if (aa < 0.01 ) {
getJson(i+1)
}
}
}
});
});
function getJson(page) {
var msg_list = $('#shixun_list_block');
if (msg_list.height() + msg_list[0].scrollTop >= msg_list[0].scrollHeight - 60) {
msg_list_loading = true;
$.getJSON("<%= choose_shixuns_exercise_path(@exercise) %>&page="+page, function(json) {
if (json) {
msg_list_loading = false;
var str = "";
$.each(json, function(index, array) {
console.log(array);
str = '<tr>' +
' <td class="clearfix" style="padding-left: 20px">' +
' <input name="shixun_exercise[]" type="checkbox" class="magic-checkbox" id="shixun_input_'+array["id"]+'" value="'+array["id"]+'">' +
' <label style="top:2px" for="shixun_input_'+array["id"]+'"></label>' +
' <a href="'+array["shixun_path"]+'" class="edu-info-dark task-hide mt3 ml20" style="text-align:left" target="_blank">'+array["name"]+'</a>' +
' </td>' +
' <td><a href="'+array["owner_path"]+'" class="edu-txt-w140 mt3 task-hide" target="_blank">'+array["shixun_owner"]+'</a></td>' +
' <td>'+array["shixun_level"]+'</td>' +
' </tr>';
$("#shixun_list_block").append(str);
});
i ++;
}
});
}
}
</script>
<script>
//滑动到底加载

@ -1717,10 +1717,9 @@ function copy_course(url){
}
function new_shixun_exercise(id){
if($("input[name='shixun_exercise']:checked").length == 0){
if($("input[name='shixun_exercise[]']:checked").length == 0){
$("#exercise_type_notice").show();
} else{
var type=$("input[name='shixun_exercise']:checked").val();
$("#shixun_exercise_question").submit();
hideModal();
}

Loading…
Cancel
Save