Add event length limitations

This commit is contained in:
Petko Bordjukov 2015-08-20 00:24:22 +03:00
parent f14c3bc665
commit a87c7bd496
6 changed files with 26 additions and 11 deletions

View File

@ -52,7 +52,8 @@ module Management
def conference_params def conference_params
params.require(:conference).permit( params.require(:conference).permit(
:title, :email, :start_date, :end_date, :description, :host_name, :title, :email, :start_date, :end_date, :description, :host_name,
event_types_attributes: [:id, :name, :description, :_destroy], event_types_attributes: [:id, :name, :description, :maximum_length,
:minimum_length, :_destroy],
tracks_attributes: [:id, :name, :color, :description, :_destroy], tracks_attributes: [:id, :name, :color, :description, :_destroy],
halls_attributes: [:id, :name, :_destroy] halls_attributes: [:id, :name, :_destroy]
) )

View File

@ -13,14 +13,15 @@ class Event < ActiveRecord::Base
validates :conference, presence: true validates :conference, presence: true
validates :title, presence: true validates :title, presence: true
validates :length, presence: true, numericality: {only_integer: true, greater_than: 0}
validates :abstract, presence: true validates :abstract, presence: true
validates :description, presence: true validates :description, presence: true
validates :agreement, acceptance: true validates :agreement, acceptance: true
validates :track, presence: true validates :track, presence: true
validate :track_belongs_to_the_selected_conference validate :track_belongs_to_the_selected_conference
validates :language, inclusion: {in: I18n.available_locales.map(&:to_s)}, presence: true validates :language, inclusion: {in: I18n.available_locales.map(&:to_s)}, presence: true
validates :event_type, presence: true
validates :length, presence: true, numericality: {only_integer: true}
validate :length_is_within_the_permitted_interval
scope :confirmed, -> { where.not confirmed_at: nil } scope :confirmed, -> { where.not confirmed_at: nil }
@ -35,4 +36,10 @@ class Event < ActiveRecord::Base
errors.add :track, :must_be_a_valid_track errors.add :track, :must_be_a_valid_track
end end
end end
def length_is_within_the_permitted_interval
unless length >= event_type.minimum_length and length <= event_type.maximum_length
errors.add :length, :must_be_between, minimum: event_type.minimum_length, maximum: event_type.maximum_length
end
end
end end

View File

@ -10,6 +10,8 @@ div#event_types
.panel-body .panel-body
= ff.input :name = ff.input :name
= ff.input :description = ff.input :description
= ff.input :minimum_length
= ff.input :maximum_length
.col-lg-6 .col-lg-6
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading

View File

@ -47,6 +47,8 @@ bg:
event_type: event_type:
description: "Описание" description: "Описание"
name: "Име" name: "Име"
minimum_length: Минимална продължителност
maximum_length: Максимална продължителност
hall: hall:
name: "Име" name: "Име"
personal_profile: personal_profile:
@ -76,6 +78,8 @@ bg:
attributes: attributes:
track: track:
must_be_a_valid_track: "трябва да е някой от изброените потоци от лекции" must_be_a_valid_track: "трябва да е някой от изброените потоци от лекции"
length:
must_be_between: "трябва да е между %{minimum} и %{maximum} минути"
personal_profile: personal_profile:
attributes: attributes:
github: github:
@ -238,7 +242,7 @@ bg:
agreement: "Отбележете съгласни ли сте с това събитието Ви да бъде записано и публикувано под лиценз CC-BY-ND (Creative Commons Attribution No Derivatives)" agreement: "Отбележете съгласни ли сте с това събитието Ви да бъде записано и публикувано под лиценз CC-BY-ND (Creative Commons Attribution No Derivatives)"
description: "Подробно описание на предложението (няколко абзаца)" description: "Подробно описание на предложението (няколко абзаца)"
language: "" language: ""
length: "Продължителността на събитието (в минути)" length: "Продължителността на събитието (в минути). Продължителността на %{type} е между %{min} и %{max} минути, заедно с въпросите"
notes: "Допълнителни бележки, които искате да споделите с организаторския екип" notes: "Допълнителни бележки, които искате да споделите с организаторския екип"
subtitle: "" subtitle: ""
title: "" title: ""

View File

@ -47,6 +47,8 @@ en:
event_type: event_type:
description: Description description: Description
name: Name name: Name
minimum_length: Minimum length
maximum_length: Maximum length
hall: hall:
name: Name name: Name
personal_profile: personal_profile:
@ -76,6 +78,8 @@ en:
attributes: attributes:
track: track:
must_be_a_valid_track: must be one of the listed lecture tracks must_be_a_valid_track: must be one of the listed lecture tracks
length:
must_be_between: "must be between %{minimum} and %{maximum} minutes"
personal_profile: personal_profile:
attributes: attributes:
github: github:
@ -202,7 +206,7 @@ en:
are_you_sure: Are you sure you want to delete your registration are_you_sure: Are you sure you want to delete your registration
cancel_my_account: Delete my account cancel_my_account: Delete my account
edit_account: Edit account edit_account: Edit account
leave_blank_if_you_do_not_want_to_change: leave blank if you don't want to change it leave_blank_if_you_do_not_want_to_change: "leave blank if you don't want to change it"
minimum_characters: at least %{minimum} symbols minimum_characters: at least %{minimum} symbols
sign_me_up: Sign me up sign_me_up: Sign me up
sign_up: Registration sign_up: Registration
@ -237,8 +241,8 @@ en:
abstract: An abstract of the event that will be published for the attendees to read (around 1 paragraph) abstract: An abstract of the event that will be published for the attendees to read (around 1 paragraph)
agreement: Indicate if you accept your workshop to be recorded and published under the CC-BY-ND (Creative Commons Attribution No Derivatives) license agreement: Indicate if you accept your workshop to be recorded and published under the CC-BY-ND (Creative Commons Attribution No Derivatives) license
description: Detailed description of the event (several paragraphs) description: Detailed description of the event (several paragraphs)
language: "" language: "Language"
length: Length of the event length: "Length of the event (in minutes). The length of a %{type} is between %{min} and %{max} minutes"
notes: Notes that you'd like the organisation team to read notes: Notes that you'd like the organisation team to read
subtitle: "" subtitle: ""
title: "" title: ""

View File

@ -8,10 +8,7 @@
= form.input :title, autofocus: true = form.input :title, autofocus: true
= form.input :subtitle = form.input :subtitle
= form.association :track, wrapper: :default, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] } = form.association :track, wrapper: :default, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] }
= form.input :length, hint: t('simple_form.hints.event.length', type: @event.event_type.name.mb_chars.downcase, min: @event.event_type.minimum_length, max: @event.event_type.maximum_length)
-# TODO length is different for different types of events (translation problem)
= form.input :length
= form.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default, checked: current_user.language = form.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default, checked: current_user.language
= form.input :abstract = form.input :abstract
= form.input :description = form.input :description