2014-05-21 16:45:11 +08:00
|
|
|
class AppliedProjectController < ApplicationController
|
|
|
|
|
|
|
|
#申请加入项目
|
|
|
|
def applied_join_project
|
2014-05-21 19:30:49 +08:00
|
|
|
@user_id = params[:user_id]
|
2015-01-23 17:10:21 +08:00
|
|
|
@project = Project.find_by_id(params[:project_id])
|
|
|
|
if params[:project_join]
|
|
|
|
if @project
|
2015-01-30 11:39:19 +08:00
|
|
|
user = User.find @user_id
|
|
|
|
if user.member_of?(@project)
|
|
|
|
@status = 3
|
2015-01-26 15:41:10 +08:00
|
|
|
else
|
2015-01-30 11:39:19 +08:00
|
|
|
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
|
|
|
if @applieds.count == 0
|
|
|
|
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
|
|
|
Mailer.applied_project(appliedproject).deliver
|
|
|
|
@status = 2
|
|
|
|
else
|
|
|
|
@status = 1
|
|
|
|
end
|
2015-01-23 17:10:21 +08:00
|
|
|
end
|
|
|
|
else
|
|
|
|
@status = 0
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-05-22 11:58:43 +08:00
|
|
|
@applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id])
|
|
|
|
if @applieds.count == 0
|
2014-07-11 09:07:09 +08:00
|
|
|
appliedproject = AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
|
|
|
|
Mailer.applied_project(appliedproject).deliver
|
2014-05-22 11:58:43 +08:00
|
|
|
end
|
|
|
|
|
2014-05-21 19:30:49 +08:00
|
|
|
#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
|
2014-05-21 16:45:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
#取消申请
|
|
|
|
def unapplied_join_project
|
2014-05-21 19:30:49 +08:00
|
|
|
@project = Project.find(params[:project_id])
|
2014-05-22 11:58:43 +08:00
|
|
|
#@applied = AppliedProject.find(params[:id])
|
|
|
|
#@applied.destroy
|
|
|
|
|
|
|
|
AppliedProject.deleteappiled(params[:user_id], params[:project_id])
|
|
|
|
|
2014-05-21 19:30:49 +08:00
|
|
|
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
|
2014-05-21 16:45:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|