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/attachment.rb b/app/models/attachment.rb index 0f728fc00..f7fb9b1aa 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -442,12 +442,7 @@ class Attachment < ActiveRecord::Base def self.attach_filesex(obj, attachments,attachment_type) - if obj.is_public? - public_status = true - else - public_status = false - end - result = obj.save_attachmentsex(attachments, User.current,attachment_type, public_status) + result = obj.save_attachmentsex(attachments, User.current,attachment_type) obj.attach_saved_attachments result end diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb index 50d14b7ee..c2c8d2d10 100644 --- a/app/views/files/_attachement_list.html.erb +++ b/app/views/files/_attachement_list.html.erb @@ -21,13 +21,13 @@ <% end %> - +<% 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);', + :onchange => 'addInputFiles(this,"'+ checkBox.to_s+'");', :style => ie8? ? '': 'display:none', :data => { :max_file_size => Setting.attachment_max_size.to_i.kilobytes, 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/db/migrate/20151020013352_update_attachment.rb b/db/migrate/20151020013352_update_attachment.rb new file mode 100644 index 000000000..3e1161c09 --- /dev/null +++ b/db/migrate/20151020013352_update_attachment.rb @@ -0,0 +1,23 @@ +class UpdateAttachment < ActiveRecord::Migration + def up + count = Attachment.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + Attachment.page(i).per(30).each do |attachment| + if attachment.container_type == 'Course' + course = attachment.course + if course + if course.is_public == 0 + attachment.is_public = 0 + attachment.save + end + end + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20151020014759_delete_null_course_activity.rb b/db/migrate/20151020014759_delete_null_course_activity.rb new file mode 100644 index 000000000..0d7b11693 --- /dev/null +++ b/db/migrate/20151020014759_delete_null_course_activity.rb @@ -0,0 +1,17 @@ +class DeleteNullCourseActivity < ActiveRecord::Migration + def up + count = CourseActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + CourseActivity.page(i).per(30).each do |activity| + unless activity.course_act + activity.destroy + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 4a0d2312a..41efc5698 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151014023806) do +ActiveRecord::Schema.define(:version => 20151020014759) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index 9378013f9..682714b9b 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -93,13 +93,13 @@ module Redmine end end - def save_attachmentsex(attachments, author=User.current,attachment_type, public_status) + def save_attachmentsex(attachments, author=User.current,attachment_type) @curattachment_type = attachment_type - result = save_attachments(attachments,author, public_status) + result = save_attachments(attachments,author) result end - def save_attachments(attachments, author=User.current,public_status) + def save_attachments(attachments, author=User.current) # 清除临时文件 if attachments tempAttach = attachments[:dummy] @@ -140,16 +140,12 @@ module Redmine end end end - if public_status - if a && !attachment['is_public_checkbox'] - a.is_public = false - elsif a && attachment['is_public_checkbox'] - a.is_public = true - end - else + + if a && !attachment['is_public_checkbox'] a.is_public = false + elsif a && attachment['is_public_checkbox'] + a.is_public = true end - set_attachment_public(a) if a next unless a a.description = attachment['description'].to_s.strip diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 9c32e41dc..12384f451 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -88,7 +88,7 @@ function addFile_board(inputEl, file, eagerUpload, id) { return null; } -function addFile(inputEl, file, eagerUpload) { +function addFile(inputEl, file, eagerUpload,checkBox) { var attachments_frame = '#attachments_fields'; if ($(attachments_frame).children().length < 30) { @@ -99,50 +99,72 @@ function addFile(inputEl, file, eagerUpload) { 'id': 'attachments_' + attachmentId, 'class': 'attachment' }); - - fileSpan.append( - $('', { - 'type': 'text', - 'class': 'filename readonly', - 'name': 'attachments[' + attachmentId + '][filename]', - 'readonly': 'readonly' - }).val(file.name), - $('', { - 'type': 'text', - 'class': 'description', - 'name': 'attachments[' + attachmentId + '][description]', - 'maxlength': 254, - 'placeholder': $(inputEl).data('descriptionPlaceholder') - }).toggle(!eagerUpload), - $('' + $(inputEl).data('fieldIsPublic') + ':').attr({ - 'class': 'ispublic-label' - }), - $('', { - 'type': 'checkbox', - 'class': 'is_public_checkbox', - 'value': 1, - 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', - checked: 'checked' - }).toggle(!eagerUpload), - $(' ').attr({ - 'href': "#", - 'class': 'remove-upload' - }).click(function() { - if (confirm($(inputEl).data('areYouSure'))) { - removeFile(); - if (!eagerUpload) { - (function(e) { - reload(e); - })(fileSpan); + //alert(checkBox); + if(checkBox){ + fileSpan.append( + $('', { + 'type': 'text', + 'class': 'filename readonly', + 'name': 'attachments[' + attachmentId + '][filename]', + 'readonly': 'readonly' + }).val(file.name), + $('', { + 'type': 'text', + 'class': 'description', + 'name': 'attachments[' + attachmentId + '][description]', + 'maxlength': 254, + 'placeholder': $(inputEl).data('descriptionPlaceholder') + }).toggle(!eagerUpload), + $('
', { + 'class': 'div_attachments', + 'name': 'div_' + 'attachments_' + attachmentId + }) + ).appendTo('#attachments_fields'); + }else { + fileSpan.append( + $('', { + 'type': 'text', + 'class': 'filename readonly', + 'name': 'attachments[' + attachmentId + '][filename]', + 'readonly': 'readonly' + }).val(file.name), + $('', { + 'type': 'text', + 'class': 'description', + 'name': 'attachments[' + attachmentId + '][description]', + 'maxlength': 254, + 'placeholder': $(inputEl).data('descriptionPlaceholder') + }).toggle(!eagerUpload), + $('' + $(inputEl).data('fieldIsPublic') + ':').attr({ + 'class': 'ispublic-label' + }), + $('', { + 'type': 'checkbox', + 'class': 'is_public_checkbox', + 'value': 1, + 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', + checked: 'checked' + }).toggle(!eagerUpload), + $(' ').attr({ + 'href': "#", + 'class': 'remove-upload' + }).click(function () { + if (confirm($(inputEl).data('areYouSure'))) { + removeFile(); + if (!eagerUpload) { + (function (e) { + reload(e); + })(fileSpan); + } } - } - }).toggle(!eagerUpload), - $('
', { - 'class': 'div_attachments', - 'name': 'div_' + 'attachments_' + attachmentId - }) - ).appendTo('#attachments_fields'); + }).toggle(!eagerUpload), + $('
', { + 'class': 'div_attachments', + 'name': 'div_' + 'attachments_' + attachmentId + }) + ).appendTo('#attachments_fields'); + } if (eagerUpload) { ajaxUpload(file, attachmentId, fileSpan, inputEl); @@ -198,7 +220,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) { //gcm files count and add delete_all link - //modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ start + //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ start var containerid = $(inputEl).data('containerid'); if (containerid == undefined) { var count = $('#attachments_fields>span').length; @@ -233,7 +255,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) { })); } } - //modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ end + //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end } //gcm @@ -260,7 +282,7 @@ function removeFile() { } //gcm delete all file -//modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ start +//modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ start function removeAll(containerid) { if (confirm(deleteallfiles)) { if (containerid == undefined) { @@ -276,7 +298,7 @@ function removeAll(containerid) { } // return false; } - //modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ end + //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end //gcm function uploadBlob(blob, uploadUrl, attachmentId, options) { @@ -313,10 +335,11 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) { } function addInputFiles(inputEl) { + checkBox = arguments[1] == 'public' ? false : true; // var clearedFileInput = $(inputEl).clone().val(''); if (inputEl.files) { // upload files using ajax - uploadAndAttachFiles(inputEl.files, inputEl); + uploadAndAttachFiles(inputEl.files, inputEl,checkBox); // $(inputEl).remove(); } else { // browser not supporting the file API, upload on form submission @@ -363,7 +386,7 @@ function addInputFiles_board(inputEl, id) { //clearedFileInput.insertAfter('#attachments_fields'); } -function uploadAndAttachFiles(files, inputEl) { +function uploadAndAttachFiles(files, inputEl,checkBox) { var maxFileSize = $(inputEl).data('max-file-size'); var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); @@ -378,7 +401,7 @@ function uploadAndAttachFiles(files, inputEl) { window.alert(maxFileSizeExceeded); } else { $.each(files, function() { - addFile(inputEl, this, true); + addFile(inputEl, this, true,checkBox); }); } } diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 2fb7ec9c9..db02a0292 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -292,6 +292,7 @@ a.re_open{display:block; width:46px; border:1px solid #64bdd9; color:#64bdd9; a:hover.re_open{ background:#64bdd9; color:#fff; text-decoration:none;} a.re_de{ color:#6883b6; margin-left:15px;} .re_con_box{ border-bottom:1px dashed #dadada; padding-bottom:10px; margin-bottom:10px;} +span.re_open{display:block; width:46px; border:1px solid #64bdd9; color:#64bdd9; margin-left:10px;padding:1px 5px;text-align: center} /* 作业列表 */