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