Bug 32721: (QA follow up) - fix QA issues
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / branches.tt
1 [% USE Koha %]
2 [% USE raw %]
3 [% USE Asset %]
4 [% USE TablesSettings %]
5 [%- USE KohaSpan -%]
6 [% PROCESS 'i18n.inc' %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 [% IF library %][% SET OpacLibraryInfo = library.opac_info( lang => lang ) %][% END %]
10
11 <title>[% FILTER collapse %]
12     [% IF op == 'add_form' %]
13         [% IF library %]
14             [% tx("Modify library '{library}'", { library = library.branchcode }) | html %]
15         [% ELSE %]
16             [% t("New library") | html %]
17         [% END %] &rsaquo;
18     [% ELSIF op == 'delete_confirm' %]
19         [% tx("Confirm deletion of library '{library}'", { library = library.branchcode }) | html %] &rsaquo;
20     [% END %]
21     [% t("Libraries") | html %] &rsaquo;
22     [% t("Administration") | html %] &rsaquo;
23     [% t("Koha") | html %]
24 [% END %]</title>
25 [% INCLUDE 'doc-head-close.inc' %]
26 [% Asset.css("lib/codemirror/codemirror.min.css") | $raw %]
27 [% Asset.css("lib/codemirror/lint.min.css") | $raw %]
28 </head>
29
30 <body id="admin_branches" class="admin">
31 [% WRAPPER 'header.inc' %]
32     [% INCLUDE 'prefs-admin-search.inc' %]
33 [% END %]
34
35 [% WRAPPER 'sub-header.inc' %]
36     [% WRAPPER breadcrumbs %]
37        [% WRAPPER breadcrumb_item %]
38             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
39         [% END %]
40
41         [% IF op == 'add_form' || op == 'delete_confirm' || op == 'view' %]
42             [% WRAPPER breadcrumb_item %]
43                 <a href="/cgi-bin/koha/admin/branches.pl">Libraries</a>
44             [% END %]
45         [% ELSE %]
46             [% WRAPPER breadcrumb_item bc_active= 1 %]
47                 <span>Libraries</span>
48             [% END %]
49         [% END %]
50
51         [% IF op == 'add_form'  %]
52             [% IF library %]
53                 [% WRAPPER breadcrumb_item bc_active= 1 %]
54                     [% tx("Modify library '{library}'", { library = library.branchcode }) | html %]
55                 [% END %]
56             [% ELSE %]
57                [% WRAPPER breadcrumb_item bc_active= 1 %]
58                     <span>New library</span>
59                 [% END %]
60             [% END %]
61
62         [% ELSIF op == 'delete_confirm' %]
63             [% WRAPPER breadcrumb_item bc_active= 1 %]
64                 [% tx("Confirm deletion of library '{library}'", { library = library.branchcode }) | html %]
65             [% END %]
66
67         [% ELSIF op == 'view' %]
68             [% WRAPPER breadcrumb_item bc_active= 1 %]
69                 [% library.branchname | html %]
70             [% END %]
71
72         [% END %]
73     [% END #/ WRAPPER breadcrumbs %]
74 [% END #/ WRAPPER sub-header.inc %]
75
76 <div class="main container-fluid">
77     <div class="row">
78         <div class="col-sm-10 col-sm-push-2">
79             <main>
80
81 [% FOREACH m IN messages %]
82     <div class="dialog [% m.type | html %]">
83         [% SWITCH m.code %]
84         [% CASE 'error_on_update' %]
85             <span>An error occurred when updating this library. Perhaps it already exists.</span>
86         [% CASE 'error_on_insert' %]
87             <span>An error occurred when adding this library. The branchcode might already exist.</span>
88         [% CASE 'error_on_delete' %]
89             <span>An error occurred when deleting this library. Check the logs.</span>
90         [% CASE 'success_on_update' %]
91             <span>Library updated successfully.</span>
92         [% CASE 'success_on_insert' %]
93             <span>Library added successfully.</span>
94         [% CASE 'success_on_delete' %]
95             <span>Library deleted successfully.</span>
96         [% CASE 'cannot_delete_library' %]
97             <span>This library cannot be deleted. Patrons or items are still using it</span>
98             [% IF m.data.patrons_count and m.data.items_count %]
99                 <span>([% m.data.patrons_count | html %] patrons and [% m.data.items_count | html %] items).</span>
100             [% ELSIF m.data.patrons_count %]
101                 <span>([% m.data.patrons_count | html %] patrons).</span>
102             [% ELSIF m.data.items_count %]
103                 <span>([% m.data.items_count | html %] items).</span>
104             [% END %]
105         [% CASE %]
106             <span>[% m.code | html %]</span>
107         [% END %]
108     </div>
109 [% END %]
110
111 [% IF op == 'list' || op == 'view' %]
112     <div id="toolbar" class="btn-toolbar">
113         <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>
114         [% IF op == 'view' && library %]
115             <a class="btn btn-default" id="editbranch" href="/cgi-bin/koha/admin/branches.pl?op=add_form&branchcode=[% library.branchcode | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit library</a>
116         [% END %]
117     </div>
118 [% END %]
119
120 [% IF op == 'add_form' %]
121     <h1>
122         [% IF library %]
123             [% tx("Modify library '{library}'", { library = library.branchcode }) | html %]
124         [% ELSE %]
125             New library
126         [% END %]
127     </h1>
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                     [% IF library %]
149                         <input type="text" name="branchname" id="branchname" size="80" value="[% library.branchname | html %]" class="required focus" required="required" />
150                     [% ELSE %]
151                         <input type="text" name="branchname" id="branchname" size="80" value="[% library.branchname | html %]" class="required" required="required" />
152                     [% END %]
153                     <span class="required">Required</span>
154                 </li>
155             </ol>
156         </fieldset>
157         [% IF categories %]
158             <fieldset class="rows"><legend>Group(s):</legend>
159                 <ol>
160                     [% FOREACH category IN categories %]
161                         <li>
162                             <label for="[% category.categorycode | html %]">[% category.categoryname | html %]: </label>
163                             [% IF category and selected_categorycodes.grep(category.categorycode).size %]
164                                 <input type="checkbox" id="[% category.categorycode | html %]" name="selected_categorycode_[% category.categorycode | html %]" checked="checked" />
165                             [% ELSE %]
166                                 <input type="checkbox" id="[% category.categorycode | html %]" name="selected_categorycode_[% category.categorycode | html %]" />
167                             [% END %]
168                             <div class="hint">[% category.codedescription | html %]</div>
169                         </li>
170                     [% END %]
171                 </ol>
172             </fieldset>
173         [% END %]
174         <fieldset class="rows">
175             <ol>
176                 <li><label for="branchaddress1">Address line 1: </label><input type="text" name="branchaddress1" id="branchaddress1" size="60" value="[% library.branchaddress1 | html %]" /></li>
177                 <li><label for="branchaddress2">Address line 2: </label><input type="text" name="branchaddress2" id="branchaddress2" size="60" value="[% library.branchaddress2 | html %]" /></li>
178                 <li><label for="branchaddress3">Address line 3: </label><input type="text" name="branchaddress3" id="branchaddress3" size="60" value="[% library.branchaddress3 | html %]" /></li>
179                 <li><label for="branchcity">City: </label><input type="text" name="branchcity" id="branchcity" size="60" value="[% library.branchcity | html %]" /></li>
180                 <li><label for="branchstate">State: </label><input type="text" name="branchstate" id="branchstate" size="60" value="[% library.branchstate | html %]" /></li>
181                 <li><label for="branchzip">ZIP/Postal code: </label><input type="text" name="branchzip" id="branchzip"  size="25" maxlength="25" value="[% library.branchzip | html %]" /></li>
182                 <li><label for="branchcountry">Country: </label><input type="text" name="branchcountry" id="branchcountry" size="60" value="[% library.branchcountry | html %]" /></li>
183                 <li><label for="branchphone">Phone: </label><input type="text" name="branchphone" id="branchphone" size="60" value="[% library.branchphone | html %]" /></li>
184                 <li><label for="branchfax">Fax: </label><input type="text" name="branchfax" id="branchfax" size="60" value="[% library.branchfax | html %]" /></li>
185                 <li><label for="branchemail">Email: </label><input type="text" name="branchemail" id="branchemail" class="email"  size="80" value="[% library.branchemail | html %]" /></li>
186                 [% IF (Koha.Preference('ILLModule')) %]
187                 <li>
188                     <label for="branchillemail">ILL staff email: </label>
189                     <input type="text" name="branchillemail" id="branchillemail" class="email"  size="80" value="[% library.branchillemail | html %]" />
190                     <div class="hint">
191                         [% IF ( CAN_user_parameters_manage_sysprefs ) %]
192                             [% pref_ILLDefaultStaffEmail_link = BLOCK %]<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ILLDefaultStaffEmail">ILLDefaultStaffEmail</a>[% END %]
193                             Default: [% pref_ILLDefaultStaffEmail_link | $raw | $KohaSpan %] system preference
194                         [% ELSE %]
195                             Default: ILLDefaultStaffEmail system preference
196                         [% END %]
197                     </div>
198                 </li>
199                 [% END %]
200                 <li>
201                     <label for="branchreplyto">Reply-To: </label>
202                     <input type="text" name="branchreplyto" id="branchreplyto" class="email"  size="80" value="[% library.branchreplyto | html %]" />
203                     <div class="hint">
204                          [% IF ( CAN_user_parameters_manage_sysprefs ) %]
205                             [% pref_ReplyToDefault_link = BLOCK %]<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ReplyToDefault">ReplyToDefault</a>[% END %]
206                             Default: [% pref_ReplyToDefault_link | $raw | $KohaSpan %] system preference
207                         [% ELSE %]
208                             Default: ReplyToDefault system preference
209                         [% END %]
210                     </div>
211                 </li>
212                 <li>
213                     <label for="branchreturnpath">Return-Path: </label>
214                     <input type="text" name="branchreturnpath" id="branchreturnpath" class="email"  size="80" value="[% library.branchreturnpath | html %]" />
215                     <div class="hint">
216                          [% IF ( CAN_user_parameters_manage_sysprefs ) %]
217                             [% pref_ReturnpathDefault_link = BLOCK %]<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ReturnpathDefault">ReturnpathDefault</a>[% END %]
218                             Default: [% pref_ReturnpathDefault_link | $raw | $KohaSpan %] system preference
219                         [% ELSE %]
220                             Default: ReturnpathDefault system preference
221                         [% END %]
222                     </div>
223                 </li>
224                 <li><label for="smtp_server">SMTP server: </label>
225                     <select name="smtp_server" id="smtp_server">
226                     [% IF library AND library.smtp_server.is_system_default %]
227                         <option value="*" selected="selected">Default</option>
228                     [% ELSE %]
229                         <option value="*">Default</option>
230                     [% END %]
231                     [% FOREACH smtp_server IN smtp_servers %]
232                         [% IF library AND smtp_server.id == library.smtp_server.id %]
233                             <option value="[% smtp_server.id | html %]" selected="selected">[% smtp_server.name | html %]</option>
234                         [% ELSE %]
235                             <option value="[% smtp_server.id | html %]">[% smtp_server.name | html %]</option>
236                         [% END %]
237                     [% END %]
238                     </select>
239                 </li>
240                 <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl"  size="80" value="[% library.branchurl | html %]" class="url" /></li>
241                 <li><label for="opac_info">OPAC info: </label>
242                     [% IF OpacLibraryInfo %]<!-- opac_info -->
243                         <div>[% OpacLibraryInfo.content | $raw %]</div>
244                         <div class="hint"><a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations&op=add_form&id=[% OpacLibraryInfo.id | $raw %]&editmode=wysiwyg" target="_blank">Edit HTML content</a></div>
245                     [% ELSE %]
246                         <a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations&op=add_form&editmode=wysiwyg" target="_blank">Add HTML content</a>
247                     [% END %]
248                 </li>
249                 <li>
250                     <label for="branchip">IP: </label>
251                     <input type="text" name="branchip" id="branchip"  size="15" maxlength="15" value="[% library.branchip | html %]" />
252                     <div class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</div>
253                 </li>
254                 <li>
255                     <label for="marcorgcode">MARC organization code</label>
256                     <input type="text" name="marcorgcode" id="marcorgcode" size="16" maxlength="16" value="[% library.marcorgcode | html %]" />
257                     <div class="hint">
258                         [% IF ( CAN_user_parameters_manage_sysprefs ) %]
259                             [% pref_MARCOrgCode_link = BLOCK %]<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=MARCOrgCode">MARCOrgCode</a>[% END %]
260                             If not filled in defaults to system preference [% pref_MARCOrgCode_link | $raw | $KohaSpan %].
261                         [% ELSE %]
262                             If not filled in defaults to system preference MARCOrgCode.
263                         [% END %]
264                         You can obtain your code from <a href="http://www.loc.gov/marc/organizations/orgshome.html" target="_blank">Library of Congress</a>.
265                     </div>
266                 </li>
267                 <li><label for="branchnotes">Notes: </label><input type="text" name="branchnotes" id="branchnotes" size="80" value="[% library.branchnotes | html %]" /></li>
268                 <li><label for="pickup_location">Pickup location: </label>
269                     <select name="pickup_location" id="pickup_location">
270                         [% IF !library || library.pickup_location == 1 %]
271                         <option value="1" selected="selected">Yes</option>
272                         <option value="0">No</option>
273                         [% ELSE %]
274                         <option value="1">Yes</option>
275                         <option value="0" selected="selected">No</option>
276                         [% END %]
277                     </select>
278                 </li>
279                 <li><label for="public">Public: </label>
280                     <select name="public" id="public">
281                         [% IF !library || library.public == 1 %]
282                         <option value="1" selected="selected">Yes</option>
283                         <option value="0">No</option>
284                         [% ELSE %]
285                         <option value="1">Yes</option>
286                         <option value="0" selected="selected">No</option>
287                         [% END %]
288                     </select>
289                     <div class="hint">Set to 'yes' to show this library as a search option and on the libraries page in the OPAC.</div>
290                 </li>
291                 <li>
292                     <label for="UserJS">UserJS: </label>
293                     <div style="display:flex; flex-direction:column;">
294                         <a class="expand-textarea" id="expand_userjs" data-target="userjs" data-syntax="javascript" href="#">Click to edit</a>
295                         <textarea style="display:none" name="userjs" id="userjs" class="codemirror" rows="10" cols="40">[% library.userjs | html %]</textarea>
296                         <a class="collapse-textarea" id="collapse_userjs" data-target="userjs" data-syntax="javascript" style="display:none" href="#">Click to collapse</br></a>
297                     </div>
298                 </li>
299                 <li>
300                     <label for="UserCSS">UserCSS: </label>
301                     <div style="display:flex; flex-direction:column;">
302                         <a class="expand-textarea" id="expand_usercss" data-target="usercss" data-syntax="css" href="#">Click to edit</a>
303                         <textarea style="display:none" name="usercss" id="usercss" class="" rows="10" cols="40">[% library.usercss | html %]</textarea>
304                         <a class="collapse-textarea" id="collapse_usercss" data-target="usercss" data-syntax="css" style="display:none" href="#">Click to collapse</br></a>
305                     </div>
306                 </li>
307                 </li>
308             </ol>
309         </fieldset>
310         <fieldset class="action">
311             <input type="submit" class="btn btn-primary" value="Submit" />
312             <a class="cancel" href="/cgi-bin/koha/admin/branches.pl">Cancel</a>
313         </fieldset>
314     </form>
315 [% END %]
316
317 [% IF op == 'delete_confirm' and not ( items_count or patrons_count )%]
318     <div class="dialog alert">
319         <form action="/cgi-bin/koha/admin/branches.pl" method="post">
320             <h1>Are you sure you want to delete [% library.branchname | html %] ([% library.branchcode | html %])?</h1>
321             <input type="hidden" name="op" value="delete_confirmed" />
322             <input type="hidden" name="branchcode" value="[% library.branchcode | html %]" />
323             <input type="hidden" name="branchname" value="[% library.branchname | html %]">
324             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
325         </form>
326         <form action="/cgi-bin/koha/admin/branches.pl" method="get">
327             <button type="submit" class="deny"><i class="fa fa-fw fa-times"></i> No, do not delete</button>
328         </form>
329     </div>
330 [% END %]
331
332 [% IF op == 'list' %]
333     <h1>Libraries</h1>
334     [% IF libraries_count > 0 %]
335     <div class="page-section">
336         <table id="libraries">
337             <thead>
338                 <tr>
339                     <th>Name</th>
340                     <th>Code</th>
341                     <th>Address</th>
342                     <th>MARC organization code</th>
343                     <th>IP</th>
344                     <th>Pickup location</th>
345                     <th>Public</th>
346                     <th>SMTP server</th>
347                     <th data-class-name="actions noExport">Actions</th>
348                 </tr>
349             </thead>
350         </table>
351     </div>
352     [% ELSE %]
353         <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>
354     [% END %]
355 [% END %]
356
357 [% IF op == 'view' && library %]
358     <h1>[% library.branchname | html %]</h1>
359     <div class="center-block row page-section">
360         <div class="col-sm-6">
361             <div class="rows">
362                 <ol>
363                     <li>
364                         <span class="label">Library code: </span>
365                         [% library.branchcode | html %]
366                     </li>
367                     <li>
368                         <span class="label">Name: </span>
369                         [% library.branchname | html %]
370                     </li>
371                     <li>
372                         <span class="label">Category:</span>
373                         [% category.categoryname | html %]
374                     </li>
375                     <li>
376                         <span class="label">Address line 1: </span>
377                         [% library.branchaddress1 | html %]
378                     </li>
379                     <li>
380                         <span class="label">Address line 2: </span>
381                         [% library.branchaddress2 | html %]
382                     </li>
383                     <li>
384                         <span class="label">Address line 3: </span>
385                         [% library.branchaddress3 | html %]
386                     </li>
387                     <li>
388                         <span class="label">City: </span>
389                         [% library.branchcity | html %]
390                     </li>
391                     <li>
392                         <span class="label">State: </span>
393                         [% library.branchstate | html %]
394                     </li>
395                     <li>
396                         <span class="label">ZIP/Postal code: </span>
397                         [% library.branchzip | html %]
398                     </li>
399                     <li>
400                         <span class="label">Country: </span>
401                         [% library.branchcountry | html %]
402                     </li>
403                     <li>
404                         <span class="label">Phone: </span>
405                         [% library.branchphone | html %]
406                     </li>
407                     <li>
408                         <span class="label">Fax: </span>
409                         [% library.branchfax | html %]
410                     </li>
411                 </ol>
412             </div>
413         </div>
414         <div class="col-sm-6">
415             <div class="rows">
416                 <ol>
417                     <li>
418                         <span class="label">Email: </span>
419                         [% IF ( library.branchemail ) %]
420                             <a href="mailto:[% library.branchemail | url %]">[% library.branchemail | html %]</a>
421                         [% END %]
422                     </li>
423                     <li>
424                         <span class="label">ILL staff email: </span>
425                         [% IF ( library.branchillemail ) %]
426                             <a href="mailto:[% library.branchillemail | url %]">[% library.branchillemail | html %]</a>
427                         [% END %]
428                     </li>
429                     <li>
430                         <span class="label">Reply-To: </span>
431                         [% IF ( library.branchreplyto ) %]
432                             <a href="mailto:[% library.branchreplyto | url %]">[% library.branchreplyto | html %]</a>
433                         [% END %]
434                     </li>
435                     <li>
436                         <span class="label">Return-Path: </span>
437                         [% library.branchreturnpath | html %]
438                     </li>
439                     <li>
440                         <span class="label">SMTP server: </span>
441                         [% smtp_server.name | html %]
442                     </li>
443                     <li>
444                         <span class="label">URL: </span>
445                         [% IF ( library.branchurl ) %]
446                             <a href="[% library.branchurl | url %]" target="_blank">[% library.branchurl | html %]</a>
447                         [% END %]
448                     </li>
449                     <li>
450                         <span class="label">IP: </span>
451                         [% library.branchip | html %]
452                     </li>
453                     <li>
454                         <span class="label">MARC organization code</span>
455                         [% library.marcorgcode | html %]
456                     </li>
457                     <li>
458                         <span class="label">Notes: </span>
459                         [% library.branchnotes | html %]
460                     </li>
461                     <li>
462                         <span class="label">Pickup location: </span>
463                         [% IF ( library.pickup_location ) %]
464                             <span>Yes</span>
465                         [% ELSE %]
466                             <span>No</span>
467                         [% END %]
468                     </li>
469                     <li>
470                         <span class="label">Public: </span>
471                         [% IF ( library.public ) %]
472                             <span>Yes</span>
473                         [% ELSE %]
474                             <span>No</span>
475                         [% END %]
476                     </li>
477                 </ol>
478             </div> <!-- /.rows -->
479         </div> <!-- /.col-sm-6 -->
480     </div> <!-- /.row -->
481     [% IF OpacLibraryInfo %]<!-- opac_info -->
482         <div class="row page-section">
483             <div class="col-sm-12">
484                 <h2>OPAC information</h2>
485                 <div>[% OpacLibraryInfo.content | $raw %]</div>
486             </div>
487         </div>
488     [% END %]
489 [% ELSIF op == 'view' %]
490     <div>This library does not exist.</div>
491 [% END %]
492
493             </main>
494         </div> <!-- /.col-sm-10.col-sm-push-2 -->
495
496         <div class="col-sm-2 col-sm-pull-10">
497             <aside>
498                 [% INCLUDE 'admin-menu.inc' %]
499             </aside>
500         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
501      </div> <!-- /.row -->
502
503 [% MACRO jsinclude BLOCK %]
504     [% Asset.js("js/admin-menu.js") | $raw %]
505     [% INCLUDE 'datatables.inc' %]
506     [% INCLUDE 'columns_settings.inc' %]
507     [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
508     [% Asset.js( "lib/codemirror/css.min.js" ) | $raw %]
509     [% Asset.js( "lib/codemirror/javascript.min.js" ) | $raw %]
510     [% Asset.js( "lib/codemirror/xml.min.js" ) | $raw %]
511     [% Asset.js( "lib/codemirror/yaml.min.js" ) | $raw %]
512     [% Asset.js( "lib/codemirror/lint.min.js" ) | $raw %]
513     [% Asset.js( "lib/linters/jshint.min.js" ) | $raw %]
514     [% Asset.js( "lib/linters/htmlhint.min.js" ) | $raw %]
515     [% Asset.js( "lib/linters/csslint.min.js" ) | $raw %]
516     [% Asset.js( "lib/linters/js-yaml.min.js" ) | $raw %]
517     [% Asset.js( "lib/codemirror/html-lint.min.js" ) | $raw %]
518     [% Asset.js( "lib/codemirror/javascript-lint.min.js" ) | $raw %]
519     [% Asset.js( "lib/codemirror/css-lint.min.js" ) | $raw %]
520     [% Asset.js( "lib/codemirror/yaml-lint.min.js" ) | $raw %]
521     [% Asset.css("lib/codemirror/codemirror.css") | $raw %]
522     <style>
523         .CodeMirror {
524             border: 1px solid #EEE;
525             margin: 1em, 1em, 1em, 0;
526             resize: vertical;
527             width: 50em;
528         }
529     </style>
530     <script>
531         var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
532         var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
533         var updated_settings = get_columns_saved_state(saved_table, table_settings);
534
535         $(document).ready(function() {
536
537             var libraries_url = '/api/v1/libraries';
538             var libraries = $("#libraries").kohaTable({
539                 "ajax": {
540                     "url": libraries_url
541                 },
542                 'embed': [ 'smtp_server' ],
543                 '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>',
544                 "stateSave": true,
545                 "columnDefs": [ {
546                     "targets": [0,1,3,4,7,9,10,11,12,13,14,15,16],
547                     "render": function (data, type, row, meta) {
548                         if ( type == 'display' ) {
549                             if ( data != null ) {
550                                 return data.escapeHtml();
551                             }
552                             else {
553                                 return "";
554                             }
555                         }
556                         return data;
557                     }
558                 } ],
559                 "columns": [
560                     {
561                         "data": "name",
562                         "searchable": true,
563                         "orderable": true,
564                         "render": function( data, type, row, meta ) {
565                             return "<a href=\"/cgi-bin/koha/admin/branches.pl?op=view&branchcode=" + encodeURIComponent( row.library_id ) + "\">" + row.name.escapeHtml() + "</a>";
566                         }
567                     },
568                     {
569                         "data": "library_id",
570                         "searchable": true,
571                         "orderable": true
572                     },
573                     {
574                         "data": function( row, type, val, meta ) {
575                             const library_info = [];
576                             if ( row.address1 != null ) library_info.push(row.address1.escapeHtml());
577                             if ( row.address2 != null ) library_info.push(row.address2.escapeHtml());
578                             if ( row.address3 != null ) library_info.push(row.address3.escapeHtml());
579                             // geographical_location = city, state postal_code
580                             const locations = [];
581                             if ( row.city != null ) locations.push(row.city.escapeHtml());
582                             if ( row.state != null ) locations.push(row.state.escapeHtml());
583                             const geographical_location = locations.join(', ');
584                             if ( geographical_location != '' && row.postal_code != null) {
585                                 library_info.push(geographical_location+' '+row.postal_code.escapeHtml());
586                             }
587                             else {
588                                 library_info.push(geographical_location);
589                             }
590                             if ( row.country != null ) library_info.push(row.country.escapeHtml());
591                             if ( row.phone != null ) library_info.push(_("Ph: ") + row.phone.escapeHtml());
592                             if ( row.fax != null ) library_info.push(_("Fax: ") + row.fax.escapeHtml());
593                             if ( row.email != null ) library_info.push('<a href="mailto:'+encodeURIComponent(row.email)+'">'+row.email.escapeHtml()+'</a>');
594                             if ( row.url != null ) library_info.push('<a href="'+encodeURIComponent(row.url)+'">'+row.url.escapeHtml()+'</a>');
595                             if ( row.notes != null ) library_info.push(_("Notes")+': '+row.notes.escapeHtml());
596                             return library_info.join('<br/>');
597                         },
598                         "searchable": false,
599                         "orderable": false
600                     },
601                     {
602                         "data": "marc_org_code",
603                         "searchable": true,
604                         "orderable": true
605                     },
606                     {
607                         "data": "ip",
608                         "searchable": true,
609                         "orderable": true
610                     },
611                     {
612                         "data": "pickup_location",
613                         "searchable": true,
614                         "orderable": true,
615                         "render": function( data, type, row, meta ) {
616                             return (data) ? _("Yes") : _("No");
617                         }
618                     },
619                     {
620                         "data": "public",
621                         "searchable": true,
622                         "orderable": true,
623                         "render": function( data, type, row, meta ) {
624                             return (data) ? _("Yes") : _("No");
625                         }
626                     },
627                     {
628                         "data": "smtp_server",
629                         "render": function( data, type, row, meta ) {
630                             if ( data.smtp_server_id ) {
631                                 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>';
632                             }
633                             else {
634                                 return _("Default");
635                             }
636                         },
637                         "searchable": false,
638                         "visible": true,
639                         "orderable": false
640                     },
641                     {
642                         "data": function( row, type, val, meta ) {
643
644                             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-solid fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>';
645                             result += '<form action="/cgi-bin/koha/admin/branches.pl" method="post">';
646                             result += '<input type="hidden" name="branchcode" value="'+row.library_id.escapeHtml()+'" />'+"\n";
647                             result += '<input type="hidden" name="op" value="delete_confirm" />';
648                             result += '<button type="submit" id="delete_library_'+row.library_id.escapeHtml()+'" class="btn btn-default btn-xs" role="button"><i class="fa fa-trash-can" aria-hidden="true"></i> '+_("Delete")+'</button></form>';
649
650                             return result;
651
652                         },
653                         "searchable": false,
654                         "orderable": false
655                     },
656                     {
657                         "data": "address1",
658                         "searchable": true,
659                         "visible": false,
660                         "orderable": false
661                     },
662                     {
663                         "data": "address2",
664                         "searchable": true,
665                         "visible": false,
666                         "orderable": false
667                     },
668                     {
669                         "data": "address3",
670                         "searchable": true,
671                         "visible": false,
672                         "orderable": false
673                     },
674                     {
675                         "data": "city",
676                         "searchable": true,
677                         "visible": false,
678                         "orderable": false
679                     },
680                     {
681                         "data": "state",
682                         "searchable": true,
683                         "visible": false,
684                         "orderable": false
685                     },
686                     {
687                         "data": "postal_code",
688                         "searchable": true,
689                         "visible": false,
690                         "orderable": false
691                     },
692                     {
693                         "data": "country",
694                         "searchable": true,
695                         "visible": false,
696                         "orderable": false
697                     },
698                     {
699                         "data": function( row, type, val, meta ) {
700                             return ''; // provisional placeholder for opac_info
701                         },
702                         "searchable": false,
703                         "visible": false,
704                         "orderable": false
705                     },
706                     {
707                         "data": "notes",
708                         "searchable": true,
709                         "visible": false,
710                         "orderable": false
711                     }
712                 ]
713             }, updated_settings);
714
715             [% UNLESS library %]
716                 $("#Aform").on("submit", function( event ) {
717                     if ( $("#branchcode").val().match(/\s/) ) {
718                         event.preventDefault();
719                         alert(_("The library code entered contains whitespace characters. Please remove any whitespace characters from the library code"));
720                         return false;
721                     } else {
722                         return true;
723                     }
724                 });
725             [% END %]
726         });
727
728         $( ".expand-textarea" ).on("click", function(e){
729             e.preventDefault();
730             $(this).hide();
731             var target = $(this).data("target");
732             var syntax = $(this).data("syntax");
733             $("#collapse_" + target ).show();
734             if( syntax ){
735                 var editor = CodeMirror.fromTextArea( document.getElementById( target ), {
736                     lineNumbers: true,
737                     mode: syntax,
738                     lineWrapping: true,
739                     viewportMargin: Infinity,
740                     gutters: ["CodeMirror-lint-markers"],
741                     lint: true
742                 });
743                 editor.on("blur", function(){
744                     editor.save();
745                 });
746             } else {
747                 $( target ).show();
748             }
749         });
750
751         $( ".collapse-textarea" ).on("click", function(e){
752             e.preventDefault();
753             $(this).hide();
754             var target = $(this).data("target");
755             var syntax = $(this).data("syntax");
756             $("#expand_" + target ).show();
757             if( syntax ){
758                 var editor = $( "#" + target ).next(".CodeMirror")[0].CodeMirror;
759                 editor.toTextArea();
760             }
761             $( "#" + target ).hide();
762         });
763     </script>
764 [% END %]
765
766 [% INCLUDE 'intranet-bottom.inc' %]