Bug 27947: Add cancellation reason to article request
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / circ / request-article.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% USE Branches %]
5 [% USE ItemTypes %]
6 [% USE AuthorisedValues %]
7 [% SET footerjs = 1 %]
8 [% SET article_requests_view = 1 %]
9 [% SET biblionumber = biblio.biblionumber %]
10 [% INCLUDE 'doc-head-open.inc' %]
11 <title>Request article &rsaquo; Circulation &rsaquo; Koha</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 </head>
14
15 [% BLOCK cancel_modal %]
16     <div id="cancelModal" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
17         <div class="modal-dialog" role="document">
18             <div class="modal-content">
19                 <div class="modal-header">
20                     <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
21                     <h3>Confirm deletion</h3>
22                 </div>
23
24                 <div class="modal-body">
25                     <p>Are you sure you want to cancel this article request?</p>
26
27                     <fieldset class="action">
28                         [% SET ar_cancellation = AuthorisedValues.GetAuthValueDropbox('AR_CANCELLATION') %]
29                         [% IF ar_cancellation %]
30                             <label for="cancellation-reason" class="col-sm-4">Cancellation reason: </label>
31                             <select class="cancellation-reason col-sm-8" name="cancellation-reason" id="modal-cancellation-reason">
32                                 <option value="" selected>Other reasons</option>
33                                 [% FOREACH reason IN ar_cancellation %]
34                                     <option value="[% reason.authorised_value | html %]">[% reason.lib | html %]</option>
35                                 [% END %]
36                             </select>
37                         [% END %]
38                     </fieldset>
39                     <fieldset class="action">
40                         <div class="hint col-sm-offset-4">Enter reason</div>
41                         <input type="text" class="notes col-sm-offset-4 col-sm-8" name="notes" id="modal-notes"/>
42                     </fieldset>
43                 </div>
44
45                 <div class="modal-footer">
46                     <button id="cancelModalConfirmBtn" type="button" class="btn btn-danger" data-dismiss="modal">Confirm cancellation</button>
47                     <a href="#" data-dismiss="modal">Cancel</a>
48                 </div>
49             </div>
50         </div>
51     </div>
52 [% END %]
53
54 <body id="circ_request-article" class="circ">
55     [% INCLUDE 'header.inc' %]
56     [% INCLUDE 'circ-search.inc' %]
57
58     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
59         <ol>
60             <li>
61                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
62             </li>
63
64             [% IF blocking_error %]
65                 <li>
66                     <a href="#" aria-current="page">
67                         Catalog
68                     </a>
69                 </li>
70
71             [% ELSE %]
72                 [% INCLUDE 'biblio-title.inc' link = 1 %]
73                 <li>
74                     <a href="#" aria-current="page">
75                         Request article
76                     </a>
77                 </li>
78             [% END %]
79         </ol>
80     </nav>
81
82 [% INCLUDE 'blocking_errors.inc' %]
83 <div class="main container-fluid">
84     <div class="row">
85         <div class="col-sm-10 col-sm-push-2">
86             <main>
87
88                     <h1>Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]</h1>
89                     [% IF error_message %]
90                         <div class="dialog alert">
91                         [% SWITCH error_message %]
92                             [% CASE 'article_request_limit_reached'       %]<p>Patron reached daily limit.</p>
93                             [% CASE 'article_request_unhandled_exception' %]<p>An error has occurred. Check the logs.</p>
94                         [% END %]
95                         </div>
96                     [% END %]
97                     [% IF no_patrons_found %]
98                         <div class="dialog alert">
99                             <h3>Patron not found</h3>
100                             <p>No patron with this name, please, try another</p>
101                         </div>
102                     [% ELSIF patrons %]
103                         <form id="article_request_patron_results" method="post">
104                             <fieldset>
105                                 <table id="table_borrowers">
106                                     <thead>
107                                         <tr>
108                                             <th></th>
109                                             <th>Name</th>
110                                             <th>Cardnumber</th>
111                                             <th>Category</th>
112                                             <th>Library</th>
113                                             <th>Address</th>
114                                         </tr>
115                                     </thead>
116                                     <tbody>
117                                         [% FOREACH patron IN patrons %]
118                                             <tr>
119                                                 <td><input type="radio" name="patron_id" value="[% patron.borrowernumber | html %]"/></td>
120                                                 <td>[% patron.surname | html %], [% patron.firstname | html %]</td>
121                                                 <td>[% patron.cardnumber | html %]</td>
122                                                 <td>[% patron.categorycode | html %]</td>
123                                                 <td>[% patron.branchcode | html %]</td>
124                                                 <td>[% patron.address | html %]</td>
125                                             </tr>
126                                         [% END %]
127                                     </tbody>
128                                 </table>
129                                 <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
130                                 <fieldset class="action"><input type="submit" value="Select" /></fieldset>
131                             </fieldset>
132                         </form>
133                     [% ELSIF !patron %]
134                         <form id="article_requests_patronsearch" action="request-article.pl" method="post">
135                             <fieldset class="brief">
136                                 <label for="patron">Patron: </label>
137                                 <div class="hint">Enter patron card number or partial name:</div>
138                                 <input type="text" size="40" id="patron" class="focus" name="patron_cardnumber" />
139                                 <input type="submit" value="Search" />
140                                 <input type="hidden" name="biblionumber" value="[% biblio.id | html %]" />
141                             </fieldset>
142                         </form>
143                     [% ELSE %]
144                         [% IF biblio.can_article_request( patron ) %]
145
146                             <form id="place-article-request" method="post" action="/cgi-bin/koha/circ/request-article.pl">
147                                 <input type="hidden" name="action" value="create" />
148                                 <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblio.biblionumber | html %]" />
149                                 <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.id | html %]" />
150
151                                 <fieldset class="rows">
152                                     <legend>Place article request from [% biblio.title | html %] for [% patron.firstname | html %] [% patron.surname | html %] ( [% patron.cardnumber | html %] )</legend>
153                                     <ul>
154                                         <li>
155                                             <label for="title">Title:</label>
156                                             <input type="text" name="title" id="title" size="50"/>
157                                         </li>
158
159                                         <li>
160                                             <label for="author">Author:</label>
161                                             <input type="text" name="author" id="author" size="50"/>
162                                         </li>
163
164                                         <li>
165                                             <label for="volume">Volume:</label>
166                                             <input type="text" name="volume" id="volume" size="50"/>
167                                         </li>
168
169                                         <li>
170                                             <label for="issue">Issue:</label>
171                                             <input type="text" name="issue" id="issue" size="50"/>
172                                         </li>
173
174                                         <li>
175                                             <label for="date">Date:</label>
176                                             <input type="text" name="date" id="date" size="50"/>
177                                         </li>
178
179                                         <li>
180                                             <label for="pages">Pages:</label>
181                                             <input type="text" name="pages" id="pages" size="50"/>
182                                         </li>
183
184                                         <li>
185                                             <label for="chapters">Chapters:</label>
186                                             <input type="text" name="chapters" id="chapters" size="50"/>
187                                         </li>
188
189                                         <li>
190                                             <label for="patron_notes">Patron notes:</label>
191                                             <input type="text" name="patron_notes" id="patron_notes" size="50"/>
192                                         </li>
193
194                                         <li>
195                                             <label for="format">Format:</label>
196                                             <select name="format" id="format">
197                                                 <option value="PHOTOCOPY">Photocopy</option>
198                                                 <option value="SCAN">Digital scan</option>
199                                             </select>
200                                         </li>
201
202                                         <li>
203                                             <label for="branchcode">Pickup library:</label>
204                                             <select name="branchcode" id="branchcode">
205                                                 [% FOREACH b IN Branches.all %]
206                                                     [% IF b.branchcode == Branches.GetLoggedInBranchcode %]
207                                                         <option value="[% b.branchcode | html %]" selected="selected">[% b.branchname | html %]</option>
208                                                     [% ELSE %]
209                                                         <option value="[% b.branchcode | html %]">[% b.branchname | html %]</option>
210                                                     [% END %]
211                                                 [% END %]
212                                             </select>
213                                         </li>
214                                     </ul>
215                                 </fieldset>
216
217                                 [% SET article_request_type = biblio.article_request_type( patron ) %]
218                                 [% IF article_request_type != 'bib_only' %]
219                                     <table id="current-requests-table" class="ar-table table table-bordered table-striped">
220                                         <caption>Select item:</caption>
221                                         <thead>
222                                             <tr>
223                                                 <th>&nbsp;</th>
224                                                 <th>Item type</th>
225                                                 <th>Barcode</th>
226                                                 <th>Home library</th>
227                                                 <th>Call number</th>
228                                                 <th>Enumeration</th>
229                                             </tr>
230                                         </thead>
231
232                                         <tbody>
233                                             [% FOREACH item IN biblio.items %]
234                                                 [% IF item.can_article_request( patron ) %]
235                                                     <tr>
236                                                         <td>
237                                                             [% IF article_request_type == 'item_only' && !checked %]
238                                                                 [% SET checked = 1 %]
239                                                                 <input type="radio" name="itemnumber" value="[% item.itemnumber | html %]" checked="checked" />
240                                                             [% ELSE %]
241                                                                 <input type="radio" name="itemnumber" value="[% item.itemnumber | html %]" />
242                                                             [% END %]
243                                                         </td>
244                                                         <td>
245                                                             [% ItemTypes.GetDescription( item.itype ) | html %]
246                                                         </td>
247                                                         <td>
248                                                             [% item.barcode | html %]
249                                                         </td>
250                                                         <td>
251                                                             [% Branches.GetName( item.homebranch ) | html %]
252                                                         </td>
253                                                         <td>
254                                                             [% item.itemcallnumber | html %]
255                                                         </td>
256                                                         <td>
257                                                             [% item.enumchron | html %]
258                                                         </td>
259                                                     </tr>
260                                                 [% END %]
261                                             [% END %]
262
263                                             [% IF article_request_type != 'item_only' %]
264                                                 <tr>
265                                                     <td>
266                                                         <input type="radio" name="itemnumber" value="" checked="checked"/>
267                                                     </td>
268                                                     <td colspan="5">
269                                                         Any item
270                                                     </td>
271                                                 </tr>
272                                             [% END %]
273                                         </tbody>
274                                     </table>
275                                 [% END %]
276
277                                 <p>
278                                     <input type="submit" class="btn btn-default" value="Place request" />
279                                 </p>
280                             </form>
281                         [% ELSE %]
282                             No article requests can be made for this record.
283                         [% END %]
284
285                     [% END %]
286
287                     [% IF biblio.article_requests_current && !patron %]
288                         <fieldset class="rows left" id="current-article-requests-fieldset">
289                             <legend>Current article requests</legend>
290
291                             <table id="current-article-requests-table">
292                                 <tr>
293                                     <th>Placed on</th>
294                                     <th>Patron</th>
295                                     <th>Title</th>
296                                     <th>Author</th>
297                                     <th>Volume</th>
298                                     <th>Issue</th>
299                                     <th>Date</th>
300                                     <th>Pages</th>
301                                     <th>Chapters</th>
302                                     <th>Patron notes</th>
303                                     <th>Format</th>
304                                     <th>Item</th>
305                                     <th>Status</th>
306                                     <th>Pickup library</th>
307                                     <th>&nbsp;</th>
308                                 </tr>
309
310                                 [% FOREACH ar IN biblio.article_requests_current %]
311                                     <tr>
312                                         <td>[% ar.created_on | $KohaDates %]</td>
313                                         <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% ar.borrowernumber | uri %]">[% ar.borrower.firstname | html %] [% ar.borrower.surname | html %]</a></td>
314                                         <td>[% ar.title | html %]</td>
315                                         <td>[% ar.author | html %]</td>
316                                         <td>[% ar.volume | html %]</td>
317                                         <td>[% ar.issue | html %]</td>
318                                         <td>[% ar.date | html %]</td>
319                                         <td>[% ar.pages | html %]</td>
320                                         <td>[% ar.chapters | html %]</td>
321                                         <td>[% ar.patron_notes | html %]</td>
322                                         <td>[% IF ar.format == 'PHOTOCOPY' %]Copy[% ELSIF ar.format == 'SCAN' %]Scan[% END %]</td>
323                                         <td>
324                                             [% IF ar.item %]
325                                                 <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% ar.itemnumber | uri %]&biblionumber=[% ar.biblionumber | uri %]">[% ar.item.barcode | html %]</a>
326                                             [% END %]
327                                         </td>
328                                         <td>
329                                             [% IF ar.status == 'PENDING' %]
330                                                 Pending
331                                             [% ELSIF ar.status == 'PROCESSING' %]
332                                                 Processing
333                                             [% ELSIF ar.status == 'REQUESTED' %]
334                                                 New
335                                             [% ELSIF ar.status == 'COMPLETED' %]
336                                                 Completed
337                                             [% ELSIF ar.status == 'CANCELED' %]
338                                                 Canceled
339                                             [% END %]
340                                         </td>
341                                         <td>
342                                             <i id="update-processing-[% ar.id | html %]" class="fa fa-cog fa-spin hidden"></i>
343                                             <select name="branchcode" id="branchcode-[% ar.id | html %]" class="ar-update-branchcode">
344                                                 [% FOREACH b IN Branches.all %]
345                                                     [% IF b.branchcode == ar.branchcode %]
346                                                         <option value="[% b.branchcode | html %]" selected="selected">[% b.branchname | html %]</option>
347                                                     [% ELSE %]
348                                                         <option value="[% b.branchcode | html %]">[% b.branchname | html %]</option>
349                                                     [% END %]
350                                                 [% END %]
351                                             </select>
352                                         </td>
353                                         <td>
354                                             <a title="Cancel article request" href="#" id="cancel-[% ar.id | html %]" class="ar-cancel-request">
355                                                 <i id="cancel-processing-spinner-[% ar.id | html %]" class="fa fa-cog fa-spin hide"></i>
356                                                 <i id="cancel-processing-[% ar.id | html %]" class="fa fa-times fa-lg" style="color:red"></i>
357                                             </a>
358                                         </td>
359                                     </tr>
360                                 [% END %]
361                             </table>
362                         </fieldset>
363                         [% PROCESS cancel_modal %]
364                     [% END %]
365
366             </main>
367         </div> <!-- /.col-sm-10.col-sm-push-2 -->
368
369         <div class="col-sm-2 col-sm-pull-10">
370             <aside>
371                 [% INCLUDE 'biblio-view-menu.inc' %]
372             </aside>
373         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
374      </div> <!-- /.row -->
375
376 [% MACRO jsinclude BLOCK %]
377     [% INCLUDE 'datatables.inc' %]
378
379     <script>
380         $('#current-article-requests').ready(function() {
381             $(".hide").hide();
382         });
383
384         $(document).ready(function() {
385             if ( $( "#patron" ).size() ){
386                 $( "#patron" ).autocomplete({
387                     source: "/cgi-bin/koha/circ/ysearch.pl",
388                     minLength: 3,
389                     select: function( event, ui ) {
390                         $( "#patron" ).val( ui.item.cardnumber );
391                         $( "#holds_patronsearch" ).submit();
392                         return false;
393                     }
394                 })
395                 .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
396                     return $( "<li></li>" )
397                     .data( "ui-autocomplete-item", item )
398                     .append(
399                         "<a>"
400                             + ( item.surname ? item.surname.escapeHtml() : "" )
401                             + ", "
402                             + ( item.firstname ? item.firstname.escapeHtml() : "" )
403                             + " (" + ( item.cardnumber ? item.cardnumber.escapeHtml() : "" ) + ")"
404                             + " "
405                             + "<small>"
406                                 + ( item.address ? item.address.escapeHtml() : "" )
407                                 + " "
408                                 + ( item.city ? item.city.escapeHtml() : "" )
409                                 + " "
410                                 + ( item.zipcode ? item.zipcode.escapeHtml() : "" )
411                                 + " "
412                                 + ( item.country ? item.country.escapeHtml() : "" )
413                             + "</small>"
414                         + "</a>" )
415                     .appendTo( ul );
416                 };
417             }
418
419             $( ".ar-update-branchcode" ).on('focus', function(){
420                 previous_branchcode = this.value;
421             }).on('change', function(){
422                 var branchcode = this.value;
423                 var c = confirm(_("Are you sure you want to change the pickup library from %s to %s for this request?").format( previous_branchcode, branchcode ));
424
425                 if ( c ) {
426                     var id = this.id.split("branchcode-")[1];
427                     $("#update-processing-" + id ).css({opacity: 0, visibility: "visible"}).animate({opacity: 1.0}, 200);
428
429                     $.ajax({
430                         type: "POST",
431                         url: '/cgi-bin/koha/svc/article_request',
432                         data: {
433                             action: 'update_branchcode',
434                             id: id,
435                             branchcode: branchcode,
436                         },
437                         success: function( data ) {
438                             $("#update-processing-" + id ).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 200);
439                         },
440                         dataType: 'json'
441                     });
442
443                 } else {
444                     this.value = previous_branchcode;
445                 }
446             });
447
448             $('#modal-cancellation-reason').on('change', function(e) {
449                 let reason = $(this).val();
450                 $('#modal-notes').attr('disabled', !!reason);
451             })
452
453             let cancel_a;
454             $("#cancelModalConfirmBtn").on("click",function(e) {
455                 var id = cancel_a.attr('id').split("cancel-")[1];
456                 $("#cancel-processing-" + id ).hide('slow');
457                 $("#cancel-processing-spinner-" + id ).show('slow');
458
459                 let reason = $("#modal-cancellation-reason").val();
460                 let notes = $("#modal-notes").val();
461                 let query = '?'+(reason?'cancellation_reason='+reason:'notes='+notes)
462
463                 $.ajax({
464                     type: "DELETE",
465                     url: '/api/v1/article_requests/'+id+query,
466                     success: function( data ) {
467                         cancel_a.parents('tr').hide('slow');
468                     }
469                 });
470             });
471
472
473             $(".ar-cancel-request").on("click", function(){
474                 cancel_a = $(this);
475                 $('#cancelModal').modal();
476             });
477
478             // Initialize format(s)
479             var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | $raw %]";
480             if( !supported_formats.match(/PHOTOCOPY/) )
481                 $('#format option[value="PHOTOCOPY"]').remove();
482             if( !supported_formats.match(/SCAN/) )
483                 $('#format option[value="SCAN"]').remove();
484
485             if( $('#format option').length > 1 ) {
486             // Select first listed format
487                 var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
488                 $('#format option[value="'+first_format+'"]').attr('selected', true);
489             }
490         });
491     </script>
492 [% END %]
493
494 [% INCLUDE 'intranet-bottom.inc' %]