Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
a5b43954
Commit
a5b43954
authored
May 17, 2011
by
Gregor Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[#416] introducing separate rjs view to reduce controller code
parent
ae76abd1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
watchers_controller.rb
app/controllers/watchers_controller.rb
+10
-30
replace_selectors.rjs
app/views/watchers/replace_selectors.rjs
+22
-0
No files found.
app/controllers/watchers_controller.rb
View file @
a5b43954
...
...
@@ -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
...
...
app/views/watchers/replace_selectors.rjs
0 → 100644
View file @
a5b43954
@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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment