Bug 13952: Import and export authority types
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / authtypes.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 <title>
6 [% IF op == 'add_form' %]
7     [% IF authority_type.authtypecode.defined %]
8         Modify authority type
9     [% ELSE %]
10         New authority type
11     [% END %] &rsaquo; [% ELSIF op == 'delete_confirm' %]
12     Confirm deletion of authority type &rsaquo; [% END %]
13 Authority types &rsaquo; Administration &rsaquo; Koha
14 </title>
15 [% INCLUDE 'doc-head-close.inc' %]
16 </head>
17
18 <body id="admin_authtypes" class="admin">
19 [% INCLUDE 'header.inc' %]
20 [% INCLUDE 'prefs-admin-search.inc' %]
21
22 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
23     <ol>
24         <li>
25             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
26         </li>
27         <li>
28             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
29         </li>
30
31         [% IF op == 'add_form' %]
32             <li>
33                 <a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a>
34             </li>
35             <li>
36                 <a href="#" aria-current="page">
37                     [% IF authority_type.authtypecode.defined %]
38                         Modify
39                     [% ELSE %]
40                         New
41                     [% END %] Authority type
42                 </a>
43             </li>
44
45         [% ELSIF op == 'delete_confirm' %]
46             <li>
47                 <a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a>
48             </li>
49             <li>
50                 <a href="#" aria-current="page">
51                     Confirm deletion of authority type
52                 </a>
53             </li>
54
55         [% ELSE %]
56             <li>
57                 <a href="#" aria-current="page">Authority types</a>
58             </li>
59         [% END %]
60     </ol>
61 </nav>
62
63 <div class="main container-fluid">
64     <div class="row">
65         <div class="col-sm-10 col-sm-push-2">
66             <main>
67
68 [% FOR m IN messages %]
69     <div class="dialog [% m.type | html %]">
70         [% SWITCH m.code %]
71         [% CASE 'error_on_update' %]
72             An error occurred when updating this authority type. Perhaps it already exists.
73         [% CASE 'error_on_insert' %]
74             An error occurred when adding this authority type. The authority type code might already exist.
75         [% CASE 'error_on_delete' %]
76             An error occurred when deleting this authority type. Check the logs.
77         [% CASE 'success_on_update' %]
78             Authority type updated successfully.
79         [% CASE 'success_on_insert' %]
80             Authority type added successfully.
81         [% CASE 'success_on_delete' %]
82             Authority type deleted successfully.
83         [% CASE %]
84             [% m.code | html %]
85         [% END %]
86     </div>
87 [% END %]
88
89
90
91 [% IF op == 'add_form' %]
92     <form action="/cgi-bin/koha/admin/authtypes.pl" name="Aform" method="post" class="validated">
93         <fieldset class="rows">
94             <legend>
95                 [% IF authority_type.authtypecode.defined %]
96                     Modify authority type
97                 [% ELSE %]
98                     New authority type
99                 [% END %]
100             </legend>
101             <ol>
102                 <li>
103                     [% IF authority_type.authtypecode.defined %]
104                             <span class="label">Authority type</span>
105                             <input type="hidden" name="op" value="add_validate" />
106                             <input type="hidden" name="checked" value="0" />
107                             <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode | html %]" />[% authority_type.authtypecode | html %]
108                     [% ELSE %]
109                             <div class="hint">10 characters maximum</div>
110                             <label for="authtypecode" class="required">Authority type: </label>
111                             <input id="authtypecode" type="text" class="required" required="required" name="authtypecode" size="20" maxlength="10" />
112                             <span class="required">Required</span>
113                     [% END %]
114                 </li>
115                 <li>
116                     <label for="authtypetext" class="required">Description: </label>
117                     <input type="text" id="authtypetext" name="authtypetext" size="40" maxlength="80" value="[% authority_type.authtypetext | html %]" class="required" required="required" />
118                     <span class="required">Required</span>
119                 </li>
120                 <li>
121                     <label for="summary">Summary: </label>
122                     <textarea id="summary" name="summary" cols="55" rows="7">[% authority_type.summary | html %]</textarea>
123                 </li>
124                 <li>
125                     <div class="hint">Note: for 'Authority field to copy', enter the authority field that should be copied from the authority record to the bibliographic record. E.g., in MARC21, field 100 in the authority record should be copied to field 100 in the bibliographic record</div>
126                     <label for="auth_tag_to_report">Authority field to copy: </label>
127                     <input type="text" id="auth_tag_to_report" name="auth_tag_to_report" size="5" maxlength="3" value="[% authority_type.auth_tag_to_report | html %]" />
128                     <input type="hidden" name="op" value="add_validate" />
129                     [% IF authority_type.authtypecode.defined %]
130                         <input type="hidden" name="is_a_modif" value="1" />
131                     [% END %]
132                 </li>
133             </ol>
134         </fieldset>
135         <fieldset class="action">
136             <input type="submit" value="Submit" />
137             <a class="cancel" href="/cgi-bin/koha/admin/authtypes.pl">Cancel</a>
138         </fieldset>
139     </form>
140 [% END %]
141
142 [% IF op == 'delete_confirm' %]
143     <div class="dialog alert">
144         [% IF authorities_using_it %]
145             <h3>This authority type cannot be deleted</h3>
146             <p>This record is used <strong>[% authorities_using_it | html %]</strong> times</p>
147             <a class="cancel" href="/cgi-bin/koha/admin/authtypes.pl">Back to the list</a>
148         [% ELSE %]
149             <h3>Confirm deletion of authority structure definition for <span class="ex">'[% authority_type.authtypetext | html %]' ([% authority_type.authtypecode | html %])</span></h3>
150             <form action="/cgi-bin/koha/admin/authtypes.pl" method="post">
151                 <input type="hidden" name="op" value="delete_confirmed" />
152                 <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode | html %]" />
153                 <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
154             </form>
155             <form action="/cgi-bin/koha/admin/authtypes.pl" method="get">
156                 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
157             </form>
158         [% END %]
159     </div>
160 [% END %]
161
162 [% IF op == 'list' %]
163     <div id="toolbar" class="btn-toolbar">
164         <a id="authtype" class="btn btn-default" href="/cgi-bin/koha/admin/authtypes.pl?op=add_form"><i class="fa fa-plus"></i> New authority type</a>
165     </div>
166
167     <h1>Authority types</h1>
168     <p>Define authority types, then authority MARC structure in the same way you define itemtypes and bibliographic MARC tag structure. Authority values are managed through plugins</p>
169     <table id="authtypes">
170         <thead>
171         <tr>
172             <th>Code</th>
173             <th>Description</th>
174             <th>Summary</th>
175             <th>Auth field copied</th>
176             <th>&nbsp;</th>
177         </tr>
178         </thead>
179         <tbody>
180         [% FOREACH authority_type IN authority_types %]
181             <tr>
182                 <td>[% authority_type.authtypecode | html %]</td>
183                 <td>[% authority_type.authtypetext | html %]</td>
184                 <td>[% authority_type.summary | html %]</td>
185                 <td>[% authority_type.auth_tag_to_report | html %]</td>
186                 <td>
187                   <div class="btn-group dropup">
188                     <a class="btn btn-default btn-xs dropdown-toggle" id="authtypeactions[% authority_type.authtypecode | html %]" role="button" data-toggle="dropdown" href="#">
189                       Actions <b class="caret"></b></a>
190                     <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="authtypeactions[% authority_type.authtypecode | html %]">
191                       <li><a href="auth_tag_structure.pl?authtypecode=[% authority_type.authtypecode | uri %]" class="button parameters"><i class="fa fa-eye"></i> MARC structure</a></li>
192                       <li><a href="/cgi-bin/koha/admin/authtypes.pl?op=add_form&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-pencil"></i> Edit</a></li>
193                       [% IF authority_type.authtypecode %]<li><a href="/cgi-bin/koha/admin/authtypes.pl?op=delete_confirm&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-trash"></i> Delete</a></li>[% END %]
194                       <!-- Button to trigger modal -->
195                       <li><a href="#" data-toggle="modal" data-target="#exportModal_[% authority_type.authtypecode %][% loop.count %]" title="Export authority type (fields, subfields) to a spreadsheet file (.csv, .xml, .ods)"><i class="fa fa-upload"></i> Export</a></li>
196                       <!-- Button to trigger modal -->
197                       <li><a href="#" data-toggle="modal" data-target="#importModal_[% authority_type.authtypecode %][% loop.count %]" title="Import authority type (fields, subfields) from a spreadsheet file (.csv, .xml, .ods)"><i class="fa fa-download"></i> Import</a></li>
198                     </ul>
199                   </div>
200
201                   <!-- Modal for export -->
202                   <div class="modal" id="exportModal_[% authority_type.authtypecode %][% loop.count %]" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_[% authority_type.authtypecode %][% loop.count %]" aria-hidden="true">
203                       <div class="modal-dialog">
204                           <div class="modal-content">
205                               <div class="modal-header">
206                                   <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
207                                   <h3 id="exportLabelexportModal_[% authority_type.authtypecode %][% loop.count %]">Export [% authority_type.authtypetext %] authority type</h3>
208                               </div>
209                               <form action="import_export_authtype.pl" name="form_[% authority_type.authtypecode %]" method="get" target="_blank" class="form_export">
210                                   <div class="modal-body">
211                                       <fieldset>
212                                           <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />
213                                           <p><label for="csv_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="csv" id="csv_type_export_[% authority_type.authtypecode %][% loop.count %]" checked="checked" /> Export to CSV spreadsheet</label></p>
214                                           <p><label for="xml_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="excel" id="xml_type_export_[% authority_type.authtypecode %][% loop.count %]" /> Export to Excel with XML format, compatible with OpenOffice/LibreOffice as well</label></p>
215                                           <p><label for="ods_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="ods" id="ods_type_export_[% authority_type.authtypecode %][% loop.count %]" /> Export to OpenDocument spreadsheet format</label></p>
216                                       </fieldset>
217                                   </div>
218                                   <div class="modal-footer">
219                                       <button type="submit" class="btn btn-default">Export</button>
220                                       <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Cancel</button>
221                                   </div>
222                               </form>
223                           </div>
224                       </div>
225                   </div>
226
227                   <!-- Modal for import -->
228                   <div class="modal" id="importModal_[% authority_type.authtypecode %][% loop.count %]" tabindex="-1" role="dialog" aria-labelledby="importLabelexportModal_[% authority_type.authtypecode %][% loop.count %]" aria-hidden="true">
229                       <div class="modal-dialog">
230                           <div class="modal-content">
231                               <div class="modal-header">
232                                   <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
233                                   <h3 id="importLabelexportModal_[% authority_type.authtypecode %][% loop.count %]">Import [% authority_type.authtypecode %] authority type (fields and subfields) from a spreadsheet file (.csv, .xml, .ods)</h3>
234                               </div>
235                               <form action="/cgi-bin/koha/admin/import_export_authtype.pl" name="form_i_[% authority_type.authtypecode %]" id="form_i_[% authority_type.authtypecode %]" method="post" enctype="multipart/form-data" class="form_import">
236                                   <div class="modal-body">
237                                       <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />
238                                       <input type="hidden" name="action" value="import" />
239                                       <p><label for="file_import_[% authority_type.authtypecode %]">Upload file:</label> <input type="file" name="file_import_[% authority_type.authtypecode %]" id="file_import_[% authority_type.authtypecode %]" class="input_import" /></p>
240                                       <div id="importing_[% authority_type.authtypecode %]" style="display:none" class="importing"><img src="[% interface %]/[% theme %]/img/loading-small.gif" alt="" /><span class="importing_msg"></span></div>
241                                   </div>
242                                   <div class="modal-footer">
243                                       <button type="submit" class="btn btn-default">Import</button>
244                                       <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Close</button>
245                                   </div>
246                               </form>
247                           </div>
248                       </div>
249                   </div>
250                 </td>
251             </tr>
252         [% END %]
253         <tbody>
254     </table>
255 [% END %]
256
257             </main>
258         </div> <!-- /.col-sm-10.col-sm-push-2 -->
259
260         <div class="col-sm-2 col-sm-pull-10">
261             <aside>
262                 [% INCLUDE 'admin-menu.inc' %]
263             </aside>
264         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
265      </div> <!-- /.row -->
266
267 [% MACRO jsinclude BLOCK %]
268     [% INCLUDE 'datatables.inc' %]
269     [% Asset.js("js/admin-menu.js") | $raw %]
270     <script>
271         var importing = false;
272
273         $(document).ready(function() {
274             $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, {
275                 "aoColumnDefs": [
276                     { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
277                     { "aTargets": [ 0, 1 ], "sType": "natural" },
278                 ],
279                 "sPaginationType": "full"
280             }));
281             $("#authtypecode").on("blur",function(){
282                 toUC(this);
283             });
284
285             $("body").css("cursor", "auto");
286             $('.import_export_options').hide();
287             $('a.import_export_fw').click(function() {
288                 if (!importing) {
289                     $('.import_export_options').hide();
290                     $(this).next().show('slide');
291                 }
292                 return false;
293             });
294
295             $('.import_export_close').click(function() {
296                 if (!importing) {
297                     $('.import_export_options').fadeOut('fast');
298                     $("body").css("cursor", "auto");
299                     return false;
300                 }
301             });
302             $('.input_import').val("");
303
304             var matches = new RegExp("\\?error_import_export=(.+)$").exec(window.location.search);
305             if (matches && matches.length > 1) {
306                 alert(_("Error importing the authority type %s").format(decodeURIComponent(matches[1])));
307             }
308
309             $('input.input_import').change( function() {
310                 var filename = $(this).val();
311                 if ( ! /(?:\.csv|\.ods|\.xml)$/.test(filename)) {
312                     $(this).css("background-color","yellow");
313                     alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file."));
314                     $(this).val("");
315                     $(this).css("background-color","white");
316                 }
317             });
318             $('form.form_export').submit(function() {
319                 $('.modal').modal("hide");
320                 return true;
321             });
322             $('form.form_import').submit(function() {
323                 var id = $(this).attr('id');
324                 var obj = $('#' + id + ' input:file');
325                 if (/(?:\.csv|\.ods|\.xml)$/.test(obj.val())) {
326                     if (confirm(_("Do you really want to import the authority type fields and subfields? This will overwrite the current configuration. For safety reasons please use the export option to make a backup"))) {
327                         var authtypecode = $('#' + id + ' input:hidden[name=authtypecode]').val();
328                         $('#importing_' + authtypecode).find("span").html(_("Importing to authority type: %s. Importing from file: %s").format("<strong>" + authtypecode + "</strong>", "<i>" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "</i>"));
329                         if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
330                             var timestamp = new Date().getTime();
331                             $('#importing_' + authtypecode).find("img").attr('src', '[% interface %]/[% theme %]/img/loading-small.gif' + '?' +timestamp);
332                         }
333                         $('#importing_' + authtypecode).css('display', 'block');
334                         if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
335                         importing = true;
336                         $(".modal-footer,.closebtn").hide();
337                         return true;
338                     } else {
339                         return false;
340                     }
341                 }
342                 obj.css("background-color","yellow");
343                 alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file."));
344                 obj.val("");
345                 obj.css("background-color","white");
346                 return false;
347             });
348         });
349     </script>
350 [% END %]
351 [% INCLUDE 'intranet-bottom.inc' %]