优化用户申请加入项目界面刷新
This commit is contained in:
parent
104ee13ac7
commit
1d6816419d
|
@ -2,15 +2,28 @@ class AppliedProjectController < ApplicationController
|
|||
|
||||
#申请加入项目
|
||||
def applied_join_project
|
||||
@user_id = params[:user_id]
|
||||
@project = Project.find(params[:project_id])
|
||||
AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
||||
redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
|
||||
#redirect_to project_path(params[:project_id])
|
||||
#redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
format.js { render :partial => 'set_applied'}
|
||||
end
|
||||
end
|
||||
|
||||
#取消申请
|
||||
def unapplied_join_project
|
||||
@project = Project.find(params[:project_id])
|
||||
@applied = AppliedProject.find(params[:id])
|
||||
@applied.destroy
|
||||
redirect_to_referer_or {render :text => ( 'unsubscribe success.'), :layout => true}
|
||||
#redirect_to project_path(params[:project_id])
|
||||
#redirect_to_referer_or {render :text => ( 'unsubscribe success.'), :layout => true}
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
format.js { render :partial => 'set_applied' }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
module AppliedProjectHelper
|
||||
|
||||
def applied_css(project)
|
||||
id = project.id
|
||||
"#{project.class.to_s.underscore}-#{id}-applied"
|
||||
end
|
||||
|
||||
def applied_link(project, user, options=[])
|
||||
return '' unless user && user.logged?
|
||||
applied = project.applied_projects.find_by_user_id(user.id)
|
||||
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
|
||||
|
||||
@applied_flag = project.instance_of?(Project)
|
||||
css = @applied_flag ? ([applied_css(project), applied ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
|
||||
([applied_css(project), applied ? 'icon icon-applied ' : 'icon icon-applied-off '].join(' ') << options[0].to_s)
|
||||
if applied
|
||||
appliedid = applied.id
|
||||
end
|
||||
|
||||
url = appliedproject_path(
|
||||
:id=>appliedid,
|
||||
:user_id => user.id,
|
||||
|
@ -16,6 +23,6 @@ module AppliedProjectHelper
|
|||
)
|
||||
method = applied ? 'delete' : 'post'
|
||||
|
||||
link_to text, url, :remote => true, :method => method
|
||||
link_to text, url, :remote => true, :method => method ,:class=>css
|
||||
end
|
||||
end
|
||||
|
|
|
@ -188,22 +188,30 @@ module WatchersHelper
|
|||
end.join.html_safe
|
||||
end
|
||||
|
||||
def applied_css(project)
|
||||
id = project.id
|
||||
"#{project.class.to_s.underscore}-#{id}-applied"
|
||||
end
|
||||
|
||||
def applied_link(project, user, options=[])
|
||||
return '' unless user && user.logged?
|
||||
applied = project.applied_projects.find_by_user_id(user.id)
|
||||
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
|
||||
|
||||
@applied_flag = project.instance_of?(Project)
|
||||
css = @applied_flag ? ([applied_css(project), applied ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
|
||||
([applied_css(project), applied ? 'icon icon-applied ' : 'icon icon-applied-off '].join(' ') << options[0].to_s)
|
||||
if applied
|
||||
appliedid = applied.id
|
||||
end
|
||||
|
||||
url = appliedproject_path(
|
||||
url = appliedproject_path(
|
||||
:id=>appliedid,
|
||||
:user_id => user.id,
|
||||
:project_id => project.id
|
||||
)
|
||||
method = applied ? 'delete' : 'post'
|
||||
|
||||
link_to text, url, :remote => true, :method => method
|
||||
link_to text, url, :remote => true, :method => method ,:class=>css
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<% selector = ".#{applied_css(@project)}" %>
|
||||
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript applied_link(@project, User.current) %>")});
|
||||
|
||||
|
|
@ -105,9 +105,9 @@
|
|||
</div>
|
||||
<!--添加项目申请-->
|
||||
<div style="margin-left: 20px;">
|
||||
|
||||
<% if ( !(User.current.member_of? @project) && User.current.login?) %> <!--added by linchun-->
|
||||
<span class="icon-fav icon"></span><%= applied_link(@project, User.current) %>
|
||||
<% if ( !(User.current.member_of? @project) && User.current.login?) %>
|
||||
<span class="icon-fav icon"></span>
|
||||
<%= applied_link(@project, User.current) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue