Bug 20548: Remove copyright clearance for staff
[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 the library name
120         var createLibrary = function(data, type, row) {
121             return row.library.branchname;
122         };
123
124         // Render function for request ID
125         var createRequestId = function(data, type, row) {
126             return row.id_prefix + row.illrequest_id;
127         };
128
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         };
160
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         };
169
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         };
196
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         });
213
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         });
219
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                 });
236
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                 });
258
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         );
280
281     });
282     //]]>
283 </script>
284 </head>
285
286 <body id="illrequests" class="ill">
287 [% INCLUDE 'header.inc' %]
288 [% INCLUDE 'cat-search.inc' %]
289
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>
299
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' %]
308
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 %]
317
318                 [% IF query_type == 'create' %]
319                     <h1>New ILL request</h1>
320                     [% PROCESS $whole.template %]
321
322                 [% ELSIF query_type == 'confirm' %]
323                     <h1>Confirm ILL request</h1>
324                     [% PROCESS $whole.template %]
325
326                 [% ELSIF query_type == 'cancel' and !whole.error %]
327                     <h1>Cancel a confirmed request</h1>
328                     [% PROCESS $whole.template %]
329
330                 [% ELSIF query_type == 'generic_confirm' %]
331                     <h1>Place request with partner libraries</h1>
332                   [% IF error %]
333                     [% IF error == 'no_target_email' %]
334                         <div class="alert">
335                             No target email addresses found. Either select at least
336                             one partner or check your ILL partner library records.
337                         </div>
338                     [% ELSIF error == 'no_library_email' %]
339                         <div class="alert">
340                             Your library has no usable email address. Please set it.
341                         </div>
342                     [% ELSIF error == 'unkown_error' %]
343                         <div class="alert">
344                             Unknown error processing your request. Contact your administrator.
345                         </div>
346                     [% END %]
347                   [% END %]
348                     <!-- Start of GENERIC_EMAIL case -->
349                     [% IF whole.value.partners %]
350                        [% ill_url = "/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=" _ request.illrequest_id %]
351                         <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
352                             <fieldset class="rows">
353                                 <legend>Interlibrary loan request details</legend>
354                                 <ol>
355                                     <li>
356                                         <label for="partner_filter">Filter partner libraries:</label>
357                                         <input type="text" id="partner_filter">
358                                     </li>
359                                     <li>
360                                         <label for="partners" class="required">Select partner libraries:</label>
361                                         <select size="5" multiple="true" id="partners" name="partners" required="required">
362                                             [% FOREACH partner IN whole.value.partners %]
363                                                 <option value=[% partner.email | html %]>
364                                                     [% partner.branchcode _ " - " _ partner.surname %]
365                                                 </option>
366                                             [% END %]
367                                         </select>
368
369                                     </li>
370                                     <li>
371                                         <label for="subject" class="required">Subject Line</label>
372                                         <input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject | html %]" required="required" />
373                                     </li>
374                                     <li>
375                                         <label for="body" class="required">Email text:</label>
376                                         <textarea name="body" id="body" rows="20" cols="80" required="required">[% whole.value.draft.body | html %]</textarea>
377                                     </li>
378                                 </ol>
379                                 <input type="hidden" value="generic_confirm" name="method">
380                                 <input type="hidden" value="draft" name="stage">
381                                 <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
382                             </fieldset>
383                             <fieldset class="action">
384                                 <input type="submit" class="btn btn-default" value="Send email"/>
385                                 <span><a href="[% ill_url | html %]" title="Return to request details">Cancel</a></span>
386                             </fieldset>
387                         </form>
388                     [% ELSE %]
389                         <fieldset class="rows">
390                             <legend>Interlibrary loan request details</legend>
391                             <p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
392                             <p>Be sure to provide email addresses for these patrons.</p>
393                             <p><span><a href="[% ill_url | html %]" title="Return to request details">Cancel</a></span></p>
394                         </fieldset>
395                     [% END %]
396                 <!-- generic_confirm ends here -->
397
398                 [% ELSIF query_type == 'edit_action' %]
399                     <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
400                         <fieldset class="rows">
401                             <legend>Request details</legend>
402                             <ol>
403                                 <li class="borrowernumber">
404                                     <label for="borrowernumber">Patron ID:</label>
405                                     <input name="borrowernumber" id="borrowernumber" type="text" value="[% request.borrowernumber | html %]">
406                                 </li>
407                                 <li class="biblio_id">
408                                     <label for="biblio_id" class="biblio_id">Bibliographic record ID:</label>
409                                     <input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id | html %]">
410                                 </li>
411                                 <li class="branchcode">
412                                     <label for="library" class="branchcode">Library:</label>
413                                     <select name="branchcode" id="library">
414                                         [% PROCESS options_for_libraries libraries => Branches.all( selected => request.branchcode ) %]
415                                     </select>
416                                 </li>
417                                 <li class="status">
418                                     <label class="status">Status:</label>
419                                     [% stat = request.status | html %]
420                                     [% request.capabilities.$stat.name | html %]
421                                 </li>
422                                 <li class="updated">
423                                     <label class="updated">Last updated:</label>
424                                     [% request.updated | $KohaDates with_hours => 1 | html %]
425                                 </li>
426                                 <li class="medium">
427                                     <label class="medium">Request type:</label>
428                                     [% request.medium | html %]
429                                 </li>
430                                 <li class="cost">
431                                     <label class="cost">Cost:</label>
432                                     [% request.cost || 'N/A' | html %]
433                                 </li>
434                                 <li class="req_id">
435                                     <label class="req_id">Request number:</label>
436                                     [% request.id_prefix _ request.illrequest_id | html %]
437                                 </li>
438                                 <li class="notesstaff">
439                                     <label for="notesstaff" class="notesstaff">Staff notes:</label>
440                                     <textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff | html %]</textarea>
441                                 </li>
442                                 <li class="notesopac">
443                                     <label for="notesopac" class="notesopac">Opac notes:</label>
444                                     <textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac | html %]</textarea>
445                                 </li>
446                             </ol>
447                         </fieldset>
448                         <fieldset class="action">
449                             <input type="hidden" value="edit_action" name="method">
450                             <input type="hidden" value="form" name="stage">
451                             <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
452                             <input type="submit" value="Submit">
453                             <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Cancel</a>
454                         </fieldset>
455                     </form>
456
457                 [% ELSIF query_type == 'delete_confirm' %]
458
459                     <div class="dialog alert">
460                         <h3>Are you sure you wish to delete this request?</h3>
461                         <form action="/cgi-bin/koha/ill/ill-requests.pl" method="post">
462                             <input type="hidden" name="method" value="delete" />
463                             <input type="hidden" name="confirmed" value="1" />
464                             <input type="hidden" name="illrequest_id" value="[% request.id | html %]" />
465                             <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
466                         </form>
467                         <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>
468                     </div>
469
470                 [% ELSIF query_type == 'illview' %]
471                     [% req_status = request.status %]
472                     <h1>Manage ILL request</h1>
473                     <div id="toolbar" class="btn-toolbar">
474                         <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 %]">
475                         <span class="fa fa-pencil"></span>
476                         Edit request
477                         </a>
478                         [% FOREACH action IN request.available_actions %]
479                             [% IF action.method != 0 %]
480                                 <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 %]">
481                                 <span class="fa [% action.ui_method_icon | html %]"></span>
482                                 [% action.ui_method_name | html %]
483                                 </a>
484                             [% END %]
485                         [% END %]
486                         <a title="Display supplier metadata" id="ill-request-display-metadata" class="btn btn-sm btn-default pull-right" href="#">
487                             <span class="fa fa-eye"></span>
488                             Display supplier metadata
489                         </a>
490                     </div>
491                     <div id="ill-view-panel" class="panel panel-default">
492                         <div class="panel-heading">
493                             <h3>Request details</h3>
494                         </div>
495                         <div class="panel-body">
496                             <h4>Details from library</h4>
497                             <div class="rows">
498                                 <div class="orderid">
499                                     <span class="label orderid">Order ID:</span>
500                                     [% request.orderid || "N/A" | html %]
501                                 </div>
502                                 <div class="borrowernumber">
503                                     <span class="label borrowernumber">Patron:</span>
504                                     [% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
505                                     <a href="[% borrowerlink | html %]" title="View borrower details">
506                                     [% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" | html %]
507                                     </a>
508                                 </div>
509
510                                 <div class="biblio_id">
511                                     <span class="label biblio_id">Bibliographic record ID:</span>
512                                     [% request.biblio_id || "N/A" | html %]
513                                 </div>
514                                 <div class="branchcode">
515                                     <span class="label branchcode">Library:</span>
516                                     [% Branches.GetName(request.branchcode) | html %]
517                                 </div>
518                                 <div class="status">
519                                     <span class="label status">Status:</span>
520                                     [% request.capabilities.$req_status.name | html %]
521                                 </div>
522                                 <div class="updated">
523                                     <span class="label updated">Last updated:</span>
524                                     [% request.updated | $KohaDates with_hours => 1 | html %]
525                                 </div>
526                                 <div class="medium">
527                                     <span class="label medium">Request type:</span>
528                                     [% request.medium | html %]
529                                 </div>
530                                 <div class="cost">
531                                     <span class="label cost">Cost:</span>
532                                     [% request.cost || "N/A" | html %]
533                                 </div>
534                                 <div class="req_id">
535                                     <span class="label req_id">Request number:</span>
536                                     [% request.id_prefix _ request.illrequest_id | html %]
537                                 </div>
538                                 <div class="notesstaff">
539                                     <span class="label notes_staff">Staff notes:</span>
540                                     <pre>[% request.notesstaff | html %]</pre>
541                                 </div>
542                                 <div class="notesopac">
543                                     <span class="label notes_opac">Notes:</span>
544                                     <pre>[% request.notesopac | html %]</pre>
545                                 </div>
546                             </div>
547                             <div class="rows">
548                                 <h4>Details from supplier ([% request.backend | html %])</h4>
549                                 [% FOREACH meta IN request.metadata %]
550                                     <div class="requestmeta-[% meta.key | html %]">
551                                         <span class="label">[% meta.key | html %]:</span>
552                                         [% meta.value | html %]
553                                     </div>
554                                 [% END %]
555                             </div>
556                         </div>
557                     </div>
558
559                     <div id="dataPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
560                         <div class="modal-dialog">
561                             <div class="modal-content">
562                                 <div class="modal-header">
563                                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
564                                     <h3 id="dataPreviewLabel"> Supplier metadata</h3>
565                                 </div>
566                                 <div class="modal-body">
567                                     <div id="requestattributes">
568                                         [% FOREACH attr IN request.illrequestattributes %]
569                                         <div class="requestattr-[% attr.type | html %]">
570                                             <span class="label">[% attr.type | html %]:</span>
571                                             [% attr.value | html %]
572                                         </div>
573                                             [% END %]
574                                     </div>
575                                 </div>
576                                 <div class="modal-footer">
577                                     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
578                                 </div>
579                             </div>
580                         </div>
581                     </div>
582
583                 [% ELSIF query_type == 'illlist' %]
584                     <!-- illlist -->
585                     <h1>View ILL requests</h1>
586                     <div id="results">
587                         <h3>Details for all requests</h3>
588
589                         <table id="ill-requests">
590                             <thead>
591                                 <tr id="illview-header">
592                                     <th>Author</th>
593                                     <th>Title</th>
594                                     <th>Patron</th>
595                                     <th>Bibliographic record ID</th>
596                                     <th>Library</th>
597                                     <th>Status</th>
598                                     <th>Updated on</th>
599                                     <th>Request number</th>
600                                     <th class="actions"></th>
601                                 </tr>
602                             </thead>
603                             <tbody id="illview-body">
604                             </tbody>
605                         </table>
606                     </div>
607                 [% ELSE %]
608                 <!-- Custom Backend Action -->
609                 [% INCLUDE $whole.template %]
610
611                 [% END %]
612         [% END %]
613             </div>
614         </div>
615     </div>
616 </div>
617
618 [% TRY %]
619 [% PROCESS backend_jsinclude %]
620 [% CATCH %]
621 [% END %]
622
623 [% INCLUDE 'intranet-bottom.inc' %]