enju_circulation 0.1.0.pre11 → 0.1.0.pre12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/checked_items_controller.rb +0 -5
  3. data/app/controllers/checkins_controller.rb +0 -11
  4. data/app/controllers/reserves_controller.rb +73 -15
  5. data/app/helpers/reserves_helper.rb +2 -0
  6. data/app/models/checked_item.rb +9 -0
  7. data/app/models/checkin.rb +13 -0
  8. data/app/models/reserve.rb +186 -42
  9. data/app/views/baskets/new.html.erb +1 -1
  10. data/app/views/checked_items/_list.html.erb +1 -1
  11. data/app/views/checkins/_checkin.html.erb +1 -1
  12. data/app/views/checkins/_list.html.erb +1 -1
  13. data/app/views/manifestations/_show_detail_librarian.html.erb +141 -0
  14. data/app/views/manifestations/_show_detail_user.html.erb +136 -0
  15. data/app/views/reserves/_new.html.erb +1 -1
  16. data/app/views/reserves/_state_facet.html.erb +15 -0
  17. data/app/views/reserves/_title.html.erb +2 -1
  18. data/app/views/reserves/edit.html.erb +20 -2
  19. data/app/views/reserves/index.csv.erb +2 -2
  20. data/app/views/reserves/index.html.erb +30 -6
  21. data/app/views/reserves/show.html.erb +18 -3
  22. data/config/locales/translation_en.yml +10 -1
  23. data/config/locales/translation_ja.yml +10 -1
  24. data/db/migrate/20130303104849_add_state_index_to_reserve.rb +5 -0
  25. data/db/migrate/20130303124821_add_retained_at_to_reserve.rb +5 -0
  26. data/db/migrate/20130304015019_add_postponed_at_to_reserve.rb +5 -0
  27. data/lib/enju_circulation/item.rb +4 -0
  28. data/lib/enju_circulation/version.rb +1 -1
  29. data/spec/controllers/checkins_controller_spec.rb +2 -2
  30. data/spec/controllers/reserves_controller_spec.rb +29 -5
  31. data/spec/dummy/db/schema.rb +4 -1
  32. data/spec/dummy/db/test.sqlite3 +0 -0
  33. data/spec/dummy/solr/data/test/index/_5d.fdt +0 -0
  34. data/spec/dummy/solr/data/test/index/_5d.fdx +0 -0
  35. data/spec/dummy/solr/data/test/index/_5d.fnm +4 -0
  36. data/spec/dummy/solr/data/test/index/_5d.frq +1 -0
  37. data/spec/dummy/solr/data/test/index/_5d.nrm +1 -0
  38. data/spec/dummy/solr/data/test/index/_5d.prx +0 -0
  39. data/spec/dummy/solr/data/test/index/_5d.tii +0 -0
  40. data/spec/dummy/solr/data/test/index/_5d.tis +0 -0
  41. data/spec/dummy/solr/data/test/index/segments.gen +0 -0
  42. data/spec/dummy/solr/data/test/index/segments_at +0 -0
  43. data/spec/dummy/solr/data/test/spellchecker/segments.gen +0 -0
  44. data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
  45. data/spec/fixtures/message_templates.yml +14 -0
  46. data/spec/fixtures/reserves.yml +39 -38
  47. data/spec/models/reserve_spec.rb +25 -1
  48. metadata +65 -72
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfd5c7351216dfcfe77a9f0633f7f5a87468263d
4
+ data.tar.gz: 30b2ead9534a1a72aefcaafbe9aa1296a49e3844
5
+ SHA512:
6
+ metadata.gz: 46fc0a5edfe11edb9262fba52a01e2ea43c43e0c0d016430eb5a9d7b8d5914e8a1429ebca6962e7472b485ed39681cc65d5a0cb1d5ba99dd43674610b1e04448
7
+ data.tar.gz: 94d674c0ef4142a6a2a624d9febf0efa0a695dc6ba0a70f1ecc9100680aa79a201d47ca7fb9d1928cd2770bbcf36fd120e6d4ab3f638faebd7c877e449e2061d
@@ -57,11 +57,6 @@ class CheckedItemsController < ApplicationController
57
57
  @checked_item.librarian = current_user
