Class: LoanItemsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/loan_items_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/loan_items_controller.rb', line 85

def autocomplete
  @loan_items = LoanItem.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).includes(:taxon_name)
  data = @loan_items.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.loan_item_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html: ApplicationController.helpers.loan_item_autocomplete_selected_tag(t)
    }
  end

  render json: data
end

- (Object) batch_create

POST /loan_items/batch_create?batch_type=tags&loan_id=123&keyword_id=456&klass=Otu POST /loan_items/batch_create?batch_type=pinboard&loan_id=123&klass=Otu



102
103
104
105
106
107
108
# File 'app/controllers/loan_items_controller.rb', line 102

def batch_create
  if @loan_items = LoanItem.batch_create(batch_params)
    render :index
  else
    render json: {success: false}
  end 
end

- (Object) batch_params (private)



120
121
122
# File 'app/controllers/loan_items_controller.rb', line 120

def batch_params
  params.permit(:batch_type, :loan_id, :keyword_id, :klass).to_h.symbolize_keys.merge(project_id: sessions_current_project_id, user_id: sessions_current_user_id)
end

- (Object) create

POST /loan_items POST /loan_items.json



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/loan_items_controller.rb', line 40

def create
  @loan_item = LoanItem.new(loan_item_params)
  respond_to do |format|
    if @loan_item.save
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was successfully created.')}
      format.json { render :show, status: :created, location: @loan_item }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was NOT successfully created.')}
      format.json { render json: @loan_item.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /loan_items/1 DELETE /loan_items/1.json



69
70
71
72
73
74
75
# File 'app/controllers/loan_items_controller.rb', line 69

def destroy
  @loan_item.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was successfully destroyed.')}
    format.json { head :no_content }
  end
end

- (Object) edit

GET /loan_items/1/edit



31
32
# File 'app/controllers/loan_items_controller.rb', line 31

def edit
end

- (Object) filter_params (private)



112
113
114
# File 'app/controllers/loan_items_controller.rb', line 112

def filter_params
  params.permit(:loan_id)
end

- (Object) index

GET /loan_items GET /loan_items.json



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/loan_items_controller.rb', line 8

def index
  respond_to do |format|
    format.html {
      @recent_objects = LoanItem.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @loan_items = LoanItem.where(filter_params).with_project_id(sessions_current_project_id)
    }
  end
end

- (Object) list



34
35
36
# File 'app/controllers/loan_items_controller.rb', line 34

def list
  @loan_items = LoanItem.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10)
end

- (Object) loan_item_params (private)



124
125
126
127
128
129
130
131
# File 'app/controllers/loan_items_controller.rb', line 124

def loan_item_params
  params.require(:loan_item).permit(
    :loan_id, :collection_object_status, :date_returned, :loan_item_object_id, :loan_item_object_type,
    :date_returned_jquery, :disposition, :total,  
    :global_entity,
    :position
  )
end

- (Object) new

GET /loan_items/new



26
27
28
# File 'app/controllers/loan_items_controller.rb', line 26

def new
  @loan_item = LoanItem.new(loan: Loan.new)
end

- (Object) search



77
78
79
80
81
82
83
# File 'app/controllers/loan_items_controller.rb', line 77

def search
  if params[:id].blank?
    redirect_to loan_items_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to loan_item_path(params[:id])
  end
end

- (Object) set_loan_item (private)



116
117
118
# File 'app/controllers/loan_items_controller.rb', line 116

def set_loan_item
  @loan_item = LoanItem.with_project_id(sessions_current_project_id).find(params[:id])
end

- (Object) show

GET /loan_items/1 GET /loan_items/1.json



22
23
# File 'app/controllers/loan_items_controller.rb', line 22

def show
end

- (Object) update

PATCH/PUT /loan_items/1 PATCH/PUT /loan_items/1.json



55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/loan_items_controller.rb', line 55

def update
  respond_to do |format|
    if @loan_item.update(loan_item_params)
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was successfully updated.')}
      format.json { render :show, status: :ok, location: @loan_item }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Loan item was NOT successfully updated.' + @loan_item.errors.full_messages.join('; '))}
      format.json { render json: @loan_item.errors, status: :unprocessable_entity }
    end
  end
end