Modify views for booths
This commit is contained in:
parent
a5ce1239f2
commit
60ec569553
13 changed files with 280 additions and 92 deletions
|
|
@ -3,19 +3,88 @@ module Admin
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :booth, through: :conference
|
load_and_authorize_resource :booth, through: :conference
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@booths = @conference.booths
|
@booths = @conference.booths
|
||||||
end
|
end
|
||||||
|
|
||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def new; end
|
def new
|
||||||
|
@booth = Booth.new(conference: @conference)
|
||||||
|
end
|
||||||
|
|
||||||
def create; end
|
def create
|
||||||
|
@booth = @conference.booths.build(booth_params)
|
||||||
|
|
||||||
def update; end
|
@booth.submitter = current_user
|
||||||
|
|
||||||
def destroy; end
|
if @booth.save
|
||||||
|
redirect_to admin_conference_booths_path,
|
||||||
|
notice: "Booth successfully created."
|
||||||
|
else
|
||||||
|
flash[:error] = "Creating booth failed. #{@booth.errors.full_messages.join('. ')}."
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@booth.update_attributes(booth_params)
|
||||||
|
|
||||||
|
if @booth.save
|
||||||
|
redirect_to admin_conference_booths_path,
|
||||||
|
notice: "Successfully updated booth for #{@booth.title}."
|
||||||
|
else
|
||||||
|
flash[:error] = "An error prohibited the Booth for #{@booth.title} "\
|
||||||
|
"#{@booth.errors.full_messages.join('. ')}."
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @booth.destroy
|
||||||
|
redirect_to admin_conference_booths_path,
|
||||||
|
notice: "Booth successfully destryed."
|
||||||
|
else
|
||||||
|
redirect_to admin_conference_booths_path,
|
||||||
|
error: "Booth couldn't be deleted. #{@booth.errors.full_messages.join('. ')}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def accept
|
||||||
|
update_state(:accept, 'Booth accepted!')
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_accept
|
||||||
|
update_state(:to_accept, 'Booth to accept')
|
||||||
|
end
|
||||||
|
|
||||||
|
def reject
|
||||||
|
update_state(:reject, 'Booth rejected')
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset
|
||||||
|
update_state(:reset, 'Booth is submitted')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_state(transition, notice)
|
||||||
|
alert = @booth.update_state(transition, notice)
|
||||||
|
|
||||||
|
if alert.blank?
|
||||||
|
flash[:notice] = notice
|
||||||
|
redirect_back_or_to(admin_conference_booths_path(conference_id: @conference.short_title)) && return
|
||||||
|
else
|
||||||
|
flash[:error] = alert
|
||||||
|
return redirect_back_or_to(admin_conference_booths_path(conference_id: @conference.short_title)) && return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def booth_params
|
||||||
|
params.require(:booth).permit(:title, :description, :reasoning, :state, :logo_link, :conference_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,13 @@ module ApplicationHelper
|
||||||
include_blank: false, label: 'Speakers', input_html: { class: 'select-help-toggle', multiple: 'true' }
|
include_blank: false, label: 'Speakers', input_html: { class: 'select-help-toggle', multiple: 'true' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def responsibles_selector_input(form)
|
||||||
|
users = User.active.pluck(:id, :name, :username, :email).map { |user| [user[0], user[1].blank? ? user[2] : user[1], user[2], user[3]] }.sort_by { |user| user[1].downcase }
|
||||||
|
form.input :responsibles, as: :select,
|
||||||
|
collection: options_for_select(users.map {|user| ["#{user[1]} (#{user[2]}) #{user[3]}", user[0]]}, @booth.responsibles.map(&:id)),
|
||||||
|
include_blank: false, label: 'Responsibles', input_html: { class: 'select-help-toggle', multiple: 'true' }
|
||||||
|
end
|
||||||
|
|
||||||
def event_types(conference)
|
def event_types(conference)
|
||||||
conference.program.event_types.map { |et| et.title.pluralize }.to_sentence
|
conference.program.event_types.map { |et| et.title.pluralize }.to_sentence
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
class Booth < ActiveRecord::Base
|
class Booth < ActiveRecord::Base
|
||||||
|
include ActiveRecord::Transitions
|
||||||
|
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
has_many :booth_requests
|
has_many :booth_requests
|
||||||
has_many :users, through: :booth_requests
|
has_many :users, through: :booth_requests
|
||||||
|
|
||||||
|
has_one :submitter_booth_user, -> { where(role: 'submitter') }, class_name: 'BoothRequest'
|
||||||
|
has_one :submitter, through: :submitter_booth_user, source: :user
|
||||||
|
|
||||||
|
has_many :responsibles_booth_user, -> { where(role: 'responsibles') }, class_name: 'BoothRequest'
|
||||||
|
has_many :responsibles, through: :responsibles_booth_user, source: :user
|
||||||
|
|
||||||
validates :title,
|
validates :title,
|
||||||
uniqueness: { case_sensitive: false },
|
uniqueness: { case_sensitive: false },
|
||||||
presence: true
|
presence: true
|
||||||
|
|
@ -10,7 +18,53 @@ class Booth < ActiveRecord::Base
|
||||||
validates :description,
|
validates :description,
|
||||||
:reasoning,
|
:reasoning,
|
||||||
:state,
|
:state,
|
||||||
:logo_link,
|
|
||||||
:conference_id,
|
:conference_id,
|
||||||
presence: true
|
presence: true
|
||||||
|
|
||||||
|
validate :logo_link
|
||||||
|
|
||||||
|
include Gravtastic
|
||||||
|
gravtastic size: 32
|
||||||
|
|
||||||
|
state_machine initial: :submitted do
|
||||||
|
state :submitted
|
||||||
|
state :withdrawn
|
||||||
|
state :to_accept
|
||||||
|
state :accepted
|
||||||
|
state :rejected
|
||||||
|
|
||||||
|
event :restart do
|
||||||
|
transitions to: :submitted, from: [:withdrawn]
|
||||||
|
end
|
||||||
|
event :withdrawn do
|
||||||
|
transitions to: :withdrawn, from: [:submitted, :to_accept, :accepted]
|
||||||
|
end
|
||||||
|
event :to_accept do
|
||||||
|
transitions to: :to_accept, from: [:submitted, :rejected, :accepted]
|
||||||
|
end
|
||||||
|
event :accept do
|
||||||
|
transitions to: :accepted, from: [:submitted, :to_accept]
|
||||||
|
end
|
||||||
|
event :reject do
|
||||||
|
transitions to: :rejected, from: [:submitted]
|
||||||
|
end
|
||||||
|
event :reset do
|
||||||
|
transitions to: :submitted, from: [:to_accept, :rejected, :accepted]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def transition_possible?(transition)
|
||||||
|
self.class.state_machine.events_for(current_state).include?(transition)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_state(transition, notice)
|
||||||
|
alert = ''
|
||||||
|
begin
|
||||||
|
send(transition)
|
||||||
|
save
|
||||||
|
rescue Transitions::InvalidTransition => e
|
||||||
|
alert = "Update state failed. #{e.message}"
|
||||||
|
end
|
||||||
|
alert
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,5 @@ class BoothRequest < ActiveRecord::Base
|
||||||
:role,
|
:role,
|
||||||
presence: true
|
presence: true
|
||||||
|
|
||||||
|
ROLES = %w[submitter responsibles]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class Conference < ActiveRecord::Base
|
||||||
has_one :splashpage, dependent: :destroy
|
has_one :splashpage, dependent: :destroy
|
||||||
has_one :contact, dependent: :destroy
|
has_one :contact, dependent: :destroy
|
||||||
has_one :registration_period, dependent: :destroy
|
has_one :registration_period, dependent: :destroy
|
||||||
has_one :call_for_booths, dependent: :destroy
|
has_one :call_for_booths
|
||||||
has_one :email_settings, dependent: :destroy
|
has_one :email_settings, dependent: :destroy
|
||||||
has_one :program, dependent: :destroy
|
has_one :program, dependent: :destroy
|
||||||
has_one :venue, dependent: :destroy
|
has_one :venue, dependent: :destroy
|
||||||
|
|
|
||||||
30
app/views/admin/booths/_change_state_dropdown.html.haml
Normal file
30
app/views/admin/booths/_change_state_dropdown.html.haml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
- if booth.transition_possible? :accept
|
||||||
|
%li= link_to 'Accept booth',
|
||||||
|
accept_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, id: "accept_booth_#{booth.id}"
|
||||||
|
|
||||||
|
- if booth.transition_possible? :reject
|
||||||
|
%li= link_to 'Reject booth',
|
||||||
|
reject_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, confirm: 'Are you sure?', id: "reject_booth_#{booth.id}"
|
||||||
|
|
||||||
|
|
||||||
|
- if booth.transition_possible? :restart
|
||||||
|
%li= link_to 'Start review',
|
||||||
|
restart_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, id: "restart_booth_#{booth.id}"
|
||||||
|
|
||||||
|
- if booth.transition_possible? :to_accept
|
||||||
|
%li= link_to 'To accept booth',
|
||||||
|
to_accept_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, id: "to_accept_booth_#{booth.id}"
|
||||||
|
|
||||||
|
- if booth.transition_possible? :reset
|
||||||
|
%li= link_to 'Reset',
|
||||||
|
reset_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, id: "reset_booth_#{booth.id}"
|
||||||
|
|
||||||
|
- if booth.transition_possible? :cancel
|
||||||
|
%li= link_to 'Cancel booth',
|
||||||
|
cancel_admin_conference_booth_path(@conference.short_title, booth),
|
||||||
|
method: :patch, id: "cancel_booth_#{booth.id}"
|
||||||
|
|
@ -1,28 +1,27 @@
|
||||||
= form_for @booth do |f|
|
.row
|
||||||
- if @booth.errors.any?
|
.col-md-12
|
||||||
#error_explanation
|
.page-header
|
||||||
%h2= "#{pluralize(@booth.errors.count, "error")} prohibited this booth from being saved:"
|
%title Request a Booth
|
||||||
%ul
|
.row
|
||||||
- @booth.errors.full_messages.each do |msg|
|
.col-md-8
|
||||||
%li= msg
|
= semantic_form_for(@booth, url: @booth.new_record? ? admin_conference_booths_path(@conference.short_title) : admin_conference_booth_path(@conference.short_title, @booth.id), html: {multipart: true}) do |f|
|
||||||
|
= f.input :title, as: :string, required: true
|
||||||
|
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true
|
||||||
|
= f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true
|
||||||
|
= responsibles_selector_input f
|
||||||
|
= f.input :logo_link, as: :string, required: true
|
||||||
|
|
||||||
.field
|
|
||||||
= f.label :title
|
%p.text-right
|
||||||
= f.text_field :title
|
- if @booth.new_record?
|
||||||
.field
|
= f.submit 'Create Booth Request', class: 'btn btn-success'
|
||||||
= f.label :conference_id
|
- else
|
||||||
= f.number_field :conference_id
|
= f.submit 'Update Booth Request', class: 'btn btn-success'
|
||||||
.field
|
|
||||||
= f.label :description
|
:javascript
|
||||||
= f.text_area :description
|
$(document).ready(function() {
|
||||||
.field
|
$('#booth_responsible_ids').selectize({
|
||||||
= f.label :state
|
plugins: ['remove_button'],
|
||||||
= f.text_field :state
|
maxItems: 2
|
||||||
.field
|
} )
|
||||||
= f.label :reasoning
|
});
|
||||||
= f.text_area :reasoning
|
|
||||||
.field
|
|
||||||
= f.label :logo_link
|
|
||||||
= f.text_field :logo_link
|
|
||||||
.actions
|
|
||||||
= f.submit 'Save'
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
%h1 Editing booth
|
%h1 Editing booth
|
||||||
|
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
|
||||||
= link_to 'Show', @booth
|
|
||||||
\|
|
|
||||||
= link_to 'Back', booths_path
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,54 @@
|
||||||
%h1 Listing booths
|
.row
|
||||||
|
.col-md-12
|
||||||
%table
|
.page-header
|
||||||
%tr
|
%h1
|
||||||
%th Title
|
Booths
|
||||||
%th Conference
|
= "(#{@booths.length})" if @booths.any?
|
||||||
%th Description
|
.pull-right
|
||||||
%th State
|
- if can? :create, Booth
|
||||||
%th Reasoning
|
= link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-default btn-info'
|
||||||
%th Logo link
|
%p.text-muted
|
||||||
%th
|
All the booth requests
|
||||||
%th
|
.row
|
||||||
%th
|
.col-md-12
|
||||||
|
.margin-event-table
|
||||||
- @booths.each do |booth|
|
%table.table.table-striped.table-bordered.table-hover.datatable
|
||||||
%tr
|
%thead
|
||||||
%td= booth.title
|
%th
|
||||||
%td= booth.conference_id
|
%b ID
|
||||||
%td= booth.description
|
%th
|
||||||
%td= booth.state
|
%b Title
|
||||||
%td= booth.reasoning
|
%th
|
||||||
%td= booth.logo_link
|
%b Submitter
|
||||||
%td= link_to 'Show', booth
|
%th
|
||||||
%td= link_to 'Edit', edit_booth_path(booth)
|
%b Responsibles
|
||||||
%td= link_to 'Destroy', booth, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
%th
|
||||||
|
%b State
|
||||||
%br
|
%th
|
||||||
|
%b Actions
|
||||||
= link_to 'New Booth', new_admin_conference_booth_path
|
- @booths.each do |booth|
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
= booth.id
|
||||||
|
%td
|
||||||
|
= link_to booth.title, admin_conference_booth_path(@conference.short_title, booth)
|
||||||
|
%td
|
||||||
|
= booth.submitter.name if booth.submitter
|
||||||
|
%td
|
||||||
|
- booth.responsibles.each do |responsibles|
|
||||||
|
.responsibles
|
||||||
|
= link_to responsible.name, admin_user_path(responsibles)
|
||||||
|
%td
|
||||||
|
.btn-group
|
||||||
|
%button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' }
|
||||||
|
= booth.state.humanize
|
||||||
|
%span.caret
|
||||||
|
%ul.dropdown-menu{ role: 'menu' }
|
||||||
|
= render 'change_state_dropdown', booth: booth
|
||||||
|
%td
|
||||||
|
.btn-group{role: "group"}
|
||||||
|
= link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id),
|
||||||
|
method: :get, class: 'btn btn-primary'
|
||||||
|
= link_to 'Delete', admin_conference_booth_path(@conference.short_title, booth.id),
|
||||||
|
method: :delete, class: 'btn btn-danger',
|
||||||
|
data: { confirm: "Do you really want to delete #{booth.title}? Attention: This booth will be removed from all Events that have it set" }
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
|
||||||
= link_to 'Back', booths_path
|
= link_to 'Back', admin_conference_booths_path
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,20 @@
|
||||||
%p#notice= notice
|
.row
|
||||||
|
.col-md-12
|
||||||
|
%h3
|
||||||
|
= @booth.title
|
||||||
|
.btn-group.pull-right
|
||||||
|
= link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, @booth), class: 'btn btn-mini btn-primary'
|
||||||
|
|
||||||
%p
|
.row
|
||||||
%b Title:
|
.col-md-12
|
||||||
= @booth.title
|
%table.table
|
||||||
%p
|
%tr
|
||||||
%b Conference:
|
%td.col-md-2
|
||||||
= @booth.conference_id
|
%b Description
|
||||||
%p
|
%td
|
||||||
%b Description:
|
= @booth.description
|
||||||
= @booth.description
|
%tr
|
||||||
%p
|
%td.col-md-2
|
||||||
%b State:
|
%b Reasoning
|
||||||
= @booth.state
|
%td
|
||||||
%p
|
= @booth.reasoning
|
||||||
%b Reasoning:
|
|
||||||
= @booth.reasoning
|
|
||||||
%p
|
|
||||||
%b Logo link:
|
|
||||||
= @booth.logo_link
|
|
||||||
|
|
||||||
= link_to 'Edit', edit_booth_path(@booth)
|
|
||||||
\|
|
|
||||||
= link_to 'Back', booths_path
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ Osem::Application.routes.draw do
|
||||||
resources :conferences do
|
resources :conferences do
|
||||||
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
||||||
resources :schedules, only: [:index, :create, :show, :update, :destroy]
|
resources :schedules, only: [:index, :create, :show, :update, :destroy]
|
||||||
resources :booths
|
|
||||||
resources :event_schedules, only: [:create, :update, :destroy]
|
resources :event_schedules, only: [:create, :update, :destroy]
|
||||||
get 'commercials/render_commercial' => 'commercials#render_commercial'
|
get 'commercials/render_commercial' => 'commercials#render_commercial'
|
||||||
resources :commercials, only: [:index, :create, :update, :destroy]
|
resources :commercials, only: [:index, :create, :update, :destroy]
|
||||||
|
|
@ -39,6 +39,17 @@ Osem::Application.routes.draw do
|
||||||
get '/volunteers' => 'volunteers#index', as: 'volunteers_info'
|
get '/volunteers' => 'volunteers#index', as: 'volunteers_info'
|
||||||
patch '/volunteers' => 'volunteers#update', as: 'volunteers_update'
|
patch '/volunteers' => 'volunteers#update', as: 'volunteers_update'
|
||||||
|
|
||||||
|
resources :booths do
|
||||||
|
member do
|
||||||
|
patch :accept
|
||||||
|
patch :restart
|
||||||
|
patch :withdrawn
|
||||||
|
patch :to_accept
|
||||||
|
patch :reject
|
||||||
|
patch :reset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :registrations, except: [:create, :new] do
|
resources :registrations, except: [:create, :new] do
|
||||||
member do
|
member do
|
||||||
patch :toggle_attendance
|
patch :toggle_attendance
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ describe 'Booth' do
|
||||||
it { is_expected.to validate_presence_of(:conference) }
|
it { is_expected.to validate_presence_of(:conference) }
|
||||||
|
|
||||||
it 'is not valid without a title' do
|
it 'is not valid without a title' do
|
||||||
should validate_presence_of(:title)
|
is_expected.to validate_presence_of(:title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue