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