diff --git a/app/controllers/management/conferences_controller.rb b/app/controllers/management/conferences_controller.rb index 5b706d9..652ddd2 100644 --- a/app/controllers/management/conferences_controller.rb +++ b/app/controllers/management/conferences_controller.rb @@ -52,7 +52,8 @@ module Management def conference_params params.require(:conference).permit( :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], halls_attributes: [:id, :name, :_destroy] ) diff --git a/app/models/event.rb b/app/models/event.rb index 3d8d28a..ecf9973 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -13,14 +13,15 @@ class Event < ActiveRecord::Base validates :conference, presence: true validates :title, presence: true - validates :length, presence: true, numericality: {only_integer: true, greater_than: 0} validates :abstract, presence: true validates :description, presence: true validates :agreement, acceptance: true validates :track, presence: true validate :track_belongs_to_the_selected_conference 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 } @@ -35,4 +36,10 @@ class Event < ActiveRecord::Base errors.add :track, :must_be_a_valid_track 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 diff --git a/app/views/management/conferences/_form_event_types.slim b/app/views/management/conferences/_form_event_types.slim index cd57e83..cb2cb05 100644 --- a/app/views/management/conferences/_form_event_types.slim +++ b/app/views/management/conferences/_form_event_types.slim @@ -10,6 +10,8 @@ div#event_types .panel-body = ff.input :name = ff.input :description + = ff.input :minimum_length + = ff.input :maximum_length .col-lg-6 .panel.panel-default .panel-heading diff --git a/config/locales/bg.yml b/config/locales/bg.yml index a86497a..76d21df 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -47,6 +47,8 @@ bg: event_type: description: "Описание" name: "Име" + minimum_length: Минимална продължителност + maximum_length: Максимална продължителност hall: name: "Име" personal_profile: @@ -76,6 +78,8 @@ bg: attributes: track: must_be_a_valid_track: "трябва да е някой от изброените потоци от лекции" + length: + must_be_between: "трябва да е между %{minimum} и %{maximum} минути" personal_profile: attributes: github: @@ -238,7 +242,7 @@ bg: agreement: "Отбележете съгласни ли сте с това събитието Ви да бъде записано и публикувано под лиценз CC-BY-ND (Creative Commons – Attribution – No Derivatives)" description: "Подробно описание на предложението (няколко абзаца)" language: "" - length: "Продължителността на събитието (в минути)" + length: "Продължителността на събитието (в минути). Продължителността на %{type} е между %{min} и %{max} минути, заедно с въпросите" notes: "Допълнителни бележки, които искате да споделите с организаторския екип" subtitle: "" title: "" diff --git a/config/locales/en.yml b/config/locales/en.yml index 133be12..5075984 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,6 +47,8 @@ en: event_type: description: Description name: Name + minimum_length: Minimum length + maximum_length: Maximum length hall: name: Name personal_profile: @@ -76,6 +78,8 @@ en: attributes: track: 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: attributes: github: @@ -202,7 +206,7 @@ en: are_you_sure: Are you sure you want to delete your registration cancel_my_account: Delete my 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 sign_me_up: Sign me up 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) 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) - language: "" - length: Length of the event + language: "Language" + 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 subtitle: "" title: "" diff --git a/lib/initfest/views/public/events/_form.slim b/lib/initfest/views/public/events/_form.slim index 7c9fd38..74f66a3 100644 --- a/lib/initfest/views/public/events/_form.slim +++ b/lib/initfest/views/public/events/_form.slim @@ -8,10 +8,7 @@ = form.input :title, autofocus: true = form.input :subtitle = form.association :track, wrapper: :default, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] } - - -# TODO length is different for different types of events (translation problem) - = form.input :length - + = 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) = form.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default, checked: current_user.language = form.input :abstract = form.input :description