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