/upstream/templates/admin/loans.tmpl
Type: /type/template
body: value: $def with (loans, action)

$ _x = ctx.setdefault('bodyid', 'admin')
$ _x = ctx.setdefault('usergroup', 'admin')

$ pdf_count = len([pdf for pdf in loans if pdf['resource_type'] == 'pdf'])
$ epub_count = len([epub for epub in loans if epub['resource_type'] == 'epub'])
$ bookreader_count = len([bookreader for bookreader in loans if bookreader['resource_type'] == 'bookreader'])
$ total = pdf_count + epub_count + bookreader_count + 0.0
$ pdf_percent = "%d" % (pdf_count / total * 100)
$ epub_percent = "%d" % (epub_count / total * 100)
$ bookreader_percent = "%d" % (bookreader_count / total * 100)

<div id="contentHead">
    <div class="superNav"><a href="/admin">Admin</a> /</div>
    <h1>Outstanding eBook Loans</h1>
    <p id="note">
        <em class="red">Note:</em> ACS4 loan status for ePub and PDF is updated hourly and also on demand (when a user looks at a borrow page or their own loans).  You can refresh the status of a loan (synchronize with ACS4 server) by clicking on "refresh". BookReader loan status is always current.  
    </p>
    <p>
        $# could do user checking here
        $if True:
            <form method="post" id="adminAction" name="adminAction" class="olform">
                <input type="hidden" name="action" value="updateall" />
                <input type="submit" value="Update ACS4 loan statuses" />
            </form>
        $else:
            <span class="adminOnly" style="font-size: 24px; line-height: 1.5em;"><i>THIS PAGE ISN'T UPDATING LIVE.</u><br />We're currently collecting stats - bulk status update is disabled.  <br />Please do not refresh loan status manually, thanks.</span>
    </p>
        
</div>
<div id="contentBody">
    <div id="borrowTable" class="borrow collapse">
    <table>
        <thead>
            <tr>
                <th class="titles" colspan="2">
                $if len(loans) == 1:
                    $_("1 Current Loan")
                $else:
                    $len(loans) $_("Current Loans")<br/>
                    $bookreader_count ($bookreader_percent%) $_("BookReader") - $pdf_count ($pdf_percent%) $_("PDF") - $epub_count ($epub_percent%) $_("ePub")
                </th>
                <th class="expires">$_("Loan Expires")</th>
                <th class="what">$_("What")</th>
                <th>$_("Who")</th>
                <th>$_("Actions")</th>
            </tr>
        </thead>
        <tbody>
        <!-- for each borrow -->
        $for loan in loans:
            $ book = get_document(loan['book'])
            <tr>
                <td class="cover">
                $:render_template('covers/book_cover_small', book)
                </td>
                <td class="titles">
                    <span class="book">
                    <a href="$book.key" class="borrowResults">
                    <strong>$book.title</strong>
                    </a>
                    </span>
                    
                    <span class="author">
                    $# :macros.AuthorList(book.get_authors())
                    </span>
                    <div class="date">
                    Borrowed $datestr(datetime_from_utc_timestamp(loan['loaned_at']))
                    </div>
                </td>
                <td class="expires">
                    $:macros.FormatExpiry(loan['expiry'])
                </td>
                <td class="user">
                    $if loan['resource_type'] == 'pdf':
                        PDF
                    $elif loan['resource_type'] == 'epub':
                        ePub
                    $elif loan['resource_type'] == 'bookreader':
                        BookReader
                    $else:
                        $loan['resource_type']
                </td>
                <td class="user">
                    $# user = get_document(loan['user'])
                    $# <a href="$user.key">$user.name</a>
                    <a href="$loan['user']">$loan['user']</a>
                </td>
                <td class="action">
                    $ borrow_admin = loan['book'] + '/title/borrow_admin'
                    <a href="$borrow_admin">debug_info</a><br/><br/>
                    <a href="$borrow_admin" class="smaller plain">refresh</a>
                </td>
            </tr>
        </tbody>
    </table>
    </div>
</div>
plugin: admin
title: Loan admin page
m: edit