Class: Tasks::LoansController

Inherits:
ApplicationController
  • Object
show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/tasks/loans_controller.rb

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

Instance Method Details

- (Object) add_determination



40
41
42
43
44
45
46
47
48
# File 'app/controllers/tasks/loans_controller.rb', line 40

def add_determination
  if LoanItem.batch_determine_loan_items(ids: loan_item_ids_params, params: taxon_determination_params)
    flash[:notice] = "Updated determinations."
  else
    flash[:notice] = "Failed to update #{loan_item_ids_params.count} records."
  end

  render :complete
end

- (Object) complete



6
7
8
9
10
# File 'app/controllers/tasks/loans_controller.rb', line 6

def complete
  @loan                = Loan.find(params['id'])
  @taxon_determination = TaxonDetermination.new()
  @loan_item           = LoanItem.new(loan: @loan)
end

- (Object) loan_item_ids_params (private)



57
58
59
60
# File 'app/controllers/tasks/loans_controller.rb', line 57

def loan_item_ids_params
  items = params.permit(loan_items: [:id])[:loan_items]
  items ? items.collect { |k, v| v['id'] } : []
end

- (Object) return_items



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/tasks/loans_controller.rb', line 26

def return_items
  if params[:date_returned].blank?
    flash[:notice] = "Select a return date first."
  else
    if LoanItem.batch_update_attribute(ids: loan_item_ids_params, attribute: :date_returned, value: params.fetch(:date_returned))
      flash[:notice] = "Updated return of #{loan_item_ids_params.count} records."
    else
      flash[:notice] = "Failed to update #{loan_item_ids_params.count} records."
    end
  end

  render :complete
end

- (Object) set_objects (private)



52
53
54
55
# File 'app/controllers/tasks/loans_controller.rb', line 52

def set_objects
  @loan                = Loan.find(params['id'])
  @taxon_determination = TaxonDetermination.new()
end

- (Object) taxon_determination_params (private)



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/tasks/loans_controller.rb', line 62

def taxon_determination_params
  params.require(:taxon_determination).permit(:biological_collection_object_id,
                                              :otu_id,
                                              :year_made,
                                              :month_made,
                                              :day_made,
                                              roles_attributes: [:id,
                                                                 :_destroy,
                                                                 :type,
                                                                 :person_id,
                                                                 :position,
                                                                 person_attributes: [:last_name,
                                                                                     :first_name,
                                                                                     :suffix,
                                                                                     :prefix]],
                                              otu_attributes:   [:id,
                                                                 :_destroy,
                                                                 :name,
                                                                 :taxon_name_id]
  )
end

- (Object) update_status



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/tasks/loans_controller.rb', line 12

def update_status
  if params[:disposition].blank?
    flash[:notice] = "Select a status first."
  else
    if LoanItem.batch_update_attribute(ids: loan_item_ids_params, attribute: :disposition, value: params.fetch(:disposition))
      flash[:notice] = "Updated status of #{loan_item_ids_params.count} records."
    else
      flash[:notice] = "Failed to update #{loan_item_ids_params.count} records."
    end
  end

  render :complete
end