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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/loan_items_controller.rb', line 78

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) create

POST /loan_items POST /loan_items.json



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/loan_items_controller.rb', line 33

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 json: @loan_item, 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



62
63
64
65
66
67
68
# File 'app/controllers/loan_items_controller.rb', line 62

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



24
25
# File 'app/controllers/loan_items_controller.rb', line 24

def edit
end

- (Object) index

GET /loan_items GET /loan_items.json



8
9
10
11
# File 'app/controllers/loan_items_controller.rb', line 8

def index
  @recent_objects = LoanItem.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



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

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)

Never trust parameters from the scary internet, only allow the white list through.



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

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



19
20
21
# File 'app/controllers/loan_items_controller.rb', line 19

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

- (Object) search



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

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)

Use callbacks to share common setup or constraints between actions.



95
96
97
# File 'app/controllers/loan_items_controller.rb', line 95

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



15
16
# File 'app/controllers/loan_items_controller.rb', line 15

def show
end

- (Object) update

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



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/loan_items_controller.rb', line 48

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