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