组织资源栏目增加标签功能

This commit is contained in:
ouyangxuhua 2015-12-15 17:30:24 +08:00
parent d9df926c2b
commit af157a9c63
10 changed files with 137 additions and 33 deletions

View File

@ -395,6 +395,7 @@ class FilesController < ApplicationController
@containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
@organization = Organization.find(@containers.first.organization_id)
show_attachments @containers
@tag_list = attachment_tag_list @all_attachments
render :layout => 'base_org'
# @subfield = params[:org_subfield_id]
end
@ -523,14 +524,29 @@ class FilesController < ApplicationController
end
elsif @org_subfield
@addTag=false
# if params[:in_org_subfield_toolbar]
# @in_org_subfield_toolbar = params[:in_org_subfield_toolbar]
# end
attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type])
# if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
# Mailer.run.attachments_added(attachments[:files])
# end
if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type].is_a?(Array)
params[:org_subfield_attachment_type].each do |type|
tag_name = get_tag_name_by_type_number type
if !attachments.empty? && attachments[:files] && tag_name != ""
attachments[:files].each do |attachment|
attachment.tag_list.add(tag_name)
attachment.save
end
end
end
else
if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type] != "5"
tag_name = get_tag_name_by_type_number params[:org_subfield_attachment_type]
if !attachments.empty? && attachments[:files] && tag_name != ""
attachments[:files].each do |attachment|
attachment.tag_list.add(tag_name)
attachment.save
end
end
end
end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
@ -542,7 +558,7 @@ class FilesController < ApplicationController
@containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)]
show_attachments @containers
@tag_list = attachment_tag_list @all_attachments
@attachtype = 0
@contenttype = 0
@ -733,6 +749,32 @@ class FilesController < ApplicationController
end
end
#搜索资源栏目的指定TAG的资源列表
def search_org_subfield_tag_attachment
@q,@tag_name,@order = params[:q],params[:tag_name]
@is_remote = true
if params[:sort]
order_by = params[:sort].split(":")
@sort = order_by[0]
if order_by.count > 1
@order = order_by[1]
end
sort = "#{@sort} #{@order}"
end
q = "%#{@q.strip}%"
@result = find_org_subfield_attache q,@org_subfield,sort
@result = visable_attachemnts @result
@result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
@searched_attach = paginateHelper @result,10
@tag_list = get_org_subfield_tag_list @org_subfield
respond_to do |format|
format.js
# format.html
end
end
def subfield_upload_file
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
end

View File

@ -227,6 +227,12 @@ class TagsController < ApplicationController
@tag_list = get_course_tag_list @course
@select_tag_name = params[:select_tag_name]
end
if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield)
@org_subfield = @obj.container
@tag_list = get_org_subfield_tag_list @org_subfield
@select_tag_name = params[:select_tag_name]
end
# end
end
end

View File

@ -2376,6 +2376,15 @@ module ApplicationHelper
tag_list
end
def get_org_subfield_tag_list org_subfield
all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? ||
(attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))||
attachment.author_id == User.current.id
}
tag_list = attachment_tag_list all_attachments
tag_list
end
#获取匿评相关连接代码
def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1)
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")

View File

@ -14,9 +14,9 @@
</p>
</div>
<div class="cl"></div>
<!--<div class="files_tag" id="files_tag">-->
<!--<%#= render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => course,:tag_name => @tag_name}%>-->
<!--</div>-->
<div class="files_tag" id="files_tag">
<%= render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name}%>
</div>
<div class="cl"></div>
<div class="for_img_thumbnails">

View File

@ -15,9 +15,9 @@
{
switch(obj)
{
case 1:
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 1}) %>');
break;
// case 1:
// $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 1}) %>');
// break;
case 2:
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 2}) %>');
break;
@ -27,9 +27,9 @@
case 4:
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 4}) %>');
break;
case 6:
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 6}) %>');
break;
// case 6:
// $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 6}) %>');
// break;
default:
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 5}) %>');
}
@ -77,11 +77,11 @@
<!--<a href="javascript:void(0)" class="re_fabu f_r b_lblue" onclick="show_upload();">上传资源</a>-->
<p class="c_grey fr mt10 mr5">
上传:
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(1);">课件</a>&nbsp;|&nbsp;
<!--<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(1);">课件</a>&nbsp;|&nbsp;-->
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(2);">软件</a>&nbsp;|&nbsp;
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(3);">媒体</a>&nbsp;|&nbsp;
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(4);">代码</a>&nbsp;|&nbsp;
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(6);">论文</a>&nbsp;|&nbsp;
<!--<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(6);">论文</a>&nbsp;|&nbsp;-->
<a href="javascript:void(0);" class=" c_dblue font_bold" onclick="show_upload(5);">其他</a>
</p>
<%# end %>

View File

