2014-04-03 20:47:09 +08:00
|
|
|
module ApplyProjectMastersHelper
|
|
|
|
def apply_super_user(objects, user, options=[])
|
|
|
|
return '' unless user && user.logged?
|
|
|
|
objects = Array.wrap(objects)
|
|
|
|
|
|
|
|
applied = objects.any? {|object| object.applied_by?(user)}
|
|
|
|
allowed = objects.any? {|object| object.allowed?(user)}
|
|
|
|
# @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid)))
|
|
|
|
# css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) :
|
|
|
|
# ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s)
|
|
|
|
|
2014-04-06 16:34:23 +08:00
|
|
|
css = apply_css(objects) << options[0].to_s
|
|
|
|
|
2014-04-06 22:12:16 +08:00
|
|
|
text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master)
|
2014-04-03 20:47:09 +08:00
|
|
|
|
2014-04-06 16:34:23 +08:00
|
|
|
url = apply_project_masters_path(
|
2014-04-03 20:47:09 +08:00
|
|
|
:object_type => objects.first.class.to_s.underscore,
|
|
|
|
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
|
|
|
)
|
|
|
|
method = applied ? 'delete' : 'post'
|
|
|
|
|
2014-04-06 16:34:23 +08:00
|
|
|
link_to text, url, :remote => true, :method => method, :class => css
|
2014-04-03 20:47:09 +08:00
|
|
|
end
|
2014-04-06 16:34:23 +08:00
|
|
|
|
|
|
|
def apply_css(objects)
|
|
|
|
objects = Array.wrap(objects)
|
|
|
|
id = (objects.size == 1 ? objects.first.id : 'bulk')
|
|
|
|
"#{objects.first.class.to_s.underscore}-#{id}-watcher"
|
|
|
|
end
|
|
|
|
|
2014-04-03 20:47:09 +08:00
|
|
|
end
|