Bug 23112: (follow-up) Conditionally prevent checkout
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / ill / ill-requests.tt
index fd7f78c..b5ccab4 100644 (file)
 [% USE Branches %]
 [% USE Koha %]
 [% USE KohaDates %]
+[% SET footerjs = 1 %]
+[% USE AuthorisedValues %]
+[% USE ColumnsSettings %]
+[% USE Price %]
 
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; ILL requests  &rsaquo;</title>
+<title>Koha &rsaquo; ILL requests</title>
 [% INCLUDE 'doc-head-close.inc' %]
-[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
-[% Asset.css("css/datatables.css") | $raw %]
-[% INCLUDE 'datatables.inc' %]
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
-    //<![CDATA[
-    $(document).ready(function() {
-
-        // Illview Datatable setup
-
-        var table;
-
-        // Filters that are active
-        var activeFilters = {};
-
-        // Fields we don't want to display
-        var ignore = [
-            'accessurl',
-            'backend',
-            'branchcode',
-            'completed',
-            'capabilities',
-            'cost',
-            'medium',
-            'notesopac',
-            'notesstaff',
-            'replied'
-        ];
-
-        // Fields we need to expand (flatten)
-        var expand = [
-            'metadata',
-            'patron'
-        ];
-
-        // Expanded fields
-        // This is auto populated
-        var expanded = {};
-
-        // The core fields that should be displayed first
-        var core = [
-            'metadata_author',
-            'metadata_title',
-            'borrowername',
-            'patron_cardnumber',
-            'biblio_id',
-            'library',
-            'status',
-            'placed',
-            'placed_formatted',
-            'updated',
-            'updated_formatted',
-            'illrequest_id',
-            'comments',
-            'action' // Action should always be last
-        ];
-
-        // Filterable columns
-        var filterable = {
-            status: {
-                prep: function(tableData, oData) {
-                    var uniques = {};
-                    tableData.forEach(function(row) {
-                        var resolvedName = getStatusName(
-                            oData[0].capabilities[row.status].name
-                        );
-                        uniques[resolvedName] = 1
-                    });
-                    Object.keys(uniques).sort().forEach(function(unique) {
-                        $('#illfilter_status').append(
-                            '<option value="' + unique  +
-                            '">' + unique +  '</option>'
-                        );
-                    });
-                },
-                listener: function() {
-                    var me = 'status';
-                    $('#illfilter_status').change(function() {
-                        var sel = $('#illfilter_status option:selected').val();
-                        if (sel && sel.length > 0) {
-                            activeFilters[me] = function() {
-                                table.column(6).search(sel);
-                            }
-                        } else {
-                            if (activeFilters.hasOwnProperty(me)) {
-                                delete activeFilters[me];
-                            }
-                        }
-                    });
-                },
-                clear: function() {
-                    $('#illfilter_status').val('');
-                }
-            },
-            pickupBranch: {
-                prep: function(tableData, oData) {
-                    var uniques = {};
-                    tableData.forEach(function(row) {
-                        uniques[row.library.branchname] = 1
-                    });
-                    Object.keys(uniques).sort().forEach(function(unique) {
-                        $('#illfilter_branchname').append(
-                            '<option value="' + unique  +
-                            '">' + unique +  '</option>'
-                        );
-                    });
-                },
-                listener: function() {
-                    var me = 'pickupBranch';
-                    $('#illfilter_branchname').change(function() {
-                        var sel = $('#illfilter_branchname option:selected').val();
-                        if (sel && sel.length > 0) {
-                            activeFilters[me] = function() {
-                                table.column(5).search(sel);
-                            }
-                        } else {
-                            if (activeFilters.hasOwnProperty(me)) {
-                                delete activeFilters[me];
-                            }
-                        }
-                    });
-                },
-                clear: function() {
-                    $('#illfilter_branchname').val('');
-                }
-            },
-            barcode: {
-                listener: function() {
-                    var me = 'barcode';
-                    $('#illfilter_barcode').change(function() {
-                        var val = $('#illfilter_barcode').val();
-                        if (val && val.length > 0) {
-                            activeFilters[me] = function() {
-                                table.column(3).search(val);
-                            }
-                        } else {
-                            if (activeFilters.hasOwnProperty(me)) {
-                                delete activeFilters[me];
-                            }
-                        }
-                    });
-                },
-                clear: function() {
-                    $('#illfilter_barcode').val('');
-                }
-            },
-            dateModified: {
-                clear: function() {
-                    $('#illfilter_datemodified_start, #illfilter_datemodified_end').val('');
-                }
-            },
-            datePlaced: {
-                clear: function() {
-                    $('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val('');
-                }
-            }
-        };
-
-        // Remove any fields we're ignoring
-        var removeIgnore = function(dataObj) {
-            dataObj.forEach(function(thisRow) {
-                ignore.forEach(function(thisIgnore) {
-                    if (thisRow.hasOwnProperty(thisIgnore)) {
-                        delete thisRow[thisIgnore];
-                    }
-                });
-            });
-        };
-
-        // Expand any fields we're expanding
-        var expandExpand = function(row) {
-            expand.forEach(function(thisExpand) {
-                if (row.hasOwnProperty(thisExpand)) {
-                    if (!expanded.hasOwnProperty(thisExpand)) {
-                        expanded[thisExpand] = [];
-                    }
-                    var expandObj = row[thisExpand];
-                    Object.keys(expandObj).forEach(
-                        function(thisExpandCol) {
-                            var expColName = thisExpand + '_' + thisExpandCol;
-                            // Keep a list of fields that have been expanded
-                            // so we can create toggle links for them
-                            if (expanded[thisExpand].indexOf(expColName) == -1) {
-                                expanded[thisExpand].push(expColName);
-                            }
-                            expandObj[expColName] =
-                                expandObj[thisExpandCol];
-                            delete expandObj[thisExpandCol];
-                        }
-                    );
-                    $.extend(true, row, expandObj);
-                    delete row[thisExpand];
-                }
-            });
-        };
-
-        // Build a de-duped list of all column names
-        var allCols = {};
-        core.map(function(thisCore) {
-            allCols[thisCore] = 1;
-        });
-
-        // Strip the expand prefix if it exists, we do this for display
-        var stripPrefix = function(value) {
-            expand.forEach(function(thisExpand) {
-                var regex = new RegExp(thisExpand + '_', 'g');
-                value = value.replace(regex, '');
-            });
-            return value;
-        };
-
-        // Our 'render' function for borrowerlink
-        var createPatronLink = function(data, type, row) {
-            var patronLink = '<a title="' + _("View borrower details") + '" ' +
-                'href="/cgi-bin/koha/members/moremember.pl?' +
-                'borrowernumber='+row.borrowernumber+'">';
-                if ( row.patron_firstname ) {
-                    patronLink = patronLink + row.patron_firstname + ' ';
-                }
-                patronLink = patronLink + row.patron_surname + '</a>';
-            return patronLink
-        };
-
-        // Our 'render' function for biblio_id
-        var createBiblioLink = function(data, type, row) {
-            return (row.biblio_id) ?
-                '<a title="' + _("View biblio details") + '" ' +
-                'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' +
-                row.biblio_id + '">' +
-                row.biblio_id +
-                '</a>' : '';
-        };
-
-        // Our 'render' function for the library name
-        var createLibrary = function(data, type, row) {
-            return row.library.branchname;
-        };
-
-        // Render function for request ID
-        var createRequestId = function(data, type, row) {
-            return row.id_prefix + row.illrequest_id;
-        };
-
-        // Render function for request status
-        var createStatus = function(data, type, row, meta) {
-            var origData = meta.settings.oInit.originalData;
-            if (origData.length > 0) {
-                var status_name = meta.settings.oInit.originalData[0].capabilities[
-                    row.status
-                ].name;
-                return getStatusName(status_name);
-            } else {
-                return '';
-            }
-        };
-
-        var getStatusName = function(origName) {
-            switch( origName ) {
-                case "New request":
-                    return _("New request");
-                case "Requested":
-                    return _("Requested");
-                case "Requested from partners":
-                    return _("Requested from partners");
-                case "Request reverted":
-                    return _("Request reverted");
-                case "Queued request":
-                    return _("Queued request");
-                case "Cancellation requested":
-                    return _("Cancellation requested");
-                case "Completed":
-                    return _("Completed");
-                case "Delete request":
-                    return _("Delete request");
-                default:
-                    return origName;
-            }
-        };
-
-        // Render function for creating a row's action link
-        var createActionLink = function(data, type, row) {
-            return '<a class="btn btn-default btn-sm" ' +
-                'href="/cgi-bin/koha/ill/ill-requests.pl?' +
-                'method=illview&amp;illrequest_id=' +
-                row.illrequest_id +
-                '">' + _("Manage request") + '</a>';
-        };
-
-        // Columns that require special treatment
-        var specialCols = {
-            action: {
-                name: '',
-                func: createActionLink
-            },
-            borrowername: {
-                name: _("Patron"),
-                func: createPatronLink
-            },
-            illrequest_id: {
-                name: _("Request number"),
-                func: createRequestId
-            },
-            status: {
-                name: _("Status"),
-                func: createStatus
-            },
-            biblio_id: {
-                name: _("Bibliographic record ID"),
-                func: createBiblioLink
-            },
-            library: {
-                name: _("Library"),
-                func: createLibrary
-            },
-            updated: {
-                name: _("Updated on"),
-            },
-            patron_cardnumber: {
-                name: _("Patron barcode")
-            }
-        };
-
-        // Toggle request attributes in Illview
-        $('#toggle_requestattributes').on('click', function(e) {
-            e.preventDefault();
-            $('#requestattributes').toggleClass('content_hidden');
-        });
-
-        // Toggle new comment form in Illview
-        $('#toggle_addcomment').on('click', function(e) {
-            e.preventDefault();
-            $('#addcomment').toggleClass('content_hidden');
-        });
-
-        // Filter partner list
-        $('#partner_filter').keyup(function() {
-            var needle = $('#partner_filter').val();
-            $('#partners > option').each(function() {
-                var regex = new RegExp(needle, 'i');
-                if (
-                    needle.length == 0 ||
-                    $(this).is(':selected') ||
-                    $(this).text().match(regex)
-                ) {
-                    $(this).show();
-                } else {
-                    $(this).hide();
-                }
-            });
-        });
-
-        // Display the modal containing request supplier metadata
-        $('#ill-request-display-metadata').on('click', function(e) {
-            e.preventDefault();
-            $('#dataPreview').modal({show:true});
-        });
-
-        // Get our data from the API and process it prior to passing
-        // it to datatables
-        var ajax = $.ajax(
-            '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
-            ).done(function() {
-                var data = JSON.parse(ajax.responseText);
-                // Make a copy, we'll be removing columns next and need
-                // to be able to refer to data that has been removed
-                var dataCopy = $.extend(true, [], data);
-                // Remove all columns we're not interested in
-                removeIgnore(dataCopy);
-                // Expand columns that need it and create an array
-                // of all column names
-                $.each(dataCopy, function(k, row) {
-                    expandExpand(row);
-                });
-
-                // Assemble an array of column definitions for passing
-                // to datatables
-                var colData = [];
-                Object.keys(allCols).forEach(function(thisCol) {
-                    // Create the base column object
-                    var colObj = {
-                        name: thisCol,
-                        className: thisCol,
-                        defaultContent: ''
-                    };
-                    // We may need to process the data going in this
-                    // column, so do it if necessary
-                    if (
-                        specialCols.hasOwnProperty(thisCol) &&
-                        specialCols[thisCol].hasOwnProperty('func')
-                    ) {
-                        colObj.render = specialCols[thisCol].func;
-                    } else {
-                        colObj.data = thisCol;
-                    }
-                    colData.push(colObj);
-                });
-
-                // Initialise the datatable
-                table = $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, {
-                    'aoColumnDefs': [
-                        { // Last column shouldn't be sortable or searchable
-                            'aTargets': [ 'actions' ],
-                            'bSortable': false,
-                            'bSearchable': false
-                        },
-                        { // Hide the two date columns we use just for sorting
-                            'aTargets': [ 'placed', 'updated' ],
-                            'bVisible': false,
-                            'bSearchable': true
-                        },
-                        { // When sorting 'placed', we want to use the
-                          // unformatted column
-                          'aTargets': [ 'placed_formatted'],
-                          'iDataSort': 7
-                        },
-                        { // When sorting 'updated', we want to use the
-                          // unformatted column
-                          'aTargets': [ 'updated_formatted'],
-                          'iDataSort': 9
-                        }
-                    ],
-                    'aaSorting': [[ 9, 'desc' ]], // Default sort, updated descending
-                    'processing': true, // Display a message when manipulating
-                    'iDisplayLength': 10, // 10 results per page
-                    'sPaginationType': "full_numbers", // Pagination display
-                    'deferRender': true, // Improve performance on big datasets
-                    'data': dataCopy,
-                    'columns': colData,
-                    'originalData': data, // Enable render functions to access
-                                          // our original data
-                    'initComplete': function() {
-
-                        // Prepare any filter elements that need it
-                        for (var el in filterable) {
-                            if (filterable.hasOwnProperty(el)) {
-                                if (filterable[el].hasOwnProperty('prep')) {
-                                    filterable[el].prep(dataCopy, data);
-                                }
-                                if (filterable[el].hasOwnProperty('listener')) {
-                                    filterable[el].listener();
-                                }
-                            }
-                        }
-
-                    }
-                }));
-
-                // Custom date range filtering
-                $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
-                    console.log(data);
-                    var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate');
-                    var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate');
-                    var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate');
-                    var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate');
-                    var rowPlaced = data[7] ? new Date(data[7]) : null;
-                    var rowModified = data[9] ? new Date(data[9]) : null;
-                    var placedPassed = true;
-                    var modifiedPassed = true;
-                    if (placedStart && rowPlaced && rowPlaced < placedStart) {
-                        placedPassed = false
-                    };
-                    if (placedEnd && rowPlaced && rowPlaced > placedEnd) {
-                        placedPassed = false;
-                    }
-                    if (modifiedStart && rowModified && rowModified < modifiedStart) {
-                        modifiedPassed = false
-                    };
-                    if (modifiedEnd && rowModified && rowModified > modifiedEnd) {
-                        modifiedPassed = false;
-                    }
-
-                    return placedPassed && modifiedPassed;
-
-                });
-
-            }
-        );
-
-        var clearSearch = function() {
-            table.search('').columns().search('');
-            activeFilters = {};
-            for (var filter in filterable) {
-                if (
-                    filterable.hasOwnProperty(filter) &&
-                    filterable[filter].hasOwnProperty('clear')
-                ) {
-                    filterable[filter].clear();
-                }
-            }
-            table.draw();
-        };
-
-        // Apply any search filters, or clear any previous
-        // ones
-        $('#illfilter_form').submit(function(event) {
-            event.preventDefault();
-            table.search('').columns().search('');
-            for (var active in activeFilters) {
-                if (activeFilters.hasOwnProperty(active)) {
-                    activeFilters[active]();
-                }
-            }
-            table.draw();
-        });
-
-        // Clear all filters
-        $('#clear_search').click(function() {
-            clearSearch();
-        });
-
-    });
-    //]]>
-</script>
 </head>
 
 <body id="illrequests" class="ill">
     [% END %]
 </div>
 
