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) css = apply_css(objects) << options[0].to_s text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master) url = apply_project_masters_path( :object_type => objects.first.class.to_s.underscore, :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) ) method = applied ? 'delete' : 'post' link_to text, url, :remote => true, :method => method, :class => css end 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 end