Bug 27945: Add limit article request feature
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / opac-request-article.tt
1 [% USE Koha %]
2 [% USE Branches %]
3 [% USE ItemTypes %]
4 [% USE AdditionalContents %]
5 [% USE raw %]
6 [% INCLUDE 'doc-head-open.inc' %]
7
8 <title>Request article &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% BLOCK cssinclude %][% END %]
11 </head>
12
13 [% INCLUDE 'bodytag.inc' bodyid='opac-request-article' %]
14 [% INCLUDE 'masthead.inc' %]
15
16 [% SET disclaimer = AdditionalContents.get( location => "ArticleRequestsDisclaimerText", lang => lang, library => Branches.GetLoggedInBranchcode ) %]
17
18 <div class="main">
19     <nav aria-label="breadcrumb">
20         <ul class="breadcrumb">
21             <li class="breadcrumb-item">
22                 <a href="/cgi-bin/koha/opac-main.pl">Home</a>
23             </li>
24             <li class="breadcrumb-item">
25                 <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | uri %]">Details for: [% biblio.title | html %]</a>
26             </li>
27             <li class="breadcrumb-item active" aria-current="page">
28                 <a href="#">Request article</a>
29             </li>
30         </ul>
31     </nav>
32
33     <div class="container-fluid maincontent">
34         <div class="row">
35             <div class="col">
36                 [% IF !error_message && biblio.can_article_request( patron ) %]
37                     <h1>Place article request for [% biblio.title | html %]</h1>
38                     [% IF ( disclaimer && !action) %]
39                         <div class="alert alert-warning">
40                             [% PROCESS koha_news_block news => disclaimer %]
41                             <a href="/cgi-bin/koha/opac-request-article.pl?biblionumber=[% biblio.biblionumber | uri %]&amp;action=accept"
42                             class="btn btn-sm btn-primary"><i class="fa fa-check" aria-hidden="true"></i> Accept</a>
43                         </div>
44                     [% ELSE %]
45                         [% SET article_request_type = biblio.article_request_type( patron ) %]
46
47                         [% IF article_request_type == 'yes' %]       [% SET mandatory_fields = Koha.Preference('ArticleRequestsMandatoryFields') %]           [% END %]
48                         [% IF article_request_type == 'bib_only' %]  [% SET mandatory_fields = Koha.Preference('ArticleRequestsMandatoryFieldsRecordOnly') %] [% END %]
49                         [% IF article_request_type == 'item_only' %] [% SET mandatory_fields = Koha.Preference('ArticleRequestsMandatoryFieldsItemOnly') %]   [% END %]
50
51
52                         <form id="place-article-request" method="post" action="/cgi-bin/koha/opac-request-article.pl">
53                             <legend class="sr-only">Place article request</legend>
54                             <input type="hidden" name="action" value="create" />
55                             <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblio.biblionumber | html %]" />
56
57                             <fieldset class="rows">
58                                 <ul>
59                                     <li>
60                                         [% IF mandatory_fields.search('title') %]
61                                             <label for="title" class="required">Title:</label>
62                                             <input type="text" required="required" name="title" id="title" size="50" value="[% title | html %]"/>
63                                         [% ELSE %]
64                                             <label for="title">Title:</label>
65                                             <input type="text" name="title" id="title" size="50" value="[% title | html %]"/>
66                                         [% END %]
67                                     </li>
68
69                                     <li>
70                                         [% IF mandatory_fields.search('author') %]
71                                             <label for="author" class="required">Author:</label>
72                                             <input type="text" required="required" name="author" id="author" size="50" value="[% author | html %]"/>
73                                         [% ELSE %]
74                                             <label for="author">Author:</label>
75                                             <input type="text" name="author" id="author" size="50" value="[% author | html %]"/>
76                                         [% END %]
77                                     </li>
78
79                                     <li>
80                                         [% IF mandatory_fields.search('volume') %]
81                                             <label for="volume" class="required">Volume:</label>
82                                             <input type="text" required="required" name="volume" id="volume" size="50"/>
83                                         [% ELSE %]
84                                             <label for="volume">Volume:</label>
85                                             <input type="text" name="volume" id="volume" size="50"/>
86                                         [% END %]
87                                     </li>
88
89                                     <li>
90                                         [% IF mandatory_fields.search('issue') %]
91                                             <label for="issue" class="required">Issue:</label>
92                                             <input type="text" required="required" name="issue" id="issue" size="50"/>
93                                         [% ELSE %]
94                                             <label for="issue">Issue:</label>
95                                             <input type="text" name="issue" id="issue" size="50"/>
96                                         [% END %]
97                                     </li>
98
99                                     <li>
100                                         [% IF mandatory_fields.search('date') %]
101                                             <label for="date" class="required">Date:</label>
102                                             <input type="text" required="required" name="date" id="date" size="50"/>
103                                         [% ELSE %]
104                                             <label for="date">Date:</label>
105                                             <input type="text" name="date" id="date" size="50"/>
106                                         [% END %]
107                                     </li>
108
109                                     <li>
110                                         [% IF mandatory_fields.search('pages') %]
111                                             <label for="pages" class="required">Pages:</label>
112                                             <input type="text" required="required" name="pages" id="pages" size="50" value="[% pageinfo | html %]"/>
113                                         [% ELSE %]
114                                             <label for="pages">Pages:</label>
115                                             <input type="text" name="pages" id="pages" size="50" value="[% pageinfo | html %]"/>
116                                         [% END %]
117                                     </li>
118
119                                     <li>
120                                         [% IF mandatory_fields.search('chapters') %]
121                                             <label for="chapters" class="required">Chapters:</label>
122                                             <input type="text" required="required" name="chapters" id="chapters" size="50"/>
123                                         [% ELSE %]
124                                             <label for="chapters">Chapters:</label>
125                                             <input type="text" name="chapters" id="chapters" size="50"/>
126                                         [% END %]
127                                     </li>
128
129                                     <li>
130                                         <label for="patron_notes">Notes:</label>
131                                         <input type="text" name="patron_notes" id="patron_notes" size="50"/>
132                                     </li>
133
134                                     <li>
135                                         <label for="format">Format:</label>
136                                         <select name="format" id="format">
137                                             <option value="PHOTOCOPY">Photocopy</option>
138                                             <option value="SCAN">Digital scan</option>
139                                         </select>
140                                     </li>
141
142                                     <li>
143                                         <label for="branchcode">Pickup library:</label>
144                                         <select name="branchcode" id="branchcode" required="required">
145                                             [% FOREACH b IN Branches.all %]
146                                                 [% IF b.branchcode == Branches.GetLoggedInBranchcode %]
147                                                     <option value="[% b.branchcode | html %]" selected="selected">[% b.branchname | html %]</option>
148                                                 [% ELSE %]
149                                                     <option value="[% b.branchcode | html %]">[% b.branchname | html %]</option>
150                                                 [% END %]
151                                             [% END %]
152                                         </select>
153                                     </li>
154                                 </ul>
155                             </fieldset>
156
157                             [% IF article_request_type != 'bib_only' %]
158                                 <table class="copiesrow table table-bordered table-striped">
159                                     <caption>Select a specific item:</caption>
160                                     <thead>
161                                         <tr>
162                                             <th>&nbsp;</th>
163                                             <th>Item type</th>
164                                             <th>Barcode</th>
165                                             <th>Home library</th>
166                                             <th>Call number</th>
167                                             <th>Enumeration</th>
168                                         </tr>
169                                     </thead>
170
171                                     <tbody>
172                                         [% FOREACH item IN biblio.items %]
173                                             [% IF item.can_article_request( patron ) %]
174                                                 <tr>
175                                                     <td>
176                                                         [% IF article_request_type == 'item_only' && !checked %]
177                                                             [% SET checked = 1 %]
178                                                             <input type="radio" name="itemnumber" value="[% item.itemnumber | html %]" checked="checked" />
179                                                         [% ELSE %]
180                                                             <input type="radio" name="itemnumber" value="[% item.itemnumber | html %]" />
181                                                         [% END %]
182                                                     </td>
183                                                     <td>
184                                                         [% ItemTypes.GetDescription( item.itype ) | html %]
185                                                     </td>
186                                                     <td>
187                                                         [% item.barcode | html %]
188                                                     </td>
189                                                     <td>
190                                                         [% Branches.GetName( item.homebranch ) | html %]
191                                                     </td>
192                                                     <td>
193                                                         [% item.itemcallnumber | html %]
194                                                     </td>
195                                                     <td>
196                                                         [% item.enumchron | html %]
197                                                     </td>
198                                                 </tr>
199                                             [% END %]
200                                         [% END %]
201
202                                         [% IF article_request_type != 'item_only' %]
203                                             <tr>
204                                                 <td>
205                                                     <input type="radio" name="itemnumber" value="" checked="checked"/>
206                                                 </td>
207                                                 <td colspan="6">
208                                                     Any item
209                                                 </td>
210                                             </tr>
211                                         [% END %]
212                                     </tbody>
213                                 </table>
214                             [% END %]
215
216                             <input type="submit" class="btn btn-primary" value="Place request" />
217                         </form>
218                     [% END %]
219                 [% ELSIF error_message %]
220                     <h1 class="title">[% biblio.title | html %]</h1>
221                     <div class="alert alert-info">
222                         [% error_message | html %]
223                     </div>
224                 [% ELSE %]
225                     <h1 class="title">[% biblio.title | html %]</h1>
226                     <div class="alert alert-info">
227                         No article requests can be made for this record.
228                     </div>
229                 [% END %]
230             </div> <!-- /.col -->
231         </div> <!-- /.row -->
232     </div> <!-- / .container-fluid -->
233 </div> <!-- / .main -->
234
235 [% INCLUDE 'opac-bottom.inc' %]
236
237 [% BLOCK jsinclude %]
238 <script>
239 $(document).ready( function() {
240     allow_submit = false;
241     $('#place-article-request').on('submit', function( event ){
242         if ( ! allow_submit ) {
243             event.preventDefault();
244
245             [% IF article_request_type == 'item_only' %]
246                 if ( ! $("input:radio[name='itemnumber']").is(":checked") ) {
247                     alert( _("Please select a specific item for this article request.") );
248                     return 0;
249                 }
250             [% END %]
251
252             var mandatory_fields = "[% mandatory_fields | html %]";
253             var m = new Array();
254             if ( mandatory_fields ) m = mandatory_fields.split(",");
255             var f = new Array();
256
257             for (i = 0; i < m.length; i++) {
258                 if ( ! $("#" + m[i]).val() ) {
259                     f.push( m[i] );
260                 }
261             }
262
263             if ( f.length ) {
264                 alert( _("The following fields are required and not filled in: ") + f.join(", ") );
265                 return 0;
266             }
267
268             // Check if all fields are blank
269             if( m.length == 0 && $('#title').val()=='' && $('#author').val()=='' && $('#volume').val()=='' && $('#issue').val()=='' && $('#date').val()=='' && $('#pages').val()=='' && $('#chapters').val()=='' && $('#patron_notes').val()=='' ) {
270                 alert( _("Please fill in at least one field.") );
271                 return 0;
272             }
273
274             allow_submit = true;
275             $('#place-article-request').submit();
276         }
277     });
278
279     // Initialize format(s)
280     var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | $raw %]";
281     if( !supported_formats.match(/PHOTOCOPY/) )
282         $('#format option[value="PHOTOCOPY"]').remove();
283     if( !supported_formats.match(/SCAN/) )
284         $('#format option[value="SCAN"]').remove();
285
286     if( $('#format option').length > 1 ) {
287         // Select first listed format
288         var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
289         $('#format option[value="'+first_format+'"]').attr('selected', true);
290     }
291 });
292 </script>
293 [% END %]