Bug 7317: Display all the libraries, not only one
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / ill / ill-requests.tt
1 [% USE Branches %]
2 [% USE Koha %]
3 [% USE KohaDates %]
4
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; ILL requests  &rsaquo;</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
9 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css">
10 [% INCLUDE 'datatables.inc' %]
11 <script type="text/javascript">
12     //<![CDATA[
13     $(document).ready(function() {
14
15         // Illview Datatable setup
16
17         // Fields we don't want to display
18         var ignore = [
19             'accessurl',
20             'backend',
21             'branchcode',
22             'completed',
23             'capabilities',
24             'cost',
25             'medium',
26             'notesopac',
27             'notesstaff',
28             'placed',
29             'replied'
30         ];
31
32         // Fields we need to expand (flatten)
33         var expand = [
34             'metadata',
35             'patron'
36         ];
37
38         // Expanded fields
39         // This is auto populated
40         var expanded = {};
41
42         // The core fields that should be displayed first
43         var core = [
44             'metadata_Author',
45             'metadata_Title',
46             'borrowername',
47             'biblio_id',
48             'library',
49             'status',
50             'updated',
51             'illrequest_id',
52             'action'
53         ];
54
55         // Remove any fields we're ignoring
56         var removeIgnore = function(dataObj) {
57             dataObj.forEach(function(thisRow) {
58                 ignore.forEach(function(thisIgnore) {
59                     if (thisRow.hasOwnProperty(thisIgnore)) {
60                         delete thisRow[thisIgnore];
61                     }
62                 });
63             });
64         };
65
66         // Expand any fields we're expanding
67         var expandExpand = function(row) {
68             expand.forEach(function(thisExpand) {
69                 if (row.hasOwnProperty(thisExpand)) {
70                     if (!expanded.hasOwnProperty(thisExpand)) {
71                         expanded[thisExpand] = [];
72                     }
73                     var expandObj = row[thisExpand];
74                     Object.keys(expandObj).forEach(
75                         function(thisExpandCol) {
76                             var expColName = thisExpand + '_' + thisExpandCol;
77                             // Keep a list of fields that have been expanded
78                             // so we can create toggle links for them
79                             if (expanded[thisExpand].indexOf(expColName) == -1) {
80                                 expanded[thisExpand].push(expColName);
81                             }
82                             expandObj[expColName] =
83                                 expandObj[thisExpandCol];
84                             delete expandObj[thisExpandCol];
85                         }
86                     );
87                     $.extend(true, row, expandObj);
88                     delete row[thisExpand];
89                 }
90             });
91         };
92
93         // Build a de-duped list of all column names
94         var allCols = {};
95         core.map(function(thisCore) {
96             allCols[thisCore] = 1;
97         });
98
99         // Strip the expand prefix if it exists, we do this for display
100         var stripPrefix = function(value) {
101             expand.forEach(function(thisExpand) {
102                 var regex = new RegExp(thisExpand + '_', 'g');
103                 value = value.replace(regex, '');
104             });
105             return value;
106         };
107
108         // Our 'render' function for borrowerlink
109         var createPatronLink = function(data, type, row) {
110             return '<a title="View borrower details" ' +
111                 'href="/cgi-bin/koha/members/moremember.pl?' +
112                 'borrowernumber='+row.borrowernumber+'">' +
113                 row.patron_firstname + ' ' + row.patron_surname +
114                 '</a>';
115         };
116
117         // Our 'render' function for the library name
118         var createLibrary = function(data, type, row) {
119             return row.library.branchname;
120         };
121
122         // Render function for request ID
123         var createRequestId = function(data, type, row) {
124             return row.id_prefix + row.illrequest_id;
125         };
126
127         // Render function for request status
128         var createStatus = function(data, type, row, meta) {
129             var origData = meta.settings.oInit.originalData;
130             if (origData.length > 0) {
131                 var status_name = meta.settings.oInit.originalData[0].capabilities[
132                     row.status
133                 ].name;
134                 switch( status_name ) {
135                     case "New request":
136                         return _("New request");
137                     case "Requested":
138                         return _("Requested");
139                     case "Requested from partners":
140                         return _("Requested from partners");
141                     case "Request reverted":
142                         return _("Request reverted");
143                     case "Queued request":
144                         return _("Queued request");
145                     case "Cancellation requested":
146                         return _("Cancellation requested");
147                     case "Completed":
148                         return _("Completed");
149                     case "Delete request":
150                         return _("Delete request");
151                     default:
152                         return status_name;
153                 }
154             } else {
155                 return '';
156             }
157         };
158
159         // Render function for creating a row's action link
160         var createActionLink = function(data, type, row) {
161             return '<a class="btn btn-default btn-sm" ' +
162                 'href="/cgi-bin/koha/ill/ill-requests.pl?' +
163                 'method=illview&amp;illrequest_id=' +
164                 row.illrequest_id +
165                 '">' + _("Manage request") + '</a>';
166         };
167
168         // Columns that require special treatment
169         var specialCols = {
170             action: {
171                 name: '',
172                 func: createActionLink
173             },
174             borrowername: {
175                 name: _("Patron"),
176                 func: createPatronLink
177             },
178             illrequest_id: {
179                 name: _("Request number"),
180                 func: createRequestId
181             },
182             status: {
183                 name: _("Status"),
184                 func: createStatus
185             },
186             biblio_id: {
187                 name: _("Biblio ID")
188             },
189             library: {
190                 name: _("Library"),
191                 func: createLibrary
192             }
193         };
194
195         // Toggle request attributes in Illview
196         $('#toggle_requestattributes').on('click', function(e) {
197             e.preventDefault();
198             $('#requestattributes').toggleClass('content_hidden');
199         });
200
201         // Filter partner list
202         $('#partner_filter').keyup(function() {
203             var needle = $('#partner_filter').val();
204             $('#partners > option').each(function() {
205                 var regex = new RegExp(needle, 'i');
206                 if (
207                     needle.length == 0 ||
208                     $(this).is(':selected') ||
209                     $(this).text().match(regex)
210                 ) {
211                     $(this).show();
212                 } else {
213                     $(this).hide();
214                 }
215             });
216         });
217
218         // Get our data from the API and process it prior to passing
219         // it to datatables
220         var ajax = $.ajax(
221             '/api/v1/illrequests?embed=metadata,patron,capabilities,library'
222             ).done(function() {
223                 var data = JSON.parse(ajax.responseText);
224                 // Make a copy, we'll be removing columns next and need
225                 // to be able to refer to data that has been removed
226                 var dataCopy = $.extend(true, [], data);
227                 // Remove all columns we're not interested in
228                 removeIgnore(dataCopy);
229                 // Expand columns that need it and create an array
230                 // of all column names
231                 $.each(dataCopy, function(k, row) {
232                     expandExpand(row);
233                 });
234
235                 // Assemble an array of column definitions for passing
236                 // to datatables
237                 var colData = [];
238                 Object.keys(allCols).forEach(function(thisCol) {
239                     // Create the base column object
240                     var colObj = {
241                         name: thisCol,
242                         className: thisCol
243                     };
244                     // We may need to process the data going in this
245                     // column, so do it if necessary
246                     if (
247                         specialCols.hasOwnProperty(thisCol) &&
248                         specialCols[thisCol].hasOwnProperty('func')
249                     ) {
250                         colObj.render = specialCols[thisCol].func;
251                     } else {
252                         colObj.data = thisCol;
253                     }
254                     colData.push(colObj);
255                 });
256
257                 // Initialise the datatable
258                 $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, {
259                     'aoColumnDefs': [  // Last column shouldn't be sortable or searchable
260                         {
261                             'aTargets': [ 'actions' ],
262                             'bSortable': false,
263                             'bSearchable': false
264                         },
265                     ],
266                     'aaSorting': [[ 6, 'desc' ]], // Default sort, updated descending
267                     'processing': true, // Display a message when manipulating
268                     'iDisplayLength': 10, // 10 results per page
269                     'sPaginationType': "full_numbers", // Pagination display
270                     'deferRender': true, // Improve performance on big datasets
271                     'data': dataCopy,
272                     'columns': colData,
273                     'originalData': data // Enable render functions to access
274                                        // our original data
275                 }));
276             }
277         );
278
279     });
280     //]]>
281 </script>
282 </head>
283
284 <body id="illrequests" class="ill">
285 [% INCLUDE 'header.inc' %]
286 [% INCLUDE 'cat-search.inc' %]
287
288 <div id="breadcrumbs">
289     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
290     <a href="/cgi-bin/koha/ill/ill-requests.pl">ILL requests</a>
291     [% IF query_type == 'create' %]
292          &rsaquo; New request
293     [% ELSIF query_type == 'status' %]
294          &rsaquo; Status
295     [% END %]
296 </div>
297
298 <div id="doc3" class="yui-t2">
299     <div id="bd">
300         <div id="yui-main">
301             <div id="interlibraryloans" class="yui-b">
302         [% IF !backends_available %]
303             <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>
304         [% ELSE %]
305                 [% INCLUDE 'ill-toolbar.inc' %]
306
307                 [% IF whole.error %]
308                     <h1>Error performing operation</h1>
309                     <!-- Dispatch on Status -->
310                     <p>We encountered an error:</p>
311                     <p>
312                       <pre>[% whole.message %] ([% whole.status %])</pre>
313                     </p>
314                 [% END %]
315
316                 [% IF query_type == 'create' %]
317                     <h1>New ILL request</h1>
318                     [% IF whole.stage == 'copyrightclearance' %]
319                         <div>
320                             <p>
321                                 [% Koha.Preference('ILLModuleCopyrightClearance') %]
322                             </p>
323                             <a href="?method=create&stage=copyrightclearance&backend=[% whole.value.backend %]"
324                                class="btn btn-sm btn-default btn-group"><i class="fa fa-check">Yes</i></a>
325                             <a href="/cgi-bin/koha/ill/ill-requests.pl"
326                                class="btn btn-sm btn-default btn-group"><i class="fa fa-times">No</i></a>
327                         </div>
328                     [% ELSE %]
329                         [% PROCESS $whole.template %]
330                     [% END %]
331
332                 [% ELSIF query_type == 'confirm' %]
333                     <h1>Confirm ILL request</h1>
334                     [% PROCESS $whole.template %]
335
336                 [% ELSIF query_type == 'cancel' and !whole.error %]
337                     <h1>Cancel a confirmed request</h1>
338                     [% PROCESS $whole.template %]
339
340                 [% ELSIF query_type == 'generic_confirm' %]
341                     <h1>Place request with partner libraries</h1>
342                   [% IF error %]
343                     [% IF error == 'no_target_email' %]
344                         <div class="alert">
345                             No target email addresses found. Either select at least
346                             one partner or check your ILL partner library records.
347                         </div>
348                     [% ELSIF error == 'no_library_email' %]
349                         <div class="alert">
350                             Your library has no usable email address. Please set it.
351                         </div>
352                     [% ELSIF error == 'unkown_error' %]
353                         <div class="alert">
354                             Unknown error processing your request. Contact your administrator.
355                         </div>
356                     [% END %]
357                   [% END %]
358                     <!-- Start of GENERIC_EMAIL case -->
359                     [% IF whole.value.partners %]
360                        [% ill_url = "/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=" _ request.illrequest_id %]
361                         <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
362                             <fieldset class="rows">
363                                 <legend>Interlibrary loan request details</legend>
364                                 <ol>
365                                     <li>
366                                         <label for="partner_filter">Filter partner libraries:</label>
367                                         <input type="text" id="partner_filter">
368                                     </li>
369                                     <li>
370                                         <label for="partners" class="required">Select partner libraries:</label>
371                                         <select size="5" multiple="true" id="partners" name="partners" required="required">
372                                             [% FOREACH partner IN whole.value.partners %]
373                                                 <option value=[% partner.email %]>
374                                                     [% partner.branchcode _ " - " _ partner.surname %]
375                                                 </option>
376                                             [% END %]
377                                         </select>
378
379                                     </li>
380                                     <li>
381                                         <label for="subject" class="required">Subject Line</label>
382                                         <input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject %]" required="required" />
383                                     </li>
384                                     <li>
385                                         <label for="body" class="required">Email text:</label>
386                                         <textarea name="body" id="body" rows="20" cols="80" required="required">[% whole.value.draft.body %]</textarea>
387                                     </li>
388                                 </ol>
389                                 <input type="hidden" value="generic_confirm" name="method">
390                                 <input type="hidden" value="draft" name="stage">
391                                 <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
392                             </fieldset>
393                             <fieldset class="action">
394                                 <input type="submit" class="btn btn-default" value="Send email"/>
395                                 <span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span>
396                             </fieldset>
397                         </form>
398                     [% ELSE %]
399                         <fieldset class="rows">
400                             <legend>Interlibrary loan request details</legend>
401                             <p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
402                             <p>Be sure to provide email addresses for these patrons.</p>
403                             <p><span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span></p>
404                         </fieldset>
405                     [% END %]
406                 <!-- generic_confirm ends here -->
407
408                 [% ELSIF query_type == 'edit_action' %]
409                     <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
410                         <fieldset class="rows">
411                             <legend>Request details</legend>
412                             <ol>
413                                 <li class="borrowernumber">
414                                     <label for="borrowernumber">Patron ID:</label>
415                                     <input name="borrowernumber" id="borrowernumber" type="text" value="[% request.borrowernumber %]">
416                                 </li>
417                                 <li class="biblio_id">
418                                     <label for="biblio_id" class="biblio_id">Biblio ID:</label>
419                                     <input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id %]">
420                                 </li>
421                                 <li class="branchcode">
422                                     <label for="library" class="branchcode">Library:</label>
423                                     <select name="branchcode" id="library">
424                                         [% PROCESS options_for_libraries libraries => Branches.all( selected => request.branchcode ) %]
425                                     </select>
426                                 </li>
427                                 <li class="status">
428                                     <label class="status">Status:</label>
429                                     [% stat = request.status %]
430                                     [% request.capabilities.$stat.name %]
431                                 </li>
432                                 <li class="updated">
433                                     <label class="updated">Last updated:</label>
434                                     [% request.updated | $KohaDates with_hours => 1 %]
435                                 </li>
436                                 <li class="medium">
437                                     <label class="medium">Request type:</label>
438                                     [% request.medium %]
439                                 </li>
440                                 <li class="cost">
441                                     <label class="cost">Cost:</label>
442                                     [% request.cost || 'N/A' %]
443                                 </li>
444                                 <li class="req_id">
445                                     <label class="req_id">Request number:</label>
446                                     [% request.id_prefix _ request.illrequest_id %]
447                                 </li>
448                                 <li class="notesstaff">
449                                     <label for="notesstaff" class="notesstaff">Staff notes:</label>
450                                     <textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff %]</textarea>
451                                 </li>
452                                 <li class="notesopac">
453                                     <label for="notesopac" class="notesopac">Opac notes:</label>
454                                     <textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac %]</textarea>
455                                 </li>
456                             </ol>
457                         </fieldset>
458                         <fieldset class="action">
459                             <input type="hidden" value="edit_action" name="method">
460                             <input type="hidden" value="form" name="stage">
461                             <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
462                             <input type="submit" value="Submit">
463                             <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id %]">Cancel</a>
464                         </fieldset>
465                     </form>
466
467                 [% ELSIF query_type == 'delete_confirm' %]
468
469                     <div class="dialog alert">
470                         <h3>Are you sure you wish to delete this request?</h3>
471                         <form action="/cgi-bin/koha/ill/ill-requests.pl" method="post">
472                             <input type="hidden" name="method" value="delete" />
473                             <input type="hidden" name="confirmed" value="1" />
474                             <input type="hidden" name="illrequest_id" value="[% request.id %]" />
475                             <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
476                         </form>
477                         <a class="btn btn-default btn-sm deny" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id %]"><i class="fa fa-fw fa-remove"></i>No, do not delete</a>
478                     </div>
479
480                 [% ELSIF query_type == 'illview' %]
481                     [% actions = request.available_actions %]
482                     [% capabilities = request.capabilities %]
483                     [% req_status = request.status %]
484                     <h1>Manage ILL request</h1>
485                     <div id="toolbar" class="btn-toolbar">
486                         <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 %]">
487                         <span class="fa fa-pencil"></span>
488                         Edit request
489                         </a>
490                         [% FOREACH action IN actions %]
491                             [% IF action.method != 0 %]
492                                 <a title="[% action.ui_method_name %]" id="ill-toolbar-btn-[% action.id | lower %]" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method %]&amp;illrequest_id=[% request.illrequest_id %]">
493                                 <span class="fa [% action.ui_method_icon %]"></span>
494                                 [% action.ui_method_name %]
495                                 </a>
496                             [% END %]
497                         [% END %]
498                     </div>
499                     <div id="ill-view-panel" class="panel panel-default">
500                         <div class="panel-heading">
501                             <h3>Request details</h3>
502                         </div>
503                         <div class="panel-body">
504                             <h4>Details from library</h4>
505                             <div class="rows">
506                                 <div class="orderid">
507                                     <span class="label orderid">Order ID:</span>
508                                     [% request.orderid || "N/A" %]
509                                 </div>
510                                 <div class="borrowernumber">
511                                     <span class="label borrowernumber">Patron:</span>
512                                     [% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
513                                     <a href="[% borrowerlink %]" title="View borrower details">
514                                     [% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" %]
515                                     </a>
516                                 </div>
517
518                                 <div class="biblio_id">
519                                     <span class="label biblio_id">Biblio ID:</span>
520                                     [% request.biblio_id || "N/A" %]
521                                 </div>
522                                 <div class="branchcode">
523                                     <span class="label branchcode">Library:</span>
524                                     [% Branches.GetName(request.branchcode) %]
525                                 </div>
526                                 <div class="status">
527                                     <span class="label status">Status:</span>
528                                     [% capabilities.$req_status.name %]
529                                 </div>
530                                 <div class="updated">
531                                     <span class="label updated">Last updated:</span>
532                                     [% request.updated | $KohaDates with_hours => 1 %]
533                                 </div>
534                                 <div class="medium">
535                                     <span class="label medium">Request type:</span>
536                                     [% request.medium %]
537                                 </div>
538                                 <div class="cost">
539                                     <span class="label cost">Cost:</span>
540                                     [% request.cost || "N/A" %]
541                                 </div>
542                                 <div class="req_id">
543                                     <span class="label req_id">Request number:</span>
544                                     [% request.id_prefix _ request.illrequest_id %]
545                                 </div>
546                                 <div class="notesstaff">
547                                     <span class="label notes_staff">Staff notes:</span>
548                                     <pre>[% request.notesstaff %]</pre>
549                                 </div>
550                                 <div class="notesopac">
551                                     <span class="label notes_opac">Notes:</span>
552                                     <pre>[% request.notesopac %]</pre>
553                                 </div>
554                             </div>
555                             <div class="rows">
556                                 <h4>Details from supplier ([% request.backend %])</h4>
557                                 [% FOREACH meta IN request.metadata %]
558                                     <div class="requestmeta-[% meta.key %]">
559                                         <span class="label">[% meta.key %]:</span>
560                                         [% meta.value %]
561                                     </div>
562                                 [% END %]
563                             </div>
564                             <div class="rows">
565                                 <h3><a id="toggle_requestattributes" href="#">Toggle full supplier metadata</a></h3>
566                                 <div id="requestattributes" class="content_hidden">
567                                     [% FOREACH attr IN request.illrequestattributes %]
568                                         <div class="requestattr-[% attr.type %]">
569                                             <span class="label">[% attr.type %]:</span>
570                                             [% attr.value %]
571                                         </div>
572                                     [% END %]
573                                 </div>
574
575                             </div>
576                         </div>
577                     </div>
578
579                 [% ELSIF query_type == 'illlist' %]
580                     <!-- illlist -->
581                     <h1>View ILL requests</h1>
582                     <div id="results">
583                         <h3>Details for all requests</h3>
584
585                         <table id="ill-requests">
586                             <thead>
587                                 <tr id="illview-header">
588                                     <th>Author</th>
589                                     <th>Title</th>
590                                     <th>Patron</th>
591                                     <th>Biblio ID</th>
592                                     <th>Library</th>
593                                     <th>Status</th>
594                                     <th>Updated on</th>
595                                     <th>Request number</th>
596                                     <th class="actions"></th>
597                                 </tr>
598                             </thead>
599                             <tbody id="illview-body">
600                             </tbody>
601                         </table>
602                     </div>
603                 [% ELSE %]
604                 <!-- Custom Backend Action -->
605                 [% INCLUDE $whole.template %]
606
607                 [% END %]
608         [% END %]
609             </div>
610         </div>
611     </div>
612 </div>
613
614 [% TRY %]
615 [% PROCESS backend_jsinclude %]
616 [% CATCH %]
617 [% END %]
618
619 [% INCLUDE 'intranet-bottom.inc' %]