Bug 7317: Do not use GET for deletion requests
[koha-ffzg.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">Select partner libraries:</label>
371                                         <select size="5" multiple="true" id="partners"
372                                                 name="partners">
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">Subject Line</label>
383                                         <input type="text" name="subject"
384                                                id="subject" type="text"
385                                                value="[% whole.value.draft.subject %]"/>
386                                     </li>
387                                     <li>
388                                         <label for="body">Email text:</label>
389                                         <textarea name="body" id="body" rows="20" cols="80">[% whole.value.draft.body %]</textarea>
390                                     </li>
391                                 </ol>
392                                 <input type="hidden" value="generic_confirm" name="method">
393                                 <input type="hidden" value="draft" name="stage">
394                                 <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
395                             </fieldset>
396                             <fieldset class="action">
397                                 <input type="submit" class="btn btn-default" value="Send email"/>
398                                 <span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span>
399                             </fieldset>
400                         </form>
401                     [% ELSE %]
402                         <fieldset class="rows">
403                             <legend>Interlibrary loan request details</legend>
404                             <p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
405                             <p>Be sure to provide email addresses for these patrons.</p>
406                             <p><span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span></p>
407                         </fieldset>
408                     [% END %]
409                 <!-- generic_confirm ends here -->
410
411                 [% ELSIF query_type == 'edit_action' %]
412                     <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
413                         <fieldset class="rows">
414                             <legend>Request details</legend>
415                             <ol>
416                                 <li class="borrowernumber">
417                                     <label for="borrowernumber">Patron ID:</label>
418                                     <input name="borrowernumber" id="borrowernumber" type="text" value="[% request.borrowernumber %]">
419                                 </li>
420                                 <li class="biblio_id">
421                                     <label for="biblio_id" class="biblio_id">Biblio ID:</label>
422                                     <input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id %]">
423                                 </li>
424                                 <li class="branchcode">
425                                     <label for="branchcode" class="branchcode">Library:</label>
426                                     <select name="branchcode" id="branch">
427                                         [% FOREACH branch IN branches %]
428                                             [% IF ( branch.branchcode == request.branchcode ) %]
429                                                 <option value="[% branch.branchcode %]" selected="selected">
430                                                     [% branch.branchname %]
431                                                 </option>
432                                             [% ELSE %]
433                                                 <option value="[% branch.branchcode %]">
434                                                     [% branch.branchname %]
435                                                 </option>
436                                             [% END %]
437                                         [% END %]
438                                     </select>
439                                 </li>
440                                 <li class="status">
441                                     <label class="status">Status:</label>
442                                     [% stat = request.status %]
443                                     [% request.capabilities.$stat.name %]
444                                 </li>
445                                 <li class="updated">
446                                     <label class="updated">Last updated:</label>
447                                     [% request.updated | $KohaDates with_hours => 1 %]
448                                 </li>
449                                 <li class="medium">
450                                     <label class="medium">Request type:</label>
451                                     [% request.medium %]
452                                 </li>
453                                 <li class="cost">
454                                     <label class="cost">Cost:</label>
455                                     [% request.cost || 'N/A' %]
456                                 </li>
457                                 <li class="req_id">
458                                     <label class="req_id">Request number:</label>
459                                     [% request.id_prefix _ request.illrequest_id %]
460                                 </li>
461                                 <li class="notesstaff">
462                                     <label for="notesstaff" class="notesstaff">Staff notes:</label>
463                                     <textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff %]</textarea>
464                                 </li>
465                                 <li class="notesopac">
466                                     <label for="notesopac" class="notesopac">Opac notes:</label>
467                                     <textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac %]</textarea>
468                                 </li>
469                             </ol>
470                         </fieldset>
471                         <fieldset class="action">
472                             <input type="hidden" value="edit_action" name="method">
473                             <input type="hidden" value="form" name="stage">
474                             <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
475                             <input type="submit" value="Submit">
476                             <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id %]">Cancel</a>
477                         </fieldset>
478                     </form>
479
480                 [% ELSIF query_type == 'delete_confirm' %]
481
482                     <div class="dialog alert">
483                         <h3>Are you sure you wish to delete this request?</h3>
484                         <form action="/cgi-bin/koha/ill/ill-requests.pl" method="post">
485                             <input type="hidden" name="method" value="delete" />
486                             <input type="hidden" name="confirmed" value="1" />
487                             <input type="hidden" name="illrequest_id" value="[% request.id %]" />
488                             <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
489                         </form>
490                         <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>
491                     </div>
492
493                 [% ELSIF query_type == 'illview' %]
494                     [% actions = request.available_actions %]
495                     [% capabilities = request.capabilities %]
496                     [% req_status = request.status %]
497                     <h1>Manage ILL request</h1>
498                     <div id="toolbar" class="btn-toolbar">
499                         <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 %]">
500                         <span class="fa fa-pencil"></span>
501                         Edit request
502                         </a>
503                         [% FOREACH action IN actions %]
504                             [% IF action.method != 0 %]
505                                 <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 %]">
506                                 <span class="fa [% action.ui_method_icon %]"></span>
507                                 [% action.ui_method_name %]
508                                 </a>
509                             [% END %]
510                         [% END %]
511                     </div>
512                     <div id="ill-view-panel" class="panel panel-default">
513                         <div class="panel-heading">
514                             <h3>Request details</h3>
515                         </div>
516                         <div class="panel-body">
517                             <h4>Details from library</h4>
518                             <div class="rows">
519                                 <div class="orderid">
520                                     <span class="label orderid">Order ID:</span>
521                                     [% request.orderid || "N/A" %]
522                                 </div>
523                                 <div class="borrowernumber">
524                                     <span class="label borrowernumber">Patron:</span>
525                                     [% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
526                                     <a href="[% borrowerlink %]" title="View borrower details">
527                                     [% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" %]
528                                     </a>
529                                 </div>
530
531                                 <div class="biblio_id">
532                                     <span class="label biblio_id">Biblio ID:</span>
533                                     [% request.biblio_id || "N/A" %]
534                                 </div>
535                                 <div class="branchcode">
536                                     <span class="label branchcode">Library:</span>
537                                     [% Branches.GetName(request.branchcode) %]
538                                 </div>
539                                 <div class="status">
540                                     <span class="label status">Status:</span>
541                                     [% capabilities.$req_status.name %]
542                                 </div>
543                                 <div class="updated">
544                                     <span class="label updated">Last updated:</span>
545                                     [% request.updated | $KohaDates with_hours => 1 %]
546                                 </div>
547                                 <div class="medium">
548                                     <span class="label medium">Request type:</span>
549                                     [% request.medium %]
550                                 </div>
551                                 <div class="cost">
552                                     <span class="label cost">Cost:</span>
553                                     [% request.cost || "N/A" %]
554                                 </div>
555                                 <div class="req_id">
556                                     <span class="label req_id">Request number:</span>
557                                     [% request.id_prefix _ request.illrequest_id %]
558                                 </div>
559                                 <div class="notesstaff">
560                                     <span class="label notes_staff">Staff notes:</span>
561                                     <pre>[% request.notesstaff %]</pre>
562                                 </div>
563                                 <div class="notesopac">
564                                     <span class="label notes_opac">Notes:</span>
565                                     <pre>[% request.notesopac %]</pre>
566                                 </div>
567                             </div>
568                             <div class="rows">
569                                 <h4>Details from supplier ([% request.backend %])</h4>
570                                 [% FOREACH meta IN request.metadata %]
571                                     <div class="requestmeta-[% meta.key %]">
572                                         <span class="label">[% meta.key %]:</span>
573                                         [% meta.value %]
574                                     </div>
575                                 [% END %]
576                             </div>
577                             <div class="rows">
578                                 <h3><a id="toggle_requestattributes" href="#">Toggle full supplier metadata</a></h3>
579                                 <div id="requestattributes" class="content_hidden">
580                                     [% FOREACH attr IN request.illrequestattributes %]
581                                         <div class="requestattr-[% attr.type %]">
582                                             <span class="label">[% attr.type %]:</span>
583                                             [% attr.value %]
584                                         </div>
585                                     [% END %]
586                                 </div>
587
588                             </div>
589                         </div>
590                     </div>
591
592                 [% ELSIF query_type == 'illlist' %]
593                     <!-- illlist -->
594                     <h1>View ILL requests</h1>
595                     <div id="results">
596                         <h3>Details for all requests</h3>
597
598                         <table id="ill-requests">
599                             <thead>
600                                 <tr id="illview-header">
601                                     <th>Author</th>
602                                     <th>Title</th>
603                                     <th>Patron</th>
604                                     <th>Biblio ID</th>
605                                     <th>Library</th>
606                                     <th>Status</th>
607                                     <th>Updated on</th>
608                                     <th>Request number</th>
609                                     <th class="actions"></th>
610                                 </tr>
611                             </thead>
612                             <tbody id="illview-body">
613                             </tbody>
614                         </table>
615                     </div>
616                 [% ELSE %]
617                 <!-- Custom Backend Action -->
618                 [% INCLUDE $whole.template %]
619
620                 [% END %]
621         [% END %]
622             </div>
623         </div>
624     </div>
625 </div>
626
627 [% TRY %]
628 [% PROCESS backend_jsinclude %]
629 [% CATCH %]
630 [% END %]
631
632 [% INCLUDE 'intranet-bottom.inc' %]