29 lines
1.0 KiB
Ruby
29 lines
1.0 KiB
Ruby
module NoUsesHelper
|
|
def no_use_link(objects, user, options=[])
|
|
return '' unless user && user.logged?
|
|
objects = Array.wrap(objects)
|
|
|
|
clicked = objects.any? {|object| object.no_use_for?(user)}
|
|
# @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid)))
|
|
css = no_use_css(objects) << options[0].to_s
|
|
# ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s)
|
|
|
|
text = clicked ? l(:cancel_no_use) : l(:no_use)
|
|
|
|
url = no_uses_path(
|
|
:object_type => objects.first.class.to_s.underscore,
|
|
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
|
)
|
|
method = clicked ? 'delete' : 'post'
|
|
|
|
link_to text, url, :remote => true, :method => method, :class => css
|
|
#, :class => css
|
|
end
|
|
|
|
def no_use_css(objects)
|
|
objects = Array.wrap(objects)
|
|
id = (objects.size == 1 ? objects.first.id : 'bulk')
|
|
"#{objects.first.class.to_s.underscore}-#{id}-watcher"
|
|
end
|
|
end
|