5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>MARC overlay rules › Koha › Administration</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% Asset.css("css/datatables.css") | $raw %]
9 [% INCLUDE 'datatables.inc' %]
13 background-color: #C00;
18 <body id="admin_marc-overlay-rules" class="admin">
19 [% INCLUDE 'header.inc' %]
20 [% INCLUDE 'cat-search.inc' %]
22 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
25 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
28 <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
31 <a href="#" aria-current="page">
38 <div class="main container-fluid">
40 <div class="col-sm-10 col-sm-push-2">
42 <h1>Manage MARC overlay rules</h1>
44 [% FOR m IN messages %]
45 <div class="dialog [% m.type | html %]">
47 [% CASE 'invalid_tag_regexp' %]
48 Invalid regular expression "[% m.tag | html %]".
49 [% CASE 'invalid_control_field_actions' %]
50 Invalid combination of actions for tag [% m.tag | html %]. Control field rules do not allow "Appended: Append" and "Removed: Skip".
57 [% UNLESS Koha.Preference( 'MARCOverlayRules' ) %]
58 <div class="dialog message">
59 The <b>MARCOverlayRules</b> preference is not set, don't forget to enable it for rules to take effect.
62 [% IF removeConfirm %]
63 <div class="dialog alert">
65 <p>Are you sure you want to remove the selected rule(s)?</p>
67 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="GET">
68 <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not remove</button>
70 <button type="button" class="approve" id="doremove"><i class="fa fa-fw fa-check"></i> Yes, remove</button>
74 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="POST" id="marc-overlay-rules-form">
75 <table id="marc-overlay-rules">
82 <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>
83 <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>
84 <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>
85 <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>
94 <select name="module">
95 <option value="source">Source</option>
96 <option value="categorycode">User category</option>
97 <option value="userid">Username</option>
100 <th id="filter-container"></th>
101 <th><input type="text" size="5" name="tag"/></th>
103 <select name="preset">
104 <option value="" selected>Custom</option>
105 <option value="Protect">Protect</option>
106 <option value="Overwrite">Overwrite</option>
107 <option value="Add new">Add new</option>
108 <option value="Add and append">Add and append</option>
109 <option value="Protect from deletion">Protect from deletion</option>
112 <th class="rule-operation-action-edit">
114 <option value="0">Skip</option>
115 <option value="1">Add</option>
118 <th class="rule-operation-action-edit">
119 <select name="append">
120 <option value="0">Skip</option>
121 <option value="1">Append</option>
124 <th class="rule-operation-action-edit">
125 <select name="remove">
126 <option value="0">Skip</option>
127 <option value="1">Remove</option>
130 <th class="rule-operation-action-edit">
131 <select name="delete">
132 <option value="0">Skip</option>
133 <option value="1">Delete</option>
136 <th><button class="btn btn-default btn-xs" title="Add" id="add"><i class="fa fa-plus"></i> Add rule</button></th>
137 <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>
142 [% FOREACH rule IN rules %]
143 <tr id="[% rule.id | html %]" class="rule[% IF rule.edit %]-edit[% END %]">
145 <td>[% rule.id | html %]</td>
147 <select name="module">
148 [% IF rule.module == "source" %]
149 <option value="source" selected="selected">Source</option>
151 <option value="source">Source</option>
153 [% IF rule.module == "categorycode" %]
154 <option value="categorycode" selected="selected">User category</option>
156 <option value="categorycode">User category</option>
158 [% IF rule.module == "userid" %]
159 <option value="userid" selected="selected">Username</option>
161 <option value="userid">Username</option>
165 <td id="filter-container" data-filter="[% rule.filter | html %]"></td>
166 <td><input type="text" size="3" name="tag" value="[% rule.tag | html %]"/></td>
168 <select name="preset">
169 <option value="" selected>Custom</option>
170 <option value="Protect">Protect</option>
171 <option value="Overwrite">Overwrite</option>
172 <option value="Add new">Add new</option>
173 <option value="Add and append">Add and append</option>
174 <option value="Protect from deletion">Protect from deletion</option>
177 <td class="rule-operation-action-edit">
180 <option value="0">Skip</option>
181 <option value="1" selected="selected">Add</option>
183 <option value="0" selected="selected">Skip</option>
184 <option value="1">Add</option>
188 <td class="rule-operation-action-edit">
189 <select name="append">
191 <option value="0">Skip</option>
192 <option value="1" selected="selected">Append</option>
194 <option value="0" selected="selected">Skip</option>
195 <option value="1">Append</option>
199 <td class="rule-operation-action-edit">
200 <select name="remove">
202 <option value="0">Skip</option>
203 <option value="1" selected="selected">Remove</option>
205 <option value="0" selected="selected">Skip</option>
206 <option value="1">Remove</option>
210 <td class="rule-operation-action-edit">
211 <select name="delete">
213 <option value="0">Skip</option>
214 <option value="1" selected="selected">Delete</option>
216 <option value="0" selected="selected">Skip</option>
217 <option value="1">Delete</option>
222 <button class="btn btn-default btn-xs" title="Save" id="doedit" value="[% rule.id | html %]"><i class="fa fa-check"></i> Save</button>
223 <button type="submit" class="btn btn-default btn-xs" title="Cancel" ><i class="fa fa-times"></i> Cancel</button>
227 <td>[% rule.id | html %]</td>
228 <td class="rule-module">[% rule.module | html %]</td>
229 <td class="rule-filter">[% rule.filter | html %]</td>
230 <td>[% rule.tag | html %]</td>
231 <td class="rule-preset"></td>
232 <td class="rule-operation-action" data-operation="add">[% IF rule.add %]Add[% ELSE %]Skip[% END %]</td>
233 <td class="rule-operation-action" data-operation="append">[% IF rule.append %]Append[% ELSE %]Skip[% END %]</td>
234 <td class="rule-operation-action" data-operation="remove">[% IF rule.remove %]Remove[% ELSE %]Skip[% END %]</td>
235 <td class="rule-operation-action" data-operation="delete">[% IF rule.delete %]Delete[% ELSE %]Skip[% END %]</td>
237 <a href="?op=remove&id=[% rule.id | uri %]" title="Delete" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a>
238 <a href="?op=edit&id=[% rule.id | uri %]" title="Edit" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
241 [% IF rule.removemarked %]
242 <input type="checkbox" name="batchremove" value="[% rule.id | html %]" checked="checked"/>
244 <input type="checkbox" name="batchremove" value="[% rule.id | html %]"/>
254 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="post">
255 <input type="hidden" name="op" value="redo-matching" />
258 </div><!-- /.col-sm-10.col-sm-push-2 -->
260 <div class="col-sm-2 col-sm-pull-10">
262 [% INCLUDE 'admin-menu.inc' %]
267 </div><!-- /main container-fluid -->
269 [% MACRO jsinclude BLOCK %]
271 function doSubmit(op, id) {
272 $('<input type="hidden"/>')
275 .appendTo('#marc-overlay-rules-form');
278 $('<input type="hidden"/>')
281 .appendTo('#marc-overlay-rules-form');
285 if (op == 'add' || op == 'edit') {
287 $('#marc-overlay-rules-form input[name="filter"]'),
288 $('#marc-overlay-rules-form input[name="tag"]')
290 for(var i = 0; i < validate.length; i++) {
291 if (validate[i].length) {
292 if(validate[i].val().length == 0) {
293 validate[i].addClass('required');
296 validate[i].removeClass('required');
303 $('#marc-overlay-rules-form').submit();
309 $(document).ready(function(){
310 $('#doremove').on('click', function(){
311 doSubmit('doremove');
313 $('#doedit').on('click', function(){
314 doSubmit('doedit', $("#doedit").attr('value'));
316 $('#add').on('click', function(){
320 $('#btn_batchremove').on('click', function(){
324 /* Disable batch remove unless one or more checkboxes are checked */
325 $('input[name="batchremove"]').change(function() {
326 if($('input[name="batchremove"]:checked').length > 0) {
327 $('#btn_batchremove').removeAttr('disabled');
329 $('#btn_batchremove').attr('disabled', 'disabled');
333 $.fn.dataTable.ext.order['dom-input'] = function (settings, col) {
334 return this.api().column(col, { order: 'index' }).nodes()
335 .map(function (td, i) {
336 if($('input', td).val() != undefined) {
337 return $('input', td).val();
338 } else if($('select', td).val() != undefined) {
339 return $('option[selected="selected"]', td).val();
346 $('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, {
348 {"bSearchable": false, "bSortable": false},
349 {"sSortDataType": "dom-input"},
350 {"sSortDataType": "dom-input"},
351 {"bSearchable": false, "sSortDataType": "dom-input"},
352 {"bSearchable": false, "sSortDataType": "dom-input"},
353 {"bSearchable": false, "sSortDataType": "dom-input"},
354 {"bSearchable": false, "sSortDataType": "dom-input"},
355 {"bSearchable": false, "sSortDataType": "dom-input"},
356 {"bSearchable": false, "sSortDataType": "dom-input"},
357 {"bSearchable": false, "bSortable": false},
358 {"bSearchable": false, "bSortable": false}
360 "pagingType": "simple"
363 var overlay_rules_presets = {};
364 overlay_rules_presets[_("Protect")] = {
370 overlay_rules_presets[_("Overwrite")] = {
376 overlay_rules_presets[_("Add new")] = {
382 overlay_rules_presets[_("Add and append")] = {
388 overlay_rules_presets[_("Protect from deletion")] = {
395 var overlay_rules_label_to_value = {};
396 overlay_rules_label_to_value[_("Add")] = 1;
397 overlay_rules_label_to_value[_("Append")] = 1;
398 overlay_rules_label_to_value[_("Remove")] = 1;
399 overlay_rules_label_to_value[_("Delete")] = 1;
400 overlay_rules_label_to_value[_("Skip")] = 0;
402 function hash_config(config) {
403 return JSON.stringify(config, Object.keys(config).sort());
406 var overlay_rules_preset_map = {};
407 $.each(overlay_rules_presets, function(preset, config) {
408 overlay_rules_preset_map[hash_config(config)] = preset;
411 function operations_config_overlay_rule_preset(config) {
412 return overlay_rules_preset_map[hash_config(config)] || '';
415 /* Set preset values according to operation config */
416 $('.rule').each(function() {
418 var operations_config = {};
419 $('.rule-operation-action', $this).each(function() {
420 var $operation = $(this);
421 operations_config[$operation.data('operation')] = overlay_rules_label_to_value[$operation.text()];
423 $('.rule-preset', $this).text(
424 operations_config_overlay_rule_preset(operations_config) || _("Custom")
428 /* Listen to operations config changes and set presets accordingly */
429 $('.rule-operation-action-edit select').change(function() {
430 var operations_config = {};
431 var $parent_row = $(this).closest('tr');
432 $('.rule-operation-action-edit select', $parent_row).each(function() {
434 operations_config[$this.attr('name')] = parseInt($this.val());
436 $('select[name="preset"]', $parent_row).val(
437 operations_config_overlay_rule_preset(operations_config)
441 /* Listen to preset changes and set operations config accordingly */
442 $('select[name="preset"]').change(function() {
444 var $parent_row = $this.closest('tr');
445 var preset = $this.val();
447 $.each(overlay_rules_presets[preset], function(operation, action) {
448 $('select[name="' + operation + '"]', $parent_row).val(action);
453 var module_filter_options = {
456 batchmod: _("Batch record modification"),
457 intranet: _("Staff client MARC editor"),
458 batchimport: _("Staged MARC import"),
460 /* bulkmarcimport: _("bulkmarcimport.pl"), */
461 import_lexile: _("import_lexile.pl")
465 [% FOREACH categorycode IN categorycodes %]
466 [% categorycode.categorycode | html %]: "[% categorycode.description | html %]",
471 //Kind of hack: Replace filter value with label when one exist
472 $('.rule-module').each(function() {
474 var module = $this.text();
475 if (module in module_filter_options) {
476 let $filter = $this.siblings('.rule-filter');
477 if ($filter.text() in module_filter_options[module]) {
478 $filter.text(module_filter_options[module][$filter.text()]);
483 var $filter_container = $('#filter-container');
485 /* Listen to module changes and set filter input accordingly */
486 $('select[name="module"]').change(function() {
488 var module_name = $this.val();
490 /* Remove current element if any */
491 $filter_container.empty();
493 var filter_elem = null;
494 if (module_name in module_filter_options) {
495 // Create select element
496 filter_elem = document.createElement('select');
497 for (var filter_value in module_filter_options[module_name]) {
498 var option = document.createElement('option');
499 option.value = filter_value;
500 option.text = module_filter_options[module_name][filter_value];
501 filter_elem.appendChild(option);
505 // Create text input element
506 filter_elem = document.createElement('input');
507 filter_elem.type = 'text';
508 filter_elem.setAttribute('size', 5);
510 filter_elem.name = 'filter';
511 filter_elem.id = 'filter';
512 $filter_container.append(filter_elem);
513 }).change(); // Trigger change
515 // Hack: set value if editing rule
516 if ($filter_container.data('filter')) {
517 $('#filter').val($filter_container.data('filter'));
523 [% INCLUDE 'intranet-bottom.inc' %]