This commit is contained in:
Tim 2015-10-20 10:23:03 +08:00
commit ad77104485
11 changed files with 217 additions and 132 deletions

View File

@ -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
#添加学校

View File

@ -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

View File

@ -21,13 +21,13 @@
<% end %>
</span>
</div>
<% checkBox = (@course.present? && @course.is_public?) ? 'public' : 'private'%>
<button name="button" class="sub_btn" onclick="_file.click()" onmouseover="this.focus()" style="<%= ie8? ? 'display:none' : ''%>" type="button" ><%= l(:label_browse) %></button>
<%= 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,

View File

@ -39,7 +39,7 @@
</span>
<% else %>
<span id="is_public_<%= file.id %>">
<a class="f_l re_open c_blue">私有</a>
<span class="f_l re_open c_blue">私有</span>
</span>
<% end %>

View File

@ -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 = '<a onclick="window.changeValue(\'' + schoolsResult[i].school.name.replace(/\s/g, " ") + '\',\'' + schoolsResult[i].school.id + '\')" href="javascript:void(0)">' + schoolsResult[i].school.name + '</a><br/>';
$("#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 = '<a onclick="window.changeValue(\'' + data[i].school.name.replace(/\s/g," ") + '\',\'' + data[i].school.id + '\')" href="javascript:void(0)">' + data[i].school.name + '</a><br/>';
for (; i < schoolsResult.length; i++) {
link = '<a onclick="window.changeValue(\'' + schoolsResult[i].school.name.replace(/\s/g," ") + '\',\'' + schoolsResult[i].school.id + '\')" href="javascript:void(0)">' + schoolsResult[i].school.name + '</a><br/>';
$("#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 = '<a onclick="window.changeValue(\'' + data[i].school.name.replace(/\s/g," ") + '\',\'' + data[i].school.id + '\')" href="javascript:void(0)">' + data[i].school.name + '</a><br/>';
$("#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+'"的高校,<a style="color:#64bdd9" onclick="add_school(\''+ e.target.value+'\');" href="javascript:void(0);">创建高校</a>');
$("#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 = '<a onclick="window.changeValue(\'' + data[i].school.name.replace(/\s/g," ") + '\',\'' + data[i].school.id + '\')" href="javascript:void(0)">' + data[i].school.name + '</a><br/>';
// $("#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+'"的高校,<a style="color:#64bdd9" onclick="add_school(\''+ e.target.value+'\');" href="javascript:void(0);">创建高校</a>');
// $("#hint").show();
// }
// }
// });
// });
// $("#province").leanModal({top: 100, closeButton: ".modal_close"});

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
a.is_public = false
end
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

View File

@ -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(
$('<input>', {
'type': 'text',
'class': 'filename readonly',
'name': 'attachments[' + attachmentId + '][filename]',
'readonly': 'readonly'
}).val(file.name),
$('<input>', {
'type': 'text',
'class': 'description',
'name': 'attachments[' + attachmentId + '][description]',
'maxlength': 254,
'placeholder': $(inputEl).data('descriptionPlaceholder')
}).toggle(!eagerUpload),
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
'class': 'ispublic-label'
}),
$('<input>', {
'type': 'checkbox',
'class': 'is_public_checkbox',
'value': 1,
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
checked: 'checked'
}).toggle(!eagerUpload),
$('<a>&nbsp</a>').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(
$('<input>', {
'type': 'text',
'class': 'filename readonly',
'name': 'attachments[' + attachmentId + '][filename]',
'readonly': 'readonly'
}).val(file.name),
$('<input>', {
'type': 'text',
'class': 'description',
'name': 'attachments[' + attachmentId + '][description]',
'maxlength': 254,
'placeholder': $(inputEl).data('descriptionPlaceholder')
}).toggle(!eagerUpload),
$('<div>', {
'class': 'div_attachments',
'name': 'div_' + 'attachments_' + attachmentId
})
).appendTo('#attachments_fields');
}else {
fileSpan.append(
$('<input>', {
'type': 'text',
'class': 'filename readonly',
'name': 'attachments[' + attachmentId + '][filename]',
'readonly': 'readonly'
}).val(file.name),
$('<input>', {
'type': 'text',
'class': 'description',
'name': 'attachments[' + attachmentId + '][description]',
'maxlength': 254,
'placeholder': $(inputEl).data('descriptionPlaceholder')
}).toggle(!eagerUpload),
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
'class': 'ispublic-label'
}),
$('<input>', {
'type': 'checkbox',
'class': 'is_public_checkbox',
'value': 1,
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
checked: 'checked'
}).toggle(!eagerUpload),
$('<a>&nbsp</a>').attr({
'href': "#",
'class': 'remove-upload'
}).click(function () {
if (confirm($(inputEl).data('areYouSure'))) {
removeFile();
if (!eagerUpload) {
(function (e) {
reload(e);
})(fileSpan);
}
}
}
}).toggle(!eagerUpload),
$('<div>', {
'class': 'div_attachments',
'name': 'div_' + 'attachments_' + attachmentId
})
).appendTo('#attachments_fields');
}).toggle(!eagerUpload),
$('<div>', {
'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 <EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ 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 <EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ 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 <EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ 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 <EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ 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);
});
}
}

View File

@ -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}
/* 作业列表 */