Class: DmEvent::Admin::RegistrationsController

Inherits:
AdminController
  • Object
show all
Includes:
PermittedParams
Defined in:
app/controllers/dm_event/admin/registrations_controller.rb

Instance Method Summary collapse

Methods included from PermittedParams

#registration_params, #system_email_params, #workshop_params, #workshop_price_params

Instance Method Details

#action_stateObject




7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 7

def action_state
  @registration = Registration.find(params[:id])
  authorize! :manage_event_registrations, @registration.workshop

  @state_event  = params[:state_event].downcase
  case @state_event
  # when 'verify payment'
  #   @registration.verify_payment
  # when 'archive', 'unarchive'
  #   @registration.toggle_archive
  # when 'confirm', 'unconfirm'
  #   @registration.toggle_confirm
  when 'take action'
    flash[:error] = "Please select an action to take"
  else
    #--- send to state machine if it's an allowed event
    @registration.send("#{@state_event}!") if @registration.aasm.events.include? @state_event.to_sym
  end

  respond_to do |format|
    format.html { redirect_to admin_workshop(@registration.workshop) }
    format.js   { render :action => :action_state }
  end

rescue ActiveRecord::StaleObjectError
end

#ajax_delete_paymentObject




106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 106

def ajax_delete_payment
  @registration     = Registration.find(params[:id])
  authorize! :manage_event_registrations, @registration.workshop

  if @registration.delete_payment(params[:payment_id])
    redirect_to edit_admin_registration_path(@registration), notice: 'Payment was deleted'
  else
    redirect_to edit_admin_registration_path(@registration), error: 'Problem deleting payment'
  end
end

#ajax_paymentObject

Record a new payment for the event




75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 75

def ajax_payment
  @registration     = Registration.find(params[:id])
  @workshop         = @registration.workshop
  authorize! :manage_event_registrations, @registration.workshop

  previous_payment  = params[:payment_id] ? PaymentHistory.find(params[:payment_id]) : nil
  @payment_history  = @registration.manual_payment(previous_payment,
                            params[:payment_history][:cost],
                            params[:payment_history][:total_currency],
                            current_user.,
                            item_ref: params[:payment_history][:item_ref],
                            payment_method: params[:payment_history][:payment_method],
                            bill_to_name: params[:payment_history][:bill_to_name],
                            payment_date: params[:payment_history][:payment_date]
                      )

  if @payment_history.errors.empty?
    @registration.update_attribute(:receipt_requested, params[:payment_history][:receipt_requested])
  end

  respond_to do |format|
    format.html {
      flash[:notice] = "Payment was successfully added"           if @payment_history.errors.empty?
      flash[:alert]  = "There was a problem adding this payment"  unless @payment_history.errors.empty?
      redirect_to edit_admin_registration_path(@registration)
    }
    format.js { render :action => :ajax_payment }
  end
end

#destroyObject




35
36
37
38
39
40
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 35

def destroy
  registration = Registration.find(params[:id])
  authorize! :manage_event_registrations, registration.workshop
  registration.destroy
  redirect_to admin_workshop_url(registration.workshop), notice: 'Registration was successfully deleted.'
end

#editObject




43
44
45
46
47
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 43

def edit
  @registration = Registration.find(params[:id])
  @workshop     = @registration.workshop
  authorize! :manage_event_registrations, @registration.workshop
end

#updateObject




50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/dm_event/admin/registrations_controller.rb', line 50

def update
  @registration = Registration.find(params[:id])
  @workshop     = @registration.workshop
  authorize! :manage_event_registrations, @registration.workshop

  #--- save without validation, so can update without having to fill in all details
  payment_comment_text      = params[:registration].delete(:payment_comment_text)
  @registration.attributes  = registration_params(@workshop)

  if @registration.save(:validate => false)
    if @registration.payment_comment.nil? && payment_comment_text
      #--- save the payment text as a comment, and keep a pointer to it
      payment_comment = @registration.private_comments.create(body: payment_comment_text, user_id: current_user.id)
      @registration.reload.update_attribute(:payment_comment_id, payment_comment.id)
    end
    redirect_to admin_workshop_url(@workshop), notice: 'Registration was successfully updated.'
  else
    render :action => :edit
  end
rescue ActiveRecord::StaleObjectError
  redirect_to :action => :edit, :id => @registration, :alert => 'Changes not saved - registration was modified by someone else'
end