Bug 21063: Add "Columns settings" for ILL
[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 [% SET footerjs = 1 %]
7 [% USE AuthorisedValues %]
8 [% USE ColumnsSettings %]
9
10 [% INCLUDE 'doc-head-open.inc' %]
11 <title>Koha &rsaquo; ILL requests</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 </head>
14
15 <body id="illrequests" class="ill">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'cat-search.inc' %]
18
19 <div id="breadcrumbs">
20     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
21     <a href="/cgi-bin/koha/ill/ill-requests.pl">ILL requests</a>
22     [% IF query_type == 'create' %]
23          &rsaquo; New request
24     [% ELSIF query_type == 'status' %]
25          &rsaquo; Status
26     [% END %]
27 </div>
28
29 <div id="doc3" class="yui-t2">
30     <div id="bd">
31         [% IF query_type == 'illlist' %]
32         <div id="illfilter_yui_column" class="yui-b">
33             <form method="get" id="illfilter_form">
34                 <fieldset class="brief">
35                     <h3>Filters</h3>
36                     <ol>
37                         <li>
38                             <label for="illfilter_status">Status:</label>
39                             <select name="illfilter_status" id="illfilter_status">
40                                 <option value=""></option>
41                             </select>
42                         </li>
43                         <li>
44                             <label for="illfilter_dateplaced_start">Date placed between:</label>
45                             <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker" />
46                         </li>
47                         <li>
48                             <label for="illfilter_dateplaced_end">and:</label>
49                             <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker" />
50                         </li>
51                         <li>
52                             <label for="illfilter_datemodified_start">Updated between:</label>
53                             <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker" />
54                         </li>
55                         <li>
56                             <label for="illfilter_datemodified_end">and:</label>
57                             <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker" />
58                         </li>
59                         <li>
60                             <label for="illfilter_branchname">Library:</label>
61                             <select name="illfilter_branchname" id="illfilter_branchname">
62                                 <option value=""></option>
63                             </select>
64                         </li>
65                         <li>
66                             <label for="illfilter_patron">Patron:</label>
67                             <input type="text" name="illfilter_patron" id="illfilter_patron" />
68                         </li>
69                     </ol>
70                     <fieldset class="action">
71                         <input type="submit" value="Search" />
72                         <input type="button" value="Clear" id="clear_search" />
73                     </fieldset>
74                 </fieldset>
75             </form>
76         </div>
77         [% END %]
78         <div id="yui-main">
79             <div id="interlibraryloans" class="yui-b">
80         [% IF !backends_available || !has_branch %]
81             <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>
82         [% ELSE %]
83                 [% INCLUDE 'ill-toolbar.inc' %]
84
85                 [% IF whole.error %]
86                     <h1>Error performing operation</h1>
87                     <!-- Dispatch on Status -->
88                     <p>We encountered an error:</p>
89                     <p>
90                       <pre>[% whole.message | html %] ([% whole.status | html %])</pre>
91                     </p>
92                 [% END %]
93
94                 [% IF query_type == 'create' %]
95                     <h1>New ILL request</h1>
96                     [% PROCESS $whole.template %]
97
98                 [% ELSIF query_type == 'confirm' %]
99                     <h1>Confirm ILL request</h1>
100                     [% PROCESS $whole.template %]
101
102                 [% ELSIF query_type == 'cancel' and !whole.error %]
103                     <h1>Cancel a confirmed request</h1>
104                     [% PROCESS $whole.template %]
105
106                 [% ELSIF query_type == 'generic_confirm' %]
107                     <h1>Place request with partner libraries</h1>
108                   [% IF error %]
109                     [% IF error == 'no_target_email' %]
110                         <div class="alert">
111                             No target email addresses found. Either select at least
112                             one partner or check your ILL partner library records.
113                         </div>
114                     [% ELSIF error == 'no_library_email' %]
115                         <div class="alert">
116                             Your library has no usable email address. Please set it.
117                         </div>
118                     [% ELSIF error == 'unkown_error' %]
119                         <div class="alert">
120                             Unknown error processing your request. Contact your administrator.
121                         </div>
122                     [% END %]
123                   [% END %]
124                     <!-- Start of GENERIC_EMAIL case -->
125                     [% IF whole.value.partners %]
126                        [% ill_url = "/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=" _ request.illrequest_id %]
127                         <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
128                             <fieldset class="rows">
129                                 <legend>Interlibrary loan request details</legend>
130                                 <ol>
131                                     <li>
132                                         <label for="partner_filter">Filter partner libraries:</label>
133                                         <input type="text" id="partner_filter" />
134                                     </li>
135                                     <li>
136                                         <label for="partners" class="required">Select partner libraries:</label>
137                                         <select size="5" multiple="true" id="partners" name="partners" required="required">
138                                             [% FOREACH partner IN whole.value.partners %]
139                                                 <option value=[% partner.email | html %]>
140                                                     [% partner.branchcode _ " - " _ partner.surname %]
141                                                 </option>
142                                             [% END %]
143                                         </select>
144
145                                     </li>
146                                     <li>
147                                         <label for="subject" class="required">Subject line:</label>
148                                         <input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject | html %]" required="required" />
149                                     </li>
150                                     <li>
151                                         <label for="body" class="required">Email text:</label>
152                                         <textarea name="body" id="body" rows="20" cols="80" required="required">[% whole.value.draft.body | html %]</textarea>
153                                     </li>
154                                 </ol>
155                                 <input type="hidden" value="generic_confirm" name="method">
156                                 <input type="hidden" value="draft" name="stage">
157                                 <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
158                             </fieldset>
159                             <fieldset class="action">
160                                 <input type="submit" class="btn btn-default" value="Send email"/>
161                                 <span><a href="[% ill_url | url %]" title="Return to request details">Cancel</a></span>
162                             </fieldset>
163                         </form>
164                     [% ELSE %]
165                         <fieldset class="rows">
166                             <legend>Interlibrary loan request details</legend>
167                             <p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
168                             <p>Be sure to provide email addresses for these patrons.</p>
169                             <p><span><a href="[% ill_url | url %]" title="Return to request details">Cancel</a></span></p>
170                         </fieldset>
171                     [% END %]
172                 <!-- generic_confirm ends here -->
173
174                 [% ELSIF query_type == 'edit_action' %]
175                     <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
176                         <fieldset class="rows">
177                             <legend>Request details</legend>
178                             <ol>
179                                 [% type = request.get_type %]
180                                 <li class="borrowernumber">
181                                     <label for="borrowernumber">Patron ID:</label>
182                                     [% request.borrowernumber | html %]
183                                 </li>
184                                 <li class="biblio_id">
185                                     <label for="biblio_id" class="biblio_id">Bibliographic record ID:</label>
186                                     <input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id | html %]">
187                                 </li>
188                                 <li class="branchcode">
189                                     <label for="library" class="branchcode">Library:</label>
190                                     <select name="branchcode" id="library">
191                                         [% PROCESS options_for_libraries libraries => Branches.all( selected => request.branchcode ) %]
192                                     </select>
193                                 </li>
194                                 <li class="status">
195                                     <label class="status">Status:</label>
196                                     [% stat = request.status %]
197                                     [% current_alias = request.status_alias %]
198                                     <select id="status_alias" name="status_alias">
199                                         [% IF !current_alias %]
200                                         <option value="" selected>
201                                         [% ELSE %]
202                                         <option value="">
203                                         [% END %]
204                                             [% request.capabilities.$stat.name | html %]
205                                         </option>
206                                         [% FOREACH alias IN AuthorisedValues.Get('ILLSTATUS') %]
207                                             [% IF alias.authorised_value == current_alias %]
208                                             <option value="[% alias.authorised_value | html %]" selected>
209                                             [% ELSE %]
210                                             <option value="[% alias.authorised_value | html %]">
211                                             [% END %]
212                                                 [% alias.lib | html %]
213                                             </option>
214                                         [% END %]
215                                     </select>
216                                 </li>
217                                 <li class="updated">
218                                     <label class="updated">Last updated:</label>
219                                     [% request.updated | $KohaDates  with_hours => 1 %]
220                                 </li>
221                                 <li class="medium">
222                                     <label class="medium">Request type:</label>
223                                     [% IF type %][% type | html %][% ELSE %]<span>N/A</span>[% END %]
224                                 </li>
225                                 <li class="cost">
226                                     <label class="cost">Cost:</label>
227                                     [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
228                                 </li>
229                                 <li class="price_paid">
230                                     <label class="price_paid">Price paid:</label>
231                                     <input name="price_paid" id="price_paid" type="text" value="[% request.price_paid | html %]">
232                                 </li>
233                                 <li class="req_id">
234                                     <label class="req_id">Request number:</label>
235                                     [% request.id_prefix _ request.illrequest_id | html %]
236                                 </li>
237                                 <li class="notesstaff">
238                                     <label for="notesstaff" class="notesstaff">Staff notes:</label>
239                                     <textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff | html %]</textarea>
240                                 </li>
241                                 <li class="notesopac">
242                                     <label for="notesopac" class="notesopac">Opac notes:</label>
243                                     <textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac | html %]</textarea>
244                                 </li>
245                             </ol>
246                         </fieldset>
247                         <fieldset class="action">
248                             <input type="hidden" value="edit_action" name="method">
249                             <input type="hidden" value="form" name="stage">
250                             <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
251                             <input type="hidden" value="[% request.borrowernumber | html %]" name="borrowernumber">
252                             <input type="submit" value="Submit">
253                             <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id | html %]">Cancel</a>
254                         </fieldset>
255                     </form>
256
257                 [% ELSIF query_type == 'delete_confirm' %]
258
259                     <div class="dialog alert">
260                         <h3>Are you sure you wish to delete this request?</h3>
261                         <form action="/cgi-bin/koha/ill/ill-requests.pl" method="post">
262                             <input type="hidden" name="method" value="delete" />
263                             <input type="hidden" name="confirmed" value="1" />
264                             <input type="hidden" name="illrequest_id" value="[% request.id | html %]" />
265                             <button type="submit" class="btn btn-default btn-sm approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
266                         </form>
267                         <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>
268                     </div>
269
270                 [% ELSIF query_type == 'illview' %]
271                     [% req_status = request.status %]
272
273                     [% IF error %]
274                       [% IF error == 'migrate_target' %]
275                           <div class="alert">
276                               The backend you tried to migrate to does not yet support migrations, please try again with an alternative target.
277                           </div>
278                       [% END %]
279                     [% END %]
280
281                     <h1>Manage ILL request</h1>
282                     <div id="request-toolbar" class="btn-toolbar">
283                         <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 %]">
284                         <span class="fa fa-pencil"></span>
285                         Edit request
286                         </a>
287                         [% FOREACH action IN request.available_actions %]
288                             [% IF action.method == 'migrate' %]
289                                 [% IF backends.size > 2 %]
290                                     <div class="dropdown btn-group">
291                                         <button class="btn btn-sm btn-default dropdown-toggle" type="button" id="ill-migrate-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
292                                             <i class="fa [% action.ui_method_icon | html %]"></i> [% action.ui_method_name | html %] <span class="caret"></span>
293                                         </button>
294                                         <ul class="dropdown-menu" aria-labelledby="ill-migrate-dropdown">
295                                             [% FOREACH backend IN backends %]
296                                                 [% IF backend != request.backend %]
297                                                     <li><a href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;backend=[% backend | uri %]">[% backend | html %]</a></li>
298                                                 [% END %]
299                                             [% END %]
300                                         </ul>
301                                     </div>
302                                 [% ELSIF backends.size == 2 %]
303                                     [% FOREACH backend IN backends %]
304                                         [% IF backend != request.backend %]
305                                             <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 | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;backend=[% backend | uri %]">
306                                             <span class="fa [% action.ui_method_icon | html %]"></span>
307                                             [% action.ui_method_name | html %]
308                                             </a>
309                                         [% END %]
310                                     [% END %]
311                                 [% END %]
312                             [% ELSIF action.method != 0 %]
313                                 <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 | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]">
314                                 <span class="fa [% action.ui_method_icon | html %]"></span>
315                                 [% action.ui_method_name | html %]
316                                 </a>
317                             [% END %]
318                         [% END %]
319                         <a title="Display supplier metadata" id="ill-request-display-metadata" class="btn btn-sm btn-default pull-right" href="#">
320                             <span class="fa fa-eye"></span>
321                             Display supplier metadata
322                         </a>
323                         <a title="ILL request log" id="ill-request-display-log" class="btn btn-sm btn-default pull-right" href="#">
324                             <span class="fa fa-calendar"></span>
325                             ILL request log
326                         </a>
327                     </div>
328                     <div class="ill-view-panel panel panel-default">
329                         <div class="panel-heading">
330                             <h3>Request details</h3>
331                         </div>
332                         <div class="panel-body">
333                             <h4>Details from library</h4>
334                             <div class="rows">
335                                 <ol>
336                                     <li class="orderid">
337                                         <span class="label orderid">Order ID:</span>
338                                         [% IF request.orderid %][% request.orderid | html %][% ELSE %]<span>N/A</span>[% END %]
339                                     </li>
340                                     <li class="borrowernumber">
341                                         <span class="label borrowernumber">Patron:</span>
342                                         [% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
343                                         <a href="[% borrowerlink | url %]" title="View borrower details">
344                                         [% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" | html %]
345                                         </a>
346                                     </li>
347
348                                     <li class="biblio_id">
349                                         <span class="label biblio_id">Bibliographic record ID:</span>
350                                         [% IF request.biblio_id %]
351                                             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% request.biblio_id | uri %]">[% request.biblio_id | html %]</a>
352                                         [% ELSE %]
353                                             <span>N/A</span>
354                                         [% END %]
355                                     </li>
356                                     <li class="branchcode">
357                                         <span class="label branchcode">Library:</span>
358                                         [% Branches.GetName(request.branchcode) | html %]
359                                     </li>
360                                     <li class="status">
361                                         <span class="label status">Status:</span>
362                                         [% IF request.statusalias %]
363                                             [% request.statusalias.lib | html %]
364                                         [% ELSE %]
365                                             [% request.capabilities.$req_status.name | html%]
366                                         [% END %]
367                                     </li>
368                                     <li class="updated">
369                                         <span class="label updated">Last updated:</span>
370                                         [% request.updated | $KohaDates  with_hours => 1 %]
371                                     </li>
372                                     <li class="medium">
373                                         <span class="label medium">Request type:</span>
374                                         [% type = request.get_type %]
375                                         [% IF type %][% type | html %][% ELSE %]<span>N/A</span>[% END %]
376                                     </li>
377                                     <li class="cost">
378                                         <span class="label cost">Cost:</span>
379                                         [% IF request.cost %][% request.cost | html %][% ELSE %]<span>N/A</span>[% END %]
380                                     </li>
381                                     <li class="price_paid">
382                                         <span class="label price_paid">Price paid:</span>
383                                         [% IF request.price_paid %][% request.price_paid | html %][% ELSE %]<span>N/A</span>[% END %]
384                                     </li>
385                                     <li class="req_id">
386                                         <span class="label req_id">Request number:</span>
387                                         [% request.id_prefix _ request.illrequest_id | html %]
388                                     </li>
389                                     <li class="notesstaff">
390                                         <span class="label notes_staff">Staff notes:</span>
391                                         <p>[% request.notesstaff | html %]</p>
392                                     </li>
393                                     <li class="notesopac">
394                                         <span class="label notes_opac">Notes:</span>
395                                         <p>[% request.notesopac | html %]</p>
396                                     </li>
397                                 </ol>
398                             </div>
399                             <div class="rows">
400                                 <h4>Details from supplier ([% request.backend | html %])</h4>
401                                 <ol>
402                                     [% FOREACH meta IN request.metadata %]
403                                         <li class="requestmeta-[% meta.key.replace('\s','_') | html %]">
404                                             <span class="label">[% meta.key | html %]:</span>
405                                             [% meta.value | html %]
406                                         </li>
407                                     [% END %]
408                                 </ol>
409                             </div>
410                         </div>
411                     </div>
412
413                     <div id="dataPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
414                         <div class="modal-dialog">
415                             <div class="modal-content">
416                                 <div class="modal-header">
417                                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
418                                     <h3 id="dataPreviewLabel"> Supplier metadata</h3>
419                                 </div>
420                                 <div class="modal-body">
421                                     <div id="requestattributes">
422                                         [% FOREACH attr IN request.illrequestattributes %]
423                                         <div class="requestattr-[% attr.type | html %]">
424                                             <span class="label">[% attr.type | html %]:</span>
425                                             [% attr.value | html %]
426                                         </div>
427                                             [% END %]
428                                     </div>
429                                 </div>
430                                 <div class="modal-footer">
431                                     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
432                                 </div>
433                             </div>
434                         </div>
435                     </div>
436
437                     <div id="requestLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
438                         <div class="modal-dialog">
439                             <div class="modal-content">
440                                 <div class="modal-header">
441                                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
442                                     <h3 id="requestLogLabel"> Request log</h3>
443                                 </div>
444                                 <div class="modal-body">
445                                 [% IF request.logs.size > 0 %]
446                                     [% FOREACH log IN request.logs %]
447                                         [% tpl = log.template %]
448                                         [% INCLUDE $tpl log=log %]
449                                     [% END %]
450                                 [% ELSE %]
451                                     There are no recorded logs for this request
452                                 [% END %]
453                                 </div>
454                                 <div class="modal-footer">
455                                     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
456                                 </div>
457                             </div>
458                         </div>
459                     </div>
460
461                     <div class="ill-view-panel panel panel-default">
462                         <div class="panel-heading">
463                             <h3>[% request.illcomments.count | html %] comments</h3>
464                         </div>
465                         <div class="panel-body">
466                             [% IF request.illcomments.count && request.illcomments.count > 0 %]
467                                 [% FOREACH comment IN request.illcomments %]
468                                     <div class="rows comment_[% comment.patron.categorycode | html %]">
469                                     <h5>Comment by:
470                                     <a href="[% borrowerlink | url %]" title="View borrower details">
471                                     [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a>
472                                     [% comment.timestamp | $KohaDates with_hours => 1 %]</h5>
473                                     <p>[% comment.comment | html %]</p>
474                                     </div>
475                                 [% END %]
476                             [% END %]
477                                 <div class="rows">
478                                     <h3><a id="toggle_addcomment" href="#">Add comment</a></h3>
479                                     <div id="addcomment" class="content_hidden">
480                                         <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl">
481                                             <input type="hidden" value="save_comment" name="method">
482                                             <input type="hidden" value="[% csrf_token | html %]" name="csrf_token">
483                                             <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
484                                             <fieldset class="rows">
485                                                 <ol>
486                                                     <li>
487                                                         <label class="required" for="comment">Comment: </label>
488                                                         <textarea class="required" required="required" cols="80" rows="10" id="comment" name="comment"></textarea>
489                                                         <span class="required">Required</span>
490                                                     </li>
491                                                 </ol>
492                                             </fieldset>
493                                             <fieldset class="action">
494                                                 <input type="submit" value="Submit">
495                                             </fieldset>
496                                         </form>
497                                     </div>
498                                 </div>
499                         </div>
500                     </div>
501
502                 [% ELSIF query_type == 'illlist' %]
503                     <!-- illlist -->
504                     <h1>View ILL requests</h1>
505                     <div id="results">
506                         <h3>Details for all requests</h3>
507
508                         <table id="ill-requests">
509                             <thead>
510                                 <tr id="illview-header">
511                                     <th scope="col">Request ID</th>
512                                     <th scope="col">Author</th>
513                                     <th scope="col">Title</th>
514                                     <th scope="col">Article title</th>
515                                     <th scope="col">Issue</th>
516                                     <th scope="col">Volume</th>
517                                     <th scope="col">Year</th>
518                                     <th scope="col">Pages</th>
519                                     <th scope="col">Type</th>
520                                     <th scope="col">Order ID</th>
521                                     <th scope="col">Patron</th>
522                                     <th scope="col">Bibliographic record</th>
523                                     <th scope="col">Branch</th>
524                                     <th scope="col">Status</th>
525                                     <th scope="col" class="placed">&nbsp;</th>
526                                     <th scope="col" class="placed_formatted">Placed on</th>
527                                     <th scope="col" class="updated">&nbsp;</th>
528                                     <th scope="col" class="updated_formatted">Updated on</th>
529                                     <th scope="col">Replied</th>
530                                     <th scope="col" class="completed">&nbsp;</th>
531                                     <th scope="col" class="completed_formatted">Completed on</th>
532                                     <th scope="col">Access URL</th>
533                                     <th scope="col">Cost</th>
534                                     <th scope="col">Comments</th>
535                                     <th scope="col">OPAC notes</th>
536                                     <th scope="col">Staff notes</th>
537                                     <th scope="col">Backend</th>
538                                     <th scope="col" class="actions"></th>
539                                 </tr>
540                             </thead>
541                             <tbody id="illview-body">
542                             </tbody>
543                         </table>
544                     </div>
545                 [% ELSE %]
546                 <!-- Custom Backend Action -->
547                 [% PROCESS $whole.template %]
548
549                 [% END %]
550         [% END %]
551             </div>
552         </div>
553     </div>
554
555 [% TRY %]
556 [% PROCESS backend_jsinclude %]
557 [% CATCH %]
558 [% END %]
559
560 [% MACRO jsinclude BLOCK %]
561     [% INCLUDE 'datatables.inc' %]
562     [% INCLUDE 'columns_settings.inc' %]
563     [% INCLUDE 'calendar.inc' %]
564     [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
565     <script>
566         $(document).ready(function() {
567
568             // Illview Datatable setup
569
570             var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %];
571
572             var table;
573
574             // Filters that are active
575             var activeFilters = {};
576
577             // Fields we need to expand (flatten)
578             var expand = [
579                 'metadata',
580                 'patron',
581                 'library'
582             ];
583
584             // Expanded fields
585             // This is auto populated
586             var expanded = {};
587
588             // Filterable columns
589             var filterable = {
590                 status: {
591                     prep: function(tableData, oData) {
592                         var uniques = {};
593                         tableData.forEach(function(row) {
594                             var resolvedName;
595                             if (row.status_alias) {
596                                 resolvedName = row.status_alias.lib;
597                             } else {
598                                 resolvedName = getStatusName(
599                                     oData[0].capabilities[row.status].name
600                                 );
601                             }
602                             uniques[resolvedName] = 1
603                         });
604                         Object.keys(uniques).sort().forEach(function(unique) {
605                             $('#illfilter_status').append(
606                                 '<option value="' + unique  +
607                                 '">' + unique +  '</option>'
608                             );
609                         });
610                     },
611                     listener: function() {
612                         var me = 'status';
613                         $('#illfilter_status').change(function() {
614                             var sel = $('#illfilter_status option:selected').val();
615                             if (sel && sel.length > 0) {
616                                 activeFilters[me] = function() {
617                                     table.api().column(13).search(sel);
618                                 }
619                             } else {
620                                 if (activeFilters.hasOwnProperty(me)) {
621                                     delete activeFilters[me];
622                                 }
623                             }
624                         });
625                     },
626                     clear: function() {
627                         $('#illfilter_status').val('');
628                     }
629                 },
630                 pickupBranch: {
631                     prep: function(tableData, oData) {
632                         var uniques = {};
633                         tableData.forEach(function(row) {
634                             uniques[row.library_branchname] = 1
635                         });
636                         Object.keys(uniques).sort().forEach(function(unique) {
637                             $('#illfilter_branchname').append(
638                                 '<option value="' + unique  +
639                                 '">' + unique +  '</option>'
640                             );
641                         });
642                     },
643                     listener: function() {
644                         var me = 'pickupBranch';
645                         $('#illfilter_branchname').change(function() {
646                             var sel = $('#illfilter_branchname option:selected').val();
647                             if (sel && sel.length > 0) {
648                                 activeFilters[me] = function() {
649                                     table.api().column(12).search(sel);
650                                 }
651                             } else {
652                                 if (activeFilters.hasOwnProperty(me)) {
653                                     delete activeFilters[me];
654                                 }
655                             }
656                         });
657                     },
658                     clear: function() {
659                         $('#illfilter_branchname').val('');
660                     }
661                 },
662                 patron: {
663                     listener: function() {
664                         var me = 'patron';
665                         $('#illfilter_patron').change(function() {
666                             var val = $('#illfilter_patron').val();
667                             if (val && val.length > 0) {
668                                 activeFilters[me] = function() {
669                                     table.api().column(10).search(val);
670                                 }
671                             } else {
672                                 if (activeFilters.hasOwnProperty(me)) {
673                                     delete activeFilters[me];
674                                 }
675                             }
676                         });
677                     },
678                     clear: function() {
679                         $('#illfilter_patron').val('');
680                     }
681                 },
682                 dateModified: {
683                     clear: function() {
684                         $('#illfilter_datemodified_start, #illfilter_datemodified_end').val('');
685                     }
686                 },
687                 datePlaced: {
688                     clear: function() {
689                         $('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val('');
690                     }
691                 }
692             };
693
694             // Expand any fields we're expanding
695             var expandExpand = function(row) {
696                 expand.forEach(function(thisExpand) {
697                     if (row.hasOwnProperty(thisExpand)) {
698                         if (!expanded.hasOwnProperty(thisExpand)) {
699                             expanded[thisExpand] = [];
700                         }
701                         var expandObj = row[thisExpand];
702                         Object.keys(expandObj).forEach(
703                             function(thisExpandCol) {
704                                 var expColName = thisExpand + '_' + thisExpandCol.replace(/\s/g,'_');
705                                 // Keep a list of fields that have been expanded
706                                 // so we can create toggle links for them
707                                 if (expanded[thisExpand].indexOf(expColName) == -1) {
708                                     expanded[thisExpand].push(expColName);
709                                 }
710                                 expandObj[expColName] =
711                                     expandObj[thisExpandCol];
712                                 delete expandObj[thisExpandCol];
713                             }
714                         );
715                         $.extend(true, row, expandObj);
716                         delete row[thisExpand];
717                     }
718                 });
719             };
720
721             // Strip the expand prefix if it exists, we do this for display
722             var stripPrefix = function(value) {
723                 expand.forEach(function(thisExpand) {
724                     var regex = new RegExp(thisExpand + '_', 'g');
725                     value = value.replace(regex, '');
726                 });
727                 return value;
728             };
729
730             // Our 'render' function for borrowerlink
731             var createPatronLink = function(data, type, row) {
732                 var patronLink = '<a title="' + _("View borrower details") + '" ' +
733                     'href="/cgi-bin/koha/members/moremember.pl?' +
734                     'borrowernumber='+row.borrowernumber+'">';
735                 if ( row.patron_firstname ) {
736                     patronLink = patronLink + row.patron_firstname + ' ';
737                 }
738                 patronLink = patronLink + row.patron_surname +
739                     ' (' + row.patron_cardnumber + ')' + '</a>';
740                 return patronLink;
741             };
742
743             // Our 'render' function for biblio_id
744             var createBiblioLink = function(data, type, row) {
745                 return (row.biblio_id) ?
746                     '<a title="' + _("View biblio details") + '" ' +
747                     'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' +
748                     row.biblio_id + '">' +
749                     row.biblio_id +
750                     '</a>' : '';
751             };
752
753             // Our 'render' function for title
754             var createTitle = function(data, type, row) {
755                 return (
756                     row.hasOwnProperty('metadata_container_title') &&
757                     row.metadata_container_title
758                 ) ? row.metadata_container_title : row.metadata_title;
759             };
760
761             // Render function for request ID
762             var createRequestId = function(data, type, row) {
763                 return row.id_prefix + row.illrequest_id;
764             };
765
766             // Render function for type
767             var createType = function(data, type, row) {
768                 if (!row.hasOwnProperty('metadata_Type') || !row.metadata_Type) {
769                     if (row.hasOwnProperty('medium') && row.medium) {
770                         row.metadata_Type = row.medium;
771                     } else {
772                         row.metadata_Type = null;
773                     }
774                 }
775                 return row.metadata_Type;
776             };
777
778             // Render function for request status
779             var createStatus = function(data, type, row, meta) {
780                 if (row.status_alias) {
781                     return row.status_alias.lib
782                         ? row.status_alias.lib
783                         : row.status_alias.authorised_value;
784                 } else {
785                     var origData = meta.settings.oInit.originalData;
786                     if (origData.length > 0) {
787                         var status_name = meta.settings.oInit.originalData[0].capabilities[
788                             row.status
789                         ].name;
790                         return getStatusName(status_name);
791                     } else {
792                         return '';
793                     }
794                 }
795             };
796
797             var getStatusName = function(origName) {
798                 switch( origName ) {
799                     case "New request":
800                         return _("New request");
801                     case "Requested":
802                         return _("Requested");
803                     case "Requested from partners":
804                         return _("Requested from partners");
805                     case "Request reverted":
806                         return _("Request reverted");
807                     case "Queued request":
808                         return _("Queued request");
809                     case "Cancellation requested":
810                         return _("Cancellation requested");
811                     case "Completed":
812                         return _("Completed");
813                     case "Delete request":
814                         return _("Delete request");
815                     default:
816                         return origName;
817                 }
818             };
819
820             // Render function for creating a row's action link
821             var createActionLink = function(data, type, row) {
822                 return '<a class="btn btn-default btn-sm" ' +
823                     'href="/cgi-bin/koha/ill/ill-requests.pl?' +
824                     'method=illview&amp;illrequest_id=' +
825                     row.illrequest_id +
826                     '">' + _("Manage request") + '</a>';
827             };
828
829             // Columns that require special treatment
830             var specialCols = {
831                 action: {
832                     func: createActionLink,
833                     skipSanitize: true
834                 },
835                 illrequest_id: {
836                     func: createRequestId
837                 },
838                 status: {
839                     func: createStatus
840                 },
841                 biblio_id: {
842                     name: _("Bibliograpic record ID"),
843                     func: createBiblioLink,
844                     skipSanitize: true
845                 },
846                 metadata_title: {
847                     func: createTitle
848                 },
849                 metadata_Type: {
850                     func: createType
851                 },
852                 updated: {
853                     name: _("Updated on"),
854                 },
855                 patron: {
856                     skipSanitize: true,
857                     func: createPatronLink
858                 }
859             };
860
861             // Display the modal containing request supplier metadata
862             $('#ill-request-display-log').on('click', function(e) {
863                 e.preventDefault();
864                 $('#requestLog').modal({show:true});
865             });
866
867             // Toggle request attributes in Illview
868             $('#toggle_requestattributes').on('click', function(e) {
869                 e.preventDefault();
870                 $('#requestattributes').toggleClass('content_hidden');
871             });
872
873             // Toggle new comment form in Illview
874             $('#toggle_addcomment').on('click', function(e) {
875                 e.preventDefault();
876                 $('#addcomment').toggleClass('content_hidden');
877             });
878
879             // Filter partner list
880             $('#partner_filter').keyup(function() {
881                 var needle = $('#partner_filter').val();
882                 $('#partners > option').each(function() {
883                     var regex = new RegExp(needle, 'i');
884                     if (
885                         needle.length == 0 ||
886                         $(this).is(':selected') ||
887                         $(this).text().match(regex)
888                     ) {
889                         $(this).show();
890                     } else {
891                         $(this).hide();
892                     }
893                 });
894             });
895
896             // Display the modal containing request supplier metadata
897             $('#ill-request-display-metadata').on('click', function(e) {
898                 e.preventDefault();
899                 $('#dataPreview').modal({show:true});
900             });
901
902             // Allow us to chain Datatable render helpers together, so we
903             // can use our custom functions and render.text(), which
904             // provides us with data sanitization
905             $.fn.dataTable.render.multi = function(renderArray) {
906                 return function(d, type, row, meta) {
907                     for(var r = 0; r < renderArray.length; r++) {
908                         var toCall = renderArray[r].hasOwnProperty('display') ?
909                             renderArray[r].display :
910                             renderArray[r];
911                         d = toCall(d, type, row, meta);
912                     }
913                     return d;
914                 }
915             }
916
917             // Get our data from the API and process it prior to passing
918             // it to datatables
919             var ajax = $.ajax(
920                 '/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias,comments'
921                 ).done(function() {
922                     var data = JSON.parse(ajax.responseText);
923                     // Make a copy, we'll be removing columns next and need
924                     // to be able to refer to data that has been removed
925                     var dataCopy = $.extend(true, [], data);
926                     // Expand columns that need it and create an array
927                     // of all column names
928                     $.each(dataCopy, function(k, row) {
929                         expandExpand(row);
930                     });
931
932                     // Assemble an array of column definitions for passing
933                     // to datatables
934                     var colData = [];
935                     columns_settings.forEach(function(thisCol) {
936                         var colName = thisCol.columnname;
937                         // Create the base column object
938                         var colObj = $.extend({}, thisCol);
939                         colObj.name = colName;
940                         colObj.className = colName;
941                         colObj.defaultContent = '';
942
943                         // We may need to process the data going in this
944                         // column, so do it if necessary
945                         if (
946                             specialCols.hasOwnProperty(colName) &&
947                             specialCols[colName].hasOwnProperty('func')
948                         ) {
949                             var renderArray = [
950                                 specialCols[colName].func
951                             ];
952                             if (!specialCols[colName].skipSanitize) {
953                                 renderArray.push(
954                                     $.fn.dataTable.render.text()
955                                 );
956                             }
957
958                             colObj.render = $.fn.dataTable.render.multi(
959                                 renderArray
960                             );
961                         } else {
962                             colObj.data = colName;
963                             colObj.render = $.fn.dataTable.render.text()
964                         }
965                         // Make sure properties that aren't present in the API
966                         // response are populated with null to avoid Datatables
967                         // choking on their absence
968                         dataCopy.forEach(function(thisData) {
969                             if (!thisData.hasOwnProperty(colName)) {
970                                 thisData[colName] = null;
971                             }
972                         });
973                         colData.push(colObj);
974                     });
975
976                     // Initialise the datatable
977                     table = KohaTable("ill-requests", {
978                         'aoColumnDefs': [
979                             { // Last column shouldn't be sortable or searchable
980                                 'aTargets': [ 'actions' ],
981                                 'bSortable': false,
982                                 'bSearchable': false
983                             },
984                             { // When sorting 'placed', we want to use the
985                               // unformatted column
986                               'aTargets': [ 'placed_formatted'],
987                               'iDataSort': 14
988                             },
989                             { // When sorting 'updated', we want to use the
990                               // unformatted column
991                               'aTargets': [ 'updated_formatted'],
992                               'iDataSort': 16
993                             },
994                             { // When sorting 'completed', we want to use the
995                               // unformatted column
996                               'aTargets': [ 'completed_formatted'],
997                               'iDataSort': 19
998                             }
999                         ],
1000                         'aaSorting': [[ 16, 'desc' ]], // Default sort, updated descending
1001                         'processing': true, // Display a message when manipulating
1002                         'sPaginationType': "full_numbers", // Pagination display
1003                         'deferRender': true, // Improve performance on big datasets
1004                         'data': dataCopy,
1005                         'columns': colData,
1006                         'originalData': data, // Enable render functions to access
1007                                               // our original data
1008                         'initComplete': function() {
1009
1010                             // Prepare any filter elements that need it
1011                             for (var el in filterable) {
1012                                 if (filterable.hasOwnProperty(el)) {
1013                                     if (filterable[el].hasOwnProperty('prep')) {
1014                                         filterable[el].prep(dataCopy, data);
1015                                     }
1016                                     if (filterable[el].hasOwnProperty('listener')) {
1017                                         filterable[el].listener();
1018                                     }
1019                                 }
1020                             }
1021
1022                         }
1023                     }, columns_settings);
1024
1025                     // Custom date range filtering
1026                     $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
1027                         var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate');
1028                         var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate');
1029                         var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate');
1030                         var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate');
1031                         var rowPlaced = data[14] ? new Date(data[14]) : null;
1032                         var rowModified = data[16] ? new Date(data[16]) : null;
1033                         var placedPassed = true;
1034                         var modifiedPassed = true;
1035                         if (placedStart && rowPlaced && rowPlaced < placedStart) {
1036                             placedPassed = false
1037                         };
1038                         if (placedEnd && rowPlaced && rowPlaced > placedEnd) {
1039                             placedPassed = false;
1040                         }
1041                         if (modifiedStart && rowModified && rowModified < modifiedStart) {
1042                             modifiedPassed = false
1043                         };
1044                         if (modifiedEnd && rowModified && rowModified > modifiedEnd) {
1045                             modifiedPassed = false;
1046                         }
1047
1048                         return placedPassed && modifiedPassed;
1049
1050                     });
1051
1052                 }
1053             );
1054
1055             var clearSearch = function() {
1056                 table.api().search('').columns().search('');
1057                 activeFilters = {};
1058                 for (var filter in filterable) {
1059                     if (
1060                         filterable.hasOwnProperty(filter) &&
1061                         filterable[filter].hasOwnProperty('clear')
1062                     ) {
1063                         filterable[filter].clear();
1064                     }
1065                 }
1066                 table.api().draw();
1067             };
1068
1069             // Apply any search filters, or clear any previous
1070             // ones
1071             $('#illfilter_form').submit(function(event) {
1072                 event.preventDefault();
1073                 table.api().search('').columns().search('');
1074                 for (var active in activeFilters) {
1075                     if (activeFilters.hasOwnProperty(active)) {
1076                         activeFilters[active]();
1077                     }
1078                 }
1079                 table.api().draw();
1080             });
1081
1082             // Clear all filters
1083             $('#clear_search').click(function() {
1084                 clearSearch();
1085             });
1086
1087         });
1088     </script>
1089 [% END %]
1090
1091 [% INCLUDE 'intranet-bottom.inc' %]