6 [% PROCESS 'i18n.inc' %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>MARC overlay rules › Koha › Administration</title>
9 [% INCLUDE 'doc-head-close.inc' %]
13 background-color: #C00;
18 <body id="admin_marc-overlay-rules" class="admin">
19 [% WRAPPER 'header.inc' %]
20 [% INCLUDE 'cat-search.inc' %]
23 [% WRAPPER 'sub-header.inc' %]
24 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
27 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
30 <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
33 <a href="#" aria-current="page">
41 <div class="main container-fluid">
43 <div class="col-sm-10 col-sm-push-2">
45 <h1>Manage MARC overlay rules</h1>
47 [% FOR m IN messages %]
48 <div class="dialog [% m.type | html %]">
50 [% CASE 'invalid_tag_regexp' %]
51 <span>Invalid regular expression "[% m.tag | html %]".</span>
52 [% CASE 'invalid_control_field_actions' %]
53 <span>Invalid combination of actions for tag [% m.tag | html %]. Control field rules do not allow "Appended: Append" and "Removed: Skip".</span>
55 <span>[% m.code | html %]</span>
60 [% UNLESS Koha.Preference( 'MARCOverlayRules' ) %]
61 [% SET pref_MARCOverlayRules_link = '<a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=MARCOverlayRules">MARCOverlayRules</a>' %]
62 <div class="dialog message">
63 The [% pref_MARCOverlayRules_link | $raw | $KohaSpan %] preference is not set, don't forget to enable it for rules to take effect.
66 [% IF removeConfirm %]
67 <div class="dialog alert">
69 <p>Are you sure you want to remove the selected rule(s)?</p>
71 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="GET">
72 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not remove</button>
74 <button type="button" class="approve" id="doremove"><i class="fa fa-fw fa-check"></i> Yes, remove</button>
78 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="POST" id="marc-overlay-rules-form">
79 <table id="marc-overlay-rules">
83 <th>[% tp('noun', 'Filter') | html %]</th>
86 <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>
87 <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>
88 <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>
89 <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>
98 <select name="module">
99 <option value="source">Source</option>
100 <option value="categorycode">User category</option>
101 <option value="userid">Username</option>
104 <th id="filter-container"></th>
105 <th><input type="text" size="5" name="tag"/></th>
107 <select name="preset">
108 <option value="" selected>Custom</option>
109 <option value="Protect">Protect</option>
110 <option value="Overwrite">Overwrite</option>
111 <option value="Add new">Add new</option>
112 <option value="Add and append">Add and append</option>
113 <option value="Protect from deletion">Protect from deletion</option>
116 <th class="rule-operation-action-edit">
118 <option value="0">Skip</option>
119 <option value="1">Add</option>
122 <th class="rule-operation-action-edit">
123 <select name="append">
124 <option value="0">Skip</option>
125 <option value="1">Append</option>
128 <th class="rule-operation-action-edit">
129 <select name="remove">
130 <option value="0">Skip</option>
131 <option value="1">Remove</option>
134 <th class="rule-operation-action-edit">
135 <select name="delete">
136 <option value="0">Skip</option>
137 <option value="1">Delete</option>
140 <th><button class="btn btn-default btn-xs" title="Add" id="add"><i class="fa fa-plus"></i> Add rule</button></th>
141 <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>
146 [% FOREACH rule IN rules %]
147 <tr id="[% rule.id | html %]" class="rule[% IF rule.edit %]-edit[% END %]">
149 <td>[% rule.id | html %]</td>
151 <select name="module">
152 [% IF rule.module == "source" %]
153 <option value="source" selected="selected">Source</option>
155 <option value="source">Source</option>
157 [% IF rule.module == "categorycode" %]
158 <option value="categorycode" selected="selected">User category</option>
160 <option value="categorycode">User category</option>
162 [% IF rule.module == "userid" %]
163 <option value="userid" selected="selected">Username</option>
165 <option value="userid">Username</option>
169 <td id="filter-container" data-filter="[% rule.filter | html %]"></td>
170 <td><input type="text" size="3" name="tag" value="[% rule.tag | html %]"/></td>
172 <select name="preset">
173 <option value="" selected>Custom</option>
174 <option value="Protect">Protect</option>
175 <option value="Overwrite">Overwrite</option>
176 <option value="Add new">Add new</option>
177 <option value="Add and append">Add and append</option>
178 <option value="Protect from deletion">Protect from deletion</option>
181 <td class="rule-operation-action-edit">
184 <option value="0">Skip</option>
185 <option value="1" selected="selected">Add</option>
187 <option value="0" selected="selected">Skip</option>
188 <option value="1">Add</option>
192 <td class="rule-operation-action-edit">
193 <select name="append">
195 <option value="0">Skip</option>
196 <option value="1" selected="selected">Append</option>
198 <option value="0" selected="selected">Skip</option>
199 <option value="1">Append</option>
203 <td class="rule-operation-action-edit">
204 <select name="remove">
206 <option value="0">Skip</option>
207 <option value="1" selected="selected">Remove</option>
209 <option value="0" selected="selected">Skip</option>
210 <option value="1">Remove</option>
214 <td class="rule-operation-action-edit">
215 <select name="delete">
217 <option value="0">Skip</option>
218 <option value="1" selected="selected">Delete</option>
220 <option value="0" selected="selected">Skip</option>
221 <option value="1">Delete</option>
226 <button class="btn btn-default btn-xs" title="Save" id="doedit" value="[% rule.id | html %]"><i class="fa fa-check"></i> Save</button>
227 <button type="submit" class="btn btn-default btn-xs" title="Cancel" ><i class="fa fa-times"></i> Cancel</button>
231 <td>[% rule.id | html %]</td>
232 <td class="rule-module">[% rule.module | html %]</td>
233 <td class="rule-filter">[% rule.filter | html %]</td>
234 <td>[% rule.tag | html %]</td>
235 <td class="rule-preset"></td>
236 <td class="rule-operation-action" data-operation="add">[% IF rule.add %]Add[% ELSE %]Skip[% END %]</td>
237 <td class="rule-operation-action" data-operation="append">[% IF rule.append %]Append[% ELSE %]Skip[% END %]</td>
238 <td class="rule-operation-action" data-operation="remove">[% IF rule.remove %]Remove[% ELSE %]Skip[% END %]</td>
239 <td class="rule-operation-action" data-operation="delete">[% IF rule.delete %]Delete[% ELSE %]Skip[% END %]</td>
241 <a href="?op=remove&id=[% rule.id | uri %]" title="Delete" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a>
242 <a href="?op=edit&id=[% rule.id | uri %]" title="Edit" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
245 [% IF rule.removemarked %]
246 <input type="checkbox" name="batchremove" value="[% rule.id | html %]" checked="checked"/>
248 <input type="checkbox" name="batchremove" value="[% rule.id | html %]"/>
258 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="post">
259 <input type="hidden" name="op" value="redo-matching" />
262 </div><!-- /.col-sm-10.col-sm-push-2 -->
264 <div class="col-sm-2 col-sm-pull-10">
266 [% INCLUDE 'admin-menu.inc' %]
271 </div><!-- /main container-fluid -->
273 [% MACRO jsinclude BLOCK %]
274 [% Asset.js("js/admin-menu.js") | $raw %]
275 [% INCLUDE 'datatables.inc' %]
278 $(document).ready(function(){
279 function doSubmit(op, id) {
280 $('<input type="hidden"/>')
283 .appendTo('#marc-overlay-rules-form');
286 $('<input type="hidden"/>')
289 .appendTo('#marc-overlay-rules-form');
293 if (op == 'add' || op == 'edit') {
295 $('#marc-overlay-rules-form input[name="filter"]'),
296 $('#marc-overlay-rules-form input[name="tag"]')
298 for(var i = 0; i < validate.length; i++) {
299 if (validate[i].length) {
300 if(validate[i].val().length == 0) {
301 validate[i].addClass('required');
304 validate[i].removeClass('required');
311 $('#marc-overlay-rules-form').submit();
317 $('#doremove').on('click', function(){
318 doSubmit('doremove');
320 $('#doedit').on('click', function(){
321 doSubmit('doedit', $("#doedit").attr('value'));
323 $('#add').on('click', function(){
327 $('#btn_batchremove').on('click', function(){
331 /* Disable batch remove unless one or more checkboxes are checked */
332 $('input[name="batchremove"]').change(function() {
333 if($('input[name="batchremove"]:checked').length > 0) {
334 $('#btn_batchremove').removeAttr('disabled');
336 $('#btn_batchremove').attr('disabled', 'disabled');
340 $.fn.dataTable.ext.order['dom-input'] = function (settings, col) {
341 return this.api().column(col, { order: 'index' }).nodes()
342 .map(function (td, i) {
343 if($('input', td).val() != undefined) {
344 return $('input', td).val();
345 } else if($('select', td).val() != undefined) {
346 return $('option[selected="selected"]', td).val();
353 $('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, {
355 {"bSearchable": false, "bSortable": false},
356 {"sSortDataType": "dom-input"},
357 {"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, "sSortDataType": "dom-input"},
364 {"bSearchable": false, "bSortable": false},
365 {"bSearchable": false, "bSortable": false}
367 "pagingType": "simple"
370 var overlay_rules_presets = {};
371 overlay_rules_presets[_("Protect")] = {
377 overlay_rules_presets[_("Overwrite")] = {
383 overlay_rules_presets[_("Add new")] = {
389 overlay_rules_presets[_("Add and append")] = {
395 overlay_rules_presets[_("Protect from deletion")] = {
402 var overlay_rules_label_to_value = {};
403 overlay_rules_label_to_value[_("Add")] = 1;
404 overlay_rules_label_to_value[_("Append")] = 1;
405 overlay_rules_label_to_value[_("Remove")] = 1;
406 overlay_rules_label_to_value[_("Delete")] = 1;
407 overlay_rules_label_to_value[_("Skip")] = 0;
409 function hash_config(config) {
410 return JSON.stringify(config, Object.keys(config).sort());
413 var overlay_rules_preset_map = {};
414 $.each(overlay_rules_presets, function(preset, config) {
415 overlay_rules_preset_map[hash_config(config)] = preset;
418 function operations_config_overlay_rule_preset(config) {
419 return overlay_rules_preset_map[hash_config(config)] || '';
422 /* Set preset values according to operation config */
423 $('.rule').each(function() {
425 var operations_config = {};
426 $('.rule-operation-action', $this).each(function() {
427 var $operation = $(this);
428 operations_config[$operation.data('operation')] = overlay_rules_label_to_value[$operation.text()];
430 $('.rule-preset', $this).text(
431 operations_config_overlay_rule_preset(operations_config) || _("Custom")
435 /* Listen to operations config changes and set presets accordingly */
436 $('.rule-operation-action-edit select').change(function() {
437 var operations_config = {};
438 var $parent_row = $(this).closest('tr');
439 $('.rule-operation-action-edit select', $parent_row).each(function() {
441 operations_config[$this.attr('name')] = parseInt($this.val());
443 $('select[name="preset"]', $parent_row).val(
444 operations_config_overlay_rule_preset(operations_config)
448 /* Listen to preset changes and set operations config accordingly */
449 $('select[name="preset"]').change(function() {
451 var $parent_row = $this.closest('tr');
452 var preset = $this.val();
454 $.each(overlay_rules_presets[preset], function(operation, action) {
455 $('select[name="' + operation + '"]', $parent_row).val(action);
460 var module_filter_options = {
463 batchmod: _("Batch record modification"),
464 intranet: _("Staff interface MARC editor"),
465 batchimport: _("Staged MARC import"),
467 /* bulkmarcimport: _("bulkmarcimport.pl"), */
468 import_lexile: _("import_lexile.pl")
472 [% FOREACH categorycode IN categorycodes %]
473 [% categorycode.categorycode | html %]: "[% categorycode.description | html %]",
478 //Kind of hack: Replace filter value with label when one exist
479 $('.rule-module').each(function() {
481 var module = $this.text();
482 if (module in module_filter_options) {
483 let $filter = $this.siblings('.rule-filter');
484 if ($filter.text() in module_filter_options[module]) {
485 $filter.text(module_filter_options[module][$filter.text()]);
490 var $filter_container = $('#filter-container');
492 /* Listen to module changes and set filter input accordingly */
493 $('select[name="module"]').change(function() {
495 var module_name = $this.val();
497 /* Remove current element if any */
498 $filter_container.empty();
500 var filter_elem = null;
501 if (module_name in module_filter_options) {
502 // Create select element
503 filter_elem = document.createElement('select');
504 for (var filter_value in module_filter_options[module_name]) {
505 var option = document.createElement('option');
506 option.value = filter_value;
507 option.text = module_filter_options[module_name][filter_value];
508 filter_elem.appendChild(option);
512 // Create text input element
513 filter_elem = document.createElement('input');
514 filter_elem.type = 'text';
515 filter_elem.setAttribute('size', 5);
517 filter_elem.name = 'filter';
518 filter_elem.id = 'filter';
519 $filter_container.append(filter_elem);
520 }).change(); // Trigger change
522 // Hack: set value if editing rule
523 if ($filter_container.data('filter')) {
524 $('#filter').val($filter_container.data('filter'));
530 [% INCLUDE 'intranet-bottom.inc' %]