diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 85bd6a784..d20a58b75 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -125,16 +125,18 @@ class SchoolController < ApplicationController end end if(condition == '') - @school = School.all + @school = School.page((params[:page].to_i || 1) - 1).per(100) + @school_count = School.count else - @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").all + @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").page((params[:page].to_i || 1) - 1).per(100) + @school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count end result = [] # @school.each do |sc| # result << {:value=>sc.name,:data=>sc.id} # end - render :json => @school.to_json + render :json =>{ :schools => @school,:count=>@school_count}.to_json end #添加学校 diff --git a/app/models/course.rb b/app/models/course.rb index 46599dbfc..a583990c1 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -50,6 +50,8 @@ class Course < ActiveRecord::Base validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]+$/ validates_length_of :description, :maximum => 10000 before_save :self_validate + # 公开课程变成私有课程,所有资源都变成私有 + after_update :update_files_public after_create :create_board_sync, :act_as_course_activity, :act_as_course_message before_destroy :delete_all_members @@ -213,6 +215,14 @@ class Course < ActiveRecord::Base end + def update_files_public + unless self.is_public? + self.attachments.each do |a| + a.update_attributes(:is_public => false) + end + end + end + # 创建课程讨论区 def create_board_sync @board = self.boards.build diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb index c2c8d2d10..4c631d22f 100644 --- a/app/views/files/_attachement_list.html.erb +++ b/app/views/files/_attachement_list.html.erb @@ -23,23 +23,44 @@ <% checkBox = (@course.present? && @course.is_public?) ? 'public' : 'private'%> -<%= file_field_tag 'attachments[dummy][file]', - :id => '_file', - :class => ie8? ? '':'file_selector', - :multiple => true, - :onchange => 'addInputFiles(this,"'+ checkBox.to_s+'");', - :style => ie8? ? '': 'display:none', - :data => { - :max_file_size => Setting.attachment_max_size.to_i.kilobytes, - :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), - :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, - :upload_path => uploads_path(:format => 'js'), - :description_placeholder => l(:label_optional_description), - :field_is_public => l(:field_is_public), - :are_you_sure => l(:text_are_you_sure), - :file_count => l(:label_file_count), - :delete_all_files => l(:text_are_you_sure_all) - } %> +<% if @course %> + <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => ie8? ? '':'file_selector', + :multiple => true, + :onchange => 'addInputFilesCourseSource(this,"'+ checkBox.to_s+'");', + :style => ie8? ? '': 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description), + :field_is_public => l(:field_is_public), + :are_you_sure => l(:text_are_you_sure), + :file_count => l(:label_file_count), + :delete_all_files => l(:text_are_you_sure_all) + } %> +<% else %> + <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => ie8? ? '':'file_selector', + :multiple => true, + :onchange => 'addInputFiles(this);', + :style => ie8? ? '': 'display:none', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description), + :field_is_public => l(:field_is_public), + :are_you_sure => l(:text_are_you_sure), + :file_count => l(:label_file_count), + :delete_all_files => l(:text_are_you_sure_all) + } %> +<% end %> + diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 3c6d545db..4cc249c20 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -39,7 +39,7 @@ <% else %> - 私有 + 私有 <% end %> diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 4a2fe446d..0531ea9e7 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -542,19 +542,41 @@ }); } var lastSearchCondition = ''; + var page = 1; //唯一控制页码 变量 + var count = 0; //查询结果的总量 + var maxPage = 0 ;//最大页面值 $(function() { -// $("input[name='province']").keydown(function(e){ -// if(e.keyCode == 13 && $("#search_school_result_list").css('display') == 'block'){ -// str = $("#search_school_result_list").children().eq(0).attr('onclick').match(/\(.*\)/)[0] -// -// str = str.replace(/\(/,'').replace(/\)/,''); -// arr = str.split(','); -// id = arr[1].replace(/\'/,'') -// name = arr.replace(/\'/,'') -// changeValue(name,id); -// return false; -// } -// }); + $("#search_school_result_list").scroll(function(e){ + nScrollHight = $(this)[0].scrollHeight; + nScrollTop = $(this)[0].scrollTop; + var nDivHight = $(this).height(); + if(nScrollTop + nDivHight >= nScrollHight) //到底部了, + { + //判断页码是否是最大值,如果是的,就不去请求了 + if(page >= maxPage){ + return; + }else{ //如果不是,那就请求下一页,请求数据处理 + page ++; + $.ajax({ + url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + $("input[name='province']").val() + '&page=' + page, + type: 'post', + success: function (data) { + schoolsResult = data.schools; + if (schoolsResult.length != undefined && schoolsResult.length != 0) { + var i = 0; + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].school.name + '
'; + $("#search_school_result_list").append(link); + } + } else { + + } + } + }); + } + + } + }); //查询学校 $("input[name='province']").on('input', function (e) { throttle(shcool_search_fn,window,e); @@ -568,20 +590,25 @@ } function shcool_search_fn(e){ - $("input[name='occupation']").val(''); //一旦有输入就清空id。 - if($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != ''){ + + if($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != ''){//如果输入框没有改变或者输入框为空就返回 return; } + $("input[name='occupation']").val(''); //一旦有输入就清空id。 lastSearchCondition = $(e.target).val().trim(); + page = 1; //有新的搜索,页面重置为1 $.ajax({ - url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, + url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value+'&page='+page, type: 'post', success: function (data) { - if(data.length != undefined && data.length != 0) { + schoolsResult = data.schools; + count = data.count; + maxPage = count % 100 + 1; //最大页码值 + if(schoolsResult.length != undefined && schoolsResult.length != 0) { var i = 0; $("#search_school_result_list").html(''); - for (; i < data.length; i++) { - link = '' + data[i].school.name + '
'; + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].school.name + '
'; $("#search_school_result_list").append(link); } $("#search_school_result_list").css('left', $(e.target).offset().left); @@ -590,7 +617,7 @@ $("#search_school_result_list").show(); if($(e.target).val().trim() != '') { str = e.target.value.length > 8 ? e.target.value.substr(0, 6)+"..." : e.target.value; - $("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校'); + $("#hint").html('找到了' + count + '个包含"' + str + '"的高校'); $("#hint").show(); }else{ $("#hint").hide(); @@ -610,45 +637,46 @@ $("#search_school_result_list").hide(); $("#hint").hide(); } - }) - $("input[name='province']").on('focus', function (e) { - if($(e.target).val() == ''){ // - return; - } - if( $("input[name='occupation']").val() != ''){ //如果已经有id了。肯定存在,不用去找了。 - return; - } - $.ajax({ - url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, - type: 'post', - success: function (data) { - if(data.length != undefined && data.length != 0) { - var i = 0; - $("#search_school_result_list").html(''); - for (; i < data.length; i++) { - link = '' + data[i].school.name + '
'; - $("#search_school_result_list").append(link); - } - $("#search_school_result_list").css('left', $(e.target).offset().left); - $("#search_school_result_list").css('top', $(e.target).offset().top + 28); - $("#search_school_result_list").css("position", "absolute"); - $("#search_school_result_list").show(); - if ($(e.target).val().trim() != '') { - str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; - $("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校'); - $("#hint").show(); - } else { - $("#hint").hide(); - } - }else { - $("#search_school_result_list").html(''); - str = e.target.value.length > 4 ? e.target.value.substr(0, 4)+"..." : e.target.value; - $("#hint").html('没有找到包含"'+str+'"的高校,创建高校'); - $("#hint").show(); - } - } - }); }); +// $("input[name='province']").on('focus', function (e) { +// if($(e.target).val() == ''){ // +// return; +// } +// if( $("input[name='occupation']").val() != ''){ //如果已经有id了。肯定存在,不用去找了。 +// return; +// } +// +// $.ajax({ +// url: '<%#= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, +// type: 'post', +// success: function (data) { +// if(data.length != undefined && data.length != 0) { +// var i = 0; +// $("#search_school_result_list").html(''); +// for (; i < data.length; i++) { +// link = '' + data[i].school.name + '
'; +// $("#search_school_result_list").append(link); +// } +// $("#search_school_result_list").css('left', $(e.target).offset().left); +// $("#search_school_result_list").css('top', $(e.target).offset().top + 28); +// $("#search_school_result_list").css("position", "absolute"); +// $("#search_school_result_list").show(); +// if ($(e.target).val().trim() != '') { +// str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; +// $("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校'); +// $("#hint").show(); +// } else { +// $("#hint").hide(); +// } +// }else { +// $("#search_school_result_list").html(''); +// str = e.target.value.length > 4 ? e.target.value.substr(0, 4)+"..." : e.target.value; +// $("#hint").html('没有找到包含"'+str+'"的高校,创建高校'); +// $("#hint").show(); +// } +// } +// }); +// }); // $("#province").leanModal({top: 100, closeButton: ".modal_close"}); diff --git a/app/views/school/upload_logo.html.erb b/app/views/school/upload_logo.html.erb index 96b577f46..01071fb81 100644 --- a/app/views/school/upload_logo.html.erb +++ b/app/views/school/upload_logo.html.erb @@ -61,7 +61,7 @@ function showPreview(source) {
- + <%#= submit_tag('提交',:class=>'mr5') %> <%#= submit_tag('取消') %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index 7f535f2ec..6c22976fd 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -44,10 +44,18 @@ ">发布了课程作业:
  • - <%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %>
  • + <% if !User.current.allowed_to?(:as_teacher, ma.course_message.course) && cur_user_works_for_homework(ma.course_message).nil? %> + <%= link_to ma.course_message.name, new_student_work_path(:homework => ma.course_message.id), + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover =>"message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> + <% else %> + <%= link_to ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), + :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", + :onmouseover => "message_titile_show($(this),event)", + :onmouseout => "message_titile_hide($(this))" %> + <% end %> +
  • <%= time_tag(ma.created_at).html_safe %>
  • @@ -201,7 +209,7 @@

    失败原因:提交作品的人数低于2人

    作业详情如下:

    -

    课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.term %>)

    +

    课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.time.to_s + '年' + ma.course_message.course.term %>)

    作业标题:<%= ma.course_message.name %>

    提交截止:<%= ma.course_message.end_time%>  24点 @@ -288,7 +296,11 @@ :onmouseover =>"message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %>