From ac5b1e2d4dca4fad274221631971ad76f5ca4c26 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 14 Oct 2014 23:07:50 +0300 Subject: [PATCH] Add Halls to the Conference form --- .../management/conferences_controller.rb | 24 +++++++++++++++++-- app/models/conference.rb | 3 ++- app/models/hall.rb | 1 + .../management/conferences/_form.html.slim | 8 ++++++- .../conferences/_form_halls.html.slim | 19 +++++++++++++++ .../conferences/_form_tracks.html.slim | 12 +++++++--- config/locales/bg.yml | 14 +++++++++-- 7 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 app/views/management/conferences/_form_halls.html.slim diff --git a/app/controllers/management/conferences_controller.rb b/app/controllers/management/conferences_controller.rb index ad47bbb..262873a 100644 --- a/app/controllers/management/conferences_controller.rb +++ b/app/controllers/management/conferences_controller.rb @@ -1,11 +1,12 @@ module Management class ConferencesController < ManagementController - before_action :assign_conference, only: [:edit, :open_call_for_papers, :close_call_for_papers] + before_action :assign_conference, only: [:edit, :update, :open_call_for_papers, :close_call_for_papers] before_action :assign_conferences, only: [:index, :open_call_for_papers, :close_call_for_papers] def new @conference = Conference.new 3.times { @conference.tracks.build } + @conference.halls.build(name: 'Hall 1') end def create @@ -14,6 +15,12 @@ module Management render :new end + def update + @conference.update conference_params + @conference.save + render :edit + end + def edit end @@ -45,7 +52,20 @@ module Management end def conference_params - params.require(:conference).permit [:title, :email, :start_date, :end_date, :description, tracks_attributes: [:id, :name, :color, :description, :_destroy]] + params.require(:conference).permit [:title, + :email, + :start_date, + :end_date, + :description, + tracks_attributes: [:id, + :name, + :color, + :description, + :_destroy], + halls_attributes: [:id, + :name, + :_destroy] + ] end end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 3ec53b1..72c8587 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -11,8 +11,9 @@ class Conference < ActiveRecord::Base has_many :tracks, -> { order('id asc') } has_many :events, through: :tracks has_many :candidate_speakers, through: :events + has_many :halls - accepts_nested_attributes_for :tracks + accepts_nested_attributes_for :tracks, :halls, allow_destroy: true scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') } diff --git a/app/models/hall.rb b/app/models/hall.rb index 9661672..cb0c70e 100644 --- a/app/models/hall.rb +++ b/app/models/hall.rb @@ -1,3 +1,4 @@ class Hall < ActiveRecord::Base belongs_to :conference + has_many :slots, dependent: :destroy end diff --git a/app/views/management/conferences/_form.html.slim b/app/views/management/conferences/_form.html.slim index 86490bf..ea021dd 100644 --- a/app/views/management/conferences/_form.html.slim +++ b/app/views/management/conferences/_form.html.slim @@ -10,7 +10,13 @@ = f.input :start_date, as: :date = f.input :end_date, as: :date = f.input :description - + hr + .row + .col-lg-12 + h2 = Hall.model_name.human(count: 2).mb_chars.capitalize + .row + = render partial: 'form_halls', locals: {form: f} + hr .row .col-lg-12 h2 = Track.model_name.human(count: 2).mb_chars.capitalize diff --git a/app/views/management/conferences/_form_halls.html.slim b/app/views/management/conferences/_form_halls.html.slim new file mode 100644 index 0000000..76e9fd6 --- /dev/null +++ b/app/views/management/conferences/_form_halls.html.slim @@ -0,0 +1,19 @@ +div#halls + = form.simple_fields_for :halls do |ff| + .col-md-3 + .panel.panel-default + .panel-heading + .panel-title + = Hall.model_name.human.mb_chars.capitalize + = ff.link_to_remove fa_icon(:remove), class: ['btn', 'btn-danger', 'btn-xs', 'pull-right'] + span.clearfix + .panel-body + = ff.input :name +.col-md-3 + .panel.panel-default + .panel-heading + .panel-title + = t 'actions.new.title_f', model: Hall.model_name.human + .panel-body + .form-group.text-center + = form.link_to_add t('actions.create.button', model: Hall.model_name.human), :halls, data: {target: '#halls'}, class: 'btn btn-success' diff --git a/app/views/management/conferences/_form_tracks.html.slim b/app/views/management/conferences/_form_tracks.html.slim index db3b338..b4eb773 100644 --- a/app/views/management/conferences/_form_tracks.html.slim +++ b/app/views/management/conferences/_form_tracks.html.slim @@ -2,13 +2,19 @@ div#tracks = form.simple_fields_for :tracks do |ff| .col-lg-6 .panel.panel-default + .panel-heading + .panel-title + = Track.model_name.human.mb_chars.capitalize + = ff.link_to_remove fa_icon(:remove), class: ['btn', 'btn-danger', 'btn-xs', 'pull-right', ff.object.events.any? ? 'disabled' : nil] + .panel-body = ff.input :name = ff.input :color, as: :color = ff.input :description - .panel-footer.text-right - = ff.link_to_remove t('actions.destroy.button', model: Track.model_name.human), class: ['btn', 'btn-danger', ff.object.events.any? ? 'disabled' : nil] .col-lg-6 .panel.panel-default - .panel-body.text-right + .panel-heading + .panel-title + = t 'actions.new.title_m', model: Track.model_name.human + .panel-body.text-center = form.link_to_add t('actions.create.button', model: Track.model_name.human), :tracks, data: {target: '#tracks'}, class: 'btn btn-success' diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 606a243..e2145c4 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -33,13 +33,17 @@ bg: button: Прегледай %{model} title: Преглед на %{model} are_you_sure: Сигурен ли си? - - create_new: Създаване на %{model_name} + new: + title_f: Нова %{model} + title_m: Нов %{model} event_mailer: acceptance_notification: subject: 'Предложението ви за %{conference} за %{submission_type} „%{title}“ е одобрено' activerecord: models: + hall: + one: зала + other: зали user: one: Потребител other: Потребители @@ -59,6 +63,12 @@ bg: one: конференция other: конференции attributes: + hall: + name: Име + track: + name: Име + color: Цвят + description: Описание conference: email: E-mail title: Заглавие