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 182-189
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
182 |
|
182 |
|
183 |
var inputs = divs[i].getElementsByTagName('input'); |
183 |
var inputs = divs[i].getElementsByTagName('input'); |
184 |
var id_input = ""; |
184 |
var id_input = ""; |
185 |
var olddiv; |
|
|
186 |
var oldcontrol; |
187 |
|
185 |
|
188 |
for( j = 0 ; j < inputs.length ; j++ ) { |
186 |
for( j = 0 ; j < inputs.length ; j++ ) { |
189 |
if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){ |
187 |
if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){ |
Lines 224-234
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
224 |
} |
222 |
} |
225 |
} |
223 |
} |
226 |
} |
224 |
} |
227 |
if( $(inputs[1]).hasClass('framework_plugin') ) { |
|
|
228 |
olddiv= original.getElementsByTagName('li')[i]; |
229 |
oldcontrol= olddiv.getElementsByTagName('input')[1]; |
230 |
AddEventHandlers( oldcontrol,inputs[1],id_input ); |
231 |
} |
232 |
} |
225 |
} |
233 |
// when cloning a subfield, re set its label too. |
226 |
// when cloning a subfield, re set its label too. |
234 |
try { |
227 |
try { |
Lines 266-287
function CloneField(index, hideMarc, advancedMARCEditor) {
Link Here
|
266 |
if(!CloneButtonPlus){ // it s impossible to have + ... (buttonDot AND buttonPlus) |
259 |
if(!CloneButtonPlus){ // it s impossible to have + ... (buttonDot AND buttonPlus) |
267 |
buttonDot = spans[0]; |
260 |
buttonDot = spans[0]; |
268 |
if(buttonDot){ |
261 |
if(buttonDot){ |
269 |
// 2 possibilities : |
262 |
try { |
270 |
try{ |
263 |
// do not copy the script section. |
271 |
if( $(buttonDot).hasClass('framework_plugin') ) { |
264 |
var script = spans[0].getElementsByTagName('script')[0]; |
272 |
olddiv= original.getElementsByTagName('li')[i]; |
265 |
spans[0].removeChild(script); |
273 |
oldcontrol= olddiv.getElementsByTagName('a')[0]; |
266 |
} catch(e) { |
274 |
AddEventHandlers(oldcontrol,buttonDot,id_input); |
267 |
// do nothing if there is no script |
275 |
} |
|
|
276 |
try { |
277 |
// do not copy the script section. |
278 |
var script = spans[0].getElementsByTagName('script')[0]; |
279 |
spans[0].removeChild(script); |
280 |
} catch(e) { |
281 |
// do nothing if there is no script |
282 |
} |
283 |
} catch(e){ |
284 |
// |
285 |
} |
268 |
} |
286 |
} |
269 |
} |
287 |
} |
270 |
} |
Lines 343-349
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
343 |
var selects = clone.getElementsByTagName('select'); |
326 |
var selects = clone.getElementsByTagName('select'); |
344 |
var textareas = clone.getElementsByTagName('textarea'); |
327 |
var textareas = clone.getElementsByTagName('textarea'); |
345 |
var linkid; |
328 |
var linkid; |
346 |
var oldcontrol; |
|
|
347 |
|
329 |
|
348 |
// input |
330 |
// input |
349 |
var id_input = ""; |
331 |
var id_input = ""; |
Lines 357-368
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
357 |
linkid = id_input; |
339 |
linkid = id_input; |
358 |
} |
340 |
} |
359 |
|
341 |
|
360 |
// Plugin input |
|
|
361 |
if( $(inputs[1]).hasClass('framework_plugin') ) { |
362 |
oldcontrol= original.getElementsByTagName('input')[1]; |
363 |
AddEventHandlers( oldcontrol, inputs[1], linkid ); |
364 |
} |
365 |
|
366 |
// select |
342 |
// select |
367 |
for(i=0,len=selects.length; i<len ; i++ ){ |
343 |
for(i=0,len=selects.length; i<len ; i++ ){ |
368 |
id_input = selects[i].getAttribute('id')+new_key; |
344 |
id_input = selects[i].getAttribute('id')+new_key; |
Lines 382-394
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
382 |
linkid = id_input; |
358 |
linkid = id_input; |
383 |
} |
359 |
} |
384 |
|
360 |
|
385 |
// Handle click event on buttonDot for plugin |
|
|
386 |
var links = clone.getElementsByTagName('a'); |
387 |
if( $(links[0]).hasClass('framework_plugin') ) { |
388 |
oldcontrol= original.getElementsByTagName('a')[0]; |
389 |
AddEventHandlers( oldcontrol, links[0], linkid ); |
390 |
} |
391 |
|
392 |
if(advancedMARCEditor == '0') { |
361 |
if(advancedMARCEditor == '0') { |
393 |
// when cloning a subfield, reset its label too. |
362 |
// when cloning a subfield, reset its label too. |
394 |
var label = clone.getElementsByTagName('label')[0]; |
363 |
var label = clone.getElementsByTagName('label')[0]; |
Lines 427-449
function CloneSubfield(index, advancedMARCEditor){
Link Here
|
427 |
clone.querySelectorAll('input.input_marceditor').value = ""; |
396 |
clone.querySelectorAll('input.input_marceditor').value = ""; |
428 |
} |
397 |
} |
429 |
|
398 |
|
430 |
function AddEventHandlers (oldcontrol, newcontrol, newinputid ) { |
|
|
431 |
// This function is a helper for CloneField and CloneSubfield. |
432 |
// It adds the event handlers from oldcontrol to newcontrol. |
433 |
// newinputid is the id attribute of the cloned controlling input field |
434 |
// Note: This code depends on the jQuery data for events; this structure |
435 |
// is moved to _data as of jQuery 1.8. |
436 |
var ev= $(oldcontrol).data('events'); |
437 |
if(typeof ev != 'undefined') { |
438 |
$.each(ev, function(prop,val) { |
439 |
$.each(val, function(prop2,val2) { |
440 |
$(newcontrol).off( val2.type ); |
441 |
$(newcontrol).on( val2.type, {id: newinputid}, val2.handler ); |
442 |
}); |
443 |
}); |
444 |
} |
445 |
} |
446 |
|
447 |
/** |
399 |
/** |
448 |
* This function removes or clears unwanted subfields |
400 |
* This function removes or clears unwanted subfields |
449 |
*/ |
401 |
*/ |
Lines 639-641
$(document).ready(function() {
Link Here
|
639 |
}); |
591 |
}); |
640 |
|
592 |
|
641 |
}); |
593 |
}); |
642 |
- |
594 |
|
|
|
595 |
Koha.frameworkPlugins ||= {}; |
596 |
function registerFrameworkPluginHandler(name, eventType, handler) { |
597 |
// 'focus' and 'blur' events do not bubble, |
598 |
// so we have to use 'focusin' and 'focusout' instead |
599 |
if (eventType === 'focus') eventType = 'focusin'; |
600 |
else if (eventType === 'blur') eventType = 'focusout'; |
601 |
|
602 |
Koha.frameworkPlugins[name] ||= {}; |
603 |
Koha.frameworkPlugins[name][eventType] ||= handler; |
604 |
} |
605 |
$(document).ready(function() { |
606 |
function callPluginEventHandler (event) { |
607 |
event.preventDefault(); |
608 |
event.stopPropagation(); |
609 |
|
610 |
const plugin = event.target.getAttribute('data-plugin'); |
611 |
if (plugin && plugin in Koha.frameworkPlugins && event.type in Koha.frameworkPlugins[plugin]) { |
612 |
event.data = {}; |
613 |
if (event.target.classList.contains('buttonDot')) { |
614 |
event.data.id = event.target.closest('.subfield_line').querySelector('input.input_marceditor').id; |
615 |
} else { |
616 |
event.data.id = event.target.id; |
617 |
} |
618 |
|
619 |
Koha.frameworkPlugins[plugin][event.type].call(this, event); |
620 |
} |
621 |
} |
622 |
|
623 |
// We use delegated event handlers here so that dynamically added elements |
624 |
// (like when cloning a field or a subfield) respond to these events |
625 |
// without having to re-attach events manually |
626 |
$('.marc_editor').on('click', '.buttonDot', callPluginEventHandler) |
627 |
$('.marc_editor').on('focusin focusout', 'input.input_marceditor.framework_plugin', callPluginEventHandler); |
628 |
}); |