Skip to content

Commit

Permalink
Merge pull request #3138 from AndrewKvalheim/track-help
Browse files Browse the repository at this point in the history
Display track description on event proposal form
  • Loading branch information
hennevogel committed Apr 19, 2023
2 parents 4af293c + cdee712 commit af44d58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/osem.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,17 @@ function word_count(text, divId, maxcount) {
/* Wait for the DOM to be ready before attaching events to the elements */
$( document ).ready(function() {
/* Set the minimum and maximum proposal abstract word length */
$("#event_event_type_id").change(function () {
function updateEventTypeRequirements() {
var $selected = $("#event_event_type_id option:selected")
var max = $selected.data("max-words");
var min = $selected.data("min-words");

$("#abstract-maximum-word-count").text(max);
$("#abstract-minimum-word-count").text(min);
word_count($('#event_abstract').get(0), 'abstract-count', max);
})
.trigger('change');
}
$("#event_event_type_id").change(updateEventTypeRequirements);
updateEventTypeRequirements();

/* Count the proposal abstract length */
$("#event_abstract").on('input', function() {
Expand Down
14 changes: 7 additions & 7 deletions app/views/proposals/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
- if @program.tracks.confirmed.cfp_active.any?
.form-group
= f.label :track_id, 'Track'
= f.select :track_id, @program.tracks.confirmed.cfp_active.pluck(:name, :id), { include_blank: '(Please select)' }, { class: 'form-control' }
= f.select :track_id, @program.tracks.confirmed.cfp_active.pluck(:name, :id), { include_blank: '(Please select)' }, { class: 'form-control select-help-toggle' }
= render 'shared/select_help_text', f: f, for: :track_id, include_blank: true, options: @program.tracks.confirmed.cfp_active do |track|
= markdown(track.description)
.form-group
= f.label :event_type_id, 'Type'
= f.select :event_type_id, event_type_select_options(@conference.program.event_types), { include_blank: false }, { class: 'select-help-toggle form-control' }
- if @program.languages.present?
.form-group
= f.label :language
= f.select :language, @languages, { include_blank: false}, { class: 'select-help-toggle form-control' }
- @conference.program.event_types.each do |event_type|
%span{ class: 'help-block select-help-text event_event_type_id collapse', id: "#{event_type.id}-help" }
= event_type.description
= render 'shared/select_help_text', f: f, for: :event_type_id, options: @conference.program.event_types do |event_type|
= event_type.description
- if action_is_edit
- if @conference.program.difficulty_levels.any?
= f.label :difficulty_level
= f.select :difficulty_level_id, @conference.program.difficulty_levels.map{|level| [level.title, level.id ] }, {include_blank: false}, { class: 'select-help-toggle form-control' }
- @conference.program.difficulty_levels.each do |difficulty_level|
%span{ class: 'help-block select-help-text collapse event_difficulty_level_id', id: "#{difficulty_level.id}-help" }
= difficulty_level.description
= render 'shared/select_help_text', f: f, for: :difficulty_level_id, options: @conference.program.difficulty_levels do |difficulty_level|
= difficulty_level.description
.form-group
= f.label :abstract
= f.text_area :abstract, required: true, rows: 5, data: { provide: 'markdown' }, class: 'form-control'
Expand Down
10 changes: 10 additions & 0 deletions app/views/shared/_select_help_text.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:ruby
include_blank ||= false
select_id = field_id(f.object_name, local_assigns[:for])
value = f.object.send(local_assigns[:for])

- options.each_with_index do |option, i|
- selected = value.present? ? option.id == value : !include_blank && i == 0

%span.help-block.select-help-text.collapse{ id: "#{option.id}-help", class: [select_id, ('in' if selected)] }
= yield option
1 change: 1 addition & 0 deletions spec/factories/event_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
factory :event_type do
title { 'Example Event Type' }
length { 30 }
description { 'This event type is an example.' }
minimum_abstract_length { 0 }
maximum_abstract_length { 500 }
color { '#ffffff' }
Expand Down
15 changes: 11 additions & 4 deletions spec/features/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
@event.accept!(@options)
end

scenario 'not signed_in user submits proposal' do
scenario 'not signed_in user submits proposal', js: true do
expected_count_event = Event.count + 1
expected_count_user = User.count + 1

Expand All @@ -80,7 +80,9 @@
fill_in 'user_password_confirmation', with: 'testuserpassword'
end
fill_in 'event_title', with: 'Example Proposal'
expect(page).to have_selector '.in', text: 'Presentation in lecture format'
select('Example Event Type', from: 'event[event_type_id]')
expect(page).to have_selector '.in', text: 'This event type is an example.'
fill_in 'event_abstract', with: 'Lorem ipsum abstract'

click_button 'Create Proposal'
Expand All @@ -102,8 +104,11 @@
expect(page).to have_content 'Proposal Information'
end

scenario 'update a proposal' do
scenario 'update a proposal', js: true do
conference = create(:conference)
create :track, program: conference.program,
name: 'Example Track',
description: 'This track is an *example*.'
create(:cfp, program: conference.program)
proposal = create(:event, program: conference.program)

Expand All @@ -112,7 +117,10 @@
visit edit_conference_program_proposal_path(proposal.program.conference.short_title, proposal)

fill_in 'event_subtitle', with: 'My event subtitle'
select 'Example Track', from: 'Track'
expect(page).to have_selector '.in', text: 'This track is an example.'
select('Easy', from: 'event[difficulty_level_id]')
expect(page).to have_selector '.in', text: 'Events are understandable for everyone without knowledge of the topic.'

click_button 'Update Proposal'
page.find('#flash')
Expand All @@ -125,11 +133,10 @@

visit conference_program_proposals_path(conference.short_title)
click_link 'New Proposal'
expect(page).to have_selector(".in[id='#{find_field('event[event_type_id]').value}-help']") # End of animation

fill_in 'event_title', with: 'Example Proposal'
select('Example Event Type', from: 'event[event_type_id]')
expect(page).to have_selector(".in[id='#{find_field('event[event_type_id]').value}-help']") # End of animation
expect(page).to have_selector '.in', text: 'This event type is an example.'

fill_in 'event_abstract', with: 'Lorem ipsum abstract'
expect(page).to have_text('You have used 3 words')
Expand Down

0 comments on commit af44d58

Please sign in to comment.