This commit is contained in:
z9hang 2014-05-20 11:36:12 +08:00
commit 5b8b2045f1
13 changed files with 359 additions and 27 deletions

View File

@ -52,16 +52,59 @@ class FilesController < ApplicationController
end
def create
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type])
render_attachment_warning_if_needed(container)
if params[:tag_name]
tag_saveEx
render :text =>"success"
else
@addTag=false
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type])
render_attachment_warning_if_needed(container)
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.attachments_added(attachments[:files]).deliver
end
redirect_to project_files_path(@project)
end
redirect_to project_files_path(@project)
end
def tag_saveEx
@tags = params[:tag_name][:name]
@obj_id = params[:object_id]
@obj_flag = params[:object_flag]
case @obj_flag
when '1' then
@obj = User.find_by_id(@obj_id)
when '2' then
@obj = Project.find_by_id(@obj_id)
when '3' then
@obj = Issue.find_by_id(@obj_id)
when '4' then
@obj = Bid.find_by_id(@obj_id)
when '5' then
@obj = Forum.find_by_id(@obj_id)
when '6'
@obj = Attachment.find_by_id(@obj_id)
when '7' then
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
else
@obj = nil
end
unless @obj.nil?
@obj.tag_list.add(@tags.split(","))
else
return
end
if @obj.save
## 执行成功的操作。
else
#捕获异常
end
end
# 返回制定资源类型的资源列表
def getattachtype
sort_init 'created_on', 'desc'

View File

@ -30,7 +30,7 @@ class UsersController < ApplicationController
#Ended by young
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
#edit has been deleted by huang, 2013-9-23
@ -39,10 +39,10 @@ class UsersController < ApplicationController
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
before_filter :auth_user_extension, only: :show
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
#william
before_filter :require_login, :only => :tag_save
before_filter :require_login, :only => [:tag_save,:tag_saveEx]
helper :sort
@ -209,6 +209,8 @@ class UsersController < ApplicationController
## 判断课程是否过期 [需封装]
@memberships_doing = []
@memberships_done = []
@OwningCouses =[]
@JoinCouses=[]
now_time = Time.now.year
@memberships.map { |e|
end_time = e.project.course_extra.get_time.year
@ -218,6 +220,12 @@ class UsersController < ApplicationController
else
@memberships_doing.push e
end
if e.project.course_extra.tea_id == User.current.id
@OwningCouses.push e
else
@JoinCouses.push e
end
}
# respond_to do |format|
# format.html
@ -683,11 +691,51 @@ class UsersController < ApplicationController
#捕获异常
end
respond_to do |format|
format.html
format.js
end
format.html
end
end
def tag_saveEx
@tags = params[:tag_name][:name]
@obj_id = params[:obj_id]
@obj_flag = params[:obj_flag]
case @obj_flag
when '1' then
@obj = User.find_by_id(@obj_id)
when '2' then
@obj = Project.find_by_id(@obj_id)
when '3' then
@obj = Issue.find_by_id(@obj_id)
when '4' then
@obj = Bid.find_by_id(@obj_id)
when '5' then
@obj = Forum.find_by_id(@obj_id)
when '6'
@obj = Attachment.find_by_id(@obj_id)
when '7' then
@obj = Contest.find_by_id(@obj_id)
when '8'
@obj = OpenSourceProject.find_by_id(@obj_id)
else
@obj = nil
end
unless @obj.nil?
@obj.tag_list.add(@tags.split(","))
else
return
end
if @obj.save
## 执行成功的操作。
else
#捕获异常
end
respond_to do |format|
format.js
format.html
end
end
###add by huang
def user_watchlist
end

View File

@ -12,5 +12,6 @@ fileSpan.find('a.remove-upload')
})
.off('click');
var divattach = fileSpan.find('div.div_attachments');
divattach.html('<%= j(render :partial => 'tags/tag', :locals => {:obj => @attachment, :object_flag => "6"})%>');
divattach.html('<%#= j(render :partial => 'tags/tagEx', :locals => {:obj => @attachment, :object_flag => "6"})%>');
<% end %>

View File

