Class: CheckinsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /checkins POST /checkins.json



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/checkins_controller.rb', line 59

def create
  unless @basket
    access_denied; return
  end
  @checkin.basket = @basket
  @checkin.librarian = current_user

  flash[:message] = ''
  if @checkin.item_identifier.blank?
    flash[:message] << t('checkin.enter_item_identifier') if @checkin.item_identifier.blank?
  else
    item = Item.where(:item_identifier => @checkin.item_identifier.to_s.strip).first
  end
  @checkin.item = item

  respond_to do |format|
    if @checkin.save
      flash[:message] << t('checkin.successfully_checked_in', :model => t('activerecord.models.checkin'))
      message = @checkin.item_checkin(current_user)
      flash[:message] << message if message
      format.html { redirect_to basket_checkins_url(@checkin.basket) }
      format.json { render :json => @checkin, :status => :created, :location => @checkin }
      format.js { redirect_to basket_checkins_url(@basket, :format => :js) }
    else
      @checkins = @basket.checkins
      format.html { render :action => "new" }
      format.json { render :json => @checkin.errors, :status => :unprocessable_entity }
      format.js { render :action => "index" }
    end
  end
end

#destroyObject

DELETE /checkins/1 DELETE /checkins/1.json



114
115
116
117
118
119
120
121
122
# File 'app/controllers/checkins_controller.rb', line 114

def destroy
  #@checkin = Checkin.find(params[:id])
  @checkin.destroy

  respond_to do |format|
    format.html { redirect_to checkins_url }
    format.json { head :no_content }
  end
end

#editObject

GET /checkins/1/edit



53
54
55
# File 'app/controllers/checkins_controller.rb', line 53

def edit
  #@checkin = Checkin.find(params[:id])
end

#indexObject

GET /checkins GET /checkins.json



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

def index
  if @basket
    @checkins = @basket.checkins.paginate(:page => params[:page])
  else
    @checkins = Checkin.paginate(:page => params[:page])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @checkins }
    format.js { @checkin = Checkin.new }
  end
end

#newObject

GET /checkins/new



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/checkins_controller.rb', line 36

def new
  if flash[:checkin_basket_id]
    @basket = Basket.find(flash[:checkin_basket_id])
  else
    @basket = Basket.create!(:user => current_user)
  end
  @checkin = Checkin.new
  @checkins = []
  flash[:checkin_basket_id] = @basket.id

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

#showObject

GET /checkins/1 GET /checkins/1.json



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

def show
  #@checkin = Checkin.find(params[:id])

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

#updateObject

PUT /checkins/1 PUT /checkins/1.json



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/checkins_controller.rb', line 93

def update
  #@checkin = Checkin.find(params[:id])
  @checkin.item_identifier = params[:checkin][:item_identifier] rescue nil
  unless @checkin.item_identifier.blank?
    item = Item.where(:item_identifier => @checkin.item_identifier.to_s.strip).first
  end
  @checkin.item = item

  respond_to do |format|
    if @checkin.update_attributes(params[:checkin])
      format.html { redirect_to @checkin, :notice => t('controller.successfully_updated', :model => t('activerecord.models.checkin')) }
      format.json { head :no_content }
    else
      format.html { render :action => "edit" }
      format.json { render :json => @checkin.errors, :status => :unprocessable_entity }
    end
  end
end