Bug 27944: Add "requested" stage in article request process
[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 [% USE Asset %]
6 [% USE raw %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>Article requests &rsaquo; Circulation &rsaquo; Koha</title>
10 [% INCLUDE 'doc-head-close.inc' %]
11 <style>p { margin-top: 0; } [id^="article-menu-"] { display: none; } [id^="article-menu-"]:before { content: "|"; } .starthidden { display:none; }</style>
12 </head>
13
14 [% BLOCK actions %]
15     <div id="[% menuid | html %]" class="btn-group dropup">
16         <a class="btn btn-default btn-xs dropdown-toggle ar-actions" role="button" data-toggle="dropdown" href="#">
17             Actions <b class="caret"></b>
18         </a>
19
20         <ul class="dropdown-menu [% pull_right | html %]" role="menu" aria-labelledby="[% aria_menu | html %]">
21             <li>
22                 <a class="ar-set-pending-request" href="#" onclick="HandleMulti( SetPending, [% id_arg | html %], $(this) ); return false;">
23                     <i class="fa fa-bars"></i>
24                     Set request as pending
25                 </a>
26
27                 <a class="ar-process-request" href="#" onclick="HandleMulti( Process, [% id_arg | html %], $(this) ); return false;">
28                     <i class="fa fa-cog"></i>
29                     Process request
30                 </a>
31
32                 [% IF id_arg && format=='SCAN' %]
33                 <a class="ar-edit-urls" href="#" onclick="HandleMulti( EditURLs, [% id_arg | html %], $(this) ); return false;">
34                     <i class="fa fa-edit"></i>
35                     Edit URLs
36                 </a>
37                 [% END %]
38
39                 <a class="ar-complete-request" href="#" onclick="HandleMulti( Complete, [% id_arg | html %], $(this) ); return false;">
40                     <i class="fa fa-check-circle"></i>
41                     Complete request
42                 </a>
43
44                 <a class="ar-cancel-request" href="#" onclick="HandleMulti( Cancel, [% id_arg | html %], $(this) ); return false;">
45                     <i class="fa fa-minus-circle"></i>
46                     Cancel request
47                 </a>
48
49                 [% IF id_arg %][%# TODO: Does not work with multi-select %]
50                 <a class="ar-print-request" href="#" onclick="HandleMulti( PrintSlip, [% id_arg | html %], $(this) ); return false;">
51                     <i class="fa fa-print"></i>
52                     Print slip
53                 </a>
54                 [% END %]
55             </li>
56         </ul>
57     </div>
58 [% END %]
59 [% BLOCK item_status %]
60     [% IF myitem.onloan %]<span>Checked out</span>
61     [% ELSIF myitem.holds({ found => ['W', 'T'] }).count > 0 %]<span>On hold</span>
62     [% ELSIF myitem.notforloan > 0 OR myitem.itemtype.notforloan %]<span>Not for loan</span>
63     [% ELSIF myitem.notforloan < 0 %]<span>On order</span>
64     [% END %]
65 [% END %]
66 [% BLOCK urls_modal %]
67     <div id="myModal" class="modal fade modal-lg" role="dialog">
68       <div class="modal-dialog">
69         <div class="modal-content">
70           <div class="modal-header">
71              <h4 class="modal-title">Edit URL(s)</h4>
72           </div>
73           <div class="modal-body">
74             <textarea id="urls" style="width:100%;"></textarea>
75           </div>
76           <div class="modal-footer">
77             <button type="button" class="btn btn-default" data-dismiss="modal">Save</button>
78           </div>
79         </div>
80       </div>
81     </div>
82 [% END %]
83
84 <body id="circ_article-requests" class="circ">
85     [% INCLUDE 'header.inc' %]
86     [% INCLUDE 'cat-search.inc' %]
87
88
89     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
90         <ol>
91             <li>
92                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
93             </li>
94             <li>
95                 <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a>
96             </li>
97             <li>
98                 <a href="#" aria-current="page">Article requests</a>
99             </li>
100         </ol>
101     </nav>
102
103     <div class="main container-fluid starthidden">
104         <div class="row">
105             <div class="col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">
106
107                 <h1>Article requests</h1>
108                 [% PROCESS urls_modal %]
109
110                 <form id="ar-branchcode-form" method="post">
111                     <select name="branchcode" id="branchcode">
112                         <option value="">All libraries</option>
113                         [% FOREACH b IN Branches.all( only_from_group => 1 ) %]
114                             [% IF b.branchcode == branchcode %]
115                                 <option value="[% b.branchcode | html %]" selected="selected">[% b.branchname | html %]</option>
116                             [% ELSE %]
117                                 <option value="[% b.branchcode | html %]">[% b.branchname | html %]</option>
118                             [% END %]
119                         [% END %]
120                     </select>
121                     <button type="submit" class="btn btn-default btn-xs">
122                         <i class="fa fa-refresh"></i> Update
123                     </button>
124                 </form>
125
126                 <div id="article-request-tabs" class="toptabs">
127                     <ul>
128                         <li>
129                             <a href="#article-requests-requested">
130                                 New (<span id="ar_requested_count">[% article_requests_requested.count | html %]</span>)
131                             </a>
132                         </li>
133
134                         <li>
135                             <a href="#article-requests-pending">
136                                 Pending (<span id="ar_pending_count">[% article_requests_pending.count | html %]</span>)
137                             </a>
138                         </li>
139
140                         <li>
141                             <a href="#article-requests-processing">
142                                 Processing (<span id="ar_processing_count">[% article_requests_processing.count | html %]</span>)
143                             </a>
144                         </li>
145                     </ul>
146
147                     <div id="article-requests-requested">
148                         <div class="article-requests-requested_table_controls">
149                             <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>
150                             [% PROCESS actions menuid='article-menu-requested' id_arg=0 pull_right='' aria_menu='table_controls' %]
151                         </div>
152
153                         <table id="article-requests-requested-table">
154                             <thead>
155                                 <tr>
156                                     <th/>
157                                     <th class="ar-title">Title</th>
158                                     <th class="ar-request">Requested article</th>
159                                     <th class="ar-collection">Collection</th>
160                                     <th class="ar-itemtype">Item type</th>
161                                     <th class="ar-callnumber">Call number</th>
162                                     <th class="ar-status">Status</th>
163                                     <th class="ar-copynumber">Copy number</th>
164                                     <th class="ar-enumchron">Enumeration</th>
165                                     <th class="ar-barcode">Barcode</th>
166                                     <th class="ar-format">Format</th>
167                                     <th class="ar-urls">URLs</th>
168                                     <th class="ar-patron">Patron</th>
169                                     <th class="ar-date">Date</th>
170                                     <th class="ar-actions noExport">Actions</th>
171                                 </tr>
172                             </thead>
173
174                              <tbody>
175                                 [% FOREACH ar IN article_requests_requested %]
176                                     <tr class="ar-row ar-requested">
177                                         <td><input type="checkbox" reqid="[% ar.id | html %]"/></td>
178                                         <td class="ar-title">
179                                             <p>
180                                                 <a class="title" href="/cgi-bin/koha/circ/request-article.pl?biblionumber=[% ar.biblionumber | uri %]">
181                                                     [% INCLUDE 'biblio-title.inc' biblio=ar.biblio %]
182                                                 </a>
183                                             </p>
184
185                                             <p>
186                                                 <div class="ar-biblionumber content_hidden">[% ar.biblionumber | html %]</div>
187                                                 <div class="ar-author">[% ar.biblio.author | html %]</div>
188                                                 <div class="ar-pubdata">
189                                                     [% ar.biblio.biblioitem.publishercode | html %]
190
191                                                     [% IF ar.biblio.biblioitem.publicationyear %]
192                                                         [% ar.biblio.biblioitem.publicationyear | html %]
193                                                     [% ELSIF ar.biblio.copyrightdate %]
194                                                         [% ar.biblio.copyrightdate | html %]
195                                                     [% END %]
196
197                                                     [% IF ar.biblio.biblioitem.pages %]
198                                                         : [% ar.biblio.biblioitem.pages | html %]
199                                                     [% END %]
200
201                                                     [% r.biblio.biblioitem.size | html %]
202
203                                                     [% IF ar.biblio.biblioitem.isbn %]
204                                                         ISBN: [% ar.biblio.biblioitem.isbn | html %]
205                                                     [% END %]
206                                                 </div>
207                                             </p>
208                                         </td>
209                                         <td class="ar-request">
210                                             [% IF ar.title %]        <p><strong>Title:</strong>        [% ar.title | html %]        </p> [% END %]
211                                             [% IF ar.author %]       <p><strong>Author:</strong>       [% ar.author | html %]       </p> [% END %]
212                                             [% IF ar.volume %]       <p><strong>Volume:</strong>       [% ar.volume | html %]       </p> [% END %]
213                                             [% IF ar.issue %]        <p><strong>Issue:</strong>        [% ar.issue | html %]        </p> [% END %]
214                                             [% IF ar.date %]         <p><strong>Date:</strong>         [% ar.date | html %]         </p> [% END %]
215                                             [% IF ar.pages %]        <p><strong>Pages:</strong>        [% ar.pages | html %]        </p> [% END %]
216                                             [% IF ar.chapters %]     <p><strong>Chapters:</strong>     [% ar.chapters | html %]     </p> [% END %]
217                                             [% IF ar.patron_notes %] <p><strong>Patron notes:</strong> [% ar.patron_notes | html %] </p> [% END %]
218                                         </td>
219                                         <td class="ar-collection">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => ar.item.ccode ) | html %]</td>
220                                         <td class="ar-itemtype">[% ItemTypes.GetDescription( ar.item.effective_itemtype ) | html %]</td>
221                                         <td class="ar-callnumber">
222                                             [% IF ar.item.location %]
223                                                 <em>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ar.item.location ) | html %]</em>
224                                             [% END %]
225
226                                             [% ar.item.itemcallnumber | html %]
227                                         </td>
228                                         <td class="ar-status">[% PROCESS 'item_status' myitem = ar.item IF ar.item %]</td>
229                                         <td class="ar-copynumber">[% ar.item.copynumber | html %]</td>
230                                         <td class="ar-enumchron">[% ar.item.enumchron | html %]</td>
231                                         <td class="ar-barcode">[% ar.item.barcode | html %]</td>
232                                         <td class="ar-format">[% IF ar.format == 'PHOTOCOPY' %]Copy[% ELSIF ar.format == 'SCAN' %]Scan[% END %]</td>
233                                         <td class="ar-urls">[% IF ar.format == 'SCAN' %]<span id="url_yesno_[% ar.id | html %]">[% IF ar.urls %]Yes[% ELSE %]No[% END%]</span><span id="url_[% ar.id | html %]" style="display:none;">[% ar.urls | url %]</span>[% END %]</td>
234                                         <td class="ar-patron">
235                                             <p>
236                                                 <a href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% ar.borrower.cardnumber | uri %]">
237                                                     [% ar.borrower.surname | html %][% IF ar.borrower.firstname %], [% ar.borrower.firstname | html %][% END %] ([% ar.borrower.cardnumber | html %])
238                                                 </a>
239                                             </p>
240
241                                             <p>[% ar.borrower.phone | html %]</p>
242                                         </td>
243                                         <td class="ar-date"><span title="[% ar.created_on | html %]">[% ar.created_on | $KohaDates %]</span></td>
244                                         <td class="ar-actions">
245                                             [% PROCESS actions menuid = "row" _ ar.id id_arg=ar.id pull_right='pull-right' aria_menu='ar-actions' %]
246                                         </td>
247                                     </tr>
248                                 [% END %]
249                             </tbody>
250                         </table>
251                     </div>
252
253                     <div id="article-requests-pending">
254                         <div class="article-requests-pending_table_controls">
255                             <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>
256                             [% PROCESS actions menuid='article-menu-pending' id_arg=0 pull_right='' aria_menu='table_controls' %]
257                         </div>
258
259                         <table id="article-requests-pending-table">
260                             <thead>
261                                 <tr>
262                                     <th/>
263                                     <th class="ar-title">Title</th>
264                                     <th class="ar-request">Requested article</th>
265                                     <th class="ar-collection">Collection</th>
266                                     <th class="ar-itemtype">Item type</th>
267                                     <th class="ar-callnumber">Call number</th>
268                                     <th class="ar-status">Status</th>
269                                     <th class="ar-copynumber">Copy number</th>
270                                     <th class="ar-enumchron">Enumeration</th>
271                                     <th class="ar-barcode">Barcode</th>
272                                     <th class="ar-format">Format</th>
273                                     <th class="ar-urls">URLs</th>
274                                     <th class="ar-patron">Patron</th>
275                                     <th class="ar-date">Date</th>
276                                     <th class="ar-actions noExport">Actions</th>
277                                 </tr>
278                             </thead>
279
280                              <tbody>
281                                 [% FOREACH ar IN article_requests_pending %]
282                                     <tr class="ar-row ar-pending">
283                                         <td><input type="checkbox" reqid="[% ar.id | html %]"/></td>
284                                         <td class="ar-title">
285                                             <p>
286                                                 <a class="title" href="/cgi-bin/koha/circ/request-article.pl?biblionumber=[% ar.biblionumber | uri %]">
287                                                     [% INCLUDE 'biblio-title.inc' biblio=ar.biblio %]
288                                                 </a>
289                                             </p>
290
291                                             <p>
292                                                 <div class="ar-biblionumber content_hidden">[% ar.biblionumber | html %]</div>
293                                                 <div class="ar-author">[% ar.biblio.author | html %]</div>
294                                                 <div class="ar-pubdata">
295                                                     [% ar.biblio.biblioitem.publishercode | html %]
296
297                                                     [% IF ar.biblio.biblioitem.publicationyear %]
298                                                         [% ar.biblio.biblioitem.publicationyear | html %]
299                                                     [% ELSIF ar.biblio.copyrightdate %]
300                                                         [% ar.biblio.copyrightdate | html %]
301                                                     [% END %]
302
303                                                     [% IF ar.biblio.biblioitem.pages %]
304                                                         : [% ar.biblio.biblioitem.pages | html %]
305                                                     [% END %]
306
307                                                     [% r.biblio.biblioitem.size | html %]
308
309                                                     [% IF ar.biblio.biblioitem.isbn %]
310                                                         ISBN: [% ar.biblio.biblioitem.isbn | html %]
311                                                     [% END %]
312                                                 </div>
313                                             </p>
314                                         </td>
315                                         <td class="ar-request">
316                                             [% IF ar.title %]        <p><strong>Title:</strong>        [% ar.title | html %]        </p> [% END %]
317                                             [% IF ar.author %]       <p><strong>Author:</strong>       [% ar.author | html %]       </p> [% END %]
318                                             [% IF ar.volume %]       <p><strong>Volume:</strong>       [% ar.volume | html %]       </p> [% END %]
319                                             [% IF ar.issue %]        <p><strong>Issue:</strong>        [% ar.issue | html %]        </p> [% END %]
320                                             [% IF ar.date %]         <p><strong>Date:</strong>         [% ar.date | html %]         </p> [% END %]
321                                             [% IF ar.pages %]        <p><strong>Pages:</strong>        [% ar.pages | html %]        </p> [% END %]
322                                             [% IF ar.chapters %]     <p><strong>Chapters:</strong>     [% ar.chapters | html %]     </p> [% END %]
323                                             [% IF ar.patron_notes %] <p><strong>Patron notes:</strong> [% ar.patron_notes | html %] </p> [% END %]
324                                         </td>
325                                         <td class="ar-collection">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => ar.item.ccode ) | html %]</td>
326                                         <td class="ar-itemtype">[% ItemTypes.GetDescription( ar.item.effective_itemtype ) | html %]</td>
327                                         <td class="ar-callnumber">
328                                             [% IF ar.item.location %]
329                                                 <em>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ar.item.location ) | html %]</em>
330                                             [% END %]
331
332                                             [% ar.item.itemcallnumber | html %]
333                                         </td>
334                                         <td class="ar-status">[% PROCESS 'item_status' myitem = ar.item IF ar.item %]</td>
335                                         <td class="ar-copynumber">[% ar.item.copynumber | html %]</td>
336                                         <td class="ar-enumchron">[% ar.item.enumchron | html %]</td>
337                                         <td class="ar-barcode">[% ar.item.barcode | html %]</td>
338                                         <td class="ar-format">[% IF ar.format == 'PHOTOCOPY' %]Copy[% ELSIF ar.format == 'SCAN' %]Scan[% END %]</td>
339                                         <td class="ar-urls">[% IF ar.format == 'SCAN' %]<span id="url_yesno_[% ar.id | html %]">[% IF ar.urls %]Yes[% ELSE %]No[% END%]</span><span id="url_[% ar.id | html %]" style="display:none;">[% ar.urls | url %]</span>[% END %]</td>
340                                         <td class="ar-patron">
341                                             <p>
342                                                 <a href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% ar.borrower.cardnumber | uri %]">
343                                                     [% ar.borrower.surname | html %][% IF ar.borrower.firstname %], [% ar.borrower.firstname | html %][% END %] ([% ar.borrower.cardnumber | html %])
344                                                 </a>
345                                             </p>
346
347                                             <p>[% ar.borrower.phone | html %]</p>
348                                         </td>
349                                         <td class="ar-date" data-order="[% ar.created_on | html %]">[% ar.created_on | $KohaDates %]</td>
350                                         <td class="ar-actions">
351                                             [% PROCESS actions menuid = "row" _ ar.id id_arg=ar.id format=ar.format pull_right='pull-right' aria_menu='ar-actions' %]
352                                         </td>
353                                     </tr>
354                                 [% END %]
355                             </tbody>
356                         </table>
357                     </div>
358
359                     <div id="article-requests-processing">
360                         <div class="article-requests-processing_table_controls">
361                             <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>
362                             [% PROCESS actions menuid='article-menu-processing' id_arg=0 pull_right='' aria_menu='table_controls' %]
363                         </div>
364                         <table id="article-requests-processing-table">
365                             <thead>
366                                 <tr>
367                                     <th/>
368                                     <th class="ar-title">Title</th>
369                                     <th class="ar-request">Requested article</th>
370                                     <th class="ar-collection">Collection</th>
371                                     <th class="ar-itemtype">Item type</th>
372                                     <th class="ar-callnumber">Call number</th>
373                                     <th class="ar-status">Status</th>
374                                     <th class="ar-copynumber">Copy number</th>
375                                     <th class="ar-enumchron">Enumeration</th>
376                                     <th class="ar-barcode">Barcode</th>
377                                     <th class="ar-format">Format</th>
378                                     <th class="ar-urls">URLs</th>
379                                     <th class="ar-patron">Patron</th>
380                                     <th class="ar-date">Date</th>
381                                     <th class="ar-actions noExport">Actions</th>
382                                 </tr>
383                             </thead>
384
385                              <tbody>
386                                 [% FOREACH ar IN article_requests_processing %]
387                                     <tr class="ar-row ar-processing">
388                                         <td><input type="checkbox" reqid="[% ar.id | html %]"/></td>
389                                         <td class="ar-title">
390                                             <p>
391                                                 [% INCLUDE 'biblio-title.inc' biblio=ar.biblio link = 1%]
392                                             </p>
393
394                                             <p>
395                                                 <div class="ar-biblionumber content_hidden">[% ar.biblionumber | html %]</div>
396                                                 <div class="ar-author">[% ar.biblio.author | html %]</div>
397                                                 <div class="ar-pubdata">
398                                                     [% ar.biblio.biblioitem.publishercode | html %]
399
400                                                     [% IF ar.biblio.biblioitem.publicationyear %]
401                                                         [% ar.biblio.biblioitem.publicationyear | html %]
402                                                     [% ELSIF ar.biblio.copyrightdate %]
403                                                         [% ar.biblio.copyrightdate | html %]
404                                                     [% END %]
405
406                                                     [% IF ar.biblio.biblioitem.pages %]
407                                                         : [% ar.biblio.biblioitem.pages | html %]
408                                                     [% END %]
409
410                                                     [% r.biblio.biblioitem.size | html %]
411
412                                                     [% IF ar.biblio.biblioitem.isbn %]
413                                                         ISBN: [% ar.biblio.biblioitem.isbn | html %]
414                                                     [% END %]
415                                                 </div>
416                                             </p>
417                                         </td>
418                                         <td class="ar-request">
419                                             [% IF ar.title %]        <p><strong>Title:</strong>        [% ar.title | html %]        </p> [% END %]
420                                             [% IF ar.author %]       <p><strong>Author:</strong>       [% ar.author | html %]       </p> [% END %]
421                                             [% IF ar.volume %]       <p><strong>Volume:</strong>       [% ar.volume | html %]       </p> [% END %]
422                                             [% IF ar.issue %]        <p><strong>Issue:</strong>        [% ar.issue | html %]        </p> [% END %]
423                                             [% IF ar.date %]         <p><strong>Date:</strong>         [% ar.date | html %]         </p> [% END %]
424                                             [% IF ar.pages %]        <p><strong>Pages:</strong>        [% ar.pages | html %]        </p> [% END %]
425                                             [% IF ar.chapters %]     <p><strong>Chapters:</strong>     [% ar.chapters | html %]     </p> [% END %]
426                                             [% IF ar.patron_notes %] <p><strong>Patron notes:</strong> [% ar.patron_notes | html %] </p> [% END %]
427                                         </td>
428                                         <td class="ar-collection">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => ar.item.ccode ) | html %]</td>
429                                         <td class="ar-itemtype">[% ItemTypes.GetDescription( ar.item.effective_itemtype ) | html %]</td>
430                                         <td class="ar-callnumber">
431                                             [% IF ar.item.location %]
432                                                 <em>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ar.item.location ) | html %]</em>
433                                             [% END %]
434
435                                             [% ar.item.itemcallnumber | html %]
436                                         </td>
437                                         <td class="ar-status">[% PROCESS 'item_status' myitem = ar.item IF ar.item %]</td>
438                                         <td class="ar-copynumber">[% ar.item.copynumber | html %]</td>
439                                         <td class="ar-enumchron">[% ar.item.enumchron | html %]</td>
440                                         <td class="ar-barcode">[% ar.item.barcode | html %]</td>
441                                         <td class="ar-format">[% IF ar.format == 'PHOTOCOPY' %]Copy[% ELSIF ar.format == 'SCAN' %]Scan[% END %]</td>
442                                         <td class="ar-urls">[% IF ar.format == 'SCAN' %]<span id="url_yesno_[% ar.id | html %]">[% IF ar.urls %]Yes[% ELSE %]No[% END%]</span><span id="url_[% ar.id | html %]" style="display:none;">[% ar.urls | url %]</span>[% END %]</td>
443                                         <td class="ar-patron">
444                                             <p>
445                                                 <a href="/cgi-bin/koha/circ/circulation.pl?findborrower=[% ar.borrower.cardnumber | uri %]">
446                                                     [% ar.borrower.surname | html %][% IF ar.borrower.firstname %], [% ar.borrower.firstname | html %][% END %] ([% ar.borrower.cardnumber | html %])
447                                                 </a>
448                                             </p>
449
450                                             <p>[% ar.borrower.phone | html %]</p>
451                                         </td>
452                                         <td class="ar-date" data-order="[% ar.created_on | html %]">[% ar.created_on | $KohaDates %]</td>
453                                         <td class="ar-actions">
454                                             [% PROCESS actions menuid="table_" _ ar.id id_arg=ar.id format=ar.format pull_right='pull-right' aria_menu='ar-actions' %]
455                                         </td>
456                                     </tr>
457                                 [% END %]
458                             </tbody>
459                         </table>
460                     </div>
461                     <br/>
462                 </div>
463             </div>
464         </div>
465     </div>
466
467 [% MACRO jsinclude BLOCK %]
468     [% INCLUDE 'datatables.inc' %]
469     <script>
470         var active_tab = "#article-requests-requested";
471         var last_cancel_reason, requested_datatable, pending_datatable, processing_datatable, active_datatable;
472         $(document).ready(function() {
473             $('#article-request-tabs').tabs({
474                 activate: function( activate_event, activate_ui ) {
475                     active_tab = activate_ui.newPanel.selector;
476                     if( active_tab == '#article-requests-requested' )
477                         active_datatable = requested_datatable;
478                     else if( active_tab == '#article-requests-pending' )
479                         active_datatable = pending_datatable;
480                     else active_datatable = processing_datatable;
481                     activateBatchActions( active_tab );
482                 },
483             });
484
485
486             $( "input:checkbox, #article-request-tabs" ).on("change", function(){
487                 activateBatchActions( active_tab );
488             });
489
490             $(".SelectAll").on("click", function(e) {
491                 e.preventDefault();
492                 $( active_tab + " input[type='checkbox']").prop('checked', true);
493                 activateBatchActions( active_tab );
494             });
495             $(".ClearAll").on("click", function(e) {
496                 e.preventDefault();
497                 $( active_tab + " input[type='checkbox']").prop('checked', false);
498                 activateBatchActions( active_tab );
499             });
500             $("a.ar-actions").on('click', function(e) {
501                 // Hide menu option ?
502                 if( $('#article-requests-requested-table:visible,#article-requests-pending-table:visible').length )
503                     $('a.ar-process-request').show();
504                 else $('a.ar-process-request').hide();
505
506                 if( $('#article-requests-requested-table').is(":visible") )
507                     $('a.ar-set-pending-request').show();
508                 else $('a.ar-set-pending-request').hide();
509             });
510
511             $('#myModal').on("shown.bs.modal", function () {
512                 $('#myModal textarea').focus();
513             });
514             $('#myModal').on("hidden.bs.modal", function () {
515                 // Set focus back to dropdown
516                 var id = $('#myModal textarea').attr('ar_id');
517                 var link = $('span#url_'+ id).parent().parent().find('td.ar-actions').find('div.dropdown a');
518                 if( link.length > 0 ) link[0].focus();
519             });
520             $( '#myModal button' ).on("click", function () {
521                 SaveURLs( $('#myModal textarea').val() );
522             });
523
524             requested_datatable = $("#article-requests-requested-table").DataTable($.extend(true, {}, dataTablesDefaults, {
525                 "aoColumnDefs": [
526                     { "aTargets": [0, -1], "bSortable": false, "bSearchable": false },
527                 ],
528             }));
529
530             pending_datatable = $("#article-requests-pending-table").DataTable($.extend(true, {}, dataTablesDefaults, {
531                 "aoColumnDefs": [
532                     { "aTargets": [0, -1], "bSortable": false, "bSearchable": false },
533                 ],
534             }));
535             processing_datatable = $("#article-requests-processing-table").DataTable($.extend(true, {}, dataTablesDefaults, {
536                 "aoColumnDefs": [
537                     { "aTargets": [0, -1], "bSortable": false, "bSearchable": false },
538                 ],
539             }));
540             active_datatable = requested_datatable;
541             activateBatchActions( active_tab );
542             $(".starthidden").show();
543         });
544
545         function activateBatchActions( active_tab ){
546             // Check to see whether batch menu should be shown based on state of checkboxes
547             if ( $( "input:checkbox", active_tab ).length > 0 ) {
548                 // There are rows with checkboxes
549                 $( "[class$='_table_controls']", active_tab ).show();
550                 if ( $( "input:checkbox:checked", active_tab ).length > 0 ) {
551                     $( "[id^='article-menu-']", active_tab ).css("display","inline-block");
552                 } else {
553                     $( "[id^='article-menu-']", active_tab ).hide();
554                 }
555             } else {
556                 // All rows have been removed
557                 $("[class$='_table_controls']", active_tab ).hide();
558             }
559         }
560
561         function HandleMulti( fnHandler, id, a ) {
562             last_cancel_reason = undefined;
563             if( id !== 0 ) { fnHandler( id, a ); return; }
564             $( active_tab + " input[type='checkbox']:checked").each(function() {
565                 fnHandler( $(this).attr('reqid'), $(this).closest('tr').find('td.ar-actions div a') );
566             });
567         }
568
569         function PrintSlip(id, a) {
570             var link = 'article-request-slip.pl?id='+id;
571             window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
572         }
573
574         function Cancel( id, a ) {
575             // last_cancel_reason: undefined means 'prompt for new reason'
576             // a null value indicates that prompt was cancelled
577             if( last_cancel_reason === undefined ) last_cancel_reason = prompt(_("Please specify the reason for cancelling selected item(s):"));
578             if ( last_cancel_reason === null ) {
579                 return;
580             }
581
582             a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
583             $.ajax({
584                 type: "POST",
585                 url: '/cgi-bin/koha/svc/article_request',
586                 data: {
587                     action: 'cancel',
588                     id: id,
589                     notes: last_cancel_reason
590                 },
591                 success: function( data ) {
592                     active_datatable.row( a.closest('tr') ).remove().draw();
593                     UpdateTabCounts();
594                     activateBatchActions( active_tab );
595                 },
596                 dataType: 'json'
597             });
598         }
599
600         function SetPending( id, a ) {
601             var table_row = a.closest('tr');
602             table_row.find('.ar-set-pending-request').remove();
603             table_row.find('input[type="checkbox"]').prop('checked', false);
604             a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
605             $.ajax({
606                 type: "POST",
607                 url: '/cgi-bin/koha/svc/article_request',
608                 data: {
609                     action: 'open',
610                     id: id,
611                 },
612                 success: function( data ) {
613                     $("img.spinner").remove();
614                     requested_datatable.row( table_row ).remove().draw();
615                     pending_datatable.row.add( table_row ).draw();
616                     UpdateTabCounts();
617                     activateBatchActions( active_tab );
618                 },
619                 dataType: 'json'
620             });
621         }
622
623         function Process( id, a ) {
624             var table_row = a.closest('tr');
625             var table = a.closest('table');
626             var orig_datatable = table.attr('id')==='article-requests-pending-table'?pending_datatable:requested_datatable;
627             table_row.find('.ar-process-request').remove();
628             table_row.find('input[type="checkbox"]').prop('checked', false);
629
630             a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
631             $.ajax({
632                 type: "POST",
633                 url: '/cgi-bin/koha/svc/article_request',
634                 data: {
635                     action: 'process',
636                     id: id,
637                 },
638                 success: function( data ) {
639                     $("img.spinner").remove();
640                     orig_datatable.row( table_row ).remove().draw();
641                     processing_datatable.row.add( table_row ).draw();
642                     UpdateTabCounts();
643                     activateBatchActions( active_tab );
644                 },
645                 dataType: 'json'
646             });
647         }
648
649         function Complete( id, a ) {
650             // if it is a scan, check if urls field is filled
651             var urlspan = $('span#url_'+id);
652             if( urlspan.length>0 && urlspan.text() === '' ) {
653                 alert( _("Please fill URL before completing request.") );
654                 return;
655             }
656             a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
657             $.ajax({
658                 type: "POST",
659                 url: '/cgi-bin/koha/svc/article_request',
660                 data: {
661                     action: 'complete',
662                     id: id,
663                 },
664                 success: function( data ) {
665                     active_datatable.row( a.closest('tr') ).remove().draw();
666                     UpdateTabCounts();
667                     activateBatchActions( active_tab );
668                 },
669                 dataType: 'json'
670             });
671         }
672
673         function UpdateTabCounts() {
674             $("#ar_requested_count").html( requested_datatable.rows().count() );
675             $("#ar_pending_count").html( pending_datatable.rows().count() );
676             $("#ar_processing_count").html( processing_datatable.rows().count() );
677         }
678
679         function EditURLs(id) {
680             var urls = $('span#url_'+ id).text();
681             $('#myModal textarea').val(urls);
682             $('#myModal textarea').attr('ar_id', id);
683             $('#myModal').modal('show');
684         }
685
686         function SaveURLs(newurl) {
687             var id = $('#myModal textarea').attr('ar_id');
688             $('span#url_'+ id).text(newurl);
689             if(newurl)
690                 $('span#url_yesno_'+id).text(_("Yes"));
691             else
692                 $('span#url_yesno_'+id).text(_("No"));
693
694             $.ajax({
695                 type: "POST",
696                 url: '/cgi-bin/koha/svc/article_request',
697                 data: { action: 'update_urls', id: id, urls: newurl },
698                 dataType: 'json',
699                 error: function() { alert('Error: Saving URL failed!'); },
700                 success: function(data) { if(!data.success) alert('Saving URL failed!'); },
701             });
702         }
703     </script>
704 [% END %]
705
706 [% INCLUDE 'intranet-bottom.inc' %]