@ -2,9 +2,8 @@
<% versions = project.versions.sort %>
<% attachmenttypes = project.attachmenttypes %>
<%= error_messages_for 'attachment' %>
<%= form_tag(project_files_path(project), :multipart => true, :class => "tabular") do %>
<%= form_tag(project_files_path(project), :multipart => true,:name=>"upload_form", :class => "tabular") do %>
<div class="box">
<p>
<table>
<tr>
@ -34,4 +33,26 @@
</div>
<%= submit_tag l(:button_add) %>
<% end %>
<div class="line_under" style="margin:20px 0px;"></div>
<div class="line_under" style="margin:20px 0px;"></div>
<script type='text/javascript'>
function tagAddClick(id,objId,objTag)
{
alert("OK");
$.ajax({
type :"POST",
url :'<%= users_tag_saveEx_path%>',
data: {
tagname: $('tag_name').value,
obj_id: encodeURIComponent(objId),
obj_flag:encodeURIComponent(objTag)
},
success: function(data, textStatus){
alert("OK");
$(id).empty();
$(id).html('123');
$("#" + id + " #name").val("");
}
})
}
</script>

View File

@ -25,9 +25,10 @@
:onchange => "attachment_contenttypes_searchex(this.value)" %>
<% end %>
<div id="upload_file_div" class="relation_file_div hidden">
<%= render :partial => 'new', locals: {project: @project} %>
</div>
<div id="upload_file_div" class="relation_file_div hidden">
<%= render :partial => 'new', locals: {project: @project} %>
</div>
<div id="relation_file_div" class="relation_file_div hidden">
<fieldset>
<legend>搜索</legend>
@ -185,4 +186,27 @@
}
});
}
</script>
</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>

View File

@ -44,7 +44,7 @@
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form-<%=obj.class%>-<%=obj.id%>" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
<%= form_for "tag_for_save",:remote=>true,:header=>"Accept: application/javascript",:url=>tag_path,
:update => "tags_show",
:complete => "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();" do |f| %>
<%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length,:style=>"width: 100px;"%>

View File

@ -0,0 +1,165 @@
<script>
window.onload=function (){
$('#upload_form').submit(function() {
$(this).ajaxSubmit( {
target : '#tags_show'
});
return false;
});
}
</script>
<div id="tags">
<%#begin
1 代表是user类型
2 代表是project类型
3 代表是issue类型
4 代表是bid类型
5 代表是forum类型
6 代表是Attachment类型
7 代表是contest类型
8 代表是OpenSourceProject类型
9 代表是RelativeMemo类型
#end%>
<!-- 3 代表的是issue 当是issue是 处理方式与前2个对象不同 -->
<% if object_flag == '3' %>
<span><%= image_tag("/images/sidebar/tags.png") %></span>
<span class="font_title_tag"><%= l(:label_tag) %>:</span>
<% if User.current.logged? %>
<span> <%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form-issue', {:focus => 'name-issue'} %></span>
<% end %>
<div id="tags_show_issue">
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form-issue" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
:update => "tags_show",
:complete => '$("#put-tag-form-issue").hide();' do |f| %>
<%= f.text_field :name ,:id => "name-issue",:size=>"30",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>1 %>
<%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<%= f.submit l(:button_project_tags_add),:class => "small"%>
<%= link_to_function l(:button_cancel), '$("#put-tag-form-issue").hide();'%>
<% end %>
</div>
<% elsif object_flag == '6' %>
<span><%#= image_tag("/images/sidebar/tags.png") %></span>
<span>
<%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %>
<%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %>
</span>
&nbsp;&nbsp;
<div id="tags_show">
<div id="tags_show-<%=obj.class%>-<%=obj.id%>" style="display:inline; ">
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form-<%=obj.class%>-<%=obj.id%>" style="display: none">
<%= text_field "tag_name" ,"name"%>
<input id="object_id" type="text" size="20" name="object_id" value='<%=obj.id%>' class="hidden">
<input id="object_flag" type="text" size="20" name="object_flag" value='<%=object_flag%>' class="hidden">
<%= button_tag "增加", :type=>"button", :onclick=>"tagAddClick(tags_show-"+obj.class.to_s + "-" +obj.id.to_s + ","+ obj.id.to_s + "," + object_flag.to_s + ")" %>
<%#= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%#= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<input type="image" name="button" onclick="submitForm('<%=obj.id%>,<%=object_flag%>')" src="/commit.png"/>
<%= submit_tag "增加", :name=>"add_tag" %>
<div class='hidden'>
<% preTags = @preTags.nil? ? [] : @preTags %>
<% preTags.each do |tag|%>
<%= link_to tag, "
javascript:(function(){
var $tagInputVal = $('#put-tag-form-"+obj.class.to_s+"-"+obj.id.to_s+"').find('#name');
var tagArr = [];
tagArr = tagArr.concat( $tagInputVal[0].value.split(',') );
tagArr = tagArr.concat('"+tag.to_s+"');
tagArr = cleanArray(tagArr);
$tagInputVal.val(tagArr.join(','));
})();
"
%>
<% end%>
</div>
<%#= link_to_function l(:button_cancel), "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();"%>
</div>
</div>
<% else %>
<span><%= image_tag("/images/sidebar/tags.png") %></span>
<span class="font_title_tag"><%= l(:label_tag) %>:</span>
<% if User.current.logged? %>
<span><%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form', {:focus => 'name'} %></span>
<% end %>
<div id="tags_show">
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
:update => "tags_show",
:complete => '$("#put-tag-form").hide();' do |f| %>
<%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length %>
<%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<%= f.submit l(:button_project_tags_add),:class => "small" %>
<%= link_to_function l(:button_cancel), '$("#put-tag-form").hide();'%>
<% end %>
</div>
<% end %>
</div>
<script language="JavaScript">
function submitForm(objId,objTag){
alert("OK");
$.ajax({
type :"POST",
url :'<%= users_tag_saveEx_path%>',
data: {
tagname: $('tag_name').value,
obj_id: encodeURIComponent(objId),
obj_flag:encodeURIComponent(objTag)
},
success: function(data, textStatus){
alert("OK");
$(id).empty();
$(id).html('123');
$("#" + id + " #name").val("");
}
})
}
function eval_ajax (xhr, textStatus) {
if (textStatus == 'success') {
eval(xhr.responseText);
} else if (textStatus == 'error') {
alert('error');
}
}
</script>
<script type='text/javascript'>
function tagAddClick(id,objId,objTag)
{
alert("OK");
$.ajax({
type :"POST",
url :'<%= users_tag_saveEx_path%>',
data: {
tagname: $('tag_name').value,
obj_id: encodeURIComponent(objId),
obj_flag:encodeURIComponent(objTag)
},
success: function(data, textStatus){
alert("OK");
$(id).empty();
$(id).html('123');
$("#" + id + " #name").val("");
}
})
}
</script>

