[#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)
|
def set_watcher(user, watching)
|
||||||
@watched.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|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js do
|
format.js do
|
||||||
render(:update) do |page|
|
if params[:replace].present?
|
||||||
replace_selectors.each do |selector|
|
if params[:replace].is_a? Array
|
||||||
next if selector.blank?
|
@replace_selectors = params[:replace]
|
||||||
|
else
|
||||||
case selector
|
@replace_selectors = params[:replace].split(',').map(&:strip)
|
||||||
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
|
end
|
||||||
|
else
|
||||||
|
@replace_selectors = ['#watcher']
|
||||||
end
|
end
|
||||||
|
@user = user
|
||||||
|
|
||||||
|
render :action => 'replace_selectors'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ::ActionController::RedirectBackError
|
rescue ::ActionController::RedirectBackError
|
||||||
|
22
app/views/watchers/replace_selectors.rjs
Normal file
22
app/views/watchers/replace_selectors.rjs
Normal file
@ -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…
x
Reference in New Issue
Block a user