Class: InterLibraryLoansController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/inter_library_loans_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /inter_library_loans POST /inter_library_loans.json



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/inter_library_loans_controller.rb', line 55

def create
  @inter_library_loan = InterLibraryLoan.new(params[:inter_library_loan])
  item = Item.where(:item_identifier => params[:inter_library_loan][:item_identifier]).first
  @inter_library_loan.item = item

  respond_to do |format|
    if @inter_library_loan.save
      @inter_library_loan.sm_request!
      flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.inter_library_loan'))
      format.html { redirect_to(@inter_library_loan) }
      format.json { render json: @inter_library_loan, :status => :created, :location => @inter_library_loan }
    else
      @libraries = Library.where('id != ?', current_user.profile.try(:library_id))
      format.html { render action: "new" }
      format.json { render json: @inter_library_loan.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /inter_library_loans/1 DELETE /inter_library_loans/1.json



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/inter_library_loans_controller.rb', line 108

def destroy
  @inter_library_loan = InterLibraryLoan.find(params[:id])
  @inter_library_loan.destroy

  respond_to do |format|
    if @item
      format.html { redirect_to item_inter_library_loans_url(@item) }
      format.json { head :no_content }
    else
      format.html { redirect_to inter_library_loans_url }
      format.json { head :no_content }
    end
  end
end

#editObject

GET /inter_library_loans/1/edit



48
49
50
51
# File 'app/controllers/inter_library_loans_controller.rb', line 48

def edit
  @inter_library_loan = InterLibraryLoan.find(params[:id])
  @libraries = Library.where('id != ?', current_user.profile.try(:library_id))
end

#indexObject

GET /inter_library_loans GET /inter_library_loans.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/inter_library_loans_controller.rb', line 9

def index
  if @item
    @inter_library_loans = @item.inter_library_loans.page(params[:page])
  else
    @inter_library_loans = InterLibraryLoan.page(params[:page])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @inter_library_loans }
    format.rss  { render :layout => false }
    format.atom
  end
end

#newObject

GET /inter_library_loans/new GET /inter_library_loans/new.json



37
38
39
40
41
42
43
44
45
# File 'app/controllers/inter_library_loans_controller.rb', line 37

def new
  @inter_library_loan = InterLibraryLoan.new
  @libraries = Library.where('id != ?', current_user.profile.try(:library_id))

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @inter_library_loan }
  end
end

#showObject

GET /inter_library_loans/1 GET /inter_library_loans/1.json



26
27
28
29
30
31
32
33
# File 'app/controllers/inter_library_loans_controller.rb', line 26

def show
  @inter_library_loan = InterLibraryLoan.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @inter_library_loan }
  end
end

#updateObject

PUT /inter_library_loans/1 PUT /inter_library_loans/1.json



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
104
# File 'app/controllers/inter_library_loans_controller.rb', line 76

def update
  @inter_library_loan = InterLibraryLoan.find(params[:id])
  @item = @inter_library_loan.item

  case @inter_library_loan.state
  when 'requested'
    @inter_library_loan.sm_ship!
  when 'shipped'
    @inter_library_loan.sm_receive!
  when 'received'
    @inter_library_loan.sm_return_ship!
  when 'return_shipped'
    @inter_library_loan.sm_return_receive!
  when 'return_received'
  end

  respond_to do |format|
    if @inter_library_loan.update_attributes(params[:inter_library_loan])
      flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.inter_library_loan'))
      format.html { redirect_to(@inter_library_loan) }
      format.json { head :no_content }
    else
      @inter_library_loan.item = @item
      @libraries = Library.where('id != ?', current_user.profile.try(:library_id))
      format.html { render action: "edit" }
      format.json { render json: @inter_library_loan.errors, :status => :unprocessable_entity }
    end
  end
end