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