-<div id="doc3" class="yui-t2">
-    <div id="bd">
+<div class="main container-fluid">
+    <div class="row">
+
         [% IF query_type == 'illlist' %]
-        <div id="illfilter_yui_column" class="yui-b">
-            <form method="get" id="illfilter_form">
-                <fieldset class="brief">
-                    <h3>Filters</h3>
-                    <ol>
-                        <li>
-                            <label for="illfilter_status">Status:</label>
-                            <select name="illfilter_status" id="illfilter_status">
-                                <option value=""></option>
-                            </select>
-                        </li>
-                        <li>
-                            <label for="illfilter_dateplaced_start">Date placed between:</label>
-                            <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker">
-                        </li>
-                        <li>
-                            <label for="illfilter_dateplaced_end">and:</label>
-                            <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker">
-                        </li>
-                        <li>
-                            <label for="illfilter_datemodified_start">Updated between:</label>
-                            <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker">
-                        </li>
-                        <li>
-                            <label for="illfilter_datemodified_end">and:</label>
-                            <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker">
-                        </li>
-                        <li>
-                            <label for="illfilter_branchname">Library:</label>
-                            <select name="illfilter_branchname" id="illfilter_branchname">
-                                <option value=""></option>
-                            </select>
-                        </li>
-                        <li>
-                            <label for="illfilter_barcode">Patron barcode:</label>
-                            <input type="text" name="illfilter_barcode" id="illfilter_barcode">
-                        </li>
-                    </ol>
-                    <fieldset class="action">
-                        <input type="submit" value="Search" />
-                        <input type="button" value="Clear" id="clear_search" />
-                    </fieldset>
-                </fieldset>
-            </form>
-        </div>
+            <div class="col-sm-2">
+                <aside>
+                    <form method="get" id="illfilter_form">
+                        <fieldset class="brief">
+                            <h3>Filters</h3>
+                            <ol>
+                                <li>
+                                    <label for="illfilter_status">Status:</label>
+                                    <select name="illfilter_status" id="illfilter_status">
+                                        <option value=""></option>
+                                    </select>
+                                </li>
+                                <li>
+                                    <label for="illfilter_dateplaced_start">Date placed between:</label>
+                                    <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker" />
+                                </li>
+                                <li>
+                                    <label for="illfilter_dateplaced_end">and:</label>
+                                    <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker" />
+                                </li>
+                                <li>
+                                    <label for="illfilter_datemodified_start">Updated between:</label>
+                                    <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker" />
+                                </li>
+                                <li>
+                                    <label for="illfilter_datemodified_end">and:</label>
+                                    <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker" />
+                                </li>
+                                <li>
+                                    <label for="illfilter_branchname">Library:</label>
+                                    <select name="illfilter_branchname" id="illfilter_branchname">
+                                        <option value=""></option>
+                                    </select>
+                                </li>
+                                <li>
+                                    <label for="illfilter_patron">Patron:</label>
+                                    <input type="text" name="illfilter_patron" id="illfilter_patron" />
+                                </li>
+                            </ol>
+                            <fieldset class="action">
+                                <input type="submit" value="Search" />
+                                <input type="button" value="Clear" id="clear_search" />
+                            </fieldset>
+                        </fieldset>
+                    </form> <!-- /#illfilter_form -->
+                </aside>
+            </div> <!-- /.col-sm-2 -->
+            <div class="col-sm-10">
+                <main>
+        [% ELSE %]
+            <div class="col-sm-10 col-sm-offset-2">
+                <main>
         [% END %]
