diff --git a/app/assets/javascripts/management/conferences.js.coffee b/app/assets/javascripts/management/conferences.js.coffee index b716601..0f0f9f4 100644 --- a/app/assets/javascripts/management/conferences.js.coffee +++ b/app/assets/javascripts/management/conferences.js.coffee @@ -1,4 +1,6 @@ $ -> + $('.cfp-toggle').click -> + $(this).addClass("disabled") Morris.Line element: 'submissions-chart' data: $('#submissions-chart').data('submissions') diff --git a/app/controllers/management/call_for_participations_controller.rb b/app/controllers/management/call_for_participations_controller.rb new file mode 100644 index 0000000..4553d53 --- /dev/null +++ b/app/controllers/management/call_for_participations_controller.rb @@ -0,0 +1,21 @@ +module Management + class CallForParticipationsController < ManagementController + before_action :assign_conference + + def create + @conference.call_for_participation.open! + render :redraw + end + + def destroy + @conference.call_for_participation.close! + render :redraw + end + + private + + def assign_conference + @conference = Conference.find params[:conference_id] + end + end +end diff --git a/app/views/management/call_for_participations/_status.html.slim b/app/views/management/call_for_participations/_status.html.slim new file mode 100644 index 0000000..17a109b --- /dev/null +++ b/app/views/management/call_for_participations/_status.html.slim @@ -0,0 +1,7 @@ +div id="cfp-status-#{conference.id}" + - if conference.call_for_participation.in_progress? + = link_to management_conference_call_for_participation_path(conference), method: :delete, class: 'btn btn-sm btn-success cfp-toggle', remote: true + = icon 'dot-circle-o', '', class: 'fa-fw' + - else + = link_to management_conference_call_for_participation_path(conference), method: :post, class: 'btn btn-sm btn-warning cfp-toggle', remote: true + = icon 'circle-o', class: 'fa-fw' diff --git a/app/views/management/call_for_participations/redraw.js.erb b/app/views/management/call_for_participations/redraw.js.erb new file mode 100644 index 0000000..4bb1499 --- /dev/null +++ b/app/views/management/call_for_participations/redraw.js.erb @@ -0,0 +1,2 @@ +$('#cfp-status-<%= @conference.id %>').replaceWith('<%= j render partial: 'status', locals: {conference: @conference}%>'); +$('#cfp-status-<%= @conference.id %>').children('.cfp-toggle').click(function() {$(this).addClass("disabled");}); diff --git a/app/views/management/conferences/_conference.html.slim b/app/views/management/conferences/_conference.html.slim index 98f279b..df99593 100644 --- a/app/views/management/conferences/_conference.html.slim +++ b/app/views/management/conferences/_conference.html.slim @@ -3,12 +3,7 @@ tr 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 '#', method: :delete, class: 'btn btn-sm btn-success cfp-toggle', remote: true, onclick: '$(".cfp-toggle").addClass("disabled")' - = icon 'dot-circle-o', '', class: 'fa-fw' - - else - = link_to '#', method: :post, class: 'btn btn-sm btn-warning cfp-toggle', remote: true, onclick: '$(".cfp-toggle").addClass("disabled")' - = icon 'circle-o', class: 'fa-fw' + = render partial: 'management/call_for_participations/status', locals: {conference: conference} td = conference.events.count td.actions diff --git a/config/routes.rb b/config/routes.rb index e44861c..25be034 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,7 @@ Rails.application.routes.draw do resources :events resources :volunteers resources :sponsorship_offers + resource :call_for_participation, only: [:create, :destroy] end resources :users end diff --git a/spec/controllers/management/call_for_participations_controller_spec.rb b/spec/controllers/management/call_for_participations_controller_spec.rb new file mode 100644 index 0000000..5723b6f --- /dev/null +++ b/spec/controllers/management/call_for_participations_controller_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe Management::CallForParticipationsController, type: :controller do + let(:user) { create :administrator } + let(:conference) { create :conference } + before { sign_in user } + + describe 'POST #create' do + it 'opens the CFP of the specified conference' do + expect do + post 'create', conference_id: conference.id, format: :js + end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(false).to(true) + end + end + + describe 'DELETE #destroy' do + it 'closes the CFP of the specified conference' do + conference.call_for_participation.open! + + expect do + delete 'destroy', conference_id: conference.id, format: :js + end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(true).to(false) + end + end +end