6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>MARC overlay rules › Koha › Administration</title>
8 [% INCLUDE 'doc-head-close.inc' %]
12 background-color: #C00;
17 <body id="admin_marc-overlay-rules" class="admin">
18 [% WRAPPER 'header.inc' %]
19 [% INCLUDE 'cat-search.inc' %]
22 [% WRAPPER 'sub-header.inc' %]
23 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
26 <a href="/cgi-bin/koha/mainpage.pl"><i class="fa fa-home"></i></a>
29 <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
32 <a href="#" aria-current="page">
40 <div class="main container-fluid">
42 <div class="col-sm-10 col-sm-push-2">
44 <h1>Manage MARC overlay rules</h1>
46 [% FOR m IN messages %]
47 <div class="dialog [% m.type | html %]">
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>
54 <span>[% m.code | html %]</span>
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.
65 [% IF removeConfirm %]
66 <div class="dialog alert">
68 <p>Are you sure you want to remove the selected rule(s)?</p>
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>
73 <button type="button" class="approve" id="doremove"><i class="fa fa-fw fa-check"></i> Yes, remove</button>
77 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="POST" id="marc-overlay-rules-form">
78 <table id="marc-overlay-rules">
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>
97 <select name="module">
98 <option value="source">Source</option>
99 <option value="categorycode">User category</option>
100 <option value="userid">Username</option>
103 <th id="filter-container"></th>
104 <th><input type="text" size="5" name="tag"/></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>
115 <th class="rule-operation-action-edit">
117 <option value="0">Skip</option>
118 <option value="1">Add</option>
121 <th class="rule-operation-action-edit">
122 <select name="append">
123 <option value="0">Skip</option>
124 <option value="1">Append</option>
127 <th class="rule-operation-action-edit">
128 <select name="remove">
129 <option value="0">Skip</option>
130 <option value="1">Remove</option>
133 <th class="rule-operation-action-edit">
134 <select name="delete">
135 <option value="0">Skip</option>
136 <option value="1">Delete</option>
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>
145 [% FOREACH rule IN rules %]
146 <tr id="[% rule.id | html %]" class="rule[% IF rule.edit %]-edit[% END %]">
148 <td>[% rule.id | html %]</td>
150 <select name="module">
151 [% IF rule.module == "source" %]
152 <option value="source" selected="selected">Source</option>
154 <option value="source">Source</option>
156 [% IF rule.module == "categorycode" %]
157 <option value="categorycode" selected="selected">User category</option>
159 <option value="categorycode">User category</option>
161 [% IF rule.module == "userid" %]
162 <option value="userid" selected="selected">Username</option>
164 <option value="userid">Username</option>
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>
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>
180 <td class="rule-operation-action-edit">
183 <option value="0">Skip</option>
184 <option value="1" selected="selected">Add</option>
186 <option value="0" selected="selected">Skip</option>
187 <option value="1">Add</option>
191 <td class="rule-operation-action-edit">
192 <select name="append">
194 <option value="0">Skip</option>
195 <option value="1" selected="selected">Append</option>
197 <option value="0" selected="selected">Skip</option>
198 <option value="1">Append</option>
202 <td class="rule-operation-action-edit">
203 <select name="remove">
205 <option value="0">Skip</option>
206 <option value="1" selected="selected">Remove</option>
208 <option value="0" selected="selected">Skip</option>
209 <option value="1">Remove</option>
213 <td class="rule-operation-action-edit">
214 <select name="delete">
216 <option value="0">Skip</option>
217 <option value="1" selected="selected">Delete</option>
219 <option value="0" selected="selected">Skip</option>
220 <option value="1">Delete</option>
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>
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>
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>
244 [% IF rule.removemarked %]
245 <input type="checkbox" name="batchremove" value="[% rule.id | html %]" checked="checked"/>
247 <input type="checkbox" name="batchremove" value="[% rule.id | html %]"/>
257 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="post">
258 <input type="hidden" name="op" value="redo-matching" />
261 </div><!-- /.col-sm-10.col-sm-push-2 -->
263 <div class="col-sm-2 col-sm-pull-10">
265 [% INCLUDE 'admin-menu.inc' %]
270 </div><!-- /main container-fluid -->
272 [% MACRO jsinclude BLOCK %]
273 [% Asset.js("js/admin-menu.js") | $raw %]
274 [% INCLUDE 'datatables.inc' %]
277 $(document).ready(function(){
278 function doSubmit(op, id) {
279 $('<input type="hidden"/>')
282 .appendTo('#marc-overlay-rules-form');
285 $('<input type="hidden"/>')
288 .appendTo('#marc-overlay-rules-form');
292 if (op == 'add' || op == 'edit') {
294 $('#marc-overlay-rules-form input[name="filter"]'),
295 $('#marc-overlay-rules-form input[name="tag"]')
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');
303 validate[i].removeClass('required');
310 $('#marc-overlay-rules-form').submit();
316 $('#doremove').on('click', function(){
317 doSubmit('doremove');
319 $('#doedit').on('click', function(){
320 doSubmit('doedit', $("#doedit").attr('value'));
322 $('#add').on('click', function(){
326 $('#btn_batchremove').on('click', function(){
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');
335 $('#btn_batchremove').attr('disabled', 'disabled');
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();
352 $('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, {
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}
366 "pagingType": "simple"
369 var overlay_rules_presets = {};
370 overlay_rules_presets[_("Protect")] = {
376 overlay_rules_presets[_("Overwrite")] = {
382 overlay_rules_presets[_("Add new")] = {
388 overlay_rules_presets[_("Add and append")] = {
394 overlay_rules_presets[_("Protect from deletion")] = {
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;
408 function hash_config(config) {
409 return JSON.stringify(config, Object.keys(config).sort());
412 var overlay_rules_preset_map = {};
413 $.each(overlay_rules_presets, function(preset, config) {
414 overlay_rules_preset_map[hash_config(config)] = preset;
417 function operations_config_overlay_rule_preset(config) {
418 return overlay_rules_preset_map[hash_config(config)] || '';
421 /* Set preset values according to operation config */
422 $('.rule').each(function() {
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()];
429 $('.rule-preset', $this).text(
430 operations_config_overlay_rule_preset(operations_config) || _("Custom")
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() {
440 operations_config[$this.attr('name')] = parseInt($this.val());
442 $('select[name="preset"]', $parent_row).val(
443 operations_config_overlay_rule_preset(operations_config)
447 /* Listen to preset changes and set operations config accordingly */
448 $('select[name="preset"]').change(function() {
450 var $parent_row = $this.closest('tr');
451 var preset = $this.val();
453 $.each(overlay_rules_presets[preset], function(operation, action) {
454 $('select[name="' + operation + '"]', $parent_row).val(action);
459 var module_filter_options = {
462 batchmod: _("Batch record modification"),
463 intranet: _("Staff interface MARC editor"),
464 batchimport: _("Staged MARC import"),
466 /* bulkmarcimport: _("bulkmarcimport.pl"), */
467 import_lexile: _("import_lexile.pl")
471 [% FOREACH categorycode IN categorycodes %]
472 [% categorycode.categorycode | html %]: "[% categorycode.description | html %]",
477 //Kind of hack: Replace filter value with label when one exist
478 $('.rule-module').each(function() {
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()]);
489 var $filter_container = $('#filter-container');
491 /* Listen to module changes and set filter input accordingly */
492 $('select[name="module"]').change(function() {
494 var module_name = $this.val();
496 /* Remove current element if any */
497 $filter_container.empty();
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);
511 // Create text input element
512 filter_elem = document.createElement('input');
513 filter_elem.type = 'text';
514 filter_elem.setAttribute('size', 5);
516 filter_elem.name = 'filter';
517 filter_elem.id = 'filter';
518 $filter_container.append(filter_elem);
519 }).change(); // Trigger change
521 // Hack: set value if editing rule
522 if ($filter_container.data('filter')) {
523 $('#filter').val($filter_container.data('filter'));
529 [% INCLUDE 'intranet-bottom.inc' %]