-        <div id="yui-main">
-            <div id="interlibraryloans" class="yui-b">
+            <div id="interlibraryloans">
         [% IF !backends_available || !has_branch %]
             <div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a></div>
         [% ELSE %]
                     <h1>Cancel a confirmed request</h1>
                     [% PROCESS $whole.template %]
 
+                [% ELSIF query_type == 'check_out' and !whole.error %]
+                    [% IF !whole.stage || whole.stage == 'form' %]
+                        <h1 id="ill-issue-title">Issue requested item to [% INCLUDE 'patron-title.inc' patron = request.patron %]</h1>
+                        [% IF !request.biblio_id || request.biblio_id.length == 0 %]
+                        <div class="alert">This item cannot be issued as it has no biblio record associated with it</div>
+                        [% END %]
+                        [% IF whole.value.errors.itemcount %]
+                        <div class="alert">The bibliographic record for this request has multiple items, it should only have one. Please fix this then try again.</div>
+                        [% END %]
+                        [% IF whole.value.errors.item_creation %]
+                        <div class="alert">An unknown error occurred while trying to add an item</div>
+                        [% END %]
+                        [% IF whole.value.errors.item_check_out %]
+                        <div class="alert">An unknown error occurred while trying to check out the item</div>
+                        [% END %]
+                        [% IF whole.value.check_out_errors %]
+                            [% IF whole.value.check_out_errors.error.STATS %]
+                            <div class="alert">
+                                Local use recorded
+                            </div>
+                            [% ELSE %]
+                            <div class="alert">
+                                There was a problem checking this item out, please check for problems with the <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% whole.value.patron.borrowernumber | uri %]">patron's account</a>
+                            </div>
+                            [% END %]
+                        [% END %]
+                        [% IF request.biblio_id && request.biblio_id.length > 0  && !whole.value.check_out_errors.error.STATS %]
+                            <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
+                                <fieldset class="rows">
+                                    <legend>Check out details</legend>
+                                    [% items = whole.value.biblio.items.unblessed %]
+                                    [% IF items.size == 1 %]
+                                        <p>The bibliographic record for this request already has an item attached to it, you are about to check it out</p>
+                                    [% ELSE %]
+                                        <p>A bibliographic record for this request exists, but no item. You are about to create an item and check it out</p>
+                                    [% END %]
+                                    <ol>
+                                        <li class="ill_checkout_inhouse">
+                                            <label for="inhouse" class="ill_checkout_inhouse_label">Statistical patron:</label>
+                                            <select id="ill_checkout_inhouse_select" name="inhouse" class="ill_checkout_inhouse_select">
+                                                <option value=""></option>
+                                                [% FOREACH stat IN whole.value.statistical %]
+                                                    [% IF stat.borrowernumber == params.inhouse %]
+                                                        <option value="[% stat.cardnumber | html %]" selected>[% INCLUDE 'patron-title.inc' patron = stat %]</option>
+                                                    [% ELSE %]
+                                                        <option value="[% stat.cardnumber | html %]">[% INCLUDE 'patron-title.inc' patron = stat %]</option>
+                                                    [% END %]
+                                                [% END %]
+                                            </select>
+                                            [% IF whole.value.errors.inhouse %]
+                                            <span class="required">You must choose a valid patron</span>
+                                            [% END %]
+                                            <div class="hint">If you do not wish to check out the item to [% INCLUDE 'patron-title.inc' patron = request.patron %] and would rather issue it to an in-house statistical patron, choose the patron here</div>
+                                        </li>
+                                        <li class="ill_checkout_item_type">
+                                            <label for="item_type" class="ill_checkout_item_type_label required">Item type:</label>
+                                            [% IF items.size != 1 %]
+                                                <select id="ill_checkout_item_type_select" name="item_type" required>
+                                                    [% FOREACH type IN whole.value.itemtypes %]
+                                                        [% IF type.itemtype == params.item_type %]
+                                                        <option value="[% type.itemtype | html %]" selected>
+                                                        [% ELSE %]
+                                                        <option value="[% type.itemtype | html %]">
+                                                        [% END %]
+                                                            [% type.description | html %]
+                                                        </option>
+                                                    [% END %]
+                                                </select>
+                                            [% ELSE %]
+                                                [% FOREACH type IN whole.value.itemtypes %]
+                                                    [% IF type.itemtype == items.0.itype %]
+                                                        [% type.description | html %]
+                                                    [% END %]
+                                                [% END %]
+                                            [% END %]
+                                            [% IF whole.value.errors.item_type %]
+                                            <span class="required">You must choose an item type</span>
+                                            [% END %]
+                                        </li>
+                                        [% IF items.size == 1 %]
+                                            <li>
+                                                <label for="barcode" class="ill_checkout_barcode_label">Item barcode:</label>
+                                                [% items.0.barcode | html %]
+                                            </li>
+                                        [% END %]
+                                        <li class="ill_checkout_branchcode">
+                                            <label for="branchcode" class="ill_checkout_branchcode_label required">Library:</label>
+                                            [% branchcode = items.size == 1 ? items.0.homebranch : params.branchcode ? params.branchcode : request.branchcode %]
+                                            [% IF items.size != 1 %]
+                                                <select name="branchcode" id="ill_checkout_branchcode_select" required>
+                                                    [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
+                                                </select>
+                                            [% ELSE %]
+                                                [% FOREACH branch IN whole.value.libraries.unblessed %]
+                                                    [% IF branch.branchcode == branchcode %]
+                                                        [% branch.branchname | html %]
+                                                    [% END %]
+                                                [% END %]
+                                            [% END %]
+                                            [% IF whole.value.errors.branchcode %]
+                                            <span class="required">You must choose a branch</span>
+                                            [% END %]
+                                        </li>
+                                        <li class="ill_checkout_due_date">
+                                            <label for="duedate" class="ill_checkout_duedate_label">Due date:</label>
+                                            <input name="duedate" id="ill_checkout_duedate_input" type="text" value="[% params.duedate | html %]"> [% INCLUDE 'date-format.inc' %]
+                                            <div class="hint">If you do not specify a due date, it will be set according to circulation rules</p>
+                                        </li>
+                                    </ol>
+                                </fieldset>
+                                <fieldset class="action">
+                                    <input type="hidden" value="check_out" name="method">
+                                    <input type="hidden" value="form" name="stage">
+                                    [% IF items.size == 1 %]
+                                        <input name="branchcode" type="hidden" value="[% branchcode | html %]">
+                                        <input name="item_type" type="hidden" value="[% items.0.itype | html %]">
+                                    [% END %]
+                                    <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
+                                    <input type="submit" value="Submit">
+                                    <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Cancel</a>
+                                </fieldset>
+                            </form>
+                        [% END %]
+                        [% IF whole.value.check_out_errors.error.STATS %]
+                            <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Return to request</a>
+                        [% END %]
+                    [% ELSIF whole.stage == 'done_check_out' %]
+                        <h1>Item checked out</h1>
+                        <fieldset class="rows">
+                            <legend>Check out details</legend>
+                            <ol>
+                                <li>
+                                    <label>Checked out to:</label>
+                                    [% INCLUDE 'patron-title.inc' patron = whole.value.patron %]
+                                </li>
+                                <li>
+                                    <label>Due date:</label>
+                                    [% whole.value.check_out.date_due | $KohaDates with_hours => 1 %]
+                                </li>
+                            </ol>
+                        </fieldset>
+                        <fieldset class="action">
+                            <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Return to request</a>
+                        </fieldset>
+                    [% END %]
+
                 [% ELSIF query_type == 'generic_confirm' %]
                     <h1>Place request with partner libraries</h1>
                   [% IF error %]
                                 <ol>
                                     <li>
                                         <label for="partner_filter">Filter partner libraries:</label>
-                                        <input type="text" id="partner_filter">
+                                        <input type="text" id="partner_filter" />
                                     </li>
                                     <li>
                                         <label for="partners" class="required">Select partner libraries:</label>
 
                                     </li>
                                     <li>
-                                        <label for="subject" class="required">Subject Line</label>
+                                        <label for="subject" class="required">Subject line:</label>
                                         <input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject | html %]" required="required" />
                                     </li>
                                     <li>
                                 <li class="status">
                                     <label class="status">Status:</label>
                                     [% stat = request.status %]
