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