58
58
 
59
59
  flash[:message] = ''
60
- item_identifier = @checked_item.item_identifier.to_s.strip
61
- unless item_identifier.blank?
62
- item = Item.where(:item_identifier => item_identifier).first
63
- end
64
- @checked_item.item = item if item
65
60
 
66
61
  respond_to do |format|
67
62
  if @checked_item.save
@@ -66,11 +66,6 @@ class CheckinsController < ApplicationController
66
66
  @checkin.librarian = current_user
67
67
 
68
68
  flash[:message] = ''
69
- item_identifier = @checkin.item_identifier.to_s.strip
70
- unless item_identifier.blank?
71
- item = Item.where(:item_identifier => item_identifier).first
72
- end
73
- @checkin.item = item if item
74
69
 
75
70
  respond_to do |format|
76
71
  if @checkin.save
@@ -92,12 +87,6 @@ class CheckinsController < ApplicationController
92
87
  # PUT /checkins/1
93
88
  # PUT /checkins/1.json
94
89
  def update
95
- #@checkin = Checkin.find(params[:id])
96
- @checkin.item_identifier = params[:checkin][:item_identifier] rescue nil
97
- unless @checkin.item_identifier.blank?
98
- item = Item.where(:item_identifier => @checkin.item_identifier.to_s.strip).first
99
- end
100
- @checkin.item = item
101
90
  @checkin.assign_attributes(params[:checkin])
102
91
  @checkin.librarian = current_user
103
92
 
@@ -7,6 +7,7 @@ class ReservesController < ApplicationController
7
7
  before_filter :store_page
8
8
  helper_method :get_manifestation
9
9
  helper_method :get_item
10
+ after_filter :convert_charset, :only => :index
10
11
 
11
12
  # GET /reserves
12
13
  # GET /reserves.json
@@ -22,24 +23,74 @@ class ReservesController < ApplicationController
22
23
  end
23
24
  end
24
25
 
26
+ search = Reserve.search
27
+ query = @query = params[:query].to_s.strip
28
+ if params[:format].to_s.downcase == 'csv'
29
+ page = 1
30
+ per_page = 65534
31
+ else
32
+ page ||= params[:page] || 1
33
+ per_page ||= Reserve.default_per_page
34
+ end
35
+
25
36
  if params[:mode] == 'hold' and current_user.has_role?('Librarian')
26
- @reserves = Reserve.hold.order('reserves.id DESC').page(params[:page])
37
+ search.build do
38
+ with(:hold).equal_to true
39
+ end
27
40
  else
28
41
  if @user
42
+ user = @user
29
43
  if current_user.has_role?('Librarian')
30
- @reserves = @user.reserves.order('reserves.id DESC').page(params[:page])
44
+ search.build do
45
+ with(:username).equal_to user.username
46
+ end
31
47
  else
32
48
  access_denied; return
33
49
  end
34
50
  else
35
- if current_user.has_role?('Librarian')
36
- @reserves = Reserve.order('reserves.id DESC').includes(:manifestation).page(params[:page])
37
- else
38
- @reserves = current_user.reserves.order('reserves.id DESC').includes(:manifestation).page(params[:page])
51
+ unless current_user.has_role?('Librarian')
52
+ search.build do
53
+ with(:username).equal_to current_user.username
54
+ end
39
55
  end
40
56
  end
41
57
  end
42
58
 
59
+ begin
60
+ reserved_from = Time.zone.parse(params[:reserved_from])
61
+ @reserved_from = params[:reserved_from].to_s.strip
62
+ rescue
63
+ reserved_from = nil
64
+ end
65
+
66
+ begin
67
+ reserved_to = Time.zone.parse(params[:reserved_to])
68
+ @reserved_to = params[:reserved_to].to_s.strip
69
+ rescue
70
+ reserved_to = nil
71
+ end
72
+
73
+ if params[:state].present?
74
+ state = params[:state].downcase
75
+ end
76
+
77
+ search.build do
78
+ fulltext query
79
+ if reserved_from
80
+ with(:created_at).greater_than_or_equal_to reserved_from.beginning_of_day
81
+ end
82
+ if reserved_to
83
+ with(:created_at).less_than reserved_to.tomorrow.beginning_of_day
84
+ end
85
+ order_by :created_at, :desc
86
+ with(:state).equal_to state if state
87
+ facet :state
88
+ paginate :page => page.to_i, :per_page => per_page
89
+ end
90
+
91
+ @reserves = search.execute.results
92
+ @state_facet = search.facet(:state).rows
93
+
43
94
  respond_to do |format|