-                                    [% request.capabilities.$stat.name | html %]
+                                    [% current_alias = request.status_alias %]
+                                    <select id="status_alias" name="status_alias">
+                                        [% IF !current_alias %]
+                                        <option value="" selected>
+                                        [% ELSE %]
+                                        <option value="">
+                                        [% END %]
+                                            [% request.capabilities.$stat.name | html %]
+                                        </option>
+                                        [% FOREACH alias IN AuthorisedValues.Get('ILLSTATUS') %]
+                                            [% IF alias.authorised_value == current_alias %]
+                                            <option value="[% alias.authorised_value | html %]" selected>
+                                            [% ELSE %]
+                                            <option value="[% alias.authorised_value | html %]">
+                                            [% END %]
+                                                [% alias.lib | html %]
+                                            </option>
+                                        [% END %]
+                                    </select>
                                 </li>
                                 <li class="updated">
                                     <label class="updated">Last updated:</label>
                                 </li>
                                 <li class="cost">
                                     <label class="cost">Cost:</label>
-                                    [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
+                                    [% IF request.cost %][% request.cost | $Price %][% ELSE %]<span>N/A</span>[% END %]
                                 </li>
                                 <li class="price_paid">
                                     <label class="price_paid">Price paid:</label>
                             <input type="hidden" name="method" value="delete" />
                             <input type="hidden" name="confirmed" value="1" />
                             <input type="hidden" name="illrequest_id" value="[% request.id | html %]" />
-                            <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
+                            <button type="submit" class="btn btn-default approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
                         </form>
-                        <a class="btn btn-default btn-sm deny" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]"><i class="fa fa-fw fa-remove"></i>No, do not delete</a>
+                        <a class="btn btn-default deny" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]"><i class="fa fa-fw fa-remove"></i>No, do not delete</a>
                     </div>
 
                 [% ELSIF query_type == 'illview' %]
 
                     <h1>Manage ILL request</h1>
                     <div id="request-toolbar" class="btn-toolbar">
