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