44
95
  format.html # index.html.erb
45
96
  format.json { render :json => @reserves }
@@ -90,13 +141,14 @@ class ReservesController < ApplicationController
90
141
 
91
142
  # GET /reserves/1/edit
92
143
  def edit
144
+ @reserve.item_identifier = @reserve.item.try(:item_identifier)
93
145
  end
94
146
 
95
147
  # POST /reserves
96
148
  # POST /reserves.json
97
149
  def create
98
150
  @reserve = Reserve.new(params[:reserve])
99
- @reserve.user = User.where(:user_number => @reserve.user_number).first if @reserve.user_number.to_s.strip.present?
151
+ @reserve.set_user
100
152
 
101
153
  if current_user.has_role?('Librarian')
102
154
  unless @reserve.user
@@ -113,7 +165,6 @@ class ReservesController < ApplicationController
113
165
  respond_to do |format|
114
166
  if @reserve.save
115
167
  @reserve.sm_request!
116
- @reserve.send_message
117
168
 
118
169
  format.html { redirect_to @reserve, :notice => t('controller.successfully_created', :model => t('activerecord.models.reserve')) }
119
170
  format.json { render :json => @reserve, :status => :created, :location => reserve_url(@reserve) }
@@ -127,24 +178,31 @@ class ReservesController < ApplicationController
127
178
  # PUT /reserves/1
128
179
  # PUT /reserves/1.json
129
180
  def update
130
- @reserve.assign_attributes(params[:reserve])
131
- @reserve.user = User.where(:user_number => @reserve.user_number).first if @reserve.user_number.to_s.strip.present?
132
-
133
- unless current_user.has_role?('Librarian')
181
+ if current_user.has_role?('Librarian')
182
+ @reserve.assign_attributes(params[:reserve], :as => :admin)
183
+ else
134
184
  if @reserve.user != current_user
135
185
  access_denied; return
136
186
  end
187
+ @reserve.assign_attributes(params[:reserve], :as => :user_update)
137
188
  end
138
189
 
139
- if params[:mode] == 'cancel'
140
- @reserve.sm_cancel!
190
+ if @reserve.valid?
191
+ if params[:mode] == 'cancel'
192
+ @reserve.sm_cancel!
193
+ else
194
+ unless @reserve.retained?
195
+ if @reserve.item and @reserve.force_retaining == '1'
196
+ @reserve.sm_retain!
197
+ end
198
+ end
199
+ end
141
200
  end
142
201
 
143
202
  respond_to do |format|
144
203
  if @reserve.save
145
204
  if @reserve.state == 'canceled'
146
205
  flash[:notice] = t('reserve.reservation_was_canceled')
147
- @reserve.send_message
148
206
  else
149
207
  flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.reserve'))
150
208
  end
@@ -12,6 +12,8 @@ module ReservesHelper
12
12
  t('reserve.canceled')
13
13
  when 'expired'
14
14
  t('reserve.expired')
15
+ when 'postponed'
16
+ t('reserve.postponed')
15
17
  when 'completed'
16
18
  t('reserve.completed')
17
19
  end
@@ -9,6 +9,7 @@ class CheckedItem < ActiveRecord::Base
9
9
  validates_uniqueness_of :item_id, :scope => :basket_id
10
10
  validate :available_for_checkout?, :on => :create
11
11
 
12
+ before_validation :set_item
12
13
  before_validation :set_due_date, :on => :create
13
14
  normalize_attributes :item_identifier
14
15
 
@@ -101,6 +102,14 @@ class CheckedItem < ActiveRecord::Base
101
102
  end
102
103
  return self.due_date
103
104
  end
105
+
106
+ def set_item
107
+ identifier = item_identifier.to_s.strip
108
+ if identifier.present?
109
+ item = Item.where(:item_identifier => identifier).first
110
+ self.item = item
111
+ end
112
+ end
104
113
  end
