Module: LoansHelper

Defined in:
app/helpers/loans_helper.rb

Instance Method Summary collapse

Instance Method Details

#keywords_on_loanable_itemsObject



77
78
79
# File 'app/helpers/loans_helper.rb', line 77

def keywords_on_loanable_items
  Keyword.joins(:tags).where(project_id: sessions_current_project_id).where(tags: {tag_object_type: ['Container', 'Otu', 'CollectionObject']}).distinct.all
end

#label_for_loan(loan) ⇒ Object



13
14
15
# File 'app/helpers/loans_helper.rb', line 13

def label_for_loan(loan)
  "loan #{loan.id}"
end

#loan_due_back_tag(loan) ⇒ Object



71
72
73
74
75
# File 'app/helpers/loans_helper.rb', line 71

def loan_due_back_tag(loan)
  'Due back on ' + 
    ( loan.date_return_expected.present? ? loan.date_return_expected.to_s : 'NOT PROVIDED' ) +
   '.'
end

#loan_history_tag(object) ⇒ Object



40
41
42
# File 'app/helpers/loans_helper.rb', line 40

def loan_history_tag(object)
  (:li, "Loaned #{object.times_loaned} times.")
end

#loan_identifier(loan) ⇒ Object



17
18
19
# File 'app/helpers/loans_helper.rb', line 17

def loan_identifier(loan)
  loan.identifiers.where(type: 'Identifier::Local::LoanCode').first
end


21
22
23
24
# File 'app/helpers/loans_helper.rb', line 21

def loan_link(loan)
  return nil if loan.nil?
  link_to(loan_tag(loan).html_safe, loan)
end

#loan_overdue_tag(loan) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/loans_helper.rb', line 58

def loan_overdue_tag(loan)
  if loan.date_return_expected.present?
    if loan.overdue?
      "#{loan.days_overdue} days overdue."
    else
      "#{loan.days_until_due} days until due."  
    end
  else
    (:span, 'Due date NOT PROVIDED.', data: {icon: :warning})
  end

end

#loan_status_tag(object) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/helpers/loans_helper.rb', line 30

def loan_status_tag(object)
  if object.has_loans? && object.has_been_loaned?
    (:h3, 'Loan status') + 
      (:ul) do
      (on_loan_tag(object) +
       loan_history_tag(object)).html_safe
    end
  end
end

#loan_tag(loan) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/loans_helper.rb', line 3

def loan_tag(loan)
  return nil if loan.nil?
  [
    (:span, (identifier_tag(loan_identifier(loan)) || loan.id), class: [:feedback, 'feedback-thin', 'feedback-primary']), 
    loan.loan_recipients.collect{|a| a.name}.join(', '),
    loan.recipient_email,
    loan.date_sent,
    loan.recipient_address].delete_if{|b| b.blank? }.join(' - ').gsub(/\n/, '; ').html_safe
end

#loans_search_formObject



26
27
28
# File 'app/helpers/loans_helper.rb', line 26

def loans_search_form
  render('/loans/quick_search_form')
end

#on_loan_tag(object) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/loans_helper.rb', line 44

def on_loan_tag(object)
  if object.has_loans? && object.on_loan?
    (:li) do
      ['On ' +  link_to('loan', object.loan) + '.', 
        loan_overdue_tag(object.loan), 
        loan_due_back_tag(object.loan)
      ].join(' ').html_safe
         #{overdue_tag(object.loan)}").html_safe
    end
  else
    ''
  end
end