-                        <a title="Edit request" id="ill-toolbar-btn-edit-action" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=edit_action&amp;illrequest_id=[% request.illrequest_id | html %]">
+                        <a title="Edit request" id="ill-toolbar-btn-edit-action" class="btn btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=edit_action&amp;illrequest_id=[% request.illrequest_id | html %]">
                         <span class="fa fa-pencil"></span>
                         Edit request
                         </a>
                         [% FOREACH action IN request.available_actions %]
+                            [% needs_prefs = action.needs_prefs.size ? action.needs_prefs : [] %]
+                            [% needs_perms = action.needs_perms.size ? action.needs_perms : [] %]
+                            [% needs_all = action.needs_all.size ? action.needs_all : [] %]
+                            [% has_prefs_count = 0 %]
+                            [% has_perms_count = 0 %]
+                            [% has_all_count = 0 %]
+                            [% FOREACH pref IN needs_prefs %]
+                                [% IF Koha.Preference(pref) %]
+                                    [% has_prefs_count = has_prefs_count + 1 %]
+                                [% END %]
+                            [% END %]
+                            [% FOREACH perm IN needs_perms %]
+                                [% perm_name = 'CAN_' _ perm %]
+                                [% IF ($perm_name) %]
+                                    [% has_perms_count = has_perms_count + 1 %]
+                                [% END %]
+                            [% END %]
+                            [% FOREACH func IN needs_all %]
+                                [% IF func(request) %]
+                                    [% has_all_count = has_all_count + 1 %]
+                                [% END %]
+                            [% END %]
+                            [% NEXT IF has_prefs_count < needs_prefs.size || has_perms_count < needs_perms.size || has_all_count < needs_all.size %]
                             [% IF action.method == 'migrate' %]
                                 [% IF backends.size > 2 %]
                                     <div class="dropdown btn-group">
