Commit a5b43954 authored by Gregor Schmidt's avatar Gregor Schmidt

[#416] introducing separate rjs view to reduce controller code

parent ae76abd1
......@@ -76,42 +76,22 @@ private
def set_watcher(user, watching)
@watched.set_watcher(user, watching)
if params[:replace].present?
if params[:replace].is_a? Array
replace_selectors = params[:replace]
else
replace_selectors = params[:replace].split(',').map(&:strip)
end
else
replace_selectors = ['#watcher']
end
respond_to do |format|
format.html { redirect_to :back }
format.js do
render(:update) do |page|
replace_selectors.each do |selector|
next if selector.blank?
case selector
when '#watchers'
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
else
page.select(selector).each do |node|
options = {:replace => replace_selectors}
last_selector = selector.split(' ').last
if last_selector.starts_with? '.'
options[:class] = last_selector[1..-1]
elsif last_selector.starts_with? '#'
options[:id] = last_selector[1..-1]
end
node.replace watcher_link(@watched, user, options)
end
end
if params[:replace].present?
if params[:replace].is_a? Array
@replace_selectors = params[:replace]
else
@replace_selectors = params[:replace].split(',').map(&:strip)
end
else
@replace_selectors = ['#watcher']
end
@user = user
render :action => 'replace_selectors'
end
end
rescue ::ActionController::RedirectBackError
......
@replace_selectors.each do |selector|
next if selector.blank?
case selector
when '#watchers'
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
else
page.select(selector).each do |node|
options = {:replace => @replace_selectors}
last_selector = selector.split(' ').last
if last_selector.starts_with? '.'
options[:class] = last_selector[1..-1]
elsif last_selector.starts_with? '#'
options[:id] = last_selector[1..-1]
end
node.replace watcher_link(@watched, @user, options)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment