Bug 20600: (follow-up) Fix filtering
[koha-equinox.git] / koha-tmpl / intranet-tmpl / prog / en / modules / ill / ill-requests.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% USE Koha %]
5 [% USE KohaDates %]
6
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; ILL requests  &rsaquo;</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
11 [% Asset.css("css/datatables.css") | $raw %]
12 [% INCLUDE 'datatables.inc' %]
13 [% INCLUDE 'calendar.inc' %]
14 <script type="text/javascript">
15     //<![CDATA[
16     $(document).ready(function() {
17
18         // Illview Datatable setup
19
20         var table;
21
22         // Filters that are active
23         var activeFilters = {};
24
25         // Fields we don't want to display
26         var ignore = [
27             'accessurl',
28             'backend',
29             'branchcode',
30             'completed',
31             'capabilities',
32             'cost',
33             'medium',
34             'notesopac',
35             'notesstaff',
36             'replied'
37         ];
38
39         // Fields we need to expand (flatten)
40         var expand = [
41             'metadata',
42             'patron'
43         ];
44
45         // Expanded fields
46         // This is auto populated
47         var expanded = {};
48
49         // The core fields that should be displayed first
50         var core = [
51             'metadata_author',
52             'metadata_title',
53             'borrowername',
54             'patron_cardnumber',
55             'biblio_id',
56             'library',
57             'status',
58             'placed',
59             'placed_formatted',
60             'updated',
61             'updated_formatted',
62             'illrequest_id',
63             'comments',
64             'action' // Action should always be last
65         ];
66
67         // Filterable columns
68         var filterable = {
69             status: {
70                 prep: function(tableData, oData) {
71                     var uniques = {};
72                     tableData.forEach(function(row) {
73                         var resolvedName = getStatusName(
74                             oData[0].capabilities[row.status].name
75                         );
76                         uniques[resolvedName] = 1
77                     });
78                     Object.keys(uniques).sort().forEach(function(unique) {
79                         $('#illfilter_status').append(
80                             '<option value="' + unique  +
81                             '">' + unique +  '</option>'
82                         );
83                     });
84                 },
85                 listener: function() {
86                     var me = 'status';
87                     $('#illfilter_status').change(function() {
88                         var sel = $('#illfilter_status option:selected').val();
89                         if (sel && sel.length > 0) {
90                             activeFilters[me] = function() {
91                                 table.column(6).search(sel);
92                             }
93                         } else {
94                             if (activeFilters.hasOwnProperty(me)) {
95                                 delete activeFilters[me];
96                             }
97                         }
98                     });
99                 },
100                 clear: function() {
101                     $('#illfilter_status').val('');
102                 }
103             },
104             pickupBranch: {
105                 prep: function(tableData, oData) {
106                     var uniques = {};
107                     tableData.forEach(function(row) {
108                         uniques[row.library.branchname] = 1
109                     });
110                     Object.keys(uniques).sort().forEach(function(unique) {
111                         $('#illfilter_branchname').append(
112                             '<option value="' + unique  +
113                             '">' + unique +  '</option>'
114                         );
115                     });
116                 },
117                 listener: function() {
118                     var me = 'pickupBranch';
119                     $('#illfilter_branchname').change(function() {
120                         var sel = $('#illfilter_branchname option:selected').val();
121                         if (sel && sel.length > 0) {
122                             activeFilters[me] = function() {
123                                 table.column(5).search(sel);
124                             }
125                         } else {
126                             if (activeFilters.hasOwnProperty(me)) {
127                                 delete activeFilters[me];
128                             }
129                         }
130                     });
131                 },
132                 clear: function() {
133                     $('#illfilter_branchname').val('');
134                 }
135             },
136             barcode: {
137                 listener: function() {
138                     var me = 'barcode';
139                     $('#illfilter_barcode').change(function() {
140                         var val = $('#illfilter_barcode').val();
141                         if (val && val.length > 0) {
142                             activeFilters[me] = function() {
143                                 table.column(3).search(val);
144                             }
145                         } else {
146                             if (activeFilters.hasOwnProperty(me)) {
147                                 delete activeFilters[me];
148                             }
149                         }
150                     });
151                 },
152                 clear: function() {
153                     $('#illfilter_barcode').val('');
154                 }
155             },
156             dateModified: {
157                 clear: function() {
158                     $('#illfilter_datemodified_start, #illfilter_datemodified_end').val('');
159                 }
160             },
161             datePlaced: {
162                 clear: function() {
163                     $('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val('');
164                 }
165             }
166         };
167
168         // Remove any fields we're ignoring
169         var removeIgnore = function(dataObj) {
170             dataObj.forEach(function(thisRow) {
171                 ignore.forEach(function(thisIgnore) {
172                     if (thisRow.hasOwnProperty(thisIgnore)) {
173                         delete thisRow[thisIgnore];
174                     }
175                 });
176             });
177         };
178
179         // Expand any fields we're expanding
180         var expandExpand = function(row) {
181             expand.forEach(function(thisExpand) {
182                 if (row.hasOwnProperty(thisExpand)) {
183                     if (!expanded.hasOwnProperty(thisExpand)) {
184                         expanded[thisExpand] = [];
185                     }
186                     var expandObj = row[thisExpand];
187                     Object.keys(expandObj).forEach(
188                         function(thisExpandCol) {
189                             var expColName = thisExpand + '_' + thisExpandCol;
190                             // Keep a list of fields that have been expanded
191                             // so we can create toggle links for them
192                             if (expanded[thisExpand].indexOf(expColName) == -1) {
193                                 expanded[thisExpand].push(expColName);
194                             }
195                             expandObj[expColName] =
196                                 expandObj[thisExpandCol];
197                             delete expandObj[thisExpandCol];
198                         }
199                     );
200                     $.extend(true, row, expandObj);
201                     delete row[thisExpand];
202                 }
203             });
204         };
205
206         // Build a de-duped list of all column names
207         var allCols = {};
208         core.map(function(thisCore) {
209             allCols[thisCore] = 1;
210         });
211
212         // Strip the expand prefix if it exists, we do this for display
213         var stripPrefix = function(value) {
214             expand.forEach(function(thisExpand) {
215                 var regex = new RegExp(thisExpand + '_', 'g');
216                 value = value.replace(regex, '');
217             });
218             return value;
219         };
220
221         // Our 'render' function for borrowerlink
222         var createPatronLink = function(data, type, row) {
223             var patronLink = '<a title="' + _("View borrower details") + '" ' +
224                 'href="/cgi-bin/koha/members/moremember.pl?' +
225                 'borrowernumber='+row.borrowernumber+'">';
226                 if ( row.patron_firstname ) {
227                     patronLink = patronLink + row.patron_firstname + ' ';
228                 }
229                 patronLink = patronLink + row.patron_surname + '</a>';
230             return patronLink
231         };
232
233         // Our 'render' function for biblio_id
234         var createBiblioLink = function(data, type, row) {
235             return (row.biblio_id) ?
236                 '<a title="' + _("View biblio details") + '" ' +
237                 'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' +
238                 row.biblio_id + '">' +
239                 row.biblio_id +
240                 '</a>' : '';
241         };
242
243         // Our 'render' function for the library name
244         var createLibrary = function(data, type, row) {
245             return row.library.branchname;
246         };
247
248         // Render function for request ID
249         var createRequestId = function(data, type, row) {
250             return row.id_prefix + row.illrequest_id;
251         };
252
253         // Render function for request status
254         var createStatus = function(data, type, row, meta) {
255             var origData = meta.settings.oInit.originalData;
256             if (origData.length > 0) {
257                 var status_name = meta.settings.oInit.originalData[0].capabilities[
258                     row.status
259                 ].name;
260                 return getStatusName(status_name);
261             } else {
262                 return '';
263             }
264         };
265
266         var getStatusName = function(origName) {
267             switch( origName ) {
268                 case "New request":
269                     return _("New request");
270                 case "Requested":
271                     return _("Requested");
272                 case "Requested from partners":
273                     return _("Requested from partners");
274                 case "Request reverted":
275                     return _("Request reverted");
276                 case "Queued request":
277                     return _("Queued request");
278                 case "Cancellation requested":
279                     return _("Cancellation requested");
280                 case "Completed":
281                     return _("Completed");
282                 case "Delete request":
283                     return _("Delete request");
284                 default:
285                     return origName;
286             }
287         };
288
289         // Render function for creating a row's action link
290         var createActionLink = function(data, type, row) {
291             return '<a class="btn btn-default btn-sm" ' +
292                 'href="/cgi-bin/koha/ill/ill-requests.pl?' +
293                 'method=illview&amp;illrequest_id=' +
294                 row.illrequest_id +
295                 '">' + _("Manage request") + '</a>';
296         };
297
298         // Columns that require special treatment
299         var specialCols = {
300             action: {
301                 name: '',
302                 func: createActionLink
303             },
304             borrowername: {
305                 name: _("Patron"),
306                 func: createPatronLink
307             },
308             illrequest_id: {
309                 name: _("Request number"),
310                 func: createRequestId
311             },
312             status: {
313                 name: _("Status"),
314                 func: createStatus
315             },
316             biblio_id: {
317                 name: _("Bibliographic record ID"),
318                 func: createBiblioLink
319             },
320             library: {
321                 name: _("Library"),
322                 func: createLibrary
323             },
324             updated: {
325                 name: _("Updated on"),
326             },
327             patron_cardnumber: {
328                 name: _("Patron barcode")
329             }
330         };
331
332         // Toggle request attributes in Illview
333         $('#toggle_requestattributes').on('click', function(e) {
334             e.preventDefault();
335             $('#requestattributes').toggleClass('content_hidden');
336         });
337
338         // Toggle new comment form in Illview
339         $('#toggle_addcomment').on('click', function(e) {
340             e.preventDefault();
341             $('#addcomment').toggleClass('content_hidden');
342         });
343
344         // Filter partner list
345         $('#partner_filter').keyup(function() {
346             var needle = $('#partner_filter').val();
347             $('#partners > option').each(function() {
348                 var regex = new RegExp(needle, 'i');
349                 if (
350                     needle.length == 0 ||
351                     $(this).is(':selected') ||
352                     $(this).text().match(regex)
353                 ) {
354                     $(this).show();
355                 } else {
356                     $(this).hide();
357                 }
358             });
359         });
360
361         // Display the modal containing request supplier metadata
362         $('#ill-request-display-metadata').on('click', function(e) {
363             e.preventDefault();
364             $('#dataPreview').modal({show:true});
365         });
366
367         // Get our data from the API and process it prior to passing
368         // it to datatables
369         var ajax = $.ajax(
370             '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
371             ).done(function() {
372                 var data = JSON.parse(ajax.responseText);
373                 // Make a copy, we'll be removing columns next and need
374                 // to be able to refer to data that has been removed
375                 var dataCopy = $.extend(true, [], data);
376                 // Remove all columns we're not interested in
377                 removeIgnore(dataCopy);
378                 // Expand columns that need it and create an array
379                 // of all column names
380                 $.each(dataCopy, function(k, row) {
381                     expandExpand(row);
382                 });
383
384                 // Assemble an array of column definitions for passing
385                 // to datatables
386                 var colData = [];
387                 Object.keys(allCols).forEach(function(thisCol) {
388                     // Create the base column object
389                     var colObj = {
390                         name: thisCol,
391                         className: thisCol,
392                         defaultContent: ''
393                     };
394                     // We may need to process the data going in this
395                     // column, so do it if necessary
396                     if (
397                         specialCols.hasOwnProperty(thisCol) &&
398                         specialCols[thisCol].hasOwnProperty('func')
399                     ) {
400                         colObj.render = specialCols[thisCol].func;
401                     } else {
402                         colObj.data = thisCol;
403                     }
404                     colData.push(colObj);
405                 });
406
407                 // Initialise the datatable
408                 table = $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, {
409                     'aoColumnDefs': [
410                         { // Last column shouldn't be sortable or searchable
411                             'aTargets': [ 'actions' ],
412                             'bSortable': false,
413                             'bSearchable': false
414                         },
415                         { // Hide the two date columns we use just for sorting
416                             'aTargets': [ 'placed', 'updated' ],
417                             'bVisible': false,
418                             'bSearchable': true
419                         },
420                         { // When sorting 'placed', we want to use the
421                           // unformatted column
422                           'aTargets': [ 'placed_formatted'],
423                           'iDataSort': 7
424                         },
425                         { // When sorting 'updated', we want to use the
426                           // unformatted column
427                           'aTargets': [ 'updated_formatted'],
428                           'iDataSort': 9
429                         }
430                     ],
431                     'aaSorting': [[ 9, 'desc' ]], // Default sort, updated descending
432                     'processing': true, // Display a message when manipulating
433                     'iDisplayLength': 10, // 10 results per page
434                     'sPaginationType': "full_numbers", // Pagination display
435                     'deferRender': true, // Improve performance on big datasets
436                     'data': dataCopy,
437                     'columns': colData,
438                     'originalData': data, // Enable render functions to access
439                                           // our original data
440                     'initComplete': function() {
441
442                         // Prepare any filter elements that need it
443                         for (var el in filterable) {
444                             if (filterable.hasOwnProperty(el)) {
445                                 if (filterable[el].hasOwnProperty('prep')) {
446                                     filterable[el].prep(dataCopy, data);
447                                 }
448                                 if (filterable[el].hasOwnProperty('listener')) {
449                                     filterable[el].listener();
450                                 }
451                             }
452                         }
453
454                     }
455                 }));
456
457                 // Custom date range filtering
458                 $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
459                     console.log(data);
460                     var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate');
461                     var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate');
462                     var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate');
463                     var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate');
464                     var rowPlaced = data[7] ? new Date(data[7]) : null;
465                     var rowModified = data[9] ? new Date(data[9]) : null;
466                     var placedPassed = true;
467                     var modifiedPassed = true;
468                     if (placedStart && rowPlaced && rowPlaced < placedStart) {
469                         placedPassed = false
470                     };
471                     if (placedEnd && rowPlaced && rowPlaced > placedEnd) {
472                         placedPassed = false;
473                     }
474                     if (modifiedStart && rowModified && rowModified < modifiedStart) {
475                         modifiedPassed = false
476                     };
477                     if (modifiedEnd && rowModified && rowModified > modifiedEnd) {
478                         modifiedPassed = false;
479                     }
480
481                     return placedPassed && modifiedPassed;
482
483                 });
484
485             }
486         );
487
488         var clearSearch = function() {
489             table.search('').columns().search('');
490             activeFilters = {};
491             for (var filter in filterable) {
492                 if (
493                     filterable.hasOwnProperty(filter) &&
494                     filterable[filter].hasOwnProperty('clear')
495                 ) {
496                     filterable[filter].clear();
497                 }
498             }
499             table.draw();
500         };
501
502         // Apply any search filters, or clear any previous
503         // ones
504         $('#illfilter_form').submit(function(event) {
505             event.preventDefault();
506             table.search('').columns().search('');
507             for (var active in activeFilters) {
508                 if (activeFilters.hasOwnProperty(active)) {
509                     activeFilters[active]();
510                 }
511             }
512             table.draw();
513         });
514
515         // Clear all filters
516         $('#clear_search').click(function() {
517             clearSearch();
518         });
519
520     });
521     //]]>
522 </script>
523 </head>
524
525 <body id="illrequests" class="ill">
526 [% INCLUDE 'header.inc' %]
527 [% INCLUDE 'cat-search.inc' %]
528
529 <div id="breadcrumbs">
530     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
531     <a href="/cgi-bin/koha/ill/ill-requests.pl">ILL requests</a>
532     [% IF query_type == 'create' %]
533          &rsaquo; New request
534     [% ELSIF query_type == 'status' %]
535          &rsaquo; Status
536     [% END %]
537 </div>
538
539 <div id="doc3" class="yui-t2">
540     <div id="bd">
541         [% IF query_type == 'illlist' %]
542         <div id="illfilter_yui_column" class="yui-b">
543             <form method="get" id="illfilter_form">
544                 <fieldset class="brief">
545                     <h3>Filters</h3>
546                     <ol>
547                         <li>
548                             <label for="illfilter_status">Status:</label>
549                             <select name="illfilter_status" id="illfilter_status">
550                                 <option value=""></option>
551                             </select>
552                         </li>
553                         <li>
554                             <label for="illfilter_dateplaced_start">Date placed between:</label>
555                             <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker">
556                         </li>
557                         <li>
558                             <label for="illfilter_dateplaced_end">and:</label>
559                             <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker">
560                         </li>
561                         <li>
562                             <label for="illfilter_datemodified_start">Updated between:</label>
563                             <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker">
564                         </li>
565                         <li>
566                             <label for="illfilter_datemodified_end">and:</label>
567                             <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker">
568                         </li>
569                         <li>
570                             <label for="illfilter_branchname">Library:</label>
571                             <select name="illfilter_branchname" id="illfilter_branchname">
572                                 <option value=""></option>
573                             </select>
574                         </li>
575                         <li>
576                             <label for="illfilter_barcode">Patron barcode:</label>
577                             <input type="text" name="illfilter_barcode" id="illfilter_barcode">
578                         </li>
579                     </ol>
580                     <fieldset class="action">
581                         <input type="submit" value="Search" />
582                         <input type="button" value="Clear" id="clear_search" />
583                     </fieldset>
584                 </fieldset>
585             </form>
586         </div>
587         [% END %]
588         <div id="yui-main">
589             <div id="interlibraryloans" class="yui-b">
590         [% IF !backends_available || !has_branch %]
591             <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>
592         [% ELSE %]
593                 [% INCLUDE 'ill-toolbar.inc' %]
594
595                 [% IF whole.error %]
596                     <h1>Error performing operation</h1>
597                     <!-- Dispatch on Status -->
598                     <p>We encountered an error:</p>
599                     <p>
600                       <pre>[% whole.message | html %] ([% whole.status | html %])</pre>
601                     </p>
602                 [% END %]
603
604                 [% IF query_type == 'create' %]
605                     <h1>New ILL request</h1>
606                     [% PROCESS $whole.template %]
607
608                 [% ELSIF query_type == 'confirm' %]
609                     <h1>Confirm ILL request</h1>
610                     [% PROCESS $whole.template %]
611
612                 [% ELSIF query_type == 'cancel' and !whole.error %]
613                     <h1>Cancel a confirmed request</h1>
614                     [% PROCESS $whole.template %]
615
616                 [% ELSIF query_type == 'generic_confirm' %]
617                     <h1>Place request with partner libraries</h1>
618                   [% IF error %]
619                     [% IF error == 'no_target_email' %]
620                         <div class="alert">
621                             No target email addresses found. Either select at least
622                             one partner or check your ILL partner library records.
623                         </div>
624                     [% ELSIF error == 'no_library_email' %]
625                         <div class="alert">
626                             Your library has no usable email address. Please set it.
627                         </div>
628                     [% ELSIF error == 'unkown_error' %]
629                         <div class="alert">
630                             Unknown error processing your request. Contact your administrator.
631                         </div>
632                     [% END %]
633                   [% END %]
634                     <!-- Start of GENERIC_EMAIL case -->
635                     [% IF whole.value.partners %]
636                        [% ill_url = "/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=" _ request.illrequest_id %]
637                         <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
638                             <fieldset class="rows">
639                                 <legend>Interlibrary loan request details</legend>
640                                 <ol>
641                                     <li>
642                                         <label for="partner_filter">Filter partner libraries:</label>
643                                         <input type="text" id="partner_filter">
644                                     </li>
645                                     <li>
646                                         <label for="partners" class="required">Select partner libraries:</label>
647                                         <select size="5" multiple="true" id="partners" name="partners" required="required">
648                                             [% FOREACH partner IN whole.value.partners %]
649                                                 <option value=[% partner.email | html %]>
650                                                     [% partner.branchcode _ " - " _ partner.surname %]
651                                                 </option>
652                                             [% END %]
653                                         </select>
654
655                                     </li>
656                                     <li>
657                                         <label for="subject" class="required">Subject Line</label>
658                                         <input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject | html %]" required="required" />
659                                     </li>
660                                     <li>
661                                         <label for="body" class="required">Email text:</label>
662                                         <textarea name="body" id="body" rows="20" cols="80" required="required">[% whole.value.draft.body | html %]</textarea>
663                                     </li>
664                                 </ol>
665                                 <input type="hidden" value="generic_confirm" name="method">
666                                 <input type="hidden" value="draft" name="stage">
667                                 <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
668                             </fieldset>
669                             <fieldset class="action">
670                                 <input type="submit" class="btn btn-default" value="Send email"/>
671                                 <span><a href="[% ill_url | url %]" title="Return to request details">Cancel</a></span>
672                             </fieldset>
673                         </form>
674                     [% ELSE %]
675                         <fieldset class="rows">
676                             <legend>Interlibrary loan request details</legend>
677                             <p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
678                             <p>Be sure to provide email addresses for these patrons.</p>
679                             <p><span><a href="[% ill_url | url %]" title="Return to request details">Cancel</a></span></p>
680                         </fieldset>
681                     [% END %]
682                 <!-- generic_confirm ends here -->
683
684                 [% ELSIF query_type == 'edit_action' %]
685                     <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
686                         <fieldset class="rows">
687                             <legend>Request details</legend>
688                             <ol>
689                                 [% type = request.get_type %]
690                                 <li class="borrowernumber">
691                                     <label for="borrowernumber">Patron ID:</label>
692                                     [% request.borrowernumber | html %]
693                                 </li>
694                                 <li class="biblio_id">
695                                     <label for="biblio_id" class="biblio_id">Bibliographic record ID:</label>
696                                     <input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id | html %]">
697                                 </li>
698                                 <li class="branchcode">
699                                     <label for="library" class="branchcode">Library:</label>
700                                     <select name="branchcode" id="library">
701                                         [% PROCESS options_for_libraries libraries => Branches.all( selected => request.branchcode ) %]
702                                     </select>
703                                 </li>
704                                 <li class="status">
705                                     <label class="status">Status:</label>
706                                     [% stat = request.status %]
707                                     [% request.capabilities.$stat.name | html %]
708                                 </li>
709                                 <li class="updated">
710                                     <label class="updated">Last updated:</label>
711                                     [% request.updated | $KohaDates  with_hours => 1 %]
712                                 </li>
713                                 <li class="medium">
714                                     <label class="medium">Request type:</label>
715                                     [% IF type %][% type | html %][% ELSE %]<span>N/A</span>[% END %]
716                                 </li>
717                                 <li class="cost">
718                                     <label class="cost">Cost:</label>
719                                     [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
720                                 </li>
721                                 <li class="price_paid">
722                                     <label class="price_paid">Price paid:</label>
723                                     <input name="price_paid" id="price_paid" type="text" value="[% request.price_paid | html %]">
724                                 </li>
725                                 <li class="req_id">
726                                     <label class="req_id">Request number:</label>
727                                     [% request.id_prefix _ request.illrequest_id | html %]
728                                 </li>
729                                 <li class="notesstaff">
730                                     <label for="notesstaff" class="notesstaff">Staff notes:</label>
731                                     <textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff | html %]</textarea>
732                                 </li>
733                                 <li class="notesopac">
734                                     <label for="notesopac" class="notesopac">Opac notes:</label>
735                                     <textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac | html %]</textarea>
736                                 </li>
737                             </ol>
738                         </fieldset>
739                         <fieldset class="action">
740                             <input type="hidden" value="edit_action" name="method">
741                             <input type="hidden" value="form" name="stage">
742                             <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
743                             <input type="hidden" value="[% request.borrowernumber | html %]" name="borrowernumber">
744                             <input type="submit" value="Submit">
745                             <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Cancel</a>
746                         </fieldset>
747                     </form>
748
749                 [% ELSIF query_type == 'delete_confirm' %]
750
751                     <div class="dialog alert">
752                         <h3>Are you sure you wish to delete this request?</h3>
753                         <form action="/cgi-bin/koha/ill/ill-requests.pl" method="post">
754                             <input type="hidden" name="method" value="delete" />
755                             <input type="hidden" name="confirmed" value="1" />
756                             <input type="hidden" name="illrequest_id" value="[% request.id | html %]" />
757                             <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
758                         </form>
759                         <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>
760                     </div>
761
762                 [% ELSIF query_type == 'illview' %]
763                     [% req_status = request.status %]
764
765                     [% IF error %]
766                       [% IF error == 'migrate_target' %]
767                           <div class="alert">
768                               The backend you tried to migrate to does not yet support migrations, please try again with an alternative target.
769                           </div>
770                       [% END %]
771                     [% END %]
772
773                     <h1>Manage ILL request</h1>
774                     <div id="request-toolbar" class="btn-toolbar">
775                         <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 %]">
776                         <span class="fa fa-pencil"></span>
777                         Edit request
778                         </a>
779                         [% FOREACH action IN request.available_actions %]
780                             [% IF action.method == 'migrate' %]
781                                 [% IF backends.size > 2 %]
782                                     <div class="dropdown btn-group">
783                                         <button class="btn btn-sm btn-default dropdown-toggle" type="button" id="ill-migrate-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
784                                             <i class="fa [% action.ui_method_icon | html %]"></i> [% action.ui_method_name | html %] <span class="caret"></span>
785                                         </button>
786                                         <ul class="dropdown-menu" aria-labelledby="ill-migrate-dropdown">
787                                             [% FOREACH backend IN backends %]
788                                                 [% IF backend != request.backend %]
789                                                     <li><a href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;backend=[% backend | uri %]">[% backend | html %]</a></li>
790                                                 [% END %]
791                                             [% END %]
792                                         </ul>
793                                     </div>
794                                 [% ELSIF backends.size == 2 %]
795                                     [% FOREACH backend IN backends %]
796                                         [% IF backend != request.backend %]
797                                             <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 %]">
798                                             <span class="fa [% action.ui_method_icon | html %]"></span>
799                                             [% action.ui_method_name | html %]
800                                             </a>
801                                         [% END %]
802                                     [% END %]
803                                 [% END %]
804                             [% ELSIF action.method != 0 %]
805                                 <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 %]">
806                                 <span class="fa [% action.ui_method_icon | html %]"></span>
807                                 [% action.ui_method_name | html %]
808                                 </a>
809                             [% END %]
810                         [% END %]
811                         <a title="Display supplier metadata" id="ill-request-display-metadata" class="btn btn-sm btn-default pull-right" href="#">
812                             <span class="fa fa-eye"></span>
813                             Display supplier metadata
814                         </a>
815                     </div>
816                     <div class="ill-view-panel panel panel-default">
817                         <div class="panel-heading">
818                             <h3>Request details</h3>
819                         </div>
820                         <div class="panel-body">
821                             <h4>Details from library</h4>
822                             <div class="rows">
823                                 <ol>
824                                     <li class="orderid">
825                                         <span class="label orderid">Order ID:</span>
826                                         [% IF request.orderid %][% request.orderid | html %][% ELSE %]<span>N/A</span>[% END %]
827                                     </li>
828                                     <li class="borrowernumber">
829                                         <span class="label borrowernumber">Patron:</span>
830                                         [% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
831                                         <a href="[% borrowerlink | url %]" title="View borrower details">
832                                         [% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" | html %]
833                                         </a>
834                                     </li>
835
836                                     <li class="biblio_id">
837                                         <span class="label biblio_id">Bibliographic record ID:</span>
838                                         [% IF request.biblio_id %]
839                                             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% request.biblio_id | uri %]">[% request.biblio_id | html %]</a>
840                                         [% ELSE %]
841                                             <span>N/A</span>
842                                         [% END %]
843                                     </li>
844                                     <li class="branchcode">
845                                         <span class="label branchcode">Library:</span>
846                                         [% Branches.GetName(request.branchcode) | html %]
847                                     </li>
848                                     <li class="status">
849                                         <span class="label status">Status:</span>
850                                         [% request.capabilities.$req_status.name | html %]
851                                     </li>
852                                     <li class="updated">
853                                         <span class="label updated">Last updated:</span>
854                                         [% request.updated | $KohaDates  with_hours => 1 %]
855                                     </li>
856                                     <li class="medium">
857                                         <span class="label medium">Request type:</span>
858                                         [% type = request.get_type %]
859                                         [% IF type %][% type | html %][% ELSE %]<span>N/A</span>[% END %]
860                                     </li>
861                                     <li class="cost">
862                                         <span class="label cost">Cost:</span>
863                                         [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
864                                     </li>
865                                     <li class="price_paid">
866                                         <span class="label price_paid">Price paid:</span>
867                                         [% IF request.price_paid %][% request.price_paid | html %][% ELSE %]<span>N/A</span>[% END %]
868                                     </li>
869                                     <li class="req_id">
870                                         <span class="label req_id">Request number:</span>
871                                         [% request.id_prefix _ request.illrequest_id | html %]
872                                     </li>
873                                     <li class="notesstaff">
874                                         <span class="label notes_staff">Staff notes:</span>
875                                         <p>[% request.notesstaff | html %]</p>
876                                     </li>
877                                     <li class="notesopac">
878                                         <span class="label notes_opac">Notes:</span>
879                                         <p>[% request.notesopac | html %]</p>
880                                     </li>
881                                 </ol>
882                             </div>
883                             <div class="rows">
884                                 <h4>Details from supplier ([% request.backend | html %])</h4>
885                                 <ol>
886                                     [% FOREACH meta IN request.metadata %]
887                                         <li class="requestmeta-[% meta.key.replace('\s','_') | html %]">
888                                             <span class="label">[% meta.key | html %]:</span>
889                                             [% meta.value | html %]
890                                         </li>
891                                     [% END %]
892                                 </ol>
893                             </div>
894                         </div>
895                     </div>
896
897                     <div id="dataPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
898                         <div class="modal-dialog">
899                             <div class="modal-content">
900                                 <div class="modal-header">
901                                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
902                                     <h3 id="dataPreviewLabel"> Supplier metadata</h3>
903                                 </div>
904                                 <div class="modal-body">
905                                     <div id="requestattributes">
906                                         [% FOREACH attr IN request.illrequestattributes %]
907                                         <div class="requestattr-[% attr.type | html %]">
908                                             <span class="label">[% attr.type | html %]:</span>
909                                             [% attr.value | html %]
910                                         </div>
911                                             [% END %]
912                                     </div>
913                                 </div>
914                                 <div class="modal-footer">
915                                     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
916                                 </div>
917                             </div>
918                         </div>
919                     </div>
920
921                     <div class="ill-view-panel panel panel-default">
922                         <div class="panel-heading">
923                             <h3>[% request.illcomments.count | html %] comments</h3>
924                         </div>
925                         <div class="panel-body">
926                             [% IF request.illcomments.count && request.illcomments.count > 0 %]
927                                 [% FOREACH comment IN request.illcomments %]
928                                     <div class="rows comment_[% comment.patron.categorycode | html %]">
929                                     <h5>Comment by:
930                                     <a href="[% borrowerlink | url %]" title="View borrower details">
931                                     [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a>
932                                     [% comment.timestamp | $KohaDates with_hours => 1 %]</h5>
933                                     <p>[% comment.comment | html %]</p>
934                                     </div>
935                                 [% END %]
936                             [% END %]
937                                 <div class="rows">
938                                     <h3><a id="toggle_addcomment" href="#">Add comment</a></h3>
939                                     <div id="addcomment" class="content_hidden">
940                                         <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl">
941                                             <input type="hidden" value="save_comment" name="method">
942                                             <input type="hidden" value="[% csrf_token | html %]" name="csrf_token">
943                                             <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
944                                             <fieldset class="rows">
945                                                 <ol>
946                                                     <li>
947                                                         <label class="required" for="comment">Comment: </label>
948                                                         <textarea class="required" required="required" cols="80" rows="10" id="comment" name="comment"></textarea>
949                                                         <span class="required">Required</span>
950                                                     </li>
951                                                 </ol>
952                                             </fieldset>
953                                             <fieldset class="action">
954                                                 <input type="submit" value="Submit">
955                                             </fieldset>
956                                         </form>
957                                     </div>
958                                 </div>
959                             </div>
960                     </div>
961
962                 [% ELSIF query_type == 'illlist' %]
963                     <!-- illlist -->
964                     <h1>View ILL requests</h1>
965                     <div id="results">
966                         <h3>Details for all requests</h3>
967
968                         <table id="ill-requests">
969                             <thead>
970                                 <tr id="illview-header">
971                                     <th>Author</th>
972                                     <th>Title</th>
973                                     <th>Patron</th>
974                                     <th>Bibliographic record ID</th>
975                                     <th>Library</th>
976                                     <th>Status</th>
977                                     <th class="placed">&nbsp;</th>
978                                     <th class="placed_formatted">Date placed</th>
979                                     <th class="updated">&nbsp;</th>
980                                     <th class="updated_formatted">Updated on</th>
981                                     <th>Request number</th>
982                                     <th>Comments</th>
983                                     <th class="actions"></th>
984                                 </tr>
985                             </thead>
986                             <tbody id="illview-body">
987                             </tbody>
988                         </table>
989                     </div>
990                 [% ELSE %]
991                 <!-- Custom Backend Action -->
992                 [% PROCESS $whole.template %]
993
994                 [% END %]
995         [% END %]
996             </div>
997         </div>
998     </div>
999
1000 [% TRY %]
1001 [% PROCESS backend_jsinclude %]
1002 [% CATCH %]
1003 [% END %]
1004
1005 [% INCLUDE 'intranet-bottom.inc' %]