Helper instead of template.
This commit is contained in:
parent
0a6e978db7
commit
1591467655
3 changed files with 25 additions and 25 deletions
|
@ -122,6 +122,28 @@ module ProjectsHelper
|
|||
options_for_select(values, current_tracker)
|
||||
end
|
||||
|
||||
def link_to_toggle_star(title, starred, signed_in)
|
||||
cls = 'btn'
|
||||
cls += ' disabled' unless signed_in
|
||||
content_tag 'span', class: starred ? 'turn-on' : 'turn-off' do
|
||||
link_to toggle_star_project_path(@project),
|
||||
title: title, class: cls, method: :post, remote: true,
|
||||
data: {type: 'json'} do
|
||||
content_tag('span', class: 'toggle') do
|
||||
content_tag('i', ' ', class: 'icon-star') <<
|
||||
if starred
|
||||
'Unstar'
|
||||
else
|
||||
'Star'
|
||||
end
|
||||
end <<
|
||||
content_tag('span', class: 'count') do
|
||||
@project.star_count.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_project_nav_tabs(project, current_user)
|
||||
|
|
|
@ -36,16 +36,7 @@
|
|||
%span.light.prepend-left-20= repository_size
|
||||
%span.star.js-toggler-container{class: @show_star ? 'on' : ''}
|
||||
- if current_user
|
||||
= render 'link_to_toggle_star',
|
||||
title: 'Star this project.',
|
||||
starred: false,
|
||||
signed_in: true
|
||||
= render 'link_to_toggle_star',
|
||||
title: 'Unstar this project.',
|
||||
starred: true,
|
||||
signed_in: true
|
||||
= link_to_toggle_star('Star this project.', false, true)
|
||||
= link_to_toggle_star('Unstar this project.', true, true)
|
||||
- else
|
||||
= render 'link_to_toggle_star',
|
||||
title: 'You must sign in to star a project.',
|
||||
starred: false,
|
||||
signed_in: false
|
||||
= link_to_toggle_star('You must sign in to star a project.', false, false)
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
- cls = 'btn'
|
||||
- cls += ' disabled' unless signed_in
|
||||
%span{class: starred ? 'turn-on' : 'turn-off'}
|
||||
= link_to toggle_star_project_path(@project), title: title,
|
||||
class: cls, method: :post, remote: true, data: {type: 'json'} do
|
||||
%span.toggle<>
|
||||
%i.icon-star
|
||||
- if starred
|
||||
Unstar
|
||||
- else
|
||||
Star
|
||||
%span.count<>
|
||||
= @project.star_count
|
Loading…
Reference in a new issue