socialforge/app/helpers/applied_project_helper.rb

29 lines
945 B
Ruby

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,
:project_id => project.id
)
method = applied ? 'delete' : 'post'
link_to text, url, :remote => true, :method => method ,:class=>css
end
end