Bug 27455: (follow-up) Switch form JavaScript to focus class
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / branches.tt
1 [% USE Koha %]
2 [% USE raw %]
3 [% USE Asset %]
4 [% SET footerjs = 1 %]
5 [% USE TablesSettings %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>
8 [% IF op == 'add_form' %]
9     [% IF library %]
10         Modify library
11     [% ELSE %]
12         New library [% library.branchcode | html %]
13     [% END %] &rsaquo; [% ELSIF op == 'delete_confirm' %]
14     Confirm deletion of library '[% library.branchcode | html %]' &rsaquo; [% END %]
15 Libraries &rsaquo; Administration &rsaquo; Koha
16 </title>
17 [% INCLUDE 'doc-head-close.inc' %]
18 </head>
19
20 <body id="admin_branches" class="admin">
21 [% INCLUDE 'header.inc' %]
22 [% INCLUDE 'prefs-admin-search.inc' %]
23
24 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
25     <ol>
26         <li>
27             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
28         </li>
29         <li>
30             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
31         </li>
32
33         [% IF op == 'add_form'  %]
34             <li>
35                 <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
36             </li>
37             [% IF library %]
38                 <li>
39                     <a href="#" aria-current="page">
40                         Modify library
41                     </a>
42                 </li>
43             [% ELSE %]
44                 <li>
45                     <a href="#" aria-current="page">
46                         New library [% library.branchcode | html %]
47                     </a>
48                 </li>
49             [% END %]
50
51         [% ELSIF op == 'delete_confirm' %]
52             <li>
53                 <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
54             </li>
55             <li>
56                 <a href="#" aria-current="page">
57                     Confirm deletion of library '[% library.branchcode | html %]'
58                 </a>
59             </li>
60
61         [% ELSE %]
62             <li>
63                 <a href="#" aria-current="page">
64                     Libraries
65                 </a>
66             </li>
67         [% END %]
68     </ol>
69 </nav>
70
71 <div class="main container-fluid">
72     <div class="row">
73         <div class="col-sm-10 col-sm-push-2">
74             <main>
75
76 [% FOREACH m IN messages %]
77     <div class="dialog [% m.type | html %]">
78         [% SWITCH m.code %]
79         [% CASE 'error_on_update' %]
80             An error occurred when updating this library. Perhaps it already exists.
81         [% CASE 'error_on_insert' %]
82             An error occurred when adding this library. The branchcode might already exist.
83         [% CASE 'error_on_delete' %]
84             An error occurred when deleting this library. Check the logs.
85         [% CASE 'success_on_update' %]
86             Library updated successfully.
87         [% CASE 'success_on_insert' %]
88             Library added successfully.
89         [% CASE 'success_on_delete' %]
90             Library deleted successfully.
91         [% CASE 'cannot_delete_library' %]
92             This library cannot be deleted. Patrons or items are still using it
93             [% IF m.data.patrons_count and m.data.items_count %]
94                 ([% m.data.patrons_count | html %] patrons and [% m.data.items_count | html %] items).
95             [% ELSIF m.data.patrons_count %]
96                 ([% m.data.patrons_count | html %] patrons).
97             [% ELSIF m.data.items_count %]
98                 ([% m.data.items_count | html %] items).
99             [% END %]
100         [% CASE 'error_on_update_category' %]
101             An error occurred when updating this library category. Perhaps it already exists.
102         [% CASE 'error_on_insert_category' %]
103             An error occurred when adding this library category. The categorycode might already exist.
104         [% CASE 'error_on_delete_category' %]
105             An error occurred when deleting this library category. Check the logs.
106         [% CASE 'success_on_update_category' %]
107             Library category updated successfully.
108         [% CASE 'success_on_insert_category' %]
109             Library category added successfully.
110         [% CASE 'success_on_delete_category' %]
111             Library category deleted successfully.
112         [% CASE 'cannot_delete_category' %]
113             This library category cannot be deleted. [% m.data.libraries_count | html %] libraries are still using it.
114         [% CASE %]
115             [% m.code | html %]
116         [% END %]
117     </div>
118 [% END %]
119
120 [% IF op == 'list' %]
121     <div id="toolbar" class="btn-toolbar">
122         <a class="btn btn-default" id="newbranch" href="/cgi-bin/koha/admin/branches.pl?op=add_form"><i class="fa fa-plus"></i> New library</a>
123     </div>
124 [% END %]
125
126 [% IF op == 'add_form' %]
127     <h3>[% IF library %]Modify library[% ELSE %]New library[% END %]</h3>
128     <form action="/cgi-bin/koha/admin/branches.pl" id="Aform" name="Aform" class="validated" method="post">
129         <fieldset class="rows">
130             <input type="hidden" name="op" value="add_validate" />
131             [% IF library %]
132                 <input type="hidden" name="is_a_modif" value="1" />
133             [% END %]
134             <ol>
135                 <li>
136                     [% IF library %]
137                         <span class="label">Library code: </span>
138                         <input type="hidden" name="branchcode" value="[% library.branchcode | html %]" />
139                         [% library.branchcode | html %]
140                     [% ELSE %]
141                         <label for="branchcode" class="required">Library code: </label>
142                         <input type="text" name="branchcode" id="branchcode" size="10" maxlength="10" value="[% library.branchcode | html %]" class="required focus" required="required" />
143                         <span class="required">Required</span>
144                     [% END %]
145                 </li>
146                 <li>
147                     <label for="branchname" class="required">Name: </label>
148                     <input type="text" name="branchname" id="branchname" size="80" value="[% library.branchname | html %]" class="required" required="required" />
149                     <span class="required">Required</span>
150                 </li>
151             </ol>
152         </fieldset>
153         [% IF categories %]
154             <fieldset class="rows"><legend>Group(s):</legend>
155                 <ol>
156                     [% FOREACH category IN categories %]
157                         <li>
158                             <label for="[% category.categorycode | html %]">[% category.categoryname | html %]: </label>
159                             [% IF category and selected_categorycodes.grep(category.categorycode).size %]
160                                 <input type="checkbox" id="[% category.categorycode | html %]" name="selected_categorycode_[% category.categorycode | html %]" checked="checked" />
161                             [% ELSE %]
162                                 <input type="checkbox" id="[% category.categorycode | html %]" name="selected_categorycode_[% category.categorycode | html %]" />
163                             [% END %]
164                             <div class="hint">[% category.codedescription | html %]</div>
165                         </li>
166                     [% END %]
167                 </ol>
168             </fieldset>
169         [% END %]
170         <fieldset class="rows">
171             <ol>
172                 <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% library.branchaddress1 | html %]" /></li>
173                 <li><label for="branchaddress2">Address line 2: </label><input type="text" name="branchaddress2" id="branchaddress2" size="60" value="[% library.branchaddress2 | html %]" /></li>
174                 <li><label for="branchaddress3">Address line 3: </label><input type="text" name="branchaddress3" id="branchaddress3" size="60" value="[% library.branchaddress3 | html %]" /></li>
175                 <li><label for="branchcity">City: </label><input type="text" name="branchcity" id="branchcity" size="60" value="[% library.branchcity | html %]" /></li>
176                 <li><label for="branchstate">State: </label><input type="text" name="branchstate" id="branchstate" size="60" value="[% library.branchstate | html %]" /></li>
177                 <li><label for="branchzip">ZIP/Postal code: </label><input type="text" name="branchzip" id="branchzip"  size="25" maxlength="25" value="[% library.branchzip | html %]" /></li>
178                 <li><label for="branchcountry">Country: </label><input type="text" name="branchcountry" id="branchcountry" size="60" value="[% library.branchcountry | html %]" /></li>
179                 <li><label for="branchphone">Phone: </label><input type="text" name="branchphone" id="branchphone" size="60" value="[% library.branchphone | html %]" /></li>
180                 <li><label for="branchfax">Fax: </label><input type="text" name="branchfax" id="branchfax" size="60" value="[% library.branchfax | html %]" /></li>
181                 <li><label for="branchemail">Email: </label><input type="text" name="branchemail" id="branchemail" class="email"  size="80" value="[% library.branchemail | html %]" /></li>
182                 [% IF (Koha.Preference('ILLModule')) %]
183                 <li>
184                     <label for="branchillemail">ILL staff email: </label>
185                     <input type="text" name="branchillemail" id="branchillemail" class="email"  size="80" value="[% library.branchillemail | html %]" />
186                     <div class="hint">
187                         [% IF ( CAN_user_parameters_manage_sysprefs ) %]
188                             Default: <a target="_blank" href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=ILLDefaultStaffEmail">ILLDefaultStaffEmail</a> system preference
189                         [% ELSE %]
190                             Default: ILLDefaultStaffEmail system preference
191                         [% END %]
192                     </div>
193                 </li>
194                 [% END %]
195                 <li>
196                     <label for="branchreplyto">Reply-To: </label>
197                     <input type="text" name="branchreplyto" id="branchreplyto" class="email"  size="80" value="[% library.branchreplyto | html %]" />
198                     <div class="hint">
199                          [% IF ( CAN_user_parameters_manage_sysprefs ) %]
200                             Default: <a target="_blank" href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=ReplyToDefault">ReplyToDefault</a> system preference
201                         [% ELSE %]
202                             Default: ReplyToDefault system preference
203                         [% END %]
204                     </div>
205                 </li>
206                 <li>
207                     <label for="branchreturnpath">Return-Path: </label>
208                     <input type="text" name="branchreturnpath" id="branchreturnpath" class="email"  size="80" value="[% library.branchreturnpath | html %]" />
209                     <div class="hint">
210                          [% IF ( CAN_user_parameters_manage_sysprefs ) %]
211                             Default: <a target="_blank" href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=ReturnpathDefault">ReturnpathDefault</a> system preference
212                         [% ELSE %]
213                             Default: ReturnpathDefault system preference
214                         [% END %]
215                     </div>
216                 </li>
217                 <li><label for="smtp_server">SMTP server: </label>
218                     <select name="smtp_server" id="smtp_server">
219                     [% IF selected_smtp_server.is_system_default %]
220                         <option value="*" selected="selected">Default</option>
221                     [% ELSE %]
222                         <option value="*">Default</option>
223                     [% END %]
224                     [% FOREACH smtp_server IN smtp_servers %]
225                         [% IF smtp_server.id == selected_smtp_server.id %]
226                             <option value="[% smtp_server.id | html %]" selected="selected">[% smtp_server.name | html %]</option>
227                         [% ELSE %]
228                             <option value="[% smtp_server.id | html %]">[% smtp_server.name | html %]</option>
229                         [% END %]
230                     [% END %]
231                     </select>
232                 </li>
233                 <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl"  size="80" value="[% library.branchurl | html %]" class="url" /></li>
234                 <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li>
235                 <li>
236                     <label for="branchip">IP: </label>
237                     <input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" />
238                     <div class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</div>
239                 </li>
240                 <li>
241                     <label for="marcorgcode">MARC organization code</label>
242                     <input type="text" name="marcorgcode" id="marcorgcode" size="16" value="[% library.marcorgcode | html %]" />
243                     <div class="hint">
244                         [% IF ( CAN_user_parameters_manage_sysprefs ) %]
245                             If not filled in defaults to system preference <a target="_blank" href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=MARCOrgCode">MARCOrgCode</a>.
246                         [% ELSE %]
247                             If not filled in defaults to system preference MARCOrgCode.
248                         [% END %]
249                         You can obtain your code from <a href="http://www.loc.gov/marc/organizations/orgshome.html" target="_blank">Library of Congress</a>.
250                     </div>
251                 </li>
252                 <li><label for="branchnotes">Notes: </label><input type="text" name="branchnotes" id="branchnotes" size="80" value="[% library.branchnotes | html %]" /></li>
253                 <li><label for="pickup_location">Pickup location: </label>
254                     <select name="pickup_location" id="pickup_location">
255                         [% IF !library || library.pickup_location == 1 %]
256                         <option value="1" selected="selected">Yes</option>
257                         <option value="0">No</option>
258                         [% ELSE %]
259                         <option value="1">Yes</option>
260                         <option value="0" selected="selected">No</option>
261                         [% END %]
262                     </select>
263                 </li>
264             </ol>
265         </fieldset>
266         <fieldset class="action">
267             <input type="submit" value="Submit" />
268             <a class="cancel" href="/cgi-bin/koha/admin/branches.pl">Cancel</a>
269         </fieldset>
270     </form>
271 [% END %]
272
273 [% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
274     <div class="dialog alert">
275         <form action="/cgi-bin/koha/admin/branches.pl" method="post">
276             <h3>Are you sure you want to delete [% library.branchname | html %] ([% library.branchcode | html %])?</h3>
277             <input type="hidden" name="op" value="delete_confirmed" />
278             <input type="hidden" name="branchcode" value="[% library.branchcode | html %]" />
279             <input type="hidden" name="branchname" value="[% library.branchname | html %]">
280             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
281         </form>
282         <form action="/cgi-bin/koha/admin/branches.pl" method="get">
283             <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
284         </form>
285     </div>
286 [% END %]
287
288 [% IF op == 'list' %]
289     <h3>Libraries</h3>
290     [% IF libraries_count > 0 %]
291         <table id="libraries">
292             <thead>
293                 <tr>
294                     <th>Name</th>
295                     <th>Code</th>
296                     <th>Address</th>
297                     <th>MARC organization code</th>
298                     <th>IP</th>
299                     <th>Pickup location</th>
300                     <th>SMTP server</th>
301                     <th data-class-name="actions noExport">Actions</th>
302                 </tr>
303             </thead>
304         </table>
305     [% ELSE %]
306         <div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">Start defining libraries</a>.</div>
307     [% END %]
308 [% END %]
309
310             </main>
311         </div> <!-- /.col-sm-10.col-sm-push-2 -->
312
313         <div class="col-sm-2 col-sm-pull-10">
314             <aside>
315                 [% INCLUDE 'admin-menu.inc' %]
316             </aside>
317         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
318      </div> <!-- /.row -->
319
320 [% MACRO jsinclude BLOCK %]
321     [% Asset.js("js/admin-menu.js") | $raw %]
322     [% INCLUDE 'datatables.inc' %]
323     [% INCLUDE 'columns_settings.inc' %]
324     [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
325     [% INCLUDE 'str/tinymce_i18n.inc' %]
326     <script>
327         var columns_settings = [% TablesSettings.GetColumns( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
328         $(document).ready(function() {
329
330             var libraries_url = '/api/v1/libraries';
331             var libraries = $("#libraries").api({
332                 "ajax": {
333                     "url": libraries_url
334                 },
335                 'embed': [ 'smtp_server' ],
336                 'emptyTable': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>',
337                 "columnDefs": [ {
338                     "targets": [0,1,3,4,6,8,9,10,11,12,13,14,15],
339                     "render": function (data, type, row, meta) {
340                         if ( type == 'display' ) {
341                             if ( data != null ) {
342                                 return data.escapeHtml();
343                             }
344                             else {
345                                 return "";
346                             }
347                         }
348                         return data;
349                     }
350                 } ],
351                 "columns": [
352                     {
353                         "data": "name",
354                         "searchable": true,
355                         "orderable": true
356                     },
357                     {
358                         "data": "library_id",
359                         "searchable": true,
360                         "orderable": true
361                     },
362                     {
363                         "data": function( row, type, val, meta ) {
364                             const library_info = [];
365                             if ( row.address1 != null ) library_info.push(row.address1.escapeHtml());
366                             if ( row.address2 != null ) library_info.push(row.address2.escapeHtml());
367                             if ( row.address3 != null ) library_info.push(row.address3.escapeHtml());
368                             // geographical_location = city, state postal_code
369                             const locations = [];
370                             if ( row.city != null ) locations.push(row.city.escapeHtml());
371                             if ( row.state != null ) locations.push(row.state.escapeHtml());
372                             const geographical_location = locations.join(', ');
373                             if ( geographical_location != '' && row.postal_code != null) {
374                                 library_info.push(geographical_location+' '+row.postal_code.escapeHtml());
375                             }
376                             else {
377                                 library_info.push(geographical_location);
378                             }
379                             if ( row.country != null ) library_info.push(row.country.escapeHtml());
380                             if ( row.phone != null ) library_info.push(_("Ph: ") + row.phone.escapeHtml());
381                             if ( row.fax != null ) library_info.push(_("Fax: ") + row.fax.escapeHtml());
382                             if ( row.email != null ) library_info.push('<a href="mailto:'+encodeURIComponent(row.email)+'">'+row.email.escapeHtml()+'</a>');
383                             if ( row.url != null ) library_info.push('<a href="'+encodeURIComponent(row.url)+'">'+row.url.escapeHtml()+'</a>');
384                             if ( row.opac_info != null ) library_info.push(_("OPAC Info") + ': <div>'+row.opac_info.escapeHtml()+'</div>');
385                             if ( row.notes != null ) library_info.push(_("Notes")+': '+row.notes.escapeHtml());
386                             return library_info.join('<br/>');
387                         },
388                         "searchable": false,
389                         "orderable": false
390                     },
391                     {
392                         "data": "marc_org_code",
393                         "searchable": true,
394                         "orderable": true
395                     },
396                     {
397                         "data": "ip",
398                         "searchable": true,
399                         "orderable": true
400                     },
401                     {
402                         "data": "pickup_location",
403                         "searchable": true,
404                         "orderable": true,
405                         "render": function( data, type, row, meta ) {
406                             return (data) ? _("Yes") : _("No");
407                         }
408                     },
409                     {
410                         "data": "smtp_server",
411                         "render": function( data, type, row, meta ) {
412                             if ( data.smtp_server_id ) {
413                                 return '<a href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&smtp_server_id='+encodeURIComponent(data.smtp_server_id)+'">'+data.name.escapeHtml()+'</a>';
414                             }
415                             else {
416                                 return _("Default");
417                             }
418                         },
419                         "searchable": false,
420                         "visible": true,
421                         "orderable": false
422                     },
423                     {
424                         "data": function( row, type, val, meta ) {
425
426                             var result = '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?op=add_form&amp;branchcode='+encodeURIComponent(row.library_id)+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>';
427                             result += '<form action="/cgi-bin/koha/admin/branches.pl" method="post">';
428                             result += '<input type="hidden" name="branchcode" value="'+row.library_id.escapeHtml()+'" />'+"\n";
429                             result += '<input type="hidden" name="op" value="delete_confirm" />';
430                             result += '<button type="submit" id="delete_library_'+row.library_id.escapeHtml()+'" class="btn btn-default btn-xs" role="button"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</button></form>';
431
432                             return result;
433
434                         },
435                         "searchable": false,
436                         "orderable": false
437                     },
438                     {
439                         "data": "address1",
440                         "searchable": true,
441                         "visible": false,
442                         "orderable": false
443                     },
444                     {
445                         "data": "address2",
446                         "searchable": true,
447                         "visible": false,
448                         "orderable": false
449                     },
450                     {
451                         "data": "address3",
452                         "searchable": true,
453                         "visible": false,
454                         "orderable": false
455                     },
456                     {
457                         "data": "city",
458                         "searchable": true,
459                         "visible": false,
460                         "orderable": false
461                     },
462                     {
463                         "data": "state",
464                         "searchable": true,
465                         "visible": false,
466                         "orderable": false
467                     },
468                     {
469                         "data": "postal_code",
470                         "searchable": true,
471                         "visible": false,
472                         "orderable": false
473                     },
474                     {
475                         "data": "country",
476                         "searchable": true,
477                         "visible": false,
478                         "orderable": false
479                     },
480                     {
481                         "data": "opac_info",
482                         "searchable": true,
483                         "visible": false,
484                         "orderable": false
485                     },
486                     {
487                         "data": "notes",
488                         "searchable": true,
489                         "visible": false,
490                         "orderable": false
491                     }
492                 ]
493             }, columns_settings);
494
495             [% UNLESS library %]
496                 $("#Aform").on("submit", function( event ) {
497                     if ( $("#branchcode").val().match(/\s/) ) {
498                         event.preventDefault();
499                         alert(_("The library code entered contains whitespace characters. Please remove any whitespace characters from the library code"));
500                         return false;
501                     } else {
502                         return true;
503                     }
504                 });
505             [% END %]
506         });
507
508         tinyMCE.init({
509             branding : false,
510             relative_urls : false,
511             content_css : "[% interface | html %]/[% theme | html %]/css/tinymce.css",
512             menubar : "file edit view insert format tools table",
513             mode : "specific_textareas",
514             plugins : "autoresize table hr link image charmap lists code emoticons",
515             toolbar : [
516                 "formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
517                 "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code visualaid help"
518             ],
519         });
520     </script>
521 [% END %]
522
523 [% INCLUDE 'intranet-bottom.inc' %]