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