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