-                                        <button class="btn btn-sm btn-default dropdown-toggle" type="button" id="ill-migrate-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
+                                        <button class="btn btn-default dropdown-toggle" type="button" id="ill-migrate-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                             <i class="fa [% action.ui_method_icon | html %]"></i> [% action.ui_method_name | html %] <span class="caret"></span>
                                         </button>
                                         <ul class="dropdown-menu" aria-labelledby="ill-migrate-dropdown">
                                 [% ELSIF backends.size == 2 %]
                                     [% FOREACH backend IN backends %]
                                         [% IF backend != request.backend %]
-                                            <a title="[% action.ui_method_name | html %]" id="ill-toolbar-btn-[% action.id | lower | html %]" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;backend=[% backend | uri %]">
+                                            <a title="[% action.ui_method_name | html %]" id="ill-toolbar-btn-[% action.id | lower | html %]" class="btn btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;backend=[% backend | uri %]">
                                             <span class="fa [% action.ui_method_icon | html %]"></span>
                                             [% action.ui_method_name | html %]
                                             </a>
                                     [% END %]
                                 [% END %]
                             [% ELSIF action.method != 0 %]
-                                <a title="[% action.ui_method_name | html %]" id="ill-toolbar-btn-[% action.id | lower | html %]" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]">
+                                <a title="[% action.ui_method_name | html %]" id="ill-toolbar-btn-[% action.id | lower | html %]" class="btn btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]">
                                 <span class="fa [% action.ui_method_icon | html %]"></span>
                                 [% action.ui_method_name | html %]
                                 </a>
                             [% END %]
                         [% END %]
