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