diff --git a/app/controllers/management/conferences_controller.rb b/app/controllers/management/conferences_controller.rb index 262873a..c111310 100644 --- a/app/controllers/management/conferences_controller.rb +++ b/app/controllers/management/conferences_controller.rb @@ -1,11 +1,11 @@ module Management class ConferencesController < ManagementController - 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] + before_action :assign_conference, only: [:edit, :update, :show, :destroy, :open_call_for_papers, :close_call_for_papers] + before_action :assign_conferences, only: [:index, :destroy, :open_call_for_papers, :close_call_for_papers] def new @conference = Conference.new - 3.times { @conference.tracks.build } + @conference.tracks.build(name: 'Track 1') @conference.halls.build(name: 'Hall 1') end @@ -27,6 +27,15 @@ module Management def index end + def show + end + + def destroy + @conference.destroy + + render 'reload_table' + end + def open_call_for_papers @conference.call_for_papers_open = true @conference.save diff --git a/app/models/conference.rb b/app/models/conference.rb index 72c8587..af02deb 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -8,12 +8,12 @@ class Conference < ActiveRecord::Base translates :title, :description - has_many :tracks, -> { order('id asc') } + has_many :tracks, -> { order('id asc') }, dependent: :destroy has_many :events, through: :tracks has_many :candidate_speakers, through: :events - has_many :halls + has_many :halls, dependent: :destroy - accepts_nested_attributes_for :tracks, :halls, allow_destroy: true + accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, 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 cb0c70e..1bf42eb 100644 --- a/app/models/hall.rb +++ b/app/models/hall.rb @@ -1,4 +1,6 @@ class Hall < ActiveRecord::Base belongs_to :conference has_many :slots, dependent: :destroy + + validates :name, presence: true end diff --git a/app/models/track.rb b/app/models/track.rb index f33bb85..3e9b598 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -1,6 +1,6 @@ class Track < ActiveRecord::Base belongs_to :conference - has_many :events + has_many :events, dependent: :destroy validates :name, presence: true validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i} diff --git a/app/views/management/conferences/_conference.html.slim b/app/views/management/conferences/_conference.html.slim index b519ca1..91419d8 100644 --- a/app/views/management/conferences/_conference.html.slim +++ b/app/views/management/conferences/_conference.html.slim @@ -17,5 +17,5 @@ tr = fa_icon :eye = link_to edit_management_conference_path(conference), title: t('actions.edit.button', model: Conference.model_name.human), class: 'btn btn-primary' = fa_icon :edit - = link_to management_conference_path(conference), title: t('actions.destroy.button', model: Conference.model_name.human), class: 'btn btn-danger', method: :delete, data: {confirm: t('actions.are_you_sure')} + = link_to management_conference_path(conference), title: t('actions.destroy.button', model: Conference.model_name.human), class: ['btn', 'btn-danger', conference.events.any? ? 'disabled' : nil], remote: true, method: :delete, data: {confirm: t('actions.are_you_sure')} = fa_icon :trash diff --git a/app/views/management/conferences/_form_halls.html.slim b/app/views/management/conferences/_form_halls.html.slim index 76e9fd6..88ce9d8 100644 --- a/app/views/management/conferences/_form_halls.html.slim +++ b/app/views/management/conferences/_form_halls.html.slim @@ -1,6 +1,6 @@ div#halls = form.simple_fields_for :halls do |ff| - .col-md-3 + .col-md-4 .panel.panel-default .panel-heading .panel-title @@ -9,7 +9,7 @@ div#halls span.clearfix .panel-body = ff.input :name -.col-md-3 +.col-md-4 .panel.panel-default .panel-heading .panel-title