Bug 20468: (QA follow-up) Deactivate select/clear all for empty tab
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / circ / article-requests.tt
1 [% USE KohaDates %]
2 [% USE ItemTypes %]
3 [% USE Branches %]
4 [% USE AuthorisedValues %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Circulation &rsaquo; Article requests</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 <style type="text/css"> p { margin-top: 0; } [id^="article-menu-"] { display: none; } [id^="article-menu-"]:before { content: "|"; }</style>
10 </head>
11
12 [% BLOCK actions %]
13     <div id="[% menuid %]" class="dropdown">
14         <a class="btn btn-default btn-xs dropdown-toggle ar-actions" role="button" data-toggle="dropdown" href="#">
15             Actions <b class="caret"></b>
16         </a>
17
18         <ul class="dropdown-menu [% pull_right %]" role="menu" aria-labelledby="[% aria_menu %]">
19             <li>
20                 <a class="ar-process-request" href="#" onclick="HandleMulti( Process, [% id_arg %], $(this) ); return false;">
21                     <i class="fa fa-cog"></i>
22                     Process request
23                 </a>
24
25                 <a class="ar-complete-request" href="#" onclick="HandleMulti( Complete, [% id_arg %], $(this) ); return false;">
26                     <i class="fa fa-check-circle"></i>
27                     Complete request
28                 </a>
29
30                 <a class="ar-cancel-request" href="#" onclick="HandleMulti( Cancel, [% id_arg %], $(this) ); return false;">
31                     <i class="fa fa-minus-circle"></i>
32                     Cancel request
33                 </a>
34
35                 [% IF id_arg %][%# TODO: Does not work with multi-select %]
36                 <a class="ar-print-request" href="#" onclick="HandleMulti( PrintSlip, [% id_arg %], $(this) ); return false;">
37                     <i class="fa fa-print"></i>
38                     Print slip
39                 </a>
40                 [% END %]
41             </li>
42         </ul>
43     </div>
44 [% END %]
45
46 <body id="circ_article-requests" class="circ">
47     [% INCLUDE 'header.inc' %]
48     [% INCLUDE 'cat-search.inc' %]
49
50     <div id="breadcrumbs">
51         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
52         &rsaquo;
53         <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a>
54         &rsaquo;
55         <a href="/cgi-bin/koha/circ/article-requests.pl">Article requests</a>
56     </div>
57
58     <div class="main container-fluid">
59         <div class="row">
60             <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
61
62                 <h1>Article requests</h1>
63
64                 <form id="ar-branchcode-form" method="post">
65                     <select name="branchcode" id="branchcode">
66                         <option value="">All libraries</option>
67                         [% FOREACH b IN Branches.all( only_from_group => 1 ) %]
68                             [% IF b.branchcode == branchcode %]
69                                 <option value="[% b.branchcode %]" selected="selected">[% b.branchname %]</option>
70                             [% ELSE %]
71                                 <option value="[% b.branchcode %]">[% b.branchname %]</option>
72                             [% END %]
73                         [% END %]
74                     </select>
75                     <button type="submit" class="btn btn-default btn-xs">
76                         <i class="fa fa-refresh"></i> Update
77                     </button>
78                 </form>
79
80                 <div id="article-request-tabs" class="toptabs">
81                     <ul>
82                         <li>
83                             <a href="#article-requests-pending">
84                                 Pending (<span id="ar_pending_count">[% article_requests_pending.count %]</span>)
85                             </a>
86                         </li>
87
88                         <li>
89                             <a href="#article-requests-processing">
90                                 Processing (<span id="ar_processing_count">[% article_requests_processing.count %]</span>)
91                             </a>
92                         </li>
93                     </ul>
94
95                     <div id="article-requests-pending">
96                         <div class="article-requests-pending_table_controls">
97                             <a href="#" class="SelectAll"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
98                             [% PROCESS actions menuid='article-menu-pending' id_arg=0 pull_right='' aria_menu='table_controls' %]
99                         </div>
100
101                         <table id="article-requests-pending-table">
102                             <thead>
103                                 <tr>
104                                     <th/>
105                                     <th class="ar-title">Title</th>
106                                     <th class="ar-request">Requested article</th>
107                                     <th class="ar-collection">Collection</th>
108                                     <th class="ar-itemtype">Item type</th>
109                                     <th class="ar-callnumber">Call number</th>
110                                     <th class="ar-copynumber">Copy number</th>
111                                     <th class="ar-enumchron">Enumeration</th>
112                                     <th class="ar-barcode">Barcode</th>
113                                     <th class="ar-patron">Patron</th>
114                                     <th class="ar-date">Date</th>
115                                     <th class="ar-actions">Actions</th>
116                                 </tr>
117                             </thead>
118
119                              <tbody>
120                                 <tr class="ar-pending-none">
121                                     <td colspan="12">
122                                         There are no pending article requests at this time.
123                                     </td>
124                                 </tr>
125
126                                 [% FOREACH ar IN article_requests_pending %]
127                                     <tr class="ar-row ar-pending">
128                                         <td><input type="checkbox" reqid="[% ar.id %]"/></td>
129                                         <td class="ar-title">
130                                             <p>
131                                                 <a href="/cgi-bin/koha/circ/request-article.pl?biblionumber=[% ar.biblionumber %]">
132                                                     <strong>[% ar.biblio.title | html %]</strong>
133                                                     [% FOREACH s IN itemsloo.subtitle %] [% s %][% END %]
134                                                 </a>
135                                             </p>
136
137                                             <p>
138                                                 <div class="ar-biblionumber content_hidden">[% ar.biblionumber %]</div>
139                                                 <div class="ar-author">[% ar.biblio.author %]</div>
140                                                 <div class="ar-pubdata">
141                                                     [% ar.biblio.biblioitem.publishercode %]
142
143                                                     [% IF ar.biblio.biblioitem.publicationyear %]
144                                                         [% ar.biblio.biblioitem.publicationyear %]
145                                                     [% ELSIF ar.biblio.copyrightdate %]
146                                                         [% ar.biblio.copyrightdate %]
147                                                     [% END %]
148
149                                                     [% IF ar.biblio.biblioitem.pages %]
150                                                         : [% ar.biblio.biblioitem.pages %]
151                                                     [% END %]
152
153                                                     [%  r.biblio.biblioitem.size %]
154
155                                                     [% IF ar.biblio.biblioitem.isbn %]
156                                                         ISBN: [% ar.biblio.biblioitem.isbn %]
157                                                     [% END %]
158                                                 </div>
159                                             </p>
160                                         </td>
161                                         <td class="ar-request">
162                                             [% IF ar.title %]        <p><strong>Title:</strong>        [% ar.title %]        </p> [% END %]
163                                             [% IF ar.author %]       <p><strong>Author:</strong>       [% ar.author %]       </p> [% END %]
164                                             [% IF ar.volume %]       <p><strong>Volume:</strong>       [% ar.volume %]       </p> [% END %]
165                                             [% IF ar.issue %]        <p><strong>Issue:</strong>        [% ar.issue %]        </p> [% END %]
166                                             [% IF ar.date %]         <p><strong>Date:</strong>         [% ar.date %]         </p> [% END %]
167                                             [% IF ar.pages %]        <p><strong>Pages:</strong>        [% ar.pages %]        </p> [% END %]
168                                             [% IF ar.chapters %]     <p><strong>Chapters:</strong>     [% ar.chapters %]     </p> [% END %]
169                                             [% IF ar.patron_notes %] <p><strong>Patron notes:</strong> [% ar.patron_notes %] </p> [% END %]
170                                         </td>
171                                         <td class="ar-collection">[% AuthorisedValues.GetByCode( 'CCODE', ar.item.ccode ) %]</td>
172                                         <td class="ar-itemtype">[% ItemTypes.GetDescription( ar.item.effective_itemtype ) %]</td>
173                                         <td class="ar-callnumber">
174                                             [% IF ar.item.location %]
175                                                 <em>[% AuthorisedValues.GetByCode( 'LOC', ar.item.location ) %]</em>
176                                             [% END %]
177
178                                             [% ar.item.itemcallnumber %]
179                                         </td>
180                                         <td class="ar-copynumber">[% ar.item.copynumber %]</td>
181                                         <td class="ar-enumchron">[% ar.item.enumchron %]</td>
182                                         <td class="ar-barcode">[% ar.item.barcode %]</td>
183                                         <td class="ar-patron">
184                                             <p>
185                                                 <a href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% ar.borrower.cardnumber %]">
186                                                     [% ar.borrower.surname %][% IF ar.borrower.firstname %], [% ar.borrower.firstname %][% END %] ([% ar.borrower.cardnumber %])
187                                                 </a>
188                                             </p>
189
190                                             <p>[% ar.borrower.phone %]</p>
191                                         </td>
192                                         <td class="ar-date"><span title="[% ar.created_on %]">[% ar.created_on | $KohaDates %]</span></td>
193                                         <td class="ar-actions">
194                                         <div class="dropdown">
195                                             [% PROCESS actions menuid = "row" _ ar.id id_arg=ar.id pull_right='pull-right' aria_menu='ar-actions' %]
196                                         </div>
197                                         </td>
198                                     </tr>
199                                 [% END %]
200                             </tbody>
201                         </table>
202                     </div>
203
204                     <div id="article-requests-processing">
205                         <div class="article-requests-processing_table_controls">
206                             <a href="#" class="SelectAll"><i class="fa fa-check"></i> Select all</a> | <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
207                             [% PROCESS actions menuid='article-menu-processing' id_arg=0 pull_right='' aria_menu='table_controls' %]
208                         </div>
209                         <table id="article-requests-processing-table">
210                             <thead>
211                                 <tr>
212                                     <th/>
213                                     <th class="ar-title">Title</th>
214                                     <th class="ar-request">Requested article</th>
215                                     <th class="ar-collection">Collection</th>
216                                     <th class="ar-itemtype">Item type</th>
217                                     <th class="ar-callnumber">Call number</th>
218                                     <th class="ar-copynumber">Copy number</th>
219                                     <th class="ar-enumchron">Enumeration</th>
220                                     <th class="ar-barcode">Barcode</th>
221                                     <th class="ar-patron">Patron</th>
222                                     <th class="ar-date">Date</th>
223                                     <th class="ar-actions">Actions</th>
224                                 </tr>
225                             </thead>
226
227                              <tbody>
228                                 <tr class="ar-processing-none">
229                                     <td colspan="12">
230                                         There are no article requests in processing at this time.
231                                     </td>
232                                 </tr>
233
234                                 [% FOREACH ar IN article_requests_processing %]
235                                     <tr class="ar-row ar-processing">
236                                         <td><input type="checkbox" reqid="[% ar.id %]"/></td>
237                                         <td class="ar-title">
238                                             <p>
239                                                 <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ar.biblionumber %]">
240                                                     <strong>[% ar.biblio.title | html %]</strong>
241                                                     [% FOREACH s IN itemsloo.subtitle %] [% s %][% END %]
242                                                 </a>
243                                             </p>
244
245                                             <p>
246                                                 <div class="ar-biblionumber content_hidden">[% ar.biblionumber %]</div>
247                                                 <div class="ar-author">[% ar.biblio.author %]</div>
248                                                 <div class="ar-pubdata">
249                                                     [% ar.biblio.biblioitem.publishercode %]
250
251                                                     [% IF ar.biblio.biblioitem.publicationyear %]
252                                                         [% ar.biblio.biblioitem.publicationyear %]
253                                                     [% ELSIF ar.biblio.copyrightdate %]
254                                                         [% ar.biblio.copyrightdate %]
255                                                     [% END %]
256
257                                                     [% IF ar.biblio.biblioitem.pages %]
258                                                         : [% ar.biblio.biblioitem.pages %]
259                                                     [% END %]
260
261                                                     [%  r.biblio.biblioitem.size %]
262
263                                                     [% IF ar.biblio.biblioitem.isbn %]
264                                                         ISBN: [% ar.biblio.biblioitem.isbn %]
265                                                     [% END %]
266                                                 </div>
267                                             </p>
268                                         </td>
269                                         <td class="ar-request">
270                                             [% IF ar.title %]        <p><strong>Title:</strong>        [% ar.title %]        </p> [% END %]
271                                             [% IF ar.author %]       <p><strong>Author:</strong>       [% ar.author %]       </p> [% END %]
272                                             [% IF ar.volume %]       <p><strong>Volume:</strong>       [% ar.volume %]       </p> [% END %]
273                                             [% IF ar.issue %]        <p><strong>Issue:</strong>        [% ar.issue %]        </p> [% END %]
274                                             [% IF ar.date %]         <p><strong>Date:</strong>         [% ar.date %]         </p> [% END %]
275                                             [% IF ar.pages %]        <p><strong>Pages:</strong>        [% ar.pages %]        </p> [% END %]
276                                             [% IF ar.chapters %]     <p><strong>Chapters:</strong>     [% ar.chapters %]     </p> [% END %]
277                                             [% IF ar.patron_notes %] <p><strong>Patron notes:</strong> [% ar.patron_notes %] </p> [% END %]
278                                         </td>
279                                         <td class="ar-collection">[% AuthorisedValues.GetByCode( 'CCODE', ar.item.ccode ) %]</td>
280                                         <td class="ar-itemtype">[% ItemTypes.GetDescription( ar.item.effective_itemtype ) %]</td>
281                                         <td class="ar-callnumber">
282                                             [% IF ar.item.location %]
283                                                 <em>[% AuthorisedValues.GetByCode( 'LOC', ar.item.location ) %]</em>
284                                             [% END %]
285
286                                             [% ar.item.itemcallnumber %]
287                                         </td>
288                                         <td class="ar-copynumber">[% ar.item.copynumber %]</td>
289                                         <td class="ar-enumchron">[% ar.item.enumchron %]</td>
290                                         <td class="ar-barcode">[% ar.item.barcode %]</td>
291                                         <td class="ar-patron">
292                                             <p>
293                                                 <a href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% ar.borrower.cardnumber %]">
294                                                     [% ar.borrower.surname %][% IF ar.borrower.firstname %], [% ar.borrower.firstname %][% END %] ([% ar.borrower.cardnumber %])
295                                                 </a>
296                                             </p>
297
298                                             <p>[% ar.borrower.phone %]</p>
299                                         </td>
300                                         <td class="ar-date"><span title="[% ar.created_on %]">[% ar.created_on | $KohaDates %]</span></td>
301                                         <td class="ar-actions">
302                                         <div class="dropdown">
303                                             [% PROCESS actions menuid="table_" _ ar.id id_arg=ar.id pull_right='pull-right' aria_menu='ar-actions' %]
304                                         </div>
305                                         </td>
306                                     </tr>
307                                 [% END %]
308                             </tbody>
309                         </table>
310                     </div>
311                     <br/>
312                 </div>
313             </div>
314         </div>
315     </div>
316
317 [% MACRO jsinclude BLOCK %]
318     <script>
319         var active_table = "#article-requests-pending";
320         var last_cancel_reason;
321         $(document).ready(function() {
322             $('#article-request-tabs').tabs({
323                 activate: function( activate_event, activate_ui ) {
324                     active_table = activate_ui.newPanel.selector;
325                     activateBatchActions( active_table );
326                 },
327                 create: function( create_event, create_ui ){
328                     active_table = create_ui.panel.selector;
329                 },
330             });
331
332             activateBatchActions( active_table );
333
334             [% IF article_requests_pending.count %]
335                 $(".ar-pending-none").hide();
336             [% END %]
337
338             [% IF article_requests_processing.count %]
339                 $(".ar-processing-none").hide();
340             [% END %]
341
342             $( "input:checkbox", active_table ).on("change", function(){
343                 activateBatchActions( active_table );
344             });
345
346             $(".SelectAll").on("click", function(e) {
347                 e.preventDefault();
348                 $( active_table + " input[type='checkbox']").prop('checked', true);
349                 activateBatchActions( active_table );
350             });
351             $(".ClearAll").on("click", function(e) {
352                 e.preventDefault();
353                 $( active_table + " input[type='checkbox']").prop('checked', false);
354                 activateBatchActions( active_table );
355             });
356             $("a.ar-actions").on('click', function(e) {
357                 // Hide menu option ?
358                 if( $('#article-requests-processing-table').is(":visible") )
359                     $('a.ar-process-request').hide();
360                 else $('a.ar-process-request').show();
361             });
362         });
363
364         function activateBatchActions( active_table ){
365             // Check to see whether batch menu should be shown based on state of checkboxes
366             if ( $( "input:checkbox", active_table ).length > 0 ) {
367                 // There are rows with checkboxes
368                 $( "[class$='_table_controls']", active_table ).show();
369                 if ( $( "input:checkbox:checked", active_table ).length > 0 ) {
370                     $( "[id^='article-menu-']", active_table ).css("display","inline-block");
371                 } else {
372                     $( "[id^='article-menu-']", active_table ).hide();
373                 }
374             } else {
375                 // All rows have been removed
376                 $("[class$='_table_controls']", active_table ).hide();
377             }
378         }
379
380         function HandleMulti( fnHandler, id, a ) {
381             last_cancel_reason = undefined;
382             if( id !== 0 ) { fnHandler( id, a ); return; }
383             $( active_table + " input[type='checkbox']:checked").each(function() {
384                 fnHandler( $(this).attr('reqid'), $(this).closest('tr').find('td.ar-actions div a') );
385             });
386         }
387
388         function PrintSlip(id, a) {
389             var link = 'article-request-slip.pl?id='+id;
390             window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
391         }
392
393         function Cancel( id, a ) {
394             // last_cancel_reason: undefined means 'prompt for new reason'
395             // a null value indicates that prompt was cancelled
396             if( last_cancel_reason === undefined ) last_cancel_reason = prompt(_("Please specify the reason for cancelling selected item(s):"));
397             if ( last_cancel_reason === null ) {
398                 return;
399             }
400
401             a.closest('td').prepend('<img src="[% interface %]/[% theme %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
402             $.ajax({
403                 type: "POST",
404                 url: '/cgi-bin/koha/svc/article_request',
405                 data: {
406                     action: 'cancel',
407                     id: id,
408                     notes: last_cancel_reason
409                 },
410                 success: function( data ) {
411                     a.closest('tr').remove();
412                     UpdateTabCounts();
413                     activateBatchActions( active_table );
414                 },
415                 dataType: 'json'
416             });
417         }
418
419         function Process( id, a ) {
420             var table_row = a.closest('tr').clone();
421             table_row.find('.ar-process-request').remove();
422             table_row.find('input[type="checkbox"]').prop('checked', false);
423
424             a.closest('td').prepend('<img src="[% interface %]/[% theme %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
425             $.ajax({
426                 type: "POST",
427                 url: '/cgi-bin/koha/svc/article_request',
428                 data: {
429                     action: 'process',
430                     id: id,
431                 },
432                 success: function( data ) {
433                     a.closest('tr').remove();
434                     $("#article-requests-processing-table").append( table_row );
435                     $("#article-requests-processing-table .ar-processing-none").hide();
436                     UpdateTabCounts();
437                     activateBatchActions( active_table );
438                 },
439                 dataType: 'json'
440             });
441         }
442
443         function Complete( id, a ) {
444             a.closest('td').prepend('<img src="[% interface %]/[% theme %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
445             $.ajax({
446                 type: "POST",
447                 url: '/cgi-bin/koha/svc/article_request',
448                 data: {
449                     action: 'complete',
450                     id: id,
451                 },
452                 success: function( data ) {
453                     a.closest('tr').remove();
454                     UpdateTabCounts();
455                     activateBatchActions( active_table );
456                 },
457                 dataType: 'json'
458             });
459         }
460
461         function UpdateTabCounts() {
462             var pending_count = $('#article-requests-pending-table tbody tr.ar-row').length;
463             $("#ar_pending_count").html( pending_count );
464             if ( pending_count == 0 ) $(".ar-pending-none").show();
465
466             var processing_count = $('#article-requests-processing-table tbody tr.ar-row').length;
467             $("#ar_processing_count").html( processing_count );
468             if ( processing_count == 0 ) $(".ar-processing-none").show();
469         }
470     </script>
471 [% END %]
472
473 [% INCLUDE 'intranet-bottom.inc' %]