View File

@ -26,7 +26,7 @@
<%= l(:label_homework) %> (<span class=""><%= link_to (membership.project.homeworks.count), {:controller => 'projects', :action => 'homework', :id => membership.project.identifier} %></span>)
&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (membership.project.news.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %></span>)
</td>
</span></td>
</tr>
<tr>
<td colspan="2" width="580" >

View File

@ -15,9 +15,14 @@
<span><%=l(:label_course_doing)%>(<%=@memberships_doing.count%>)</span>
<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1, :project_type => 1}, :class => 'icon icon-add' if @user == User.current %>
</p>
<div>
<%= render :partial => 'course_form', :locals => {:memberships => @memberships_doing}%>
</div>
<p>
<%= l(:label_created_course) %>
<div> <%= render :partial => 'course_form', :locals => {:memberships => @OwningCouses}%>
</div> </p>
<div style="clear:both;"></div>
<p> <%= l(:label_joined_course) %>
<div> <%= render :partial => 'course_form', :locals => {:memberships => @JoinCouses}%>
</div> </p>
<div style="clear:both;"></div>

View File

@ -0,0 +1,20 @@
<% if @obj_flag == '3'%>
$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
//$('#put-tag-form-issue').hide();
$('#name-issue').val("");
<% elsif @obj_flag == '6'%>
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty();
$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
//$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%>").hide();
$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val("");
<% else %>
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name',
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
$('#put-tag-form #name').val("");
//$('#put-tag-form').hide();
<% end %>

View File

@ -1122,6 +1122,8 @@ en:
label_activities_settings: Display settings
#end
label_joined_course: Joined Courses
label_created_course: Created Courses
#huang
label_file_new: Download
@ -1611,4 +1613,4 @@ en:
# ajax异步验证
modal_valid_passing: can be used.
modal_valid_passing: can be used.

View File

@ -1670,7 +1670,9 @@ zh:
label_no_current_participate: 该竞赛暂无参与者
#end
label_joined_course: 参加的课程
label_created_course: 创建的课程
label_course: 课程
label_course_new: 新建课程
label_course_join_student: 加入课程

View File

@ -232,6 +232,7 @@ RedmineApp::Application.routes.draw do
match 'users/:id/memberships', :to => 'users#edit_membership', :via => :post, :as => 'user_memberships'
################# added by william
match 'users/tag_save', :to => 'users#tag_save', :via => :post, :as => 'tag'
match 'users/tag_saveEx', :to => 'users#tag_saveEx', :via => :post
post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
delete 'watchers/watch', :to => 'watchers#unwatch'