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