-                        <a title="Display supplier metadata" id="ill-request-display-metadata" class="btn btn-sm btn-default pull-right" href="#">
+                        <a title="Display supplier metadata" id="ill-request-display-metadata" class="btn btn-default pull-right" href="#">
                             <span class="fa fa-eye"></span>
                             Display supplier metadata
                         </a>
+                        <a title="ILL request log" id="ill-request-display-log" class="btn btn-default pull-right" href="#">
+                            <span class="fa fa-calendar"></span>
+                            ILL request log
+                        </a>
                     </div>
                     <div class="ill-view-panel panel panel-default">
                         <div class="panel-heading">
                                     </li>
                                     <li class="status">
                                         <span class="label status">Status:</span>
-                                        [% request.capabilities.$req_status.name | html %]
+                                        [% IF request.statusalias %]
+                                            [% request.statusalias.lib | html %]
+                                        [% ELSE %]
+                                            [% request.capabilities.$req_status.name | html%]
+                                            [% IF request.requested_partners.length > 0 %]
+                                                ([% request.requested_partners | html %])
+                                            [% END %]
+                                        [% END %]
                                     </li>
                                     <li class="updated">
                                         <span class="label updated">Last updated:</span>
                                     </li>
                                     <li class="cost">
                                         <span class="label cost">Cost:</span>
