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 185-192
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
185 |
|
185 |
|
186 |
var inputs = divs[i].getElementsByTagName('input'); |
186 |
var inputs = divs[i].getElementsByTagName('input'); |
187 |
var id_input = ""; |
187 |
var id_input = ""; |
188 |
var olddiv; |
|
|
189 |
var oldcontrol; |
190 |
|
188 |
|
191 |
for( j = 0 ; j < inputs.length ; j++ ) { |
189 |
for( j = 0 ; j < inputs.length ; j++ ) { |
192 |
if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){ |
190 |
if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){ |
Lines 228-238
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
228 |
} |
226 |
} |
229 |
} |
227 |
} |
230 |
} |
228 |
} |
231 |
if( $(inputs[1]).hasClass('framework_plugin') ) { |
|
|
232 |
olddiv= original.getElementsByTagName('li')[i]; |
233 |
oldcontrol= olddiv.getElementsByTagName('input')[1]; |
234 |
AddEventHandlers( oldcontrol,inputs[1],id_input ); |
235 |
} |
236 |
} |
229 |
} |
237 |
// when cloning a subfield, re set its label too. |
230 |
// when cloning a subfield, re set its label too. |
238 |
try { |
231 |
try { |
Lines 270-291
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
270 |
if(!CloneButtonPlus){ // it s impossible to have + ... (buttonDot AND buttonPlus) |
263 |
if(!CloneButtonPlus){ // it s impossible to have + ... (buttonDot AND buttonPlus) |
271 |
buttonDot = spans[0]; |
264 |
buttonDot = spans[0]; |
272 |
if(buttonDot){ |
265 |
if(buttonDot){ |
273 |
// 2 possibilities : |
266 |
try { |
274 |
try{ |
267 |
// do not copy the script section. |
275 |
if( $(buttonDot).hasClass('framework_plugin') ) { |
268 |
var script = spans[0].getElementsByTagName('script')[0]; |
276 |
olddiv= original.getElementsByTagName('li')[i]; |
269 |
spans[0].removeChild(script); |
277 |
oldcontrol= olddiv.getElementsByTagName('a')[0]; |
270 |
} catch(e) { |
278 |
AddEventHandlers(oldcontrol,buttonDot,id_input); |
271 |
// do nothing if there is no script |
279 |
} |
|
|
280 |
try { |
281 |
// do not copy the script section. |
282 |
var script = spans[0].getElementsByTagName('script')[0]; |
283 |
spans[0].removeChild(script); |
284 |
} catch(e) { |
285 |
// do nothing if there is no script |
286 |
} |
287 |
} catch(e){ |
288 |
// |
289 |
} |
272 |
} |
290 |
} |
273 |
} |
291 |
} |
274 |
} |
Lines 353-359
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
353 |
var selects = clone.getElementsByTagName('select'); |
336 |
var selects = clone.getElementsByTagName('select'); |
354 |
var textareas = clone.getElementsByTagName('textarea'); |
337 |
var textareas = clone.getElementsByTagName('textarea'); |
355 |
var linkid; |
338 |
var linkid; |
356 |
var oldcontrol; |
|
|
357 |
|
339 |
|
358 |
// input |
340 |
// input |
359 |
var id_input = ""; |
341 |
var id_input = ""; |
Lines 367-378
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
367 |
linkid = id_input; |
349 |
linkid = id_input; |
368 |
} |
350 |
} |
369 |
|
351 |
|
370 |
// Plugin input |
|
|
371 |
if( $(inputs[1]).hasClass('framework_plugin') ) { |
372 |
oldcontrol= original.getElementsByTagName('input')[1]; |
373 |
AddEventHandlers( oldcontrol, inputs[1], linkid ); |
374 |
} |
375 |
|
376 |
// select |
352 |
// select |
377 |
for(i=0,len=selects.length; i<len ; i++ ){ |
353 |
for(i=0,len=selects.length; i<len ; i++ ){ |
378 |
id_input = selects[i].getAttribute('id')+new_key; |
354 |
id_input = selects[i].getAttribute('id')+new_key; |
Lines 393-405
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
393 |
linkid = id_input; |
369 |
linkid = id_input; |
394 |
} |
370 |
} |
395 |
|
371 |
|
396 |
// Handle click event on buttonDot for plugin |
|
|
397 |
var links = clone.getElementsByTagName('a'); |
398 |
if( $(links[0]).hasClass('framework_plugin') ) { |
399 |
oldcontrol= original.getElementsByTagName('a')[0]; |
400 |
AddEventHandlers( oldcontrol, links[0], linkid ); |
401 |
} |
402 |
|
403 |
if(advancedMARCEditor == '0') { |
372 |
if(advancedMARCEditor == '0') { |
404 |
// when cloning a subfield, reset its label too. |
373 |
// when cloning a subfield, reset its label too. |
405 |
var label = clone.getElementsByTagName('label')[0]; |
374 |
var label = clone.getElementsByTagName('label')[0]; |
Lines 438-460
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
438 |
clone.querySelectorAll('input.input_marceditor').value = ""; |
407 |
clone.querySelectorAll('input.input_marceditor').value = ""; |
439 |
} |
408 |
} |
440 |
|
409 |
|
441 |
function AddEventHandlers (oldcontrol, newcontrol, newinputid ) { |
|
|
442 |
// This function is a helper for CloneField and CloneSubfield. |
443 |
// It adds the event handlers from oldcontrol to newcontrol. |
444 |
// newinputid is the id attribute of the cloned controlling input field |
445 |
// Note: This code depends on the jQuery data for events; this structure |
446 |
// is moved to _data as of jQuery 1.8. |
447 |
var ev = $._data(oldcontrol, "events"); |
448 |
if(typeof ev != 'undefined') { |
449 |
$.each(ev, function(prop,val) { |
450 |
$.each(val, function(prop2,val2) { |
451 |
$(newcontrol).off( val2.type ); |
452 |
$(newcontrol).on( val2.type, {id: newinputid}, val2.handler ); |
453 |
}); |
454 |
}); |
455 |
} |
456 |
} |
457 |
|
458 |
/** |
410 |
/** |
459 |
* This function removes or clears unwanted subfields |
411 |
* This function removes or clears unwanted subfields |
460 |
*/ |
412 |
*/ |
Lines 654-656
$(document).ready(function() {
Link Here
|
654 |
}); |
606 |
}); |
655 |
|
607 |
|
656 |
}); |
608 |
}); |
657 |
- |
609 |
|
|
|
610 |
Koha.frameworkPlugins ||= {}; |
611 |
function registerFrameworkPluginHandler(name, eventType, handler) { |
612 |
// 'focus' and 'blur' events do not bubble, |
613 |
// so we have to use 'focusin' and 'focusout' instead |
614 |
if (eventType === 'focus') eventType = 'focusin'; |
615 |
else if (eventType === 'blur') eventType = 'focusout'; |
616 |
|
617 |
Koha.frameworkPlugins[name] ||= {}; |
618 |
Koha.frameworkPlugins[name][eventType] ||= handler; |
619 |
} |
620 |
$(document).ready(function() { |
621 |
function callClickPluginEventHandler (event) { |
622 |
event.preventDefault(); |
623 |
callPluginEventHandler.call(this, event); |
624 |
} |
625 |
|
626 |
function callPluginEventHandler (event) { |
627 |
event.stopPropagation(); |
628 |
|
629 |
const plugin = event.target.getAttribute('data-plugin'); |
630 |
if (plugin && plugin in Koha.frameworkPlugins && event.type in Koha.frameworkPlugins[plugin]) { |
631 |
event.data = {}; |
632 |
if (event.target.classList.contains('buttonDot')) { |
633 |
event.data.id = event.target.closest('.subfield_line').querySelector('input.input_marceditor').id; |
634 |
} else { |
635 |
event.data.id = event.target.id; |
636 |
} |
637 |
|
638 |
Koha.frameworkPlugins[plugin][event.type].call(this, event); |
639 |
} |
640 |
} |
641 |
|
642 |
// We use delegated event handlers here so that dynamically added elements |
643 |
// (like when cloning a field or a subfield) respond to these events |
644 |
// without having to re-attach events manually |
645 |
$('.marc_editor').on('click', '.buttonDot', callClickPluginEventHandler); |
646 |
$('.marc_editor').on('focusin focusout change mousedown mouseup keydown keyup', 'input.input_marceditor.framework_plugin', callPluginEventHandler); |
647 |
}); |