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