Lines 1-4
Link Here
|
1 |
[% USE raw %] |
1 |
[% USE raw %] |
|
|
2 |
[% USE Asset %] |
3 |
[% SET footerjs = 1 %] |
2 |
[% USE Koha %] |
4 |
[% USE Koha %] |
3 |
[% INCLUDE 'doc-head-open.inc' %] |
5 |
[% INCLUDE 'doc-head-open.inc' %] |
4 |
<title>MARC overlay rules › Koha › Administration</title> |
6 |
<title>MARC overlay rules › Koha › Administration</title> |
Lines 12-269
Link Here
|
12 |
} |
14 |
} |
13 |
</style> |
15 |
</style> |
14 |
|
16 |
|
15 |
<script> |
|
|
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> |
17 |
</head> |
268 |
<body id="admin_marc-overlay-rules" class="admin"> |
18 |
<body id="admin_marc-overlay-rules" class="admin"> |
269 |
[% INCLUDE 'header.inc' %] |
19 |
[% INCLUDE 'header.inc' %] |
Lines 502-510
$(document).ready(function(){
Link Here
|
502 |
</aside> |
252 |
</aside> |
503 |
</div> |
253 |
</div> |
504 |
|
254 |
|
505 |
</div> |
255 |
</div><!-- /.row --> |
506 |
<!-- /.row> |
256 |
</div><!-- /main container-fluid --> |
507 |
</div> |
257 |
|
508 |
<!-- /main container-fluid --> |
258 |
[% MACRO jsinclude BLOCK %] |
|
|
259 |
<script> |
260 |
function doSubmit(op, id) { |
261 |
$('<input type="hidden"/>') |
262 |
.attr('name', 'op') |
263 |
.attr('value', op) |
264 |
.appendTo('#marc-overlay-rules-form'); |
265 |
|
266 |
if(id) { |
267 |
$('<input type="hidden"/>') |
268 |
.attr('name', 'id') |
269 |
.attr('value', id) |
270 |
.appendTo('#marc-overlay-rules-form'); |
271 |
} |
272 |
|
273 |
var valid = true; |
274 |
if (op == 'add' || op == 'edit') { |
275 |
var validate = [ |
276 |
$('#marc-overlay-rules-form input[name="filter"]'), |
277 |
$('#marc-overlay-rules-form input[name="tag"]') |
278 |
]; |
279 |
for(var i = 0; i < validate.length; i++) { |
280 |
if (validate[i].length) { |
281 |
if(validate[i].val().length == 0) { |
282 |
validate[i].addClass('required'); |
283 |
valid = false; |
284 |
} else { |
285 |
validate[i].removeClass('required'); |
286 |
} |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
if (valid) { |
292 |
$('#marc-overlay-rules-form').submit(); |
293 |
} |
294 |
|
295 |
return valid; |
296 |
} |
297 |
|
298 |
$(document).ready(function(){ |
299 |
$('#doremove').on('click', function(){ |
300 |
doSubmit('doremove'); |
301 |
}); |
302 |
$('#doedit').on('click', function(){ |
303 |
doSubmit('doedit', $("#doedit").attr('value')); |
304 |
}); |
305 |
$('#add').on('click', function(){ |
306 |
doSubmit('add'); |
307 |
return false; |
308 |
}); |
309 |
$('#btn_batchremove').on('click', function(){ |
310 |
doSubmit('remove'); |
311 |
}); |
312 |
|
313 |
/* Disable batch remove unless one or more checkboxes are checked */ |
314 |
$('input[name="batchremove"]').change(function() { |
315 |
if($('input[name="batchremove"]:checked').length > 0) { |
316 |
$('#btn_batchremove').removeAttr('disabled'); |
317 |
} else { |
318 |
$('#btn_batchremove').attr('disabled', 'disabled'); |
319 |
} |
320 |
}); |
321 |
|
322 |
$.fn.dataTable.ext.order['dom-input'] = function (settings, col) { |
323 |
return this.api().column(col, { order: 'index' }).nodes() |
324 |
.map(function (td, i) { |
325 |
if($('input', td).val() != undefined) { |
326 |
return $('input', td).val(); |
327 |
} else if($('select', td).val() != undefined) { |
328 |
return $('option[selected="selected"]', td).val(); |
329 |
} else { |
330 |
return $(td).html(); |
331 |
} |
332 |
}); |
333 |
} |
334 |
|
335 |
$('#marc-overlay-rules').dataTable($.extend(true, {}, dataTablesDefaults, { |
336 |
"aoColumns": [ |
337 |
{"bSearchable": false, "bSortable": false}, |
338 |
{"sSortDataType": "dom-input"}, |
339 |
{"sSortDataType": "dom-input"}, |
340 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
341 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
342 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
343 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
344 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
345 |
{"bSearchable": false, "sSortDataType": "dom-input"}, |
346 |
{"bSearchable": false, "bSortable": false}, |
347 |
{"bSearchable": false, "bSortable": false} |
348 |
], |
349 |
"pagingType": "simple" |
350 |
})); |
351 |
|
352 |
var overlay_rules_presets = {}; |
353 |
overlay_rules_presets[_("Protect")] = { |
354 |
'add': 0, |
355 |
'append': 0, |
356 |
'remove': 0, |
357 |
'delete': 0 |
358 |
}; |
359 |
overlay_rules_presets[_("Overwrite")] = { |
360 |
'add': 1, |
361 |
'append': 1, |
362 |
'remove': 1, |
363 |
'delete': 1 |
364 |
}; |
365 |
overlay_rules_presets[_("Add new")] = { |
366 |
'add': 1, |
367 |
'append': 0, |
368 |
'remove': 0, |
369 |
'delete': 0 |
370 |
}; |
371 |
overlay_rules_presets[_("Add and append")] = { |
372 |
'add': 1, |
373 |
'append': 1, |
374 |
'remove': 0, |
375 |
'delete': 0 |
376 |
}; |
377 |
overlay_rules_presets[_("Protect from deletion")] = { |
378 |
'add': 1, |
379 |
'append': 1, |
380 |
'remove': 1, |
381 |
'delete': 0 |
382 |
}; |
383 |
|
384 |
var overlay_rules_label_to_value = {}; |
385 |
overlay_rules_label_to_value[_("Add")] = 1; |
386 |
overlay_rules_label_to_value[_("Append")] = 1; |
387 |
overlay_rules_label_to_value[_("Remove")] = 1; |
388 |
overlay_rules_label_to_value[_("Delete")] = 1; |
389 |
overlay_rules_label_to_value[_("Skip")] = 0; |
390 |
|
391 |
function hash_config(config) { |
392 |
return JSON.stringify(config, Object.keys(config).sort()); |
393 |
} |
394 |
|
395 |
var overlay_rules_preset_map = {}; |
396 |
$.each(overlay_rules_presets, function(preset, config) { |
397 |
overlay_rules_preset_map[hash_config(config)] = preset; |
398 |
}); |
399 |
|
400 |
function operations_config_overlay_rule_preset(config) { |
401 |
return overlay_rules_preset_map[hash_config(config)] || ''; |
402 |
} |
403 |
|
404 |
/* Set preset values according to operation config */ |
405 |
$('.rule').each(function() { |
406 |
var $this = $(this); |
407 |
var operations_config = {}; |
408 |
$('.rule-operation-action', $this).each(function() { |
409 |
var $operation = $(this); |
410 |
operations_config[$operation.data('operation')] = overlay_rules_label_to_value[$operation.text()]; |
411 |
}); |
412 |
$('.rule-preset', $this).text( |
413 |
operations_config_overlay_rule_preset(operations_config) || _("Custom") |
414 |
); |
415 |
}); |
509 |
|
416 |
|
|
|
417 |
/* Listen to operations config changes and set presets accordingly */ |
418 |
$('.rule-operation-action-edit select').change(function() { |
419 |
var operations_config = {}; |
420 |
var $parent_row = $(this).closest('tr'); |
421 |
$('.rule-operation-action-edit select', $parent_row).each(function() { |
422 |
var $this = $(this); |
423 |
operations_config[$this.attr('name')] = parseInt($this.val()); |
424 |
}); |
425 |
$('select[name="preset"]', $parent_row).val( |
426 |
operations_config_overlay_rule_preset(operations_config) |
427 |
); |
428 |
}); |
429 |
|
430 |
/* Listen to preset changes and set operations config accordingly */ |
431 |
$('select[name="preset"]').change(function() { |
432 |
var $this = $(this); |
433 |
var $parent_row = $this.closest('tr'); |
434 |
var preset = $this.val(); |
435 |
if (preset) { |
436 |
$.each(overlay_rules_presets[preset], function(operation, action) { |
437 |
$('select[name="' + operation + '"]', $parent_row).val(action); |
438 |
}); |
439 |
} |
440 |
}); |
441 |
|
442 |
var module_filter_options = { |
443 |
source: { |
444 |
'*': '*', |
445 |
batchmod: _("Batch record modification"), |
446 |
intranet: _("Staff client MARC editor"), |
447 |
batchimport: _("Staged MARC import"), |
448 |
z3950: _("Z39.50"), |
449 |
/* bulkmarcimport: _("bulkmarcimport.pl"), */ |
450 |
import_lexile: _("import_lexile.pl") |
451 |
}, |
452 |
categorycode: { |
453 |
'*': '*', |
454 |
[% FOREACH categorycode IN categorycodes %] |
455 |
[% categorycode.categorycode | html %]: "[% categorycode.description | html %]", |
456 |
[% END %] |
457 |
} |
458 |
}; |
459 |
|
460 |
//Kind of hack: Replace filter value with label when one exist |
461 |
$('.rule-module').each(function() { |
462 |
var $this = $(this); |
463 |
var module = $this.text(); |
464 |
if (module in module_filter_options) { |
465 |
let $filter = $this.siblings('.rule-filter'); |
466 |
if ($filter.text() in module_filter_options[module]) { |
467 |
$filter.text(module_filter_options[module][$filter.text()]); |
468 |
} |
469 |
} |
470 |
}); |
471 |
|
472 |
var $filter_container = $('#filter-container'); |
473 |
|
474 |
/* Listen to module changes and set filter input accordingly */ |
475 |
$('select[name="module"]').change(function() { |
476 |
var $this = $(this); |
477 |
var module_name = $this.val(); |
478 |
|
479 |
/* Remove current element if any */ |
480 |
$filter_container.empty(); |
481 |
|
482 |
var filter_elem = null; |
483 |
if (module_name in module_filter_options) { |
484 |
// Create select element |
485 |
filter_elem = document.createElement('select'); |
486 |
for (var filter_value in module_filter_options[module_name]) { |
487 |
var option = document.createElement('option'); |
488 |
option.value = filter_value; |
489 |
option.text = module_filter_options[module_name][filter_value]; |
490 |
filter_elem.appendChild(option); |
491 |
} |
492 |
} |
493 |
else { |
494 |
// Create text input element |
495 |
filter_elem = document.createElement('input'); |
496 |
filter_elem.type = 'text'; |
497 |
filter_elem.setAttribute('size', 5); |
498 |
} |
499 |
filter_elem.name = 'filter'; |
500 |
filter_elem.id = 'filter'; |
501 |
$filter_container.append(filter_elem); |
502 |
}).change(); // Trigger change |
503 |
|
504 |
// Hack: set value if editing rule |
505 |
if ($filter_container.data('filter')) { |
506 |
$('#filter').val($filter_container.data('filter')); |
507 |
} |
508 |
|
509 |
}); |
510 |
</script> |
511 |
[% END %] |
510 |
[% INCLUDE 'intranet-bottom.inc' %] |
512 |
[% INCLUDE 'intranet-bottom.inc' %] |
511 |
- |
|
|