diff --git a/app/assets/stylesheets/management/_record_tables.css.scss b/app/assets/stylesheets/management/_record_tables.css.scss index 1a021cd..d4faf9f 100644 --- a/app/assets/stylesheets/management/_record_tables.css.scss +++ b/app/assets/stylesheets/management/_record_tables.css.scss @@ -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; } \ No newline at end of file diff --git a/app/controllers/management/conferences_controller.rb b/app/controllers/management/conferences_controller.rb index 307bc4d..ad47bbb 100644 --- a/app/controllers/management/conferences_controller.rb +++ b/app/controllers/management/conferences_controller.rb @@ -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 diff --git a/app/models/conference.rb b/app/models/conference.rb index 273f0d4..3ec53b1 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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) diff --git a/app/views/management/conferences/_conference.html.slim b/app/views/management/conferences/_conference.html.slim index e7aa1ff..b519ca1 100644 --- a/app/views/management/conferences/_conference.html.slim +++ b/app/views/management/conferences/_conference.html.slim @@ -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 diff --git a/app/views/management/conferences/index.html.slim b/app/views/management/conferences/index.html.slim index aa349c1..d3c1643 100644 --- a/app/views/management/conferences/index.html.slim +++ b/app/views/management/conferences/index.html.slim @@ -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 diff --git a/app/views/management/conferences/reload_table.js.erb b/app/views/management/conferences/reload_table.js.erb new file mode 100644 index 0000000..64ae1b6 --- /dev/null +++ b/app/views/management/conferences/reload_table.js.erb @@ -0,0 +1 @@ +$('#conferences tbody').html('<%= j render @conferences %>'); diff --git a/config/routes.rb b/config/routes.rb index b5ed0e8..f0e89ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20141014181014_add_call_for_papers_status_to_conferences.rb b/db/migrate/20141014181014_add_call_for_papers_status_to_conferences.rb new file mode 100644 index 0000000..5bebc5b --- /dev/null +++ b/db/migrate/20141014181014_add_call_for_papers_status_to_conferences.rb @@ -0,0 +1,5 @@ +class AddCallForPapersStatusToConferences < ActiveRecord::Migration + def change + add_column :conferences, :call_for_papers_open, :boolean + end +end