105
114
 
106
115
  # == Schema Information
@@ -10,12 +10,17 @@ class Checkin < ActiveRecord::Base
10
10
  validates_uniqueness_of :item_id, :scope => :basket_id
11
11
  validates_presence_of :item_id, :basket_id
12
12
  validate :available_for_checkin?, :on => :create
13
+ before_validation :set_item
13
14
 
14
15
  attr_accessor :item_identifier
15
16
 
16
17
  paginates_per 10
17
18
 
18
19
  def available_for_checkin?
20
+ unless basket
21
+ return nil
22
+ end
23
+
19
24
  if item.blank?
20
25
  errors[:base] << I18n.t('checkin.item_not_found')
21
26
  return
@@ -69,6 +74,14 @@ class Checkin < ActiveRecord::Base
69
74
  nil
70
75
  end
71
76
  end
77
+
78
+ def set_item
79
+ identifier = item_identifier.to_s.strip
80
+ if identifier.present?
81
+ item = Item.where(:item_identifier => identifier).first
82
+ self.item = item
83
+ end
84
+ end
72
85
  end
73
86
 
74
87
  # == Schema Information
@@ -1,15 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  class Reserve < ActiveRecord::Base
3
- attr_accessible :manifestation_id, :item_identifier, :user_number, :expired_at
3
+ attr_accessible :manifestation_id, :user_number, :expired_at
4
+ attr_accessible :expired_at, :as => :user_update
4
5
  attr_accessible :manifestation_id, :item_identifier, :user_number,
5
6
  :expired_at, :request_status_type, :canceled_at, :checked_out_at,
6
- :expiration_notice_to_patron, :expiration_notice_to_library,
7
+ :expiration_notice_to_patron, :expiration_notice_to_library, :item_id,
8
+ :retained_at, :postponed_at, :force_retaining,
7
9
  :as => :admin
8
10
  scope :hold, where('item_id IS NOT NULL')
9
11
  scope :not_hold, where(:item_id => nil)
10
12
  scope :waiting, where('canceled_at IS NULL AND expired_at > ? AND state != ?', Time.zone.now, 'completed').order('reserves.id DESC')
11
- scope :completed, where('checked_out_at IS NOT NULL')
12
- scope :canceled, where('canceled_at IS NOT NULL')
13
+ scope :retained, where('retained_at IS NOT NULL AND state = ?', 'retained')
14
+ scope :completed, where('checked_out_at IS NOT NULL AND state = ?', 'completed')
15
+ scope :canceled, where('canceled_at IS NOT NULL AND state = ?', 'canceled')
16
+ scope :postponed, where('postponed_at IS NOT NULL AND state = ?', 'postponed')
13
17
  scope :will_expire_retained, lambda {|datetime| {:conditions => ['checked_out_at IS NULL AND canceled_at IS NULL AND expired_at <= ? AND state = ?', datetime, 'retained'], :order => 'expired_at'}}
14
18
  scope :will_expire_pending, lambda {|datetime| {:conditions => ['checked_out_at IS NULL AND canceled_at IS NULL AND expired_at <= ? AND state = ?', datetime, 'pending'], :order => 'expired_at'}}
15
19
  scope :created, lambda {|start_date, end_date| {:conditions => ['created_at >= ? AND created_at < ?', start_date, end_date]}}
@@ -32,17 +36,45 @@ class Reserve < ActiveRecord::Base
32
36
  validates_date :expired_at, :allow_blank => true
33
37
  validate :manifestation_must_include_item
34
38
  validate :available_for_reservation?, :on => :create
35
- before_validation :set_item_and_manifestation, :on => :create
36
- before_validation :set_expired_at
39
+ validates :item_id, :presence => true, :if => Proc.new{|reserve|
40
+ if item_id_changed?
41
+ if reserve.completed? or reserve.retained?
42
+ unless item_id_change[0]
43
+ return false
44
+ else
45
+ unless item_id_change[1]
46
+ return false
47
+ else
48
+ return true
49
+ end
50
+ end
51
+ end
52
+ else
53
+ if reserve.retained?
54
+ return true
55
+ end
56
+ end
57
+ }
58
+ validates :item_id, :uniqueness => {:scope => :state, :allow_blank => true},
59
+ :if => Proc.new{|reserve|
60
+ return false unless reserve.state_changed?
61
+ return true if reserve.completed? or reserve.retained?
62
+ }
63
+ validate :valid_item?
64
+ validate :retained_by_other_user?
65
+ before_validation :set_manifestation, :on => :create
66
+ before_validation :set_item, :set_expired_at
67
+ before_validation :set_user, :on => :update
37
68
  before_validation :set_request_status, :on => :create
38
69
 
39
- attr_accessor :user_number, :item_identifier
70
+ attr_accessor :user_number, :item_identifier, :force_retaining
40
71
 
41
72
  state_machine :initial => :pending do
42
73
  before_transition :pending => :requested, :do => :do_request
43
- before_transition [:pending, :requested, :retained] => :retained, :do => :retain
44
- before_transition [:pending ,:requested, :retained] => :canceled, :do => :cancel
45
- before_transition [:pending, :requested, :retained] => :expired, :do => :expire
74
+ before_transition :retained => :postponed, :do => :postpone
75
+ before_transition [:pending, :requested, :retained, :postponed] => :retained, :do => :retain
76
+ before_transition [:pending ,:requested, :retained, :postponed] => :canceled, :do => :cancel
77
+ before_transition [:pending, :requested, :retained, :postponed] => :expired, :do => :expire
46
78
  before_transition :retained => :completed, :do => :checkout
47
79
  after_transition any => any do |reserve, transition|
48
80
  if Rails.env == 'production'
@@ -50,20 +82,28 @@ class Reserve < ActiveRecord::Base
50
82
  end
51
83
  end
52
84
 
85
+ after_transition any => [:requested, :canceled, :retained, :postponed] do |reserve, transition|
86
+ reserve.send_message
87
+ end
88
+
53
89
  event :sm_request do
54
- transition :pending => :requested
90
+ transition [:pending, :requested] => :requested
55
91
  end
56
92
 
57
93
  event :sm_retain do
58
- transition [:pending, :requested, :retained] => :retained
94
+ transition [:pending, :requested, :retained, :postponed] => :retained
59
95
  end
60
96
 
61
97
  event :sm_cancel do
62
- transition [:pending, :requested, :retained] => :canceled
98
+ transition [:pending, :requested, :retained, :postponed] => :canceled
63
99
  end
64
100
 
65
101
  event :sm_expire do
66
- transition [:pending, :requested, :retained] => :expired
102
+ transition [:pending, :requested, :retained, :postponed] => :expired
103
+ end
104
+
105
+ event :sm_postpone do
106
+ transition :retained => :postponed
67
107
  end
68
108
 
69
109
  event :sm_complete do
@@ -73,9 +113,63 @@ class Reserve < ActiveRecord::Base
73
113
 
74
114
  paginates_per 10
75
115
 
76
- def set_item_and_manifestation
77
- item = Item.where(:item_identifier => item_identifier).first
78
- manifestation = item.manifestation if item
116
+ searchable do
117
+ text :username do
118
+ user.try(:username)
119
+ end
120
+ string :username do
121
+ user.try(:username)
122
+ end
123
+ string :user_number do
124
+ user.try(:user_number)
125
+ end
126
+ time :created_at
127
+ text :item_identifier do
128
+ manifestation.items.pluck(:item_identifier)
129
+ end
130
+ text :title do
131
+ manifestation.try(:titles)
132
+ end
133
+ boolean :hold do |reserve|
134
+ self.hold.include?(reserve)
135
+ end
136
+ string :state
137
+ end
138
+
139
+ def set_manifestation
140
+ self.manifestation = item.manifestation if item
141
+ end
142
+
143
+ def set_item
144
+ identifier = item_identifier.to_s.strip
145
+ if identifier.present?
146
+ item = Item.where(:item_identifier => identifier).first
147
+ self.item = item
148
+ end
149
+ end
150
+
151
+ def set_user
152
+ number = user_number.to_s.strip
153
+ if number.present?
154
+ user = User.where(:user_number => number).first
155
+ self.user = user
156
+ end
157
+ end
158
+
159
+ def valid_item?
160
+ if item_identifier.present?
161
+ item = Item.where(:item_identifier => item_identifier).first
162
+ errors[:base] << I18n.t('reserve.invalid_item') unless item
163
+ end
164
+ end
165
+
166
+ def retained_by_other_user?
167
+ return nil if force_retaining == '1'
168
+ if item
169
+ if Reserve.retained.where(:item_id => item.item_identifier).first
170
+ errors[:base] << I18n.t('reserve.attempt_to_update_retained_reservation')
171
+ end
172
+ end
79
173
  end
