|
Lines 1-5
Link Here
|
| 1 |
/* global __ */ |
1 |
/* global __ */ |
| 2 |
/* exported openAuth ExpandField CloneField CloneSubfield UnCloneField CloneItemSubfield CheckMandatorySubfields */ |
2 |
/* exported openAuth ExpandField CloneField CloneSubfield UnCloneField CloneItemSubfield CheckMandatorySubfields registerFrameworkPluginHandler */ |
| 3 |
|
3 |
|
| 4 |
/* |
4 |
/* |
| 5 |
* Unified file for catalogue edition |
5 |
* Unified file for catalogue edition |
|
Lines 253-260
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
| 253 |
|
253 |
|
| 254 |
var inputs = divs[i].getElementsByTagName("input"); |
254 |
var inputs = divs[i].getElementsByTagName("input"); |
| 255 |
var id_input = ""; |
255 |
var id_input = ""; |
| 256 |
var olddiv; |
|
|
| 257 |
var oldcontrol; |
| 258 |
|
256 |
|
| 259 |
for (j = 0; j < inputs.length; j++) { |
257 |
for (j = 0; j < inputs.length; j++) { |
| 260 |
if ( |
258 |
if ( |
|
Lines 323-333
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
| 323 |
} |
321 |
} |
| 324 |
} |
322 |
} |
| 325 |
} |
323 |
} |
| 326 |
if ($(inputs[1]).hasClass("framework_plugin")) { |
|
|
| 327 |
olddiv = original.getElementsByTagName("li")[i]; |
| 328 |
oldcontrol = olddiv.getElementsByTagName("input")[1]; |
| 329 |
AddEventHandlers(oldcontrol, inputs[1], id_input); |
| 330 |
} |
| 331 |
} |
324 |
} |
| 332 |
// when cloning a subfield, re set its label too. |
325 |
// when cloning a subfield, re set its label too. |
| 333 |
try { |
326 |
try { |
|
Lines 380-403
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
| 380 |
if (buttonDot) { |
373 |
if (buttonDot) { |
| 381 |
// 2 possibilities : |
374 |
// 2 possibilities : |
| 382 |
try { |
375 |
try { |
| 383 |
if ($(buttonDot).hasClass("framework_plugin")) { |
376 |
// do not copy the script section. |
| 384 |
olddiv = original.getElementsByTagName("li")[i]; |
377 |
var script = |
| 385 |
oldcontrol = |
378 |
spans[0].getElementsByTagName("script")[0]; |
| 386 |
olddiv.getElementsByTagName("a")[0]; |
379 |
spans[0].removeChild(script); |
| 387 |
AddEventHandlers( |
|
|
| 388 |
oldcontrol, |
| 389 |
buttonDot, |
| 390 |
id_input |
| 391 |
); |
| 392 |
} |
| 393 |
try { |
| 394 |
// do not copy the script section. |
| 395 |
var script = |
| 396 |
spans[0].getElementsByTagName("script")[0]; |
| 397 |
spans[0].removeChild(script); |
| 398 |
} catch (e) { |
| 399 |
// do nothing if there is no script |
| 400 |
} |
| 401 |
} catch (e) { |
380 |
} catch (e) { |
| 402 |
// |
381 |
// |
| 403 |
} |
382 |
} |
|
Lines 493-499
function CloneSubfield(index, advancedMARCEditor) {
Link Here
|
| 493 |
var selects = clone.getElementsByTagName("select"); |
472 |
var selects = clone.getElementsByTagName("select"); |
| 494 |
var textareas = clone.getElementsByTagName("textarea"); |
473 |
var textareas = clone.getElementsByTagName("textarea"); |
| 495 |
var linkid; |
474 |
var linkid; |
| 496 |
var oldcontrol; |
|
|
| 497 |
|
475 |
|
| 498 |
// input |
476 |
// input |
| 499 |
var id_input = ""; |
477 |
var id_input = ""; |
|
Lines 513-524
function CloneSubfield(index, advancedMARCEditor) {
Link Here
|
| 513 |
linkid = id_input; |
491 |
linkid = id_input; |
| 514 |
} |
492 |
} |
| 515 |
|
493 |
|
| 516 |
// Plugin input |
|
|
| 517 |
if ($(inputs[1]).hasClass("framework_plugin")) { |
| 518 |
oldcontrol = original.getElementsByTagName("input")[1]; |
| 519 |
AddEventHandlers(oldcontrol, inputs[1], linkid); |
| 520 |
} |
| 521 |
|
| 522 |
// select |
494 |
// select |
| 523 |
for (i = 0, len = selects.length; i < len; i++) { |
495 |
for (i = 0, len = selects.length; i < len; i++) { |
| 524 |
id_input = selects[i].getAttribute("id") + new_key; |
496 |
id_input = selects[i].getAttribute("id") + new_key; |
|
Lines 551-563
function CloneSubfield(index, advancedMARCEditor) {
Link Here
|
| 551 |
linkid = id_input; |
523 |
linkid = id_input; |
| 552 |
} |
524 |
} |
| 553 |
|
525 |
|
| 554 |
// Handle click event on buttonDot for plugin |
|
|
| 555 |
var links = clone.getElementsByTagName("a"); |
| 556 |
if ($(links[0]).hasClass("framework_plugin")) { |
| 557 |
oldcontrol = original.getElementsByTagName("a")[0]; |
| 558 |
AddEventHandlers(oldcontrol, links[0], linkid); |
| 559 |
} |
| 560 |
|
| 561 |
if (advancedMARCEditor == "0") { |
526 |
if (advancedMARCEditor == "0") { |
| 562 |
// when cloning a subfield, reset its label too. |
527 |
// when cloning a subfield, reset its label too. |
| 563 |
var label = clone.getElementsByTagName("label")[0]; |
528 |
var label = clone.getElementsByTagName("label")[0]; |
|
Lines 605-627
function CloneSubfield(index, advancedMARCEditor) {
Link Here
|
| 605 |
clone.querySelectorAll("input.input_marceditor").value = ""; |
570 |
clone.querySelectorAll("input.input_marceditor").value = ""; |
| 606 |
} |
571 |
} |
| 607 |
|
572 |
|
| 608 |
function AddEventHandlers(oldcontrol, newcontrol, newinputid) { |
|
|
| 609 |
// This function is a helper for CloneField and CloneSubfield. |
| 610 |
// It adds the event handlers from oldcontrol to newcontrol. |
| 611 |
// newinputid is the id attribute of the cloned controlling input field |
| 612 |
// Note: This code depends on the jQuery data for events; this structure |
| 613 |
// is moved to _data as of jQuery 1.8. |
| 614 |
var ev = $._data(oldcontrol, "events"); |
| 615 |
if (typeof ev != "undefined") { |
| 616 |
$.each(ev, function (prop, val) { |
| 617 |
$.each(val, function (prop2, val2) { |
| 618 |
$(newcontrol).off(val2.type); |
| 619 |
$(newcontrol).on(val2.type, { id: newinputid }, val2.handler); |
| 620 |
}); |
| 621 |
}); |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
/** |
573 |
/** |
| 626 |
* This function removes or clears unwanted subfields |
574 |
* This function removes or clears unwanted subfields |
| 627 |
*/ |
575 |
*/ |
|
Lines 850-852
$(document).ready(function () {
Link Here
|
| 850 |
}, |
798 |
}, |
| 851 |
}); |
799 |
}); |
| 852 |
}); |
800 |
}); |
| 853 |
- |
801 |
|
|
|
802 |
Koha.frameworkPlugins ||= {}; |
| 803 |
function registerFrameworkPluginHandler(name, eventType, handler) { |
| 804 |
// 'focus' and 'blur' events do not bubble, |
| 805 |
// so we have to use 'focusin' and 'focusout' instead |
| 806 |
if (eventType === 'focus') eventType = 'focusin'; |
| 807 |
else if (eventType === 'blur') eventType = 'focusout'; |
| 808 |
|
| 809 |
Koha.frameworkPlugins[name] ||= {}; |
| 810 |
Koha.frameworkPlugins[name][eventType] ||= handler; |
| 811 |
} |
| 812 |
$(document).ready(function() { |
| 813 |
function callClickPluginEventHandler (event) { |
| 814 |
event.preventDefault(); |
| 815 |
callPluginEventHandler.call(this, event); |
| 816 |
} |
| 817 |
|
| 818 |
function callPluginEventHandler (event) { |
| 819 |
event.stopPropagation(); |
| 820 |
|
| 821 |
const plugin = event.target.getAttribute('data-plugin'); |
| 822 |
if (plugin && plugin in Koha.frameworkPlugins && event.type in Koha.frameworkPlugins[plugin]) { |
| 823 |
event.data = {}; |
| 824 |
if (event.target.classList.contains('buttonDot')) { |
| 825 |
event.data.id = event.target.closest('.subfield_line').querySelector('input.input_marceditor').id; |
| 826 |
} else { |
| 827 |
event.data.id = event.target.id; |
| 828 |
} |
| 829 |
|
| 830 |
Koha.frameworkPlugins[plugin][event.type].call(this, event); |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
// We use delegated event handlers here so that dynamically added elements |
| 835 |
// (like when cloning a field or a subfield) respond to these events |
| 836 |
// without having to re-attach events manually |
| 837 |
$('.marc_editor').on('click', '.buttonDot', callClickPluginEventHandler); |
| 838 |
$('.marc_editor').on('focusin focusout change mousedown mouseup keydown keyup', 'input.input_marceditor.framework_plugin', callPluginEventHandler); |
| 839 |
}); |