Class: CheckoutsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CheckoutsController
- Defined in:
- app/controllers/checkouts_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /checkouts/1 DELETE /checkouts/1.json.
-
#edit ⇒ Object
GET /checkouts/1/edit.
-
#index ⇒ Object
GET /checkouts GET /checkouts.json.
- #remove_all ⇒ Object
-
#show ⇒ Object
GET /checkouts/1 GET /checkouts/1.json.
-
#update ⇒ Object
PUT /checkouts/1 PUT /checkouts/1.json.
Instance Method Details
#destroy ⇒ Object
DELETE /checkouts/1 DELETE /checkouts/1.json
151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/controllers/checkouts_controller.rb', line 151 def destroy user = @checkout.user @checkout.operator = current_user @checkout.user_id = nil @checkout.save! respond_to do |format| format.html { redirect_to checkouts_url(user_id: user.username), notice: t('controller.successfully_deleted', model: t('activerecord.models.checkout')) } format.json { head :no_content } end end |
#edit ⇒ Object
GET /checkouts/1/edit
127 128 129 |
# File 'app/controllers/checkouts_controller.rb', line 127 def edit @new_due_date = @checkout.get_new_due_date end |
#index ⇒ Object
GET /checkouts GET /checkouts.json
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/checkouts_controller.rb', line 11 def index if params[:icalendar_token].present? icalendar_user = Profile.where(checkout_icalendar_token: params[:icalendar_token]).first.try(:user) if icalendar_user.blank? raise ActiveRecord::RecordNotFound else @checkouts = icalendar_user.checkouts.not_returned.order('checkouts.id DESC') end else unless current_user access_denied; return end end if params[:format] == 'txt' per_page = 65534 else per_page = Checkout.default_per_page end unless icalendar_user search = Checkout.search if @user user = @user if current_user.try(:has_role?, 'Librarian') search.build do with(:username).equal_to user.username end else if current_user == user redirect_to checkouts_url(format: params[:format]) return else access_denied return end end else unless current_user.try(:has_role?, 'Librarian') search.build do with(:username).equal_to current_user.username unless current_user.profile.save_checkout_history? with(:checked_in_at).equal_to nil end end end end if current_user.try(:has_role?, 'Librarian') if @item item = @item search.build do with(:item_identifier).equal_to item.item_identifier end end else if @item access_denied; return end end if params[:view] == 'overdue' if params[:days_overdue] date = params[:days_overdue].to_i.days.ago.beginning_of_day else date = 1.days.ago.beginning_of_day end search.build do with(:due_date).less_than date with(:checked_in_at).equal_to nil end end if params[:reserved].present? if params[:reserved] == 'true' @reserved = reserved = true elsif params[:reserved] == 'false' @reserved = reserved = false end search.build do with(:reserved).equal_to reserved end end search.build do order_by :created_at, :desc facet :reserved end page = params[:page] || 1 search.query.paginate(page.to_i, Checkout.default_per_page) @checkouts = search.execute!.results @checkouts_facet = search.facet(:reserved).rows end @days_overdue = params[:days_overdue] ||= 1 respond_to do |format| format.html # index.html.erb format.json { render json: @checkouts } format.rss { render layout: false } format.ics format.txt format.atom end end |
#remove_all ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/controllers/checkouts_controller.rb', line 163 def remove_all if @user unless current_user.has_role?('Librarian') if @user != current_user access_denied; return end end Checkout.remove_all_history(@user) end respond_to do |format| format.html { redirect_to checkouts_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.checkout')) } format.json { head :no_content } end end |
#show ⇒ Object
GET /checkouts/1 GET /checkouts/1.json
119 120 121 122 123 124 |
# File 'app/controllers/checkouts_controller.rb', line 119 def show respond_to do |format| format.html # show.html.erb format.json { render json: @checkout } end end |
#update ⇒ Object
PUT /checkouts/1 PUT /checkouts/1.json
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/controllers/checkouts_controller.rb', line 133 def update @checkout.assign_attributes(checkout_params) @checkout.due_date = @checkout.due_date.end_of_day @checkout.checkout_renewal_count += 1 respond_to do |format| if @checkout.save format.html { redirect_to @checkout, notice: t('controller.successfully_updated', model: t('activerecord.models.checkout')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @checkout.errors, status: :unprocessable_entity } end end end |