Modify views for booths
This commit is contained in:
parent
a5ce1239f2
commit
60ec569553
13 changed files with 280 additions and 92 deletions
|
|
@ -1,8 +1,16 @@
|
|||
class Booth < ActiveRecord::Base
|
||||
include ActiveRecord::Transitions
|
||||
|
||||
belongs_to :conference
|
||||
has_many :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,
|
||||
uniqueness: { case_sensitive: false },
|
||||
presence: true
|
||||
|
|
@ -10,7 +18,53 @@ class Booth < ActiveRecord::Base
|
|||
validates :description,
|
||||
:reasoning,
|
||||
:state,
|
||||
:logo_link,
|
||||
:conference_id,
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue