diff --git a/app/models/event.rb b/app/models/event.rb index 0992eac..3d8d28a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,15 +11,28 @@ class Event < ActiveRecord::Base belongs_to :event_type + 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 + scope :confirmed, -> { where.not confirmed_at: nil } def proposer_profile proposer.personal_profile(conference) end + + private + + def track_belongs_to_the_selected_conference + unless conference.present? and conference.tracks.include?(track) + errors.add :track, :must_be_a_valid_track + end + end end diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 13dfe4a..d47dcf1 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -136,7 +136,7 @@ bg: abstract: Резюме description: Описание notes: Забележки - track_id: Поток от лекции + track: Поток от лекции agreement: Съгласен(на) съм user: Лектор event_type: @@ -144,6 +144,10 @@ bg: description: Описание errors: models: + event: + attributes: + track: + must_be_a_valid_track: трябва да е някой от изброените потоци от лекции user: attributes: email: diff --git a/lib/open_fest/app/controllers/open_fest/events_controller.rb b/lib/open_fest/app/controllers/open_fest/events_controller.rb index 1e77dfb..e8741ad 100644 --- a/lib/open_fest/app/controllers/open_fest/events_controller.rb +++ b/lib/open_fest/app/controllers/open_fest/events_controller.rb @@ -2,20 +2,23 @@ require_dependency "open_fest/application_controller" module OpenFest class EventsController < ApplicationController + before_filter :authenticate_user! + def index end def new - @event_type = current_conference.event_types.find(params[:type]) - @event = Event.new(event_type: @event_type) + event_type = current_conference.event_types.find(params[:type]) + @event = Event.new event_type: event_type end def create - @event = Event.new(event_params) + @event = Event.new event_params + @event.conference = current_conference + @event.build_proposition proposer: current_user + @event.participations.build participant: current_user, approved: true if @event.save - # TODO (2015-08-10) Flash message? - flash[:notice] = 'Event was successfully created.' redirect_to action: :index else render action: :new @@ -26,7 +29,7 @@ module OpenFest def event_params params.require(:event).permit( - :title, :subtitle, :length, :language, + :title, :subtitle, :track_id, :length, :language, :abstract, :description, :notes, :agreement, :event_type_id ) diff --git a/lib/open_fest/app/views/open_fest/events/new.slim b/lib/open_fest/app/views/open_fest/events/new.slim index 4d9638a..bcd8909 100644 --- a/lib/open_fest/app/views/open_fest/events/new.slim +++ b/lib/open_fest/app/views/open_fest/events/new.slim @@ -1,22 +1,20 @@ = simple_form_for @event, wrapper: :default do |form| + = form.input :event_type_id, as: :hidden, wrapper: false + + h2= t('submit_event', event_type: @event.event_type.name) + p = form.error_notification - h2= t('submit_event', event_type: @event_type.name) - .form-inputs - = form.input :event_type_id, as: :hidden - = form.input :title, autofocus: true = form.input :subtitle - - -# TODO tracks -> indirectly through proposition? - -# form.input :track_id, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] }, required: true + = form.association :track, wrapper: :default, collection: current_conference.tracks -# TODO length is different for different types of events (translation problem) = form.input :length - = form.input :language, collection: I18n.available_locales, include_blank: false, default: I18n.locale + = form.input :language, as: :radio_buttons, collection: I18n.available_locales, include_blank: false, default: I18n.locale, wrapper: :default = form.input :abstract = form.input :description = form.input :notes diff --git a/lib/open_fest/config/locales/simple_form.bg.yml b/lib/open_fest/config/locales/simple_form.bg.yml index 9c04343..2ddc9e7 100644 --- a/lib/open_fest/config/locales/simple_form.bg.yml +++ b/lib/open_fest/config/locales/simple_form.bg.yml @@ -23,7 +23,7 @@ bg: event: title: Заглавието на събитието Ви subtitle: Подзаглавието на събитието Ви (ако има такова) - track_id: Потокът от лекции, в който искате да попадне събитието Ви + track: Потокът от лекции, в който искате да попадне събитието Ви length: Продължителността на събитието може да бъде от 40 до 45 минути language: Език, на който ще бъде водено събитието abstract: Резюме на събитието, което да може да бъде прочетено от посетителите (1 абзац)