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