Implement missing event submission functionality

This commit is contained in:
Petko Bordjukov 2015-08-15 00:43:30 +03:00
parent d279ab6f0d
commit 9c607b6ccd
5 changed files with 34 additions and 16 deletions

View File

@ -11,15 +11,28 @@ class Event < ActiveRecord::Base
belongs_to :event_type belongs_to :event_type
validates :conference, presence: true
validates :title, presence: true validates :title, presence: true
validates :length, presence: true, numericality: {only_integer: true, greater_than: 0} 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
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 } scope :confirmed, -> { where.not confirmed_at: nil }
def proposer_profile def proposer_profile
proposer.personal_profile(conference) proposer.personal_profile(conference)
end 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 end

View File

@ -136,7 +136,7 @@ bg:
abstract: Резюме abstract: Резюме
description: Описание description: Описание
notes: Забележки notes: Забележки
track_id: Поток от лекции track: Поток от лекции
agreement: Съгласен(на) съм agreement: Съгласен(на) съм
user: Лектор user: Лектор
event_type: event_type:
@ -144,6 +144,10 @@ bg:
description: Описание description: Описание
errors: errors:
models: models:
event:
attributes:
track:
must_be_a_valid_track: трябва да е някой от изброените потоци от лекции
user: user:
attributes: attributes:
email: email:

View File

@ -2,20 +2,23 @@ require_dependency "open_fest/application_controller"
module OpenFest module OpenFest
class EventsController < ApplicationController class EventsController < ApplicationController
before_filter :authenticate_user!
def index def index
end end
def new def new
@event_type = current_conference.event_types.find(params[:type]) event_type = current_conference.event_types.find(params[:type])
@event = Event.new(event_type: @event_type) @event = Event.new event_type: event_type
end end
def create 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 if @event.save
# TODO (2015-08-10) Flash message?
flash[:notice] = 'Event was successfully created.'
redirect_to action: :index redirect_to action: :index
else else
render action: :new render action: :new
@ -26,7 +29,7 @@ module OpenFest
def event_params def event_params
params.require(:event).permit( params.require(:event).permit(
:title, :subtitle, :length, :language, :title, :subtitle, :track_id, :length, :language,
:abstract, :description, :notes, :agreement, :abstract, :description, :notes, :agreement,
:event_type_id :event_type_id
) )

View File

@ -1,22 +1,20 @@
= simple_form_for @event, wrapper: :default do |form| = 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 p
= form.error_notification = form.error_notification
h2= t('submit_event', event_type: @event_type.name)
.form-inputs .form-inputs
= form.input :event_type_id, as: :hidden
= 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
-# TODO tracks -> indirectly through proposition?
-# form.input :track_id, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] }, required: true
-# TODO length is different for different types of events (translation problem) -# TODO length is different for different types of events (translation problem)
= form.input :length = 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 :abstract
= form.input :description = form.input :description
= form.input :notes = form.input :notes

View File

@ -23,7 +23,7 @@ bg:
event: event:
title: Заглавието на събитието Ви title: Заглавието на събитието Ви
subtitle: Подзаглавието на събитието Ви (ако има такова) subtitle: Подзаглавието на събитието Ви (ако има такова)
track_id: Потокът от лекции, в който искате да попадне събитието Ви track: Потокът от лекции, в който искате да попадне събитието Ви
length: Продължителността на събитието може да бъде от 40 до 45 минути length: Продължителността на събитието може да бъде от 40 до 45 минути
language: Език, на който ще бъде водено събитието language: Език, на който ще бъде водено събитието
abstract: Резюме на събитието, което да може да бъде прочетено от посетителите (1 абзац) abstract: Резюме на събитието, което да може да бъде прочетено от посетителите (1 абзац)