Bug 31807: Context for translation: Filter (verb) vs. Filter (noun)
[koha-ffzg.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 [% PROCESS 'i18n.inc' %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>MARC overlay rules &rsaquo; Koha &rsaquo; Administration</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10
11 <style>
12     .required {
13         background-color: #C00;
14     }
15 </style>
16
17 </head>
18 <body id="admin_marc-overlay-rules" class="admin">
19 [% WRAPPER 'header.inc' %]
20     [% INCLUDE 'cat-search.inc' %]
21 [% END %]
22
23     [% WRAPPER 'sub-header.inc' %]
24     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
25         <ol>
26             <li>
27                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
28             </li>
29             <li>
30                 <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
31             </li>
32             <li>
33                 <a href="#" aria-current="page">
34                      MARC overlay rules
35                 </a>
36             </li>
37         </ol>
38     </nav>
39     [% END %]
40
41     <div class="main container-fluid">
42         <div class="row">
43             <div class="col-sm-10 col-sm-push-2">
44
45                 <h1>Manage MARC overlay rules</h1>
46
47                 [% FOR m IN messages %]
48                 <div class="dialog [% m.type | html %]">
49                     [% SWITCH m.code %]
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>
54                     [% CASE %]
55                       <span>[% m.code | html %]</span>
56                     [% END %]
57                 </div>
58                 [% END %]
59
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.
64                 </div>
65                 [% END %]
66                 [% IF removeConfirm %]
67                 <div class="dialog alert">
68                     <h3>Remove rule?</h3>
69                     <p>Are you sure you want to remove the selected rule(s)?</p>
70
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>
73                     </form>
74                     <button type="button" class="approve" id="doremove"><i class="fa fa-fw fa-check"></i> Yes, remove</button>
75                 </div>
76                 [% END %]
77
78                 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="POST" id="marc-overlay-rules-form">
79                     <table id="marc-overlay-rules">
80                         <thead><tr>
81                             <th>Rule</th>
82                             <th>Module</th>
83                             <th>[% tp('noun', 'Filter') | html %]</th>
84                             <th>Tag</th>
85                             <th>Preset</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>
90                             <th>Actions</th>
91                             <th>&nbsp;</th>
92                         </tr></thead>
93                         [% UNLESS edit %]
94                         <tfoot>
95                             <tr class="rule-new">
96                                 <th>&nbsp;</th>
97                                 <th>
98                                     <select name="module">
99                                         <option value="source">Source</option>
100                                         <option value="categorycode">User category</option>
101                                         <option value="userid">Username</option>
102                                     </select>
103                                 </th>
104                                 <th id="filter-container"></th>
105                                 <th><input type="text" size="5" name="tag"/></th>
106                                 <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>
114                                     </select>
115                                 </th>
116                                 <th class="rule-operation-action-edit">
117                                     <select name="add">
118                                         <option value="0">Skip</option>
119                                         <option value="1">Add</option>
120                                     </select>
121                                 </th>
122                                 <th class="rule-operation-action-edit">
123                                     <select name="append">
124                                         <option value="0">Skip</option>
125                                         <option value="1">Append</option>
126                                     </select>
127                                 </th>
128                                 <th class="rule-operation-action-edit">
129                                     <select name="remove">
130                                         <option value="0">Skip</option>
131                                         <option value="1">Remove</option>
132                                     </select>
133                                 </th>
134                                 <th class="rule-operation-action-edit">
135                                     <select name="delete">
136                                         <option value="0">Skip</option>
137                                         <option value="1">Delete</option>
138                                     </select>
139                                 </th>
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>
142                             </tr>
143                         </tfoot>
144                         [% END %]
145                         <tbody>
146                             [% FOREACH rule IN rules %]
147                                 <tr id="[% rule.id | html %]" class="rule[% IF rule.edit %]-edit[% END %]">
148                                 [% IF rule.edit %]
149                                     <td>[% rule.id | html %]</td>
150                                     <td>
151                                         <select name="module">
152                                             [% IF rule.module == "source" %]
153                                                 <option value="source" selected="selected">Source</option>
154                                             [% ELSE %]
155                                                 <option value="source">Source</option>
156                                             [% END %]
157                                             [% IF rule.module == "categorycode" %]
158                                                 <option value="categorycode" selected="selected">User category</option>
159                                             [% ELSE %]
160                                                 <option value="categorycode">User category</option>
161                                             [% END %]
162                                             [% IF rule.module == "userid" %]
163                                                 <option value="userid" selected="selected">Username</option>
164                                             [% ELSE %]
165                                                 <option value="userid">Username</option>
166                                             [% END %]
167                                         </select>
168                                     </td>
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>
171                                     <th>
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>
179                                         </select>
180                                     </th>
181                                     <td class="rule-operation-action-edit">
182                                         <select name="add">
183                                             [% IF rule.add %]
184                                                 <option value="0">Skip</option>
185                                                 <option value="1" selected="selected">Add</option>
186                                             [% ELSE %]
187                                                 <option value="0" selected="selected">Skip</option>
188                                                 <option value="1">Add</option>
189                                             [% END %]
190                                         </select>
191                                     </td>
192                                     <td class="rule-operation-action-edit">
193                                         <select name="append">
194                                             [% IF rule.append %]
195                                                 <option value="0">Skip</option>
196                                                 <option value="1" selected="selected">Append</option>
197                                             [% ELSE %]
198                                                 <option value="0" selected="selected">Skip</option>
199                                                 <option value="1">Append</option>
200                                             [% END %]
201                                         </select>
202                                     </td>
203                                     <td class="rule-operation-action-edit">
204                                         <select name="remove">
205                                             [% IF rule.remove %]
206                                                 <option value="0">Skip</option>
207                                                 <option value="1" selected="selected">Remove</option>
208                                             [% ELSE %]
209                                                 <option value="0" selected="selected">Skip</option>
210                                                 <option value="1">Remove</option>
211                                             [% END %]
212                                         </select>
213                                     </td>
214                                     <td class="rule-operation-action-edit">
215                                         <select name="delete">
216                                             [% IF rule.delete %]
217                                                 <option value="0">Skip</option>
218                                                 <option value="1" selected="selected">Delete</option>
219                                             [% ELSE %]
220                                                 <option value="0" selected="selected">Skip</option>
221                                                 <option value="1">Delete</option>
222                                             [% END %]
223                                         </select>
224                                     </td>
225                                     <td class="actions">
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>
228                                     </td>
229                                     <td></td>
230                                 [% ELSE %]
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>
240                                     <td class="actions">
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>
243                                     </td>
244                                     <td>
245                                         [% IF rule.removemarked %]
246                                             <input type="checkbox" name="batchremove" value="[% rule.id | html %]" checked="checked"/>
247                                         [% ELSE %]
248                                             <input type="checkbox" name="batchremove" value="[% rule.id | html %]"/>
249                                         [% END %]
250                                     </td>
251                                 [% END %]
252                                 </tr>
253                             [% END %]
254                         </tbody>
255                     </table>
256                 </form>
257
258                 <form action="/cgi-bin/koha/admin/marc-overlay-rules.pl" method="post">
259                     <input type="hidden" name="op" value="redo-matching" />
260                 </form>
261
262             </div><!-- /.col-sm-10.col-sm-push-2 -->
263
264             <div class="col-sm-2 col-sm-pull-10">
265                 <aside>
266                     [% INCLUDE 'admin-menu.inc' %]
267                 </aside>
268             </div>
269
270         </div><!-- /.row -->
271     </div><!-- /main container-fluid -->
272
273 [% MACRO jsinclude BLOCK %]
274     [% Asset.js("js/admin-menu.js") | $raw %]
275     [% INCLUDE 'datatables.inc' %]
276
277     <script>
278     $(document).ready(function(){
279         function doSubmit(op, id) {
280             $('<input type="hidden"/>')
281             .attr('name', 'op')
282             .attr('value', op)
283             .appendTo('#marc-overlay-rules-form');
284
285             if(id) {
286                 $('<input type="hidden"/>')
287                 .attr('name', 'id')
288                 .attr('value', id)
289                 .appendTo('#marc-overlay-rules-form');
290             }
291
292             var valid = true;
293             if (op == 'add' || op == 'edit') {
294                 var validate = [
295                     $('#marc-overlay-rules-form input[name="filter"]'),
296                     $('#marc-overlay-rules-form input[name="tag"]')
297                 ];
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');
302                             valid = false;
303                         } else {
304                             validate[i].removeClass('required');
305                         }
306                     }
307                 }
308             }
309
310             if (valid) {
311                 $('#marc-overlay-rules-form').submit();
312             }
313
314             return valid;
315         }
316
317         $('#doremove').on('click', function(){
318             doSubmit('doremove');
319         });
320         $('#doedit').on('click', function(){
321             doSubmit('doedit', $("#doedit").attr('value'));
322         });
323         $('#add').on('click', function(){
324             doSubmit('add');
325             return false;
326         });
327         $('#btn_batchremove').on('click', function(){
328             doSubmit('remove');
329         });
330
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');
335             } else {
336                 $('#btn_batchremove').attr('disabled', 'disabled');
337             }
338         });
339
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();
347                     } else {
348                         return $(td).html();
349                     }
350                 });
351         }
352
353         $('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, {
354             "aoColumns": [
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}
366             ],
367             "pagingType": "simple"
368         }));
369
370         var overlay_rules_presets = {};
371         overlay_rules_presets[_("Protect")] = {
372           'add': 0,
373           'append': 0,
374           'remove': 0,
375           'delete': 0
376         };
377         overlay_rules_presets[_("Overwrite")] = {
378           'add': 1,
379           'append': 1,
380           'remove': 1,
381           'delete': 1
382         };
383         overlay_rules_presets[_("Add new")] = {
384           'add': 1,
385           'append': 0,
386           'remove': 0,
387           'delete': 0
388         };
389         overlay_rules_presets[_("Add and append")] = {
390           'add': 1,
391           'append': 1,
392           'remove': 0,
393           'delete': 0
394         };
395         overlay_rules_presets[_("Protect from deletion")] = {
396           'add': 1,
397           'append': 1,
398           'remove': 1,
399           'delete': 0
400         };
401
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;
408
409         function hash_config(config) {
410           return JSON.stringify(config, Object.keys(config).sort());
411         }
412
413         var overlay_rules_preset_map = {};
414         $.each(overlay_rules_presets, function(preset, config) {
415           overlay_rules_preset_map[hash_config(config)] = preset;
416         });
417
418         function operations_config_overlay_rule_preset(config) {
419           return overlay_rules_preset_map[hash_config(config)] || '';
420         }
421
422         /* Set preset values according to operation config */
423         $('.rule').each(function() {
424           var $this = $(this);
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()];
429           });
430           $('.rule-preset', $this).text(
431             operations_config_overlay_rule_preset(operations_config) || _("Custom")
432           );
433         });
434
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() {
440             var $this = $(this);
441             operations_config[$this.attr('name')] = parseInt($this.val());
442           });
443           $('select[name="preset"]', $parent_row).val(
444               operations_config_overlay_rule_preset(operations_config)
445           );
446         });
447
448         /* Listen to preset changes and set operations config accordingly */
449         $('select[name="preset"]').change(function() {
450           var $this = $(this);
451           var $parent_row = $this.closest('tr');
452           var preset = $this.val();
453           if (preset) {
454             $.each(overlay_rules_presets[preset], function(operation, action) {
455               $('select[name="' + operation + '"]', $parent_row).val(action);
456             });
457           }
458         });
459
460         var module_filter_options = {
461           source: {
462             '*': '*',
463             batchmod: _("Batch record modification"),
464             intranet: _("Staff interface MARC editor"),
465             batchimport: _("Staged MARC import"),
466             z3950: _("Z39.50"),
467             /* bulkmarcimport: _("bulkmarcimport.pl"), */
468             import_lexile: _("import_lexile.pl")
469           },
470           categorycode: {
471             '*': '*',
472             [% FOREACH categorycode IN categorycodes %]
473               [% categorycode.categorycode | html %]: "[% categorycode.description | html %]",
474             [% END %]
475           }
476         };
477
478         //Kind of hack: Replace filter value with label when one exist
479         $('.rule-module').each(function() {
480           var $this = $(this);
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()]);
486             }
487           }
488         });
489
490         var $filter_container = $('#filter-container');
491
492         /* Listen to module changes and set filter input accordingly */
493         $('select[name="module"]').change(function() {
494           var $this = $(this);
495           var module_name = $this.val();
496
497           /* Remove current element if any */
498           $filter_container.empty();
499
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);
509             }
510           }
511           else {
512             // Create text input element
513             filter_elem = document.createElement('input');
514             filter_elem.type = 'text';
515             filter_elem.setAttribute('size', 5);
516           }
517           filter_elem.name = 'filter';
518           filter_elem.id = 'filter';
519           $filter_container.append(filter_elem);
520         }).change(); // Trigger change
521
522         // Hack: set value if editing rule
523         if ($filter_container.data('filter')) {
524           $('#filter').val($filter_container.data('filter'));
525         }
526
527     });
528     </script>
529 [% END %]
530 [% INCLUDE 'intranet-bottom.inc' %]