优化用户申请加入项目界面刷新
This commit is contained in:
parent
104ee13ac7
commit
1d6816419d
|
@ -2,15 +2,28 @@ class AppliedProjectController < ApplicationController
|
||||||
|
|
||||||
#申请加入项目
|
#申请加入项目
|
||||||
def applied_join_project
|
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])
|
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
|
end
|
||||||
|
|
||||||
#取消申请
|
#取消申请
|
||||||
def unapplied_join_project
|
def unapplied_join_project
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
@applied = AppliedProject.find(params[:id])
|
@applied = AppliedProject.find(params[:id])
|
||||||
@applied.destroy
|
@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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
module AppliedProjectHelper
|
module AppliedProjectHelper
|
||||||
|
|
||||||
|
def applied_css(project)
|
||||||
|
id = project.id
|
||||||
|
"#{project.class.to_s.underscore}-#{id}-applied"
|
||||||
|
end
|
||||||
|
|
||||||
def applied_link(project, user, options=[])
|
def applied_link(project, user, options=[])
|
||||||
return '' unless user && user.logged?
|
return '' unless user && user.logged?
|
||||||
applied = project.applied_projects.find_by_user_id(user.id)
|
applied = project.applied_projects.find_by_user_id(user.id)
|
||||||
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
|
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
|
if applied
|
||||||
appliedid = applied.id
|
appliedid = applied.id
|
||||||
end
|
end
|
||||||
|
|
||||||
url = appliedproject_path(
|
url = appliedproject_path(
|
||||||
:id=>appliedid,
|
:id=>appliedid,
|
||||||
:user_id => user.id,
|
:user_id => user.id,
|
||||||
|
@ -16,6 +23,6 @@ module AppliedProjectHelper
|
||||||
)
|
)
|
||||||
method = applied ? 'delete' : 'post'
|
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
|
end
|
||||||
|
|
|
@ -188,15 +188,22 @@ module WatchersHelper
|
||||||
end.join.html_safe
|
end.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def applied_css(project)
|
||||||
|
id = project.id
|
||||||
|
"#{project.class.to_s.underscore}-#{id}-applied"
|
||||||
|
end
|
||||||
|
|
||||||
def applied_link(project, user, options=[])
|
def applied_link(project, user, options=[])
|
||||||
return '' unless user && user.logged?
|
return '' unless user && user.logged?
|
||||||
applied = project.applied_projects.find_by_user_id(user.id)
|
applied = project.applied_projects.find_by_user_id(user.id)
|
||||||
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
|
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
|
if applied
|
||||||
appliedid = applied.id
|
appliedid = applied.id
|
||||||
end
|
end
|
||||||
|
|
||||||
url = appliedproject_path(
|
url = appliedproject_path(
|
||||||
:id=>appliedid,
|
:id=>appliedid,
|
||||||
:user_id => user.id,
|
:user_id => user.id,
|
||||||
|
@ -204,6 +211,7 @@ module WatchersHelper
|
||||||
)
|
)
|
||||||
method = applied ? 'delete' : 'post'
|
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
|
||||||
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>
|
||||||
<!--添加项目申请-->
|
<!--添加项目申请-->
|
||||||
<div style="margin-left: 20px;">
|
<div style="margin-left: 20px;">
|
||||||
|
<% if ( !(User.current.member_of? @project) && User.current.login?) %>
|
||||||
<% if ( !(User.current.member_of? @project) && User.current.login?) %> <!--added by linchun-->
|
<span class="icon-fav icon"></span>
|
||||||
<span class="icon-fav icon"></span><%= applied_link(@project, User.current) %>
|
<%= applied_link(@project, User.current) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue