[#416] introducing separate rjs view to reduce controller code
This commit is contained in:
parent
ae76abd140
commit
a5b439544a
|
@ -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
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
@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
|
||||
|
Loading…
Reference in New Issue