Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse print reserves for online resources #334

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
//= require jquery3
//= require rails-ujs
//= require datatables
//= require bootstrap
//= require_tree .
6 changes: 6 additions & 0 deletions app/assets/javascripts/reserves.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Things that need to document to be loaded to do.
$(document).ready(function(){
$('#collapsePrint').on('show.bs.collapse', function() {
$('[data-target="#collapsePrint"] input[type="checkbox"]').prop( "checked", false );
})
$('#collapsePrint').on('hide.bs.collapse', function() {
$('[data-target="#collapsePrint"] input[type="checkbox"]').prop( "checked", true );
})
$('#sw_url').on('keypress', function(e) {
if (e.keyCode == 13) {
e.preventDefault();
Expand Down
6 changes: 5 additions & 1 deletion app/models/reserve_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ReserveItem
include ActiveModel::Model

attr_accessor :title, :imprint, :ckey, :media, :online, :comment, :digital_type, :copies, :personal, :loan_period, :required
attr_accessor :title, :imprint, :ckey, :media, :online, :comment, :digital_type, :copies, :personal, :loan_period, :required, :print_needed

def copies
return @copies.presence.to_i if @copies.present?
Expand All @@ -14,6 +14,10 @@ def copies
1
end

def print_needed
ActiveModel::Type::Boolean.new.cast(@print_needed)
end

def online?
ActiveModel::Type::Boolean.new.cast(online)
end
Expand Down
41 changes: 26 additions & 15 deletions app/views/reserves/_reserves_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,38 @@
</div>
<div>
<hr />
<div class="form-group d-flex flex-column flex-md-row mb-3 mb-sm-2">
<div class="d-flex">
<%= f.label :copies, 'Print copies needed:', class: 'col-form-label' %>
<%= f.number_field :copies, class: 'form-control num_copies', max: 99 %>
<% if f.object.online? %>
<div class="form-group d-flex mb-2">
<button class="btn btn-checkbox pl-0" type="button" data-toggle="collapse" data-target="#collapsePrint" aria-expanded="<%= f.object.copies > 0 ? 'true' : 'false' %>" aria-controls="collapsePrint">
<%= f.check_box :print_needed, aria: { hidden: true }, tabindex: '-1' %>

In addition to the online copy, please reserve print versions too
</button>
</div>
<% end %>
<div id="collapsePrint" class="collapse <%= 'show' if !f.object.online? || f.object.copies > 0 %>">
<div class="form-group d-flex flex-column flex-md-row mb-3 mb-sm-2">
<div class="d-flex">
<%= f.label :copies, 'Print copies needed:', class: 'col-form-label' %>
<%= f.number_field :copies, class: 'form-control num_copies', max: 99 %>
</div>

<%= f.label :personal, class: 'col-form-label' do %>
<%= f.check_box :personal %>
<%= f.label :personal, class: 'col-form-label' do %>
<%= f.check_box :personal %>

The instructor will loan a copy to the library
<% end %>
</div>
The instructor will loan a copy to the library
<% end %>
</div>

<div class="form-group d-flex mb-2">
<%= f.label :loan_period, 'Loan period:', class: 'col-form-label' %>
<div class="form-group d-flex mb-2">
<%= f.label :loan_period, 'Loan period:', class: 'col-form-label' %>

<% if ActiveModel::Type::Boolean.new.cast(item["media"]) %>
<%= f.hidden_field :loan_period %>
<% end %>
<% if ActiveModel::Type::Boolean.new.cast(item["media"]) %>
<%= f.hidden_field :loan_period %>
<% end %>

<%= f.select :loan_period, Settings.loan_periods.to_h.values, {}, class: "loan-period form-control loan-select #{"media" if ActiveModel::Type::Boolean.new.cast(item["media"])}", disabled: ActiveModel::Type::Boolean.new.cast(item["media"]) %>
<%= f.select :loan_period, Settings.loan_periods.to_h.values, {}, class: "loan-period form-control loan-select #{"media" if ActiveModel::Type::Boolean.new.cast(item["media"])}", disabled: ActiveModel::Type::Boolean.new.cast(item["media"]) %>
</div>
</div>

<div class="form-group d-flex flex-column flex-md-row mb-2">
Expand Down