80
174
 
81
175
  def set_request_status
@@ -95,13 +189,6 @@ class Reserve < ActiveRecord::Base
95
189
  end
96
190
  end
97
191
 
98
- def manifestation_must_include_item
99
- unless item_id.blank?
100
- item = Item.find(item_id) rescue nil
101
- errors[:base] << I18n.t('reserve.invalid_item') unless manifestation.items.include?(item)
102
- end
103
- end
104
-
105
192
  def next_reservation
106
193
  if item
107
194
  Reserve.waiting.where(:manifestation_id => item.manifestation.id).first
@@ -157,6 +244,17 @@ class Reserve < ActiveRecord::Base
157
244
  request.assign_attributes({:sender => sender, :receiver => sender, :message_template => message_template_for_library}, :as => :admin)
158
245
  request.save_message_body(:manifestations => Array[item.manifestation], :user => user)
159
246
  request.sm_send_message!
247
+ when 'postponed'
248
+ message_template_for_patron = MessageTemplate.localized_template('reservation_postponed_for_patron', user.locale)
249
+ request = MessageRequest.new
250
+ request.assign_attributes({:sender => sender, :receiver => user, :message_template => message_template_for_patron}, :as => :admin)
251
+ request.save_message_body(:manifestations => Array[manifestation], :user => user)
252
+ request.sm_send_message!
253
+ message_template_for_library = MessageTemplate.localized_template('reservation_postponed_for_library', user.locale)
254
+ request = MessageRequest.new
255
+ request.assign_attributes({:sender => sender, :receiver => sender, :message_template => message_template_for_library}, :as => :admin)
256
+ request.save_message_body(:manifestations => Array[manifestation], :user => user)
257
+ request.sm_send_message!
160
258
  else
161
259
  raise 'status not defined'
162
260
  end
@@ -209,8 +307,18 @@ class Reserve < ActiveRecord::Base
209
307
  # logger.info "#{Time.zone.now} expiring reservations failed!"
210
308
  end
211
309
 
310
+ def checked_out_now?
311
+ if user and manifestation
312
+ true if !(user.checkouts.not_returned.pluck(:item_id) & manifestation.items.pluck(:item_id)).empty?
313
+ end
314
+ end
315
+
212
316
  def available_for_reservation?
213
317
  if manifestation
318
+ if checked_out_now?
319
+ errors[:base] << I18n.t('reserve.this_manifestation_is_already_checked_out')
320
+ end
321
+
214
322
  if manifestation.is_reserved_by?(user)
215
323
  errors[:base] << I18n.t('reserve.this_manifestation_is_already_reserved')
216
324
  end
@@ -225,38 +333,58 @@ class Reserve < ActiveRecord::Base
225
333
  end
226
334
  end
227
335
 
336
+ def completed?
337
+ ['canceled', 'expired', 'completed'].include?(state)
338
+ end
339
+
340
+ def retained?
341
+ return true if state == 'retained'
342
+ false
343
+ end
344
+
228
345
  private
229
346
  def do_request
230
- self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'In Process').first}, :as => :admin)
347
+ self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'In Process').first, :item_id => nil, :retained_at => nil}, :as => :admin)
231
348
  save!
232
349
  end
233
350
 
234
351
  def retain
235
352
  # TODO: 「取り置き中」の状態を正しく表す
236
- self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'In Process').first, :checked_out_at => Time.zone.now}, :as => :admin)
237
- save!
353
+ self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'In Process').first, :retained_at => Time.zone.now}, :as => :admin)
354
+ Reserve.transaction do
355
+ if item.try(:next_reservation)
356
+ reservation = item.next_reservation
357
+ reservation.sm_postpone!
358
+ end
359
+ save!
360
+ end
238
361
  end
