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