Use helpers for repeated event dropdown links

This commit is contained in:
James Mason 2018-02-13 16:33:11 -08:00
parent 4c58104a65
commit ad19a6d753
7 changed files with 370 additions and 146 deletions

View file

@ -54,4 +54,133 @@ module EventsHelper
def rating_tooltip(event, max_rating)
"#{event.average_rating}/#{max_rating}, #{pluralize(event.voters.length, 'vote')}"
end
def event_type_dropdown(event, event_types, conference_id)
selection = event.event_type.try(:title) || 'Event Type'
options = event_types.collect do |event_type|
[
event_type.title,
admin_conference_program_event_path(
conference_id,
event,
event: { event_type_id: event_type.id }
)
]
end
active_dropdown(selection, options)
end
def track_dropdown(event, tracks, conference_id)
selection = event.track.try(:name) || 'Track'
options = tracks.collect do |track|
[
track.name,
admin_conference_program_event_path(
conference_id,
event,
event: { track_id: track.id }
)
]
end
active_dropdown(selection, options)
end
def difficulty_dropdown(event, difficulties, conference_id)
selection = event.difficulty_level.try(:title) || 'Difficulty'
options = difficulties.collect do |difficulty|
[
difficulty.title,
admin_conference_program_event_path(
conference_id,
event,
event: { difficulty_level_id: difficulty.id }
)
]
end
active_dropdown(selection, options)
end
def state_dropdown(event, conference_id, email_settings)
selection = event.state.humanize
options = []
if event.transition_possible? :accept
options << [
'Accept',
accept_admin_conference_program_event_path(conference_id, event)
]
if email_settings.send_on_accepted?
options << [
'Accept (without email)',
accept_admin_conference_program_event_path(
conference_id,
event,
send_mail: false
)
]
end
end
if event.transition_possible? :reject
options << [
'Reject',
reject_admin_conference_program_event_path(conference_id, event)
]
if email_settings.send_on_rejected?
options << [
'Reject (without email)',
reject_admin_conference_program_event_path(
conference_id,
event,
send_mail: false
)
]
end
end
if event.transition_possible? :restart
options << [
'Start review',
restart_admin_conference_program_event_path(conference_id, event)
]
end
if event.transition_possible? :confirm
options << [
'Confirm',
confirm_admin_conference_program_event_path(conference_id, event)
]
end
if event.transition_possible? :cancel
options << [
'Cancel',
cancel_admin_conference_program_event_path(conference_id, event)
]
end
active_dropdown(selection, options)
end
private
def active_dropdown(selection, options)
# Consistent rendering of dropdown lists that submit patched changes
#
# Selection is the string to show by default, which is clicked to expose the
# dropdown options.
# Options is a list of 2-item lists; for each entry:
# * [0] is the text of the option,
# * [1] is the link url for the options
content_tag('div', class: 'dropdown') do
content_tag(
'a',
class: 'dropdown-toggle',
href: '#',
data: { toggle: 'dropdown' }
) do
content_tag('span', selection) +
content_tag('span', '', class: 'caret')
end +
content_tag('ul', class: 'dropdown-menu') do
options.collect do |option|
content_tag('li', link_to(option[0], option[1], method: :patch))
end.join.html_safe
end
end
end
end