-                                        [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
+                                        [% IF request.cost %][% request.cost | $Price %][% ELSE %]<span>N/A</span>[% END %]
                                     </li>
                                     <li class="price_paid">
                                         <span class="label price_paid">Price paid:</span>
-                                        [% IF request.price_paid %][% request.price_paid | html %][% ELSE %]<span>N/A</span>[% END %]
+                                        [% IF request.price_paid %][% request.price_paid | $Price %][% ELSE %]<span>N/A</span>[% END %]
                                     </li>
                                     <li class="req_id">
                                         <span class="label req_id">Request number:</span>
                         </div>
                     </div>
 
+                    <div id="requestLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
+                        <div class="modal-dialog">
+                            <div class="modal-content">
+                                <div class="modal-header">
+                                    <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
+                                    <h3 id="requestLogLabel"> Request log</h3>
+                                </div>
+                                <div class="modal-body">
+                                [% IF request.logs.size > 0 %]
+                                    [% FOREACH log IN request.logs %]
+                                        [% tpl = log.template %]
+                                        [% INCLUDE $tpl log=log %]
+                                    [% END %]
+                                [% ELSE %]
+                                    There are no recorded logs for this request
+                                [% END %]
+                                </div>
+                                <div class="modal-footer">
+                                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+
                     <div class="ill-view-panel panel panel-default">
                         <div class="panel-heading">
                             <h3>[% request.illcomments.count | html %] comments</h3>
                                         </form>
                                     </div>
                                 </div>
-                            </div>
+                        </div>
                     </div>
 
                 [% ELSIF query_type == 'illlist' %]
                     <h1>View ILL requests</h1>
                     <div id="results">
                         <h3>Details for all requests</h3>
+                        [% INCLUDE 'ill-list-table.inc' %]
 
-                        <table id="ill-requests">
-                            <thead>
-                                <tr id="illview-header">
-                                    <th>Author</th>
-                                    <th>Title</th>
-                                    <th>Patron</th>
-                                    <th>Bibliographic record ID</th>
-                                    <th>Library</th>
-                                    <th>Status</th>
-                                    <th class="placed">&nbsp;</th>
-                                    <th class="placed_formatted">Date placed</th>
-                                    <th class="updated">&nbsp;</th>
-                                    <th class="updated_formatted">Updated on</th>
-                                    <th>Request number</th>
-                                    <th>Comments</th>
-                                    <th class="actions"></th>
-                                </tr>
-                            </thead>
-                            <tbody id="illview-body">
-                            </tbody>
-                        </table>
-                    </div>
+                    </div> <!-- /#results -->
                 [% ELSE %]
                 <!-- Custom Backend Action -->
                 [% PROCESS $whole.template %]
 
                 [% END %]
         [% END %]
-            </div>
-        </div>
-    </div>
+                </div> <!-- /#interlibraryloans -->
+            </main>
+        </div> <!-- /.col-sm-10 -->
+    </div> <!-- /.row -->
+
+
+[% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'columns_settings.inc' %]
+    [% INCLUDE 'calendar.inc' %]
+    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
+    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
+    <script>
+        var prefilters = '[% prefilters | $raw %]';
+        // Set column settings
+        var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %];
+        $("#ill_checkout_duedate_input").datetimepicker({
+            hour: 23,
+            minute: 59
+        }).on("change", function(e, value) {
+            if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");}
+        });
+    </script>
+    <script>
+        $('#ill_checkout_inhouse_select').on('change', function() {
+            if ($(this).val().length > 0) {
+                $('.ill_checkout_due_date').hide();
+            } else {
+                $('.ill_checkout_due_date').show();
+            }
+        });
+    </script>
+    [% INCLUDE 'ill-list-table-strings.inc' %]
+    [% Asset.js("js/ill-list-table.js") | $raw %]
+[% END %]
 
 [% TRY %]
 [% PROCESS backend_jsinclude %]