/upstream/macros/LoanForm
Type: /type/macro
description: Format available loans as form
plugin: upstream
macro: value: $def with (page, available_loans)

$ default_type = 'bookreader'
$ type_info = { 'epub': ('Download ePub for Digital Editions', 'smaller file that may contain text conversion errors'),'pdf': ('Download Scanned Book for Digital Editions', 'high quality scanned images'),'bookreader': ('Read Online', 'in the BookReader'), }

$if not available_loans:
    $# Caller should check before calling
    No loans available

$else:
    $# sort loans
    $code:
        def loan_key(loan):
            if loan['resource_type'] == default_type:
                return '1-%s' % loan['resource_type']
            else:
                return '2-%s' % loan['resource_type']
                
        available_loans.sort(key=loan_key)

    <script type="text/javascript">
    \$().ready(function(){
        \$('#borrowbook label').click(function(){
            \$(this).find('input').attr('checked','checked');
            \$('.preSubmit').hide();
            \$('.postSubmit').show();
            \$('#borrowbook').submit();
            setTimeout('document.location.reload()', 4000);
            return true;
        });
        if (\$('fieldset.online').length == 0) {\$('form.olform').css('width','455px');};
    });
    </script>
    <div class="preSubmit" style="width:690px;">
    <form method="post" id="borrowbook" name="borrowBook" class="olform">
    $ loan_types = [loan['resource_type'] for loan in available_loans]
    $if ['epub'] == loan_types:
        <fieldset class="download">
            <legend>Download &amp; Open in Adobe Digital Editions</legend>
            <label> 
                <input type="radio" name="format" class="download" value="epub"/>  
                <strong>Download ePub</strong>
                Reflowable text version
            </label>
            <div>
                <table cellpadding="0" cellspacing="0" border="0"><tbody>
                    <tr>
                        <td class="icon"><img src="/images/icons/icon_wrench-borrow.png" width="30" height="30"/></td>
                        <td>You <strong>must <a href="http://www.adobe.com/products/digitaleditions/" title="Visit adobe.com in a new browser window to install the software" target="newwindow">install Adobe Digital Editions</a> to view</strong><br/>this book in ePub format. (It's free.)</td>
                    </tr>
                </tbody></table>
            </div>
        </fieldset>
    $else:
        $if 'bookreader' in loan_types:
            <fieldset class="online">
                <legend>Read in Browser</legend>
                <label>
                    <input type="radio" name="format" class="online" value="bookreader"/> 
                    <strong>Read in Browser</strong> 
                    Open in our BookReader
                </label>
                <div>
                    <table cellpadding="0" cellspacing="0" border="0"><tbody>
                        <tr>
                            <td class="icon"><img src="/images/icons/icon_thumbsup-borrow.png" width="25" height="25"/></td>
                            <td>Read online now.<br/>No extra software!</td>
                        </tr>
                    </tbody></table>
                </div>
            </fieldset>

        $if 'pdf' in loan_types or 'epub' in loan_types:    
            <fieldset class="download">
                <legend>Download &amp; Open in Adobe Digital Editions</legend>
                $if 'pdf' in loan_types:
                    <label style="margin-right:15px;"> 
                        <input type="radio" name="format" class="download" value="pdf"/>  
                        <strong>Download PDF</strong> 
                        High quality page images 
                    </label> 
                $if 'epub' in loan_types:
                    <label> 
                        <input type="radio" name="format" class="download" value="epub"/>  
                        <strong>Download ePub</strong> 
                        Smaller file, may contain errors 
                    </label>
                <div>
                    <table cellpadding="0" cellspacing="0" border="0"><tbody>
                        <tr>
                            <td class="icon"><img src="/images/icons/icon_wrench-borrow.png" width="30" height="30"/></td>
                            <td>You <strong>must <a href="http://www.adobe.com/products/digitaleditions/" title="Visit adobe.com in a new browser window to install the software" target="newwindow">install Adobe Digital Editions</a> to view</strong><br/>either of these format options. (It's free.)</td>
                        </tr>
                    </tbody></table>
                </div>
            </fieldset>
    <input type="submit" value="Borrow This Book" id="borrowBtn" name="borrowBtn" class="hidden"/>
    </form>
    </div>
m: edit