239
362
 
240
363
  def expire
241
- self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'Expired').first, :canceled_at => Time.zone.now}, :as => :admin)
242
- save!
243
- logger.info "#{Time.zone.now} reserve_id #{self.id} expired!"
244
- reserve = next_reservation
245
- if reserve
246
- reserve.item = item
247
- reserve.sm_retain!
248
- reserve.send_message
364
+ Reserve.transaction do
365
+ self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'Expired').first, :canceled_at => Time.zone.now}, :as => :admin)
366
+ reserve = next_reservation
367
+ if reserve
368
+ reserve.item = item
369
+ self.item = nil
370
+ save!
371
+ reserve.sm_retain!
372
+ end
249
373
  end
374
+ logger.info "#{Time.zone.now} reserve_id #{self.id} expired!"
250
375
  end
251
376
 
252
377
  def cancel
253
- self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'Cannot Fulfill Request').first, :canceled_at => Time.zone.now}, :as => :admin)
254
- save!
255
- reserve = next_reservation
256
- if reserve
257
- reserve.item = item
258
- reserve.sm_retain!
259
- reserve.send_message
378
+ Reserve.transaction do
379
+ self.assign_attributes({:request_status_type => RequestStatusType.where(:name => 'Cannot Fulfill Request').first, :canceled_at => Time.zone.now}, :as => :admin)
380
+ save!
381
+ reserve = next_reservation
382
+ if reserve
383
+ reserve.item = item
384
+ self.item = nil
385
+ save!
386
+ reserve.sm_retain!
387
+ end
260
388
  end
261
389
  end
262
390
 
@@ -265,6 +393,22 @@ class Reserve < ActiveRecord::Base
265
393
  save!
266
394
  end
267
395
 
396
+ def postpone
397
+ self.assign_attributes({
398
+ :request_status_type => RequestStatusType.where(:name => 'In Process').first,
399
+ :item_id => nil,
400
+ :retained_at => nil,
401
+ :postponed_at => Time.zone.now
402
+ }, :as => :admin)
403
+ save!
404
+ end
405
+
406
+ def manifestation_must_include_item
407
+ unless item_id.blank?
408
+ errors[:base] << I18n.t('reserve.invalid_item') unless manifestation.items.include?(item)
409
+ end
410
+ end
411
+
268
412
  if defined?(EnjuInterLibraryLoan)
269
413
  has_one :inter_library_loan
270
414
  end
@@ -17,7 +17,7 @@
17
17
  <%= f.submit t('page.read') -%>
18
18
  </div>
19
19
  <%- end -%>
20
- <%= javascript_tag("$('#basket_user_number').focus().select();") -%>
20
+ <%= javascript_tag("$(function(){$('#basket_user_number').focus().select()})") %>
21
21
  </div>
22
22
  </div>
23
23
 
@@ -10,7 +10,7 @@
10
10
  </p>
11
11
  <%- end -%>
12
12
 
13
- <%= javascript_tag("$('#checked_item_item_identifier').focus().select();") %>
13
+ <%= javascript_tag("$(function(){$('#checked_item_item_identifier').focus().select()})") %>
14
14
  </div>
15
15
 
16
16
  <%= render 'checked_item' %>
@@ -36,5 +36,5 @@
36
36
  <%- end -%>
37
37
  </table>
38
38
 
39
- <%= javascript_tag("$('#checkin_item_identifier').focus().select();") %>
39
+ <%= javascript_tag("$(function(){$('#checkin_item_identifier').focus().select()})") %>
40
40
  </script>
@@ -9,7 +9,7 @@
9
9
  <%= f.submit t('checkin.checkin'), 'data-disable-with' => t('page.saving') -%>
10
10
  </p>
11
11
  <%- end -%>
12
- <%= javascript_tag("$('#checkin_item_identifier').focus().select();") %>
12
+ <%= javascript_tag("$(function(){$('#checkin_item_identifier').focus().select()})") %>
13
13
  </div>
14
14
 
15
15
  <%= render 'checkin' %>