Bug 30952: Staff interface redesign (header)
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / marc-overlay-rules.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% USE Koha %]
5 [% USE KohaSpan %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>MARC overlay rules &rsaquo; Koha &rsaquo; Administration</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9
10 <style>
11     .required {
12         background-color: #C00;
13     }
14 </style>
15
16 </head>
17 <body id="admin_marc-overlay-rules" class="admin">
18 [% WRAPPER 'header.inc' %]
19     [% INCLUDE 'cat-search.inc' %]
20 [% END %]
21
22     [% WRAPPER 'sub-header.inc' %]
23     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
24         <ol>
25             <li>
26                 <a href="/cgi-bin/koha/mainpage.pl"><i class="fa fa-home"></i></a>
27             </li>
28             <li>
29                 <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
30             </li>
31             <li>
32                 <a href="#" aria-current="page">
33                      MARC overlay rules
34                 </a>
35             </li>
36         </ol>
37     </nav>
38     [% END %]
39
40     <div class="main container-fluid">
41         <div class="row">
42             <div class="col-sm-10 col-sm-push-2">
43
44                 <h1>Manage MARC overlay rules</h1>
45
46                 [% FOR m IN messages %]
47                 <div class="dialog [% m.type | html %]">
48                     [% SWITCH m.code %]
49                     [% CASE 'invalid_tag_regexp' %]
50                       <span>Invalid regular expression "[% m.tag | html %]".</span>
51                     [% CASE 'invalid_control_field_actions' %]
52                       <span>Invalid combination of actions for tag [% m.tag | html %]. Control field rules do not allow "Appended: Append" and "Removed: Skip".</span>
53                     [% CASE %]
54                       <span>[% m.code | html %]</span>
55                     [% END %]
56                 </div>
57                 [% END %]
58
59                 [% UNLESS Koha.Preference( 'MARCOverlayRules' ) %]
60                 [% SET pref_MARCOverlayRules_link = '<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=MARCOverlayRules">MARCOverlayRules</a>' %]
61                 <div class="dialog message">
62                     The [%  pref_MARCOverlayRules_link | $raw | $KohaSpan %] preference is not set, don't forget to enable it for rules to take effect.
63                 </div>
64                 [% END %]
65                 [% IF removeConfirm %]
66                 <div class="dialog alert">
67                     <h3>Remove rule?</h3>
68                     <p>Are you sure you want to remove the selected rule(s)?</p>
69
70                     <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="GET">
71                         <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not remove</button>
72                     </form>
73                     <button type="button" class="approve" id="doremove"><i class="fa fa-fw fa-check"></i> Yes, remove</button>
74                 </div>
75                 [% END %]
76
77                 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="POST" id="marc-overlay-rules-form">
78                     <table id="marc-overlay-rules">
79                         <thead><tr>
80                             <th>Rule</th>
81                             <th>Module</th>
82                             <th>Filter</th>
83                             <th>Tag</th>
84                             <th>Preset</th>
85                             <th>Added <i id="info_added" data-toggle="tooltip" title="If a field matching the rule tag only exists in the incoming record" data-placement="right" class="fa fa-info-circle"></i></th>
86                             <th>Appended <i id="info_appended" data-toggle="tooltip" title="If the original record has one or more fields matching with the rule tag, but one or more fields matching the rule tag differ in the incoming record" data-placement="right" class="fa fa-info-circle"></i></th>
87                             <th>Removed <i id="info_removed" data-toggle="tooltip" title="If the original record has a field matching the rule tag, but the matching field is not in the incoming record" data-placement="right" class="fa fa-info-circle"></i></th>
88                             <th>Deleted <i id="info_deleted" data-toggle="tooltip" title="If the original record has fields matching the rule tag, but no fields with this are found in the incoming record" data-placement="right" class="fa fa-info-circle"></i></th>
89                             <th>Actions</th>
90                             <th>&nbsp;</th>
91                         </tr></thead>
92                         [% UNLESS edit %]
93                         <tfoot>
94                             <tr class="rule-new">
95                                 <th>&nbsp;</th>
96                                 <th>
97                                     <select name="module">
98                                         <option value="source">Source</option>
99                                         <option value="categorycode">User category</option>
100                                         <option value="userid">Username</option>
101                                     </select>
102                                 </th>
103                                 <th id="filter-container"></th>
104                                 <th><input type="text" size="5" name="tag"/></th>
105                                 <th>
106                                     <select name="preset">
107                                         <option value="" selected>Custom</option>
108                                         <option value="Protect">Protect</option>
109                                         <option value="Overwrite">Overwrite</option>
110                                         <option value="Add new">Add new</option>
111                                         <option value="Add and append">Add and append</option>
112                                         <option value="Protect from deletion">Protect from deletion</option>
113                                     </select>
114                                 </th>
115                                 <th class="rule-operation-action-edit">
116                                     <select name="add">
117                                         <option value="0">Skip</option>
118                                         <option value="1">Add</option>
119                                     </select>
120                                 </th>
121                                 <th class="rule-operation-action-edit">
122                                     <select name="append">
123                                         <option value="0">Skip</option>
124                                         <option value="1">Append</option>
125                                     </select>
126                                 </th>
127                                 <th class="rule-operation-action-edit">
128                                     <select name="remove">
129                                         <option value="0">Skip</option>
130                                         <option value="1">Remove</option>
131                                     </select>
132                                 </th>
133                                 <th class="rule-operation-action-edit">
134                                     <select name="delete">
135                                         <option value="0">Skip</option>
136                                         <option value="1">Delete</option>
137                                     </select>
138                                 </th>
139                                 <th><button class="btn btn-default btn-xs" title="Add" id="add"><i class="fa fa-plus"></i> Add rule</button></th>
140                                 <th><button id="btn_batchremove" disabled="disabled" class="btn btn-default btn-xs" title="Batch remove"><i class="fa fa-trash"></i> Delete selected</button></th>
141                             </tr>
142                         </tfoot>
143                         [% END %]
144                         <tbody>
145                             [% FOREACH rule IN rules %]
146                                 <tr id="[% rule.id | html %]" class="rule[% IF rule.edit %]-edit[% END %]">
147                                 [% IF rule.edit %]
148                                     <td>[% rule.id | html %]</td>
149                                     <td>
150                                         <select name="module">
151                                             [% IF rule.module == "source" %]
152                                                 <option value="source" selected="selected">Source</option>
153                                             [% ELSE %]
154                                                 <option value="source">Source</option>
155                                             [% END %]
156                                             [% IF rule.module == "categorycode" %]
157                                                 <option value="categorycode" selected="selected">User category</option>
158                                             [% ELSE %]
159                                                 <option value="categorycode">User category</option>
160                                             [% END %]
161                                             [% IF rule.module == "userid" %]
162                                                 <option value="userid" selected="selected">Username</option>
163                                             [% ELSE %]
164                                                 <option value="userid">Username</option>
165                                             [% END %]
166                                         </select>
167                                     </td>
168                                     <td id="filter-container" data-filter="[% rule.filter | html %]"></td>
169                                     <td><input type="text" size="3" name="tag" value="[% rule.tag | html %]"/></td>
170                                     <th>
171                                         <select name="preset">
172                                             <option value="" selected>Custom</option>
173                                             <option value="Protect">Protect</option>
174                                             <option value="Overwrite">Overwrite</option>
175                                             <option value="Add new">Add new</option>
176                                             <option value="Add and append">Add and append</option>
177                                             <option value="Protect from deletion">Protect from deletion</option>
178                                         </select>
179                                     </th>
180                                     <td class="rule-operation-action-edit">
181                                         <select name="add">
182                                             [% IF rule.add %]
183                                                 <option value="0">Skip</option>
184                                                 <option value="1" selected="selected">Add</option>
185                                             [% ELSE %]
186                                                 <option value="0" selected="selected">Skip</option>
187                                                 <option value="1">Add</option>
188                                             [% END %]
189                                         </select>
190                                     </td>
191                                     <td class="rule-operation-action-edit">
192                                         <select name="append">
193                                             [% IF rule.append %]
194                                                 <option value="0">Skip</option>
195                                                 <option value="1" selected="selected">Append</option>
196                                             [% ELSE %]
197                                                 <option value="0" selected="selected">Skip</option>
198                                                 <option value="1">Append</option>
199                                             [% END %]
200                                         </select>
201                                     </td>
202                                     <td class="rule-operation-action-edit">
203                                         <select name="remove">
204                                             [% IF rule.remove %]
205                                                 <option value="0">Skip</option>
206                                                 <option value="1" selected="selected">Remove</option>
207                                             [% ELSE %]
208                                                 <option value="0" selected="selected">Skip</option>
209                                                 <option value="1">Remove</option>
210                                             [% END %]
211                                         </select>
212                                     </td>
213                                     <td class="rule-operation-action-edit">
214                                         <select name="delete">
215                                             [% IF rule.delete %]
216                                                 <option value="0">Skip</option>
217                                                 <option value="1" selected="selected">Delete</option>
218                                             [% ELSE %]
219                                                 <option value="0" selected="selected">Skip</option>
220                                                 <option value="1">Delete</option>
221                                             [% END %]
222                                         </select>
223                                     </td>
224                                     <td class="actions">
225                                         <button class="btn btn-default btn-xs" title="Save" id="doedit" value="[% rule.id | html %]"><i class="fa fa-check"></i> Save</button>
226                                         <button type="submit" class="btn btn-default btn-xs" title="Cancel" ><i class="fa fa-times"></i> Cancel</button>
227                                     </td>
228                                     <td></td>
229                                 [% ELSE %]
230                                     <td>[% rule.id | html %]</td>
231                                     <td class="rule-module">[% rule.module | html %]</td>
232                                     <td class="rule-filter">[% rule.filter | html %]</td>
233                                     <td>[% rule.tag | html %]</td>
234                                     <td class="rule-preset"></td>
235                                     <td class="rule-operation-action" data-operation="add">[% IF rule.add %]Add[% ELSE %]Skip[% END %]</td>
236                                     <td class="rule-operation-action" data-operation="append">[% IF rule.append %]Append[% ELSE %]Skip[% END %]</td>
237                                     <td class="rule-operation-action" data-operation="remove">[% IF rule.remove %]Remove[% ELSE %]Skip[% END %]</td>
238                                     <td class="rule-operation-action" data-operation="delete">[% IF rule.delete %]Delete[% ELSE %]Skip[% END %]</td>
239                                     <td class="actions">
240                                         <a href="?op=remove&id=[% rule.id | uri %]" title="Delete" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a>
241                                         <a href="?op=edit&id=[% rule.id | uri %]" title="Edit" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
242                                     </td>
243                                     <td>
244                                         [% IF rule.removemarked %]
245                                             <input type="checkbox" name="batchremove" value="[% rule.id | html %]" checked="checked"/>
246                                         [% ELSE %]
247                                             <input type="checkbox" name="batchremove" value="[% rule.id | html %]"/>
248                                         [% END %]
249                                     </td>
250                                 [% END %]
251                                 </tr>
252                             [% END %]
253                         </tbody>
254                     </table>
255                 </form>
256
257                 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="post">
258                     <input type="hidden" name="op" value="redo-matching" />
259                 </form>
260
261             </div><!-- /.col-sm-10.col-sm-push-2 -->
262
263             <div class="col-sm-2 col-sm-pull-10">
264                 <aside>
265                     [% INCLUDE 'admin-menu.inc' %]
266                 </aside>
267             </div>
268
269         </div><!-- /.row -->
270     </div><!-- /main container-fluid -->
271
272 [% MACRO jsinclude BLOCK %]
273     [% Asset.js("js/admin-menu.js") | $raw %]
274     [% INCLUDE 'datatables.inc' %]
275
276     <script>
277     $(document).ready(function(){
278         function doSubmit(op, id) {
279             $('<input type="hidden"/>')
280             .attr('name', 'op')
281             .attr('value', op)
282             .appendTo('#marc-overlay-rules-form');
283
284             if(id) {
285                 $('<input type="hidden"/>')
286                 .attr('name', 'id')
287                 .attr('value', id)
288                 .appendTo('#marc-overlay-rules-form');
289             }
290
291             var valid = true;
292             if (op == 'add' || op == 'edit') {
293                 var validate = [
294                     $('#marc-overlay-rules-form input[name="filter"]'),
295                     $('#marc-overlay-rules-form input[name="tag"]')
296                 ];
297                 for(var i = 0; i < validate.length; i++) {
298                     if (validate[i].length) {
299                         if(validate[i].val().length == 0) {
300                             validate[i].addClass('required');
301                             valid = false;
302                         } else {
303                             validate[i].removeClass('required');
304                         }
305                     }
306                 }
307             }
308
309             if (valid) {
310                 $('#marc-overlay-rules-form').submit();
311             }
312
313             return valid;
314         }
315
316         $('#doremove').on('click', function(){
317             doSubmit('doremove');
318         });
319         $('#doedit').on('click', function(){
320             doSubmit('doedit', $("#doedit").attr('value'));
321         });
322         $('#add').on('click', function(){
323             doSubmit('add');
324             return false;
325         });
326         $('#btn_batchremove').on('click', function(){
327             doSubmit('remove');
328         });
329
330         /* Disable batch remove unless one or more checkboxes are checked */
331         $('input[name="batchremove"]').change(function() {
332             if($('input[name="batchremove"]:checked').length > 0) {
333                 $('#btn_batchremove').removeAttr('disabled');
334             } else {
335                 $('#btn_batchremove').attr('disabled', 'disabled');
336             }
337         });
338
339         $.fn.dataTable.ext.order['dom-input'] = function (settings, col) {
340             return this.api().column(col, { order: 'index' }).nodes()
341                 .map(function (td, i) {
342                     if($('input', td).val() != undefined) {
343                         return $('input', td).val();
344                     } else if($('select', td).val() != undefined) {
345                         return $('option[selected="selected"]', td).val();
346                     } else {
347                         return $(td).html();
348                     }
349                 });
350         }
351
352         $('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, {
353             "aoColumns": [
354                 {"bSearchable": false, "bSortable": false},
355                 {"sSortDataType": "dom-input"},
356                 {"sSortDataType": "dom-input"},
357                 {"bSearchable": false, "sSortDataType": "dom-input"},
358                 {"bSearchable": false, "sSortDataType": "dom-input"},
359                 {"bSearchable": false, "sSortDataType": "dom-input"},
360                 {"bSearchable": false, "sSortDataType": "dom-input"},
361                 {"bSearchable": false, "sSortDataType": "dom-input"},
362                 {"bSearchable": false, "sSortDataType": "dom-input"},
363                 {"bSearchable": false, "bSortable": false},
364                 {"bSearchable": false, "bSortable": false}
365             ],
366             "pagingType": "simple"
367         }));
368
369         var overlay_rules_presets = {};
370         overlay_rules_presets[_("Protect")] = {
371           'add': 0,
372           'append': 0,
373           'remove': 0,
374           'delete': 0
375         };
376         overlay_rules_presets[_("Overwrite")] = {
377           'add': 1,
378           'append': 1,
379           'remove': 1,
380           'delete': 1
381         };
382         overlay_rules_presets[_("Add new")] = {
383           'add': 1,
384           'append': 0,
385           'remove': 0,
386           'delete': 0
387         };
388         overlay_rules_presets[_("Add and append")] = {
389           'add': 1,
390           'append': 1,
391           'remove': 0,
392           'delete': 0
393         };
394         overlay_rules_presets[_("Protect from deletion")] = {
395           'add': 1,
396           'append': 1,
397           'remove': 1,
398           'delete': 0
399         };
400
401         var overlay_rules_label_to_value = {};
402         overlay_rules_label_to_value[_("Add")] = 1;
403         overlay_rules_label_to_value[_("Append")] = 1;
404         overlay_rules_label_to_value[_("Remove")] = 1;
405         overlay_rules_label_to_value[_("Delete")] = 1;
406         overlay_rules_label_to_value[_("Skip")] = 0;
407
408         function hash_config(config) {
409           return JSON.stringify(config, Object.keys(config).sort());
410         }
411
412         var overlay_rules_preset_map = {};
413         $.each(overlay_rules_presets, function(preset, config) {
414           overlay_rules_preset_map[hash_config(config)] = preset;
415         });
416
417         function operations_config_overlay_rule_preset(config) {
418           return overlay_rules_preset_map[hash_config(config)] || '';
419         }
420
421         /* Set preset values according to operation config */
422         $('.rule').each(function() {
423           var $this = $(this);
424           var operations_config = {};
425           $('.rule-operation-action', $this).each(function() {
426             var $operation = $(this);
427             operations_config[$operation.data('operation')] = overlay_rules_label_to_value[$operation.text()];
428           });
429           $('.rule-preset', $this).text(
430             operations_config_overlay_rule_preset(operations_config) || _("Custom")
431           );
432         });
433
434         /* Listen to operations config changes and set presets accordingly */
435         $('.rule-operation-action-edit select').change(function() {
436           var operations_config = {};
437           var $parent_row = $(this).closest('tr');
438           $('.rule-operation-action-edit select', $parent_row).each(function() {
439             var $this = $(this);
440             operations_config[$this.attr('name')] = parseInt($this.val());
441           });
442           $('select[name="preset"]', $parent_row).val(
443               operations_config_overlay_rule_preset(operations_config)
444           );
445         });
446
447         /* Listen to preset changes and set operations config accordingly */
448         $('select[name="preset"]').change(function() {
449           var $this = $(this);
450           var $parent_row = $this.closest('tr');
451           var preset = $this.val();
452           if (preset) {
453             $.each(overlay_rules_presets[preset], function(operation, action) {
454               $('select[name="' + operation + '"]', $parent_row).val(action);
455             });
456           }
457         });
458
459         var module_filter_options = {
460           source: {
461             '*': '*',
462             batchmod: _("Batch record modification"),
463             intranet: _("Staff interface MARC editor"),
464             batchimport: _("Staged MARC import"),
465             z3950: _("Z39.50"),
466             /* bulkmarcimport: _("bulkmarcimport.pl"), */
467             import_lexile: _("import_lexile.pl")
468           },
469           categorycode: {
470             '*': '*',
471             [% FOREACH categorycode IN categorycodes %]
472               [% categorycode.categorycode | html %]: "[% categorycode.description | html %]",
473             [% END %]
474           }
475         };
476
477         //Kind of hack: Replace filter value with label when one exist
478         $('.rule-module').each(function() {
479           var $this = $(this);
480           var module = $this.text();
481           if (module in module_filter_options) {
482             let $filter = $this.siblings('.rule-filter');
483             if ($filter.text() in module_filter_options[module]) {
484               $filter.text(module_filter_options[module][$filter.text()]);
485             }
486           }
487         });
488
489         var $filter_container = $('#filter-container');
490
491         /* Listen to module changes and set filter input accordingly */
492         $('select[name="module"]').change(function() {
493           var $this = $(this);
494           var module_name = $this.val();
495
496           /* Remove current element if any */
497           $filter_container.empty();
498
499           var filter_elem = null;
500           if (module_name in module_filter_options) {
501             // Create select element
502             filter_elem = document.createElement('select');
503             for (var filter_value in module_filter_options[module_name]) {
504               var option = document.createElement('option');
505               option.value = filter_value;
506               option.text = module_filter_options[module_name][filter_value];
507               filter_elem.appendChild(option);
508             }
509           }
510           else {
511             // Create text input element
512             filter_elem = document.createElement('input');
513             filter_elem.type = 'text';
514             filter_elem.setAttribute('size', 5);
515           }
516           filter_elem.name = 'filter';
517           filter_elem.id = 'filter';
518           $filter_container.append(filter_elem);
519         }).change(); // Trigger change
520
521         // Hack: set value if editing rule
522         if ($filter_container.data('filter')) {
523           $('#filter').val($filter_container.data('filter'));
524         }
525
526     });
527     </script>
528 [% END %]
529 [% INCLUDE 'intranet-bottom.inc' %]