修改bug《选定了内容类型后再点击表头进行排序总是返回一个空白页》

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-10-28 23:38:14 +08:00
parent f3e8c8b688
commit 2bd08d1aaa
4 changed files with 325 additions and 28 deletions

View File

@ -84,7 +84,7 @@ class FilesController < ApplicationController
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder(sort).all @containers += @project.versions.includes(:attachments).reorder(sort).all
getattachtype
show_attachments @containers show_attachments @containers
render :layout => !request.xhr? render :layout => !request.xhr?
@ -122,7 +122,7 @@ class FilesController < ApplicationController
end end
end end
end end
getattachtype
@containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers show_attachments @containers
@ -262,21 +262,63 @@ class FilesController < ApplicationController
'filename' => "#{Attachment.table_name}.filename", 'filename' => "#{Attachment.table_name}.filename",
'size' => "#{Attachment.table_name}.filesize", 'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads" 'downloads' => "#{Attachment.table_name}.downloads"
sort=''
if params[:sort]
params[:sort].split(",").each do |sort_type|
order_by = sort_type.split(":")
case order_by[0]
when "filename"
attribute = "filename"
when "size"
attribute = "filesize"
when "attach_type"
attribute = "attachtype"
when "content_type"
attribute = "created_on"
when "field_file_dense"
attribute = "is_public"
when "downloads"
attribute = "downloads"
when "created_on"
attribute = "created_on"
end
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} asc "
elsif order_by.count == 2
sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
end
if sort_type != params[:sort].split(",").last
sort += ","
end
end
end
if @project if @project
@isproject = true
@containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
@containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort @containers += @project.versions.includes(:attachments).reorder(sort).all
elsif @course
@containers = [ Course.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@course.id)]
end
show_attachments @containers
show_attachments @containers
@attachtype = params[:type].to_i @attachtype = params[:type].to_i
@contenttype = params[:contentType].to_s @contenttype = params[:contentType].to_s
render :layout => 'base_projects'
respond_to do |format| elsif @course
format.js @isproject = false
format.html @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)]
show_attachments @containers
@attachtype = params[:type].to_i
@contenttype = params[:contentType].to_s
render :layout => 'base_courses'
end end
# respond_to do |format|
# format.js
# format.html
# end
end end
end end

View File

@ -67,7 +67,16 @@
<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> <% delete_allowed = User.current.allowed_to?(:manage_files, @course) %>
<div id="all_browse_div" class="all_browse_div"> <div id="all_browse_div" class="all_browse_div">
<%= render :partial => 'course_show_all_attachment' %> <%#= render :partial => 'course_show_all_attachment' %>
<% if (@attachtype==0 && @contenttype=='0') || (@attachtype.nil? && @contenttype.nil?) %>
<%= render partial: "course_show_all_attachment"%>
<%else%>
<%= render partial: "course_sort_by_attachtypel"%>
<%end%>
</div> </div>
<% html_title(l(:label_attachment_plural)) -%> <% html_title(l(:label_attachment_plural)) -%>

View File

@ -69,7 +69,17 @@
<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> <% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
<div id="all_browse_div" class="all_browse_div"> <div id="all_browse_div" class="all_browse_div">
<%= render :partial => 'show_all_attachment' %> <%#= render :partial => 'show_all_attachment' %>
<% if (@attachtype==0 && @contenttype=='0') || (@attachtype.nil? && @contenttype.nil?) %>
<%= render partial: "show_all_attachment"%>
<%else%>
<%= render partial: "sort_by_attachtypel"%>
<%end%>
</div> </div>
<% html_title(l(:label_attachment_plural)) -%> <% html_title(l(:label_attachment_plural)) -%>

View File

