|
Lines 321-566
Link Here
|
| 321 |
<script> |
321 |
<script> |
| 322 |
var categories = [% To.json( categories ) | $raw %]; |
322 |
var categories = [% To.json( categories ) | $raw %]; |
| 323 |
</script> |
323 |
</script> |
| 324 |
|
|
|
| 325 |
<script> |
324 |
<script> |
| 326 |
$(document).ready(function(){ |
325 |
$(document).ready(function () { |
| 327 |
|
326 |
var validator = $("#marc-overlay-rules-form").validate({ |
| 328 |
var validator = $( "#marc-overlay-rules-form" ).validate({ |
327 |
ignore: ".ignore", |
| 329 |
ignore: ".ignore" |
|
|
| 330 |
}); |
328 |
}); |
| 331 |
|
329 |
|
| 332 |
function prepareSubmit(op, id) { |
330 |
function prepareSubmit(op, id) { |
| 333 |
|
|
|
| 334 |
$('#marc-overlay-rules-form > input[name="op"]').val(op); |
331 |
$('#marc-overlay-rules-form > input[name="op"]').val(op); |
| 335 |
|
332 |
|
| 336 |
if(id) { |
333 |
if (id) { |
| 337 |
$('<input type="hidden"/>') |
334 |
$('<input type="hidden"/>').attr("name", "id").attr("value", id).appendTo("#marc-overlay-rules-form"); |
| 338 |
.attr('name', 'id') |
|
|
| 339 |
.attr('value', id) |
| 340 |
.appendTo('#marc-overlay-rules-form'); |
| 341 |
} |
335 |
} |
| 342 |
|
336 |
|
| 343 |
if (op == 'cud-add' || op == 'cud-edit') { |
337 |
if (op == "cud-add" || op == "cud-edit") { |
| 344 |
$('#marc-overlay-rules-form input[name="tag"]').removeClass('ignore'); |
338 |
$('#marc-overlay-rules-form input[name="tag"]').removeClass("ignore"); |
| 345 |
} else { |
339 |
} else { |
| 346 |
$('#marc-overlay-rules-form input[name="tag"]').addClass('ignore'); |
340 |
$('#marc-overlay-rules-form input[name="tag"]').addClass("ignore"); |
| 347 |
} |
341 |
} |
| 348 |
|
|
|
| 349 |
} |
342 |
} |
| 350 |
|
343 |
|
| 351 |
$('#doedit').on('click', function(){ |
344 |
$("#doedit").on("click", function () { |
| 352 |
prepareSubmit('cud-edit', $("#doedit").attr('value')); |
345 |
prepareSubmit("cud-edit", $("#doedit").attr("value")); |
| 353 |
}); |
346 |
}); |
| 354 |
$('#add').on('click', function(){ |
347 |
$("#add").on("click", function () { |
| 355 |
prepareSubmit('cud-add'); |
348 |
prepareSubmit("cud-add"); |
| 356 |
}); |
349 |
}); |
| 357 |
$('.btn_remove').on('click', function(el){ |
350 |
$(".btn_remove").on("click", function (el) { |
| 358 |
// remove all earlier selections |
351 |
// remove all earlier selections |
| 359 |
$('#marc-overlay-rules-form input[name="batchremove"]').each(function() { |
352 |
$('#marc-overlay-rules-form input[name="batchremove"]').each(function () { |
| 360 |
$(this).prop( "checked", false ); |
353 |
$(this).prop("checked", false); |
| 361 |
}); |
354 |
}); |
| 362 |
|
355 |
|
| 363 |
confirm_remove(el.currentTarget.value); |
356 |
confirm_remove(el.currentTarget.value); |
| 364 |
}); |
357 |
}); |
| 365 |
$('#btn_batchremove').on('click', function(){ |
358 |
$("#btn_batchremove").on("click", function () { |
| 366 |
confirm_remove(); |
359 |
confirm_remove(); |
| 367 |
}); |
360 |
}); |
| 368 |
|
361 |
|
| 369 |
function confirm_remove(id){ |
362 |
function confirm_remove(id) { |
| 370 |
if (confirm(_("Are you sure you want to remove the selected rule(s)?"))){ |
363 |
if (confirm(_("Are you sure you want to remove the selected rule(s)?"))) { |
| 371 |
prepareSubmit('cud-remove', id); |
364 |
prepareSubmit("cud-remove", id); |
| 372 |
$('#marc-overlay-rules-form').submit() |
365 |
$("#marc-overlay-rules-form").submit(); |
| 373 |
} |
366 |
} |
| 374 |
} |
367 |
} |
| 375 |
|
368 |
|
| 376 |
/* Disable batch remove unless one or more checkboxes are checked */ |
369 |
/* Disable batch remove unless one or more checkboxes are checked */ |
| 377 |
$('input[name="batchremove"]').change(function() { |
370 |
$('input[name="batchremove"]').change(function () { |
| 378 |
if($('input[name="batchremove"]:checked').length > 0) { |
371 |
if ($('input[name="batchremove"]:checked').length > 0) { |
| 379 |
$('#btn_batchremove').removeAttr('disabled'); |
372 |
$("#btn_batchremove").removeAttr("disabled"); |
| 380 |
} else { |
373 |
} else { |
| 381 |
$('#btn_batchremove').attr('disabled', 'disabled'); |
374 |
$("#btn_batchremove").attr("disabled", "disabled"); |
| 382 |
} |
375 |
} |
| 383 |
}); |
376 |
}); |
| 384 |
|
377 |
|
| 385 |
$.fn.dataTable.ext.order['dom-input'] = function (settings, col) { |
378 |
$.fn.dataTable.ext.order["dom-input"] = function (settings, col) { |
| 386 |
return this.api().column(col, { order: 'index' }).nodes() |
379 |
return this.api() |
|
|
380 |
.column(col, { order: "index" }) |
| 381 |
.nodes() |
| 387 |
.map(function (td, i) { |
382 |
.map(function (td, i) { |
| 388 |
if($('input', td).val() != undefined) { |
383 |
if ($("input", td).val() != undefined) { |
| 389 |
return $('input', td).val(); |
384 |
return $("input", td).val(); |
| 390 |
} else if($('select', td).val() != undefined) { |
385 |
} else if ($("select", td).val() != undefined) { |
| 391 |
return $('option[selected="selected"]', td).val(); |
386 |
return $('option[selected="selected"]', td).val(); |
| 392 |
} else { |
387 |
} else { |
| 393 |
return $(td).html(); |
388 |
return $(td).html(); |
| 394 |
} |
389 |
} |
| 395 |
}); |
390 |
}); |
| 396 |
} |
391 |
}; |
| 397 |
|
392 |
|
| 398 |
$('#marc-overlay-rules').kohaTable({ |
393 |
$("#marc-overlay-rules").kohaTable({ |
| 399 |
columns: [ |
394 |
columns: [ |
| 400 |
{searchable: false, orderable: false}, |
395 |
{ searchable: false, orderable: false }, |
| 401 |
{orderDataType: "dom-input"}, |
396 |
{ orderDataType: "dom-input" }, |
| 402 |
{orderDataType: "dom-input"}, |
397 |
{ orderDataType: "dom-input" }, |
| 403 |
{searchable: false, orderDataType: "dom-input"}, |
398 |
{ searchable: false, orderDataType: "dom-input" }, |
| 404 |
{searchable: false, orderDataType: "dom-input"}, |
399 |
{ searchable: false, orderDataType: "dom-input" }, |
| 405 |
{searchable: false, orderDataType: "dom-input"}, |
400 |
{ searchable: false, orderDataType: "dom-input" }, |
| 406 |
{searchable: false, orderDataType: "dom-input"}, |
401 |
{ searchable: false, orderDataType: "dom-input" }, |
| 407 |
{searchable: false, orderDataType: "dom-input"}, |
402 |
{ searchable: false, orderDataType: "dom-input" }, |
| 408 |
{searchable: false, orderDataType: "dom-input"}, |
403 |
{ searchable: false, orderDataType: "dom-input" }, |
| 409 |
{searchable: false, orderable: false}, |
404 |
{ searchable: false, orderable: false }, |
| 410 |
{searchable: false, orderable: false} |
405 |
{ searchable: false, orderable: false }, |
| 411 |
], |
406 |
], |
| 412 |
pagingType: "simple" |
407 |
pagingType: "simple", |
| 413 |
}); |
408 |
}); |
| 414 |
|
409 |
|
| 415 |
var overlay_rules_presets = {}; |
410 |
var overlay_rules_presets = {}; |
| 416 |
overlay_rules_presets["protect"] = { |
411 |
overlay_rules_presets["protect"] = { |
| 417 |
'add': 0, |
412 |
add: 0, |
| 418 |
'append': 0, |
413 |
append: 0, |
| 419 |
'remove': 0, |
414 |
remove: 0, |
| 420 |
'delete': 0 |
415 |
delete: 0, |
| 421 |
}; |
416 |
}; |
| 422 |
overlay_rules_presets["overwrite"] = { |
417 |
overlay_rules_presets["overwrite"] = { |
| 423 |
'add': 1, |
418 |
add: 1, |
| 424 |
'append': 1, |
419 |
append: 1, |
| 425 |
'remove': 1, |
420 |
remove: 1, |
| 426 |
'delete': 1 |
421 |
delete: 1, |
| 427 |
}; |
422 |
}; |
| 428 |
overlay_rules_presets["add"] = { |
423 |
overlay_rules_presets["add"] = { |
| 429 |
'add': 1, |
424 |
add: 1, |
| 430 |
'append': 0, |
425 |
append: 0, |
| 431 |
'remove': 0, |
426 |
remove: 0, |
| 432 |
'delete': 0 |
427 |
delete: 0, |
| 433 |
}; |
428 |
}; |
| 434 |
overlay_rules_presets["addappend"] = { |
429 |
overlay_rules_presets["addappend"] = { |
| 435 |
'add': 1, |
430 |
add: 1, |
| 436 |
'append': 1, |
431 |
append: 1, |
| 437 |
'remove': 0, |
432 |
remove: 0, |
| 438 |
'delete': 0 |
433 |
delete: 0, |
| 439 |
}; |
434 |
}; |
| 440 |
overlay_rules_presets["protectfromdeletion"] = { |
435 |
overlay_rules_presets["protectfromdeletion"] = { |
| 441 |
'add': 1, |
436 |
add: 1, |
| 442 |
'append': 1, |
437 |
append: 1, |
| 443 |
'remove': 1, |
438 |
remove: 1, |
| 444 |
'delete': 0 |
439 |
delete: 0, |
| 445 |
}; |
440 |
}; |
| 446 |
|
441 |
|
| 447 |
function hash_config(config) { |
442 |
function hash_config(config) { |
| 448 |
return JSON.stringify(config, Object.keys(config).sort()); |
443 |
return JSON.stringify(config, Object.keys(config).sort()); |
| 449 |
} |
444 |
} |
| 450 |
|
445 |
|
| 451 |
var overlay_rules_preset_map = {}; |
446 |
var overlay_rules_preset_map = {}; |
| 452 |
$.each(overlay_rules_presets, function(preset, config) { |
447 |
$.each(overlay_rules_presets, function (preset, config) { |
| 453 |
overlay_rules_preset_map[hash_config(config)] = preset; |
448 |
overlay_rules_preset_map[hash_config(config)] = preset; |
| 454 |
}); |
449 |
}); |
| 455 |
|
450 |
|
| 456 |
function operations_config_overlay_rule_preset(config) { |
451 |
function operations_config_overlay_rule_preset(config) { |
| 457 |
return overlay_rules_preset_map[hash_config(config)] || ''; |
452 |
return overlay_rules_preset_map[hash_config(config)] || ""; |
| 458 |
} |
453 |
} |
| 459 |
|
454 |
|
| 460 |
/* Set preset values according to operation config */ |
455 |
/* Set preset values according to operation config */ |
| 461 |
$('.rule').each(function() { |
456 |
$(".rule").each(function () { |
| 462 |
var $this = $(this); |
457 |
var $this = $(this); |
| 463 |
var operations_config = {}; |
458 |
var operations_config = {}; |
| 464 |
$('.rule-operation-action', $this).each(function() { |
459 |
$(".rule-operation-action", $this).each(function () { |
| 465 |
var $operation = $(this); |
460 |
var $operation = $(this); |
| 466 |
operations_config[$operation.data('operation')] = $operation.data('value'); |
461 |
operations_config[$operation.data("operation")] = $operation.data("value"); |
| 467 |
}); |
462 |
}); |
| 468 |
$('.rule-preset', $this).text( |
463 |
$(".rule-preset", $this).text($('select[name="preset"] option[value="' + operations_config_overlay_rule_preset(operations_config) + '"]').text()); |
| 469 |
$('select[name="preset"] option[value="' + operations_config_overlay_rule_preset(operations_config) + '"]').text() |
|
|
| 470 |
); |
| 471 |
}); |
464 |
}); |
| 472 |
|
465 |
|
| 473 |
/* Listen to operations config changes and set presets accordingly */ |
466 |
/* Listen to operations config changes and set presets accordingly */ |
| 474 |
$('.rule-operation-action-edit select').change(function() { |
467 |
$(".rule-operation-action-edit select").change(function () { |
| 475 |
var operations_config = {}; |
468 |
var operations_config = {}; |
| 476 |
var $parent_row = $(this).closest('tr'); |
469 |
var $parent_row = $(this).closest("tr"); |
| 477 |
$('.rule-operation-action-edit select', $parent_row).each(function() { |
470 |
$(".rule-operation-action-edit select", $parent_row).each(function () { |
| 478 |
var $this = $(this); |
471 |
var $this = $(this); |
| 479 |
operations_config[$this.attr('name')] = parseInt($this.val()); |
472 |
operations_config[$this.attr("name")] = parseInt($this.val()); |
| 480 |
}); |
473 |
}); |
| 481 |
$('select[name="preset"]', $parent_row).val( |
474 |
$('select[name="preset"]', $parent_row).val(operations_config_overlay_rule_preset(operations_config)); |
| 482 |
operations_config_overlay_rule_preset(operations_config) |
|
|
| 483 |
); |
| 484 |
}); |
475 |
}); |
| 485 |
|
476 |
|
| 486 |
/* Listen to preset changes and set operations config accordingly */ |
477 |
/* Listen to preset changes and set operations config accordingly */ |
| 487 |
$('select[name="preset"]').change(function() { |
478 |
$('select[name="preset"]').change(function () { |
| 488 |
var $this = $(this); |
479 |
var $this = $(this); |
| 489 |
var $parent_row = $this.closest('tr'); |
480 |
var $parent_row = $this.closest("tr"); |
| 490 |
var preset = $this.val(); |
481 |
var preset = $this.val(); |
| 491 |
if (preset) { |
482 |
if (preset) { |
| 492 |
$.each(overlay_rules_presets[preset], function(operation, action) { |
483 |
$.each(overlay_rules_presets[preset], function (operation, action) { |
| 493 |
$('select[name="' + operation + '"]', $parent_row).val(action); |
484 |
$('select[name="' + operation + '"]', $parent_row).val(action); |
| 494 |
}); |
485 |
}); |
| 495 |
} |
486 |
} |
| 496 |
}); |
487 |
}); |
| 497 |
|
488 |
|
| 498 |
// Add * => * to this array of objects, and *reduce* it to one object |
489 |
// Add * => * to this array of objects, and *reduce* it to one object |
| 499 |
// Note: This allows displaying a sorted list of categories later, but we still depend on an object! |
490 |
// Note: This allows displaying a sorted list of categories later, but we still depend on an object! |
| 500 |
categories.unshift({ categorycode: '*', description: '*'}); |
491 |
categories.unshift({ categorycode: "*", description: "*" }); |
| 501 |
categories = categories.reduce( ( a,c ) => ( { ...a, [c.categorycode]: c.description } ), {} ); |
492 |
categories = categories.reduce((a, c) => ({ ...a, [c.categorycode]: c.description }), {}); |
| 502 |
|
493 |
|
| 503 |
var module_filter_options = { |
494 |
var module_filter_options = { |
| 504 |
source: { |
495 |
source: { |
| 505 |
'*': '*', |
496 |
"*": "*", |
| 506 |
batchmod: _("Batch record modification"), |
497 |
batchmod: _("Batch record modification"), |
| 507 |
intranet: _("Staff interface MARC editor"), |
498 |
intranet: _("Staff interface MARC editor"), |
| 508 |
batchimport: _("Staged MARC import"), |
499 |
batchimport: _("Staged MARC import"), |
| 509 |
z3950: _("Z39.50"), |
500 |
z3950: _("Z39.50"), |
| 510 |
bulkmarcimport: _("bulkmarcimport.pl"), |
501 |
bulkmarcimport: _("bulkmarcimport.pl"), |
| 511 |
import_lexile: _("import_lexile.pl") |
502 |
import_lexile: _("import_lexile.pl"), |
| 512 |
}, |
503 |
}, |
| 513 |
|
504 |
|
| 514 |
categorycode: categories, |
505 |
categorycode: categories, |
| 515 |
}; |
506 |
}; |
| 516 |
|
507 |
|
| 517 |
//Kind of hack: Replace filter value with label when one exist |
508 |
//Kind of hack: Replace filter value with label when one exist |
| 518 |
$('.rule-module').each(function() { |
509 |
$(".rule-module").each(function () { |
| 519 |
var $this = $(this); |
510 |
var $this = $(this); |
| 520 |
var module = $this.text(); |
511 |
var module = $this.text(); |
| 521 |
if (module in module_filter_options) { |
512 |
if (module in module_filter_options) { |
| 522 |
let $filter = $this.siblings('.rule-filter'); |
513 |
let $filter = $this.siblings(".rule-filter"); |
| 523 |
if ($filter.text() in module_filter_options[module]) { |
514 |
if ($filter.text() in module_filter_options[module]) { |
| 524 |
$filter.text(module_filter_options[module][$filter.text()]); |
515 |
$filter.text(module_filter_options[module][$filter.text()]); |
|
|
516 |
} |
| 525 |
} |
517 |
} |
| 526 |
} |
|
|
| 527 |
}); |
518 |
}); |
| 528 |
|
519 |
|
| 529 |
var $filter_container = $('#filter-container'); |
520 |
var $filter_container = $("#filter-container"); |
| 530 |
|
521 |
|
| 531 |
/* Listen to module changes and set filter input accordingly */ |
522 |
/* Listen to module changes and set filter input accordingly */ |
| 532 |
$('select[name="module"]').change(function() { |
523 |
$('select[name="module"]') |
| 533 |
var $this = $(this); |
524 |
.change(function () { |
| 534 |
var module_name = $this.val(); |
525 |
var $this = $(this); |
| 535 |
|
526 |
var module_name = $this.val(); |
| 536 |
/* Remove current element if any */ |
527 |
|
| 537 |
$filter_container.empty(); |
528 |
/* Remove current element if any */ |
| 538 |
|
529 |
$filter_container.empty(); |
| 539 |
var filter_elem = null; |
530 |
|
| 540 |
if (module_name in module_filter_options) { |
531 |
var filter_elem = null; |
| 541 |
// Create select element |
532 |
if (module_name in module_filter_options) { |
| 542 |
filter_elem = document.createElement('select'); |
533 |
// Create select element |
| 543 |
for (var filter_value in module_filter_options[module_name]) { |
534 |
filter_elem = document.createElement("select"); |
| 544 |
var option = document.createElement('option'); |
535 |
for (var filter_value in module_filter_options[module_name]) { |
| 545 |
option.value = filter_value; |
536 |
var option = document.createElement("option"); |
| 546 |
option.text = module_filter_options[module_name][filter_value]; |
537 |
option.value = filter_value; |
| 547 |
filter_elem.appendChild(option); |
538 |
option.text = module_filter_options[module_name][filter_value]; |
| 548 |
} |
539 |
filter_elem.appendChild(option); |
| 549 |
} |
540 |
} |
| 550 |
else { |
541 |
} else { |
| 551 |
// Create text input element |
542 |
// Create text input element |
| 552 |
filter_elem = document.createElement('input'); |
543 |
filter_elem = document.createElement("input"); |
| 553 |
filter_elem.type = 'text'; |
544 |
filter_elem.type = "text"; |
| 554 |
filter_elem.setAttribute('size', 5); |
545 |
filter_elem.setAttribute("size", 5); |
| 555 |
} |
546 |
} |
| 556 |
filter_elem.name = 'filter'; |
547 |
filter_elem.name = "filter"; |
| 557 |
filter_elem.id = 'filter'; |
548 |
filter_elem.id = "filter"; |
| 558 |
$filter_container.append(filter_elem); |
549 |
$filter_container.append(filter_elem); |
| 559 |
}).change(); // Trigger change |
550 |
}) |
|
|
551 |
.change(); // Trigger change |
| 560 |
|
552 |
|
| 561 |
// Hack: set value if editing rule |
553 |
// Hack: set value if editing rule |
| 562 |
if ($filter_container.data('filter')) { |
554 |
if ($filter_container.data("filter")) { |
| 563 |
$('#filter').val($filter_container.data('filter')); |
555 |
$("#filter").val($filter_container.data("filter")); |
| 564 |
} |
556 |
} |
| 565 |
}); |
557 |
}); |
| 566 |
</script> |
558 |
</script> |