Skip to content

Commit

Permalink
validation for rating_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
shlok007 committed Apr 10, 2017
1 parent 1a6f8c7 commit 202b072
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/models/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def voting_period?
# ====Returns
# Errors when the condition is not true
def voting_dates_exist
errors.add(:voting_start_date, 'must be set, when voting is enabled') if rating_enabled && !voting_start_date && !voting_end_date

errors.add(:voting_end_date, 'must be set, when voting is enabled') if rating_enabled && !voting_start_date && !voting_end_date

errors.add(:voting_start_date, 'must be set, when blind voting is enabled') if blind_voting && !voting_start_date && !voting_end_date

errors.add(:voting_end_date, 'must be set, when blind voting is enabled') if blind_voting && !voting_start_date && !voting_end_date
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/programs/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
= f.input :schedule_public, label: 'Show Schedule on the home and splash page'
= f.input :schedule_fluid, label: 'Allow submitters to change their event after it is scheduled'
= f.input :languages, hint: "Enter the languages allowed for events as values of #{link_to('ISO 639-1', 'http://www.loc.gov/standards/iso639-2/php/code_list.php', target: "_blank")} language codes separated with commas. The first language would be the default language. Leave it blank if you do not want to specify languages.".html_safe
= f.input :rating_enabled, label: 'Enable voting'
= f.input :blind_voting, hint: 'Enable this feature if you do not want to show voting results and voters prior to user submitting a vote. For the feature to work you need to set the voting dates below as well'
= f.input :voting_start_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?) }
= f.input :voting_end_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?) }
= f.input :rating_enabled, label: 'Enable voting', hint: 'To enable voting you need to set voting dates as well'
= f.input :blind_voting, hint: 'Enable this feature if you do not want to show voting results and voters prior to user submitting a vote. For the feature to work you need to set the voting dates below as well', input_html: { class: 'voting_fields' }
= f.input :voting_start_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?),class: 'voting_fields' }
= f.input :voting_end_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?),class: 'voting_fields' }
%p.text-right
= f.action :submit, as: :button, button_html: {class: 'btn btn-primary'}

0 comments on commit 202b072

Please sign in to comment.