@ -1,13 +1,249 @@
<% if @attachtype==0 && @contenttype=='0' %> <!-- <h3> --><!-- %=l(:label_attachment_plural)%></h3 -->
<% if @isproject %>
<%= render :partial => 'project_file', locals: {project: @project} %>
<% else %>
<%= render :partial => 'course_file', locals: {course: @course} %>
<% end %>
<script type='text/javascript'>
var slideHeight = 29;
function readmore(aNode) {
// console.log(aNode)
// var $td_tags_area = $(aNode).parent().parent();
var $td_tags_area = $(aNode).parent().parent().parent().parent();
var $tags_area = $td_tags_area.find('.tags_area')
var $tags_gradint = $td_tags_area.find('.tags_gradint')
var $read_more = $td_tags_area.find('.read-more')
var $read_more_a = $td_tags_area.find('.read-more a')
var $tags = $td_tags_area.find('#tags')
var $icona = $td_tags_area.find('.tags_icona')
var slideHeight = 13; //px
var defHeight = $tags.height();
var curHeight = $tags_area.height();
if (curHeight == slideHeight) {
$tags_area.animate({
height: defHeight
}, 'normal');
$read_more_a.html('隐藏');
$icona.html('<%=image_tag "/images/sidebar/minus.png"%>')
$tags_gradint.fadeOut();
} else {
$tags_area.animate({
height: slideHeight
}, 'normal');
$read_more_a.html('更多');
$icona.html('<%=image_tag "/images/sidebar/add.png"%>')
$tags_gradint.fadeIn();
}
;
}
$(function () {
var slideHeight = 20; //px
var defHeight = $('.tags_area').height();
if (defHeight >= slideHeight) {
$('.tags_area').css('height', slideHeight + 'px');
}
;
});
function eval_ajax(xhr, textStatus) {
if (textStatus == 'success') {
eval(xhr.responseText);
} else if (textStatus == 'error') {
alert('error');
}
}
function attachment_contenttypes_searchex(value) {
<% if @project%> <% if @project%>
<%= render partial: "show_all_attachment"%> $.ajax({
<% elsif @course%> url: '<%=getattachtype_project_files_path(project_id: @project)%>',
<%= render partial: "course_show_all_attachment"%> type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%> <%end%>
<%else%> }
function attachtype_edit(value) {
<% if @project%> <% if @project%>
<%= render partial: "sort_by_attachtypel"%> $.ajax({
<% elsif @course%>
<%= render partial: "course_sort_by_attachtypel"%> url: '<%=getattachtype_project_files_path(project_id: @project)%>',
<%end%>; type: "POST",
<%end%> data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%>
}
function attachmenttypes_searchex(value) {
<% if @project%>
$.ajax({
url: '<%=getattachtype_project_files_path(project_id: @project)%>',
type: "POST",
data: {
type: encodeURIComponent(value),
contentType: $('#attach_sufix_browse').val()
}
}).complete(eval_ajax);
<%end%>
}
function course_attachmenttypes_searchex(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: encodeURIComponent(value),
contentType: $('#attach_sufix_browse').val()
}
}).complete(eval_ajax);
<%end%>
}
function course_attachment_contenttypes_searchex(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%>
}
function course_attachtype_edit(value) {
<% if @course%>
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: encodeURIComponent(value)
}
}).complete(eval_ajax);
<%end%>
}
function attachmenttypes_change(id, type) {
<% if @project%>
$.ajax({
url: '<%=updateType_attachments_path%>',
type: "POST",
data: {
attachmentid: encodeURIComponent(id),
newtype: encodeURIComponent(type)
}
}).complete(function (xhr, textStatus) {
if (textStatus == 'success') {
$.ajax({
url: '<%=getattachtype_project_files_path(project_id: @project)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: $('#attach_sufix_browse').val()
}
}).error(function () {
alert('error');
});
} else if (textStatus == 'error') {
alert('An error has occurred');
}
});
<%end%>
}
function course_attachmenttypes_change(id, type) {
<% if @course%>
$.ajax({
url: '<%=updateType_attachments_path%>',
type: "POST",
data: {
attachmentid: encodeURIComponent(id),
newtype: encodeURIComponent(type)
}
}).complete(function (xhr, textStatus) {
if (textStatus == 'success') {
$.ajax({
url: '<%=getattachtype_course_files_path(course_id: @course)%>',
type: "POST",
data: {
type: $('#attachment_browse').val(),
contentType: $('#attach_sufix_browse').val()
}
}).error(function () {
alert('error');
});
} else if (textStatus == 'error') {
alert('An error has occurred');
}
});
<%end%>
}
// 编辑文件密级
function file_dense_edit(id, type) {
$.ajax({
url: '<%=updateFileDense_attachments_path%>',
type: "POST",
remote:"true",
data: {
attachmentid: encodeURIComponent(id),
newtype: encodeURIComponent(type)
}
}).complete(function (xhr, textStatus) {
});
}
</script>
<script type='text/javascript'>
function tagAddClick(divid, objId, objTag) {
alert("OK");
$.ajax({
type: "POST",
url: '/users/tag_saveEx',
data: {
tagname: $('tag_name').value,
obj_id: encodeURIComponent(objId),
obj_flag: encodeURIComponent(objTag)
},
success: function (data, textStatus) {
alert("OK");
$(divid).empty();
$(divid).html('123');
$("#" + divid + " #name").val("");
}
})
}
</script>