@ -0,0 +1,43 @@
<% if org_subfield && tag_list && tag_list.empty? == false%>
<span class="files_tag_icon" >
<a title=""
onclick="search_org_subfield_tag_attachment('<%= search_org_subfield_tag_attachment_org_subfield_files_path(org_subfield)%>','','<%= @q%>','<%= org_subfield.id%>');"
>全部</a></span>
<% end %>
<% unless tag_list.nil?%>
<% tag_list.each do |k,v|%>
<% if tag_name && tag_name == k%>
<!-- 鼠标不能移动是因为 href="javascript:void(0);"导致的 -->
<span> <a class="files_tag_select" ondblclick="rename_tag($(this),'<%= k %>','',<%= 6 %>);"><%= k%>(<%= v%>)</a></span>
<% else%>
<span class="files_tag_icon" >
<a title="双击可编辑"
onclick="search_org_subfield_tag_attachment('<%= search_org_subfield_tag_attachment_org_subfield_files_path(org_subfield)%>','<%= k%>','<%= @q%>','<%= org_subfield.id%>');"
ondblclick="rename_tag($(this),'<%= k %>','',<%= 6 %>);"><%= k%>(<%= v%>)</a></span>
<% end%>
<% end%>
<% end%>
<script>
function search_org_subfield_tag_attachment(url,tag_name,q,org_subfield_id,sort) {
//alert("111");
//clearTimeout(clickFunction);
clickFunction = setTimeout(function () {
search_func();
}, 500);
function search_func() {
// if (isdb != false) return;
$.get(
url,
{
tag_name: tag_name,
q: q,
org_subfield_id: org_subfield_id
},
function (data) {
}
);
}
}
</script>

View File

@ -7,19 +7,17 @@
<div id="network_issue" style="color: red; display: none;"><%= l(:label_file_upload_error_messages)%></div>
<%= form_tag(org_subfield_files_path(org_subfield, :in_org => params[:in_org]), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %>
<!--<%# if params[:in_org] %>-->
<!--<div class="c_dark">-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="1" checked class="c_dark" >课件</input>&nbsp;<span class="c_grey">|</span>&nbsp;-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="2" class="c_dblue">软件</input>&nbsp;<span class="c_grey">|</span>&nbsp;-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="3" class="c_dblue">媒体</input>&nbsp;<span class="c_grey">|</span>&nbsp;-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="4" class="c_dblue">代码</input>&nbsp;<span class="c_grey">|</span>&nbsp;-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="6" class="c_dblue">论文</input>&nbsp;<span class="c_grey">|</span>&nbsp;-->
<!--<input name="org_subfield_attachment_type[]" type="radio" value="5" class="c_dblue">其他</input></a>-->
<!--</div>-->
<!--<%# else %>-->
<!--<input type="hidden" name="org_subfield_attachment_type" value="<%#= org_subfield_attachment_type%>">-->
<!--<%# end %>-->
<input type="hidden" name="org_subfield_attachment_type" value="<%= org_subfield_attachment_type%>">
<% if params[:in_org] %>
<div class="c_dark">
<input name="org_subfield_attachment_type[]" type="checkbox" value="2" class="c_dblue">软件</input>&nbsp;<span class="c_grey">|</span>&nbsp;
<input name="org_subfield_attachment_type[]" type="checkbox" value="3" class="c_dblue">媒体</input>&nbsp;<span class="c_grey">|</span>&nbsp;
<input name="org_subfield_attachment_type[]" type="checkbox" value="4" class="c_dblue">代码</input>&nbsp;<span class="c_grey">|</span>&nbsp;
<input name="org_subfield_attachment_type[]" type="checkbox" value="5" class="c_dblue">其他</input></a>
</div>
<% else %>
<input type="hidden" name="org_subfield_attachment_type" value="<%= org_subfield_attachment_type %>">
<% end %>
<!--<input type="hidden" name="org_subfield_attachment_type" value="<%= org_subfield_attachment_type%>">-->
<%= render :partial => 'files/attachement_list'%>
<div class="cl"></div>
<a href="javascript:void(0);" class=" fr grey_btn mr40" onclick="hideModal();"><%= l(:button_cancel)%></a>

View File

@ -0,0 +1,2 @@
$("#org_subfield_list").html("<%= escape_javascript(render :partial => 'org_subfield_list',
:locals => {org_subfield: @org_subfield,all_attachments: @result,sort:@sort,order:@order,org_subfield_attachments:@searched_attach})%>");

View File

@ -3,8 +3,12 @@
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @object_flag,:select_tag_name => @select_tag_name}) %>');
<% if @org_subfield %>
$("#files_tag").html("<%= escape_javascript(render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name})%>");
<% else %>
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>");
<% end %>
$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>");
<% end %>
<% if @object_flag == "10"%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();

View File

@ -77,7 +77,7 @@ RedmineApp::Application.routes.draw do
match "getattachtype", :via => [:get, :post]
match "search_files_in_subfield",:via => [:post,:get]
match "searchone4reload",:via => [:post,:get]
match "search_tag_attachment", :via => [:post,:get]
match "search_org_subfield_tag_attachment", :via => [:post,:get]
match "subfield_upload_file", :via => :post
end
member do