Add CFP Status to Conferences

This commit is contained in:
Petko Bordjukov 2014-10-14 21:58:13 +03:00
parent 17bbe0372a
commit 999da93b41
8 changed files with 59 additions and 9 deletions

View File

@ -3,12 +3,16 @@ th.actions, td.actions {
text-align: right;
}
td.actions {
td.action, td.actions {
i.fa {
font-size: 16px;
font-size: 14px;
}
}
th.action, td.action {
text-align: center;
}
.record-table td {
vertical-align: middle !important;
}

View File

@ -1,6 +1,7 @@
module Management
class ConferencesController < ManagementController
before_action :assign_conference, only: [:edit]
before_action :assign_conference, only: [:edit, :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
@ -17,7 +18,20 @@ module Management
end
def index
@conferences = Conference.all.order(start_date: :desc)
end
def open_call_for_papers
@conference.call_for_papers_open = true
@conference.save
render 'reload_table'
end
def close_call_for_papers
@conference.call_for_papers_open = false
@conference.save
render 'reload_table'
end
private
@ -26,6 +40,10 @@ module Management
@conference = Conference.find params[:id]
end
def assign_conferences
@conferences = Conference.all.order(start_date: :desc)
end
def conference_params
params.require(:conference).permit [:title, :email, :start_date, :end_date, :description, tracks_attributes: [:id, :name, :color, :description, :_destroy]]
end

View File

@ -16,12 +16,20 @@ class Conference < ActiveRecord::Base
scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') }
before_save :close_all_other_calls_for_papers
def self.current
future.first || last
end
private
def close_all_other_calls_for_papers
if call_for_papers_open? and call_for_papers_open_changed?
Conference.where.not(id: self.id).update_all call_for_papers_open: false
end
end
def end_date_is_before_start_date
if start_date.present? and end_date.present? and start_date > end_date
errors.add(:end_date, :cannot_be_before_start_date)

View File

@ -1,7 +1,15 @@
tr
td = conference.title
td = l conference.start_date.to_date, format: :long
td = l conference.end_date.to_date, format: :long
td.hidden-xs.hidden-sm = l conference.start_date.to_date, format: :long
td.hidden-xs.hidden-sm = l conference.end_date.to_date, format: :long
td.action
- if conference.call_for_papers_open?
= link_to cfp_management_conference_path(conference), method: :delete, class: 'btn btn-sm btn-success cfp-toggle', remote: true, onclick: '$(".cfp-toggle").addClass("disabled")'
= fa_icon 'dot-circle-o fw'
- else
= link_to cfp_management_conference_path(conference), method: :post, class: 'btn btn-sm btn-warning cfp-toggle', remote: true, onclick: '$(".cfp-toggle").addClass("disabled")'
= fa_icon 'circle-o fw'
td = conference.events.count
td.actions
div.btn-group.btn-group-sm

View File

@ -7,12 +7,13 @@
.panel-heading
h1.panel-title = Conference.model_name.human(count: 2).mb_chars.capitalize
.panel-body
table.table.table-striped.table-hover.record-table
table.table.table-striped.table-hover.record-table#conferences
thead
tr
th = Conference.human_attribute_name :title
th = Conference.human_attribute_name :start_date
th = Conference.human_attribute_name :end_date
th.hidden-xs.hidden-sm = Conference.human_attribute_name :start_date
th.hidden-xs.hidden-sm = Conference.human_attribute_name :end_date
th.action = Conference.human_attribute_name :call_for_papers_open
th = Conference.human_attribute_name :submissions
th.actions
tbody

View File

@ -0,0 +1 @@
$('#conferences tbody').html('<%= j render @conferences %>');

View File

@ -17,6 +17,11 @@ Rails.application.routes.draw do
get '/', to: 'events#index'
resources :conferences do
member do
post 'cfp', to: 'conferences#open_call_for_papers'
delete 'cfp', to: 'conferences#close_call_for_papers'
end
resources :events do
patch 'state'
end

View File

@ -0,0 +1,5 @@
class AddCallForPapersStatusToConferences < ActiveRecord::Migration
def change
add_column :conferences, :call_for_papers_open, :boolean
end
end