1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
declare(strict_types=1);
use Fisharebest\Webtrees\I18N;
/**
* @var string $id
*/
?>
<span class="input-group-text">
<a id="<?= e($id) ?>-edit" href="#" title="<?= I18N::translate('Edit the name') ?>">
<?= view('icons/edit') ?>
<span class="visually-hidden">
<?= I18N::translate('Edit the name') ?>
</span>
</a>
</span>
<script>
document.getElementById('<?= e($id) ?>-edit').addEventListener('click', function (event) {
event.preventDefault();
// Toggle the visibility of the full name inputs
// Hide the disabled input - does not send any value when posting the form
let disabledElement = document.getElementById('<?= e($id) ?>-disabled');
disabledElement.classList.add('d-none');
// Show the editable input - send value when posting the form
let editElement = document.getElementById('<?= e($id) ?>');
editElement.classList.remove('d-none');
editElement.focus();
this.parentNode.parentNode.removeChild(this.parentNode);
});
document.addEventListener('DOMContentLoaded', function () {
let NAME = document.getElementById('<?= e($id) ?>');
let NAME_DISABLED = document.getElementById('<?= e($id) ?>-disabled');
let container = NAME.parentNode.parentNode.parentNode;
let setNameValue = function(name_value) {
NAME.value = name_value;
NAME_DISABLED.value = name_value;
}
if (NAME.id.endsWith('-INDI-NAME')) {
// NAME has children at the same level.
container = container.parentNode;
} else {
// ROMN/FONE have children in a collapsable panel
container = container.nextSibling.nextSibling;
}
let NPFX = container.querySelector('[id$="-NPFX"]');
let GIVN = container.querySelector('[id$="-GIVN"]');
let SPFX = container.querySelector('[id$="-SPFX"]');
let SURN = container.querySelector('[id$="-SURN"]');
let NSFX = container.querySelector('[id$="-NSFX"]');
let generated_name = webtrees.buildNameFromParts(
NPFX ? NPFX.value : '',
GIVN ? GIVN.value : '',
SPFX ? SPFX.value : '',
SURN ? SURN.value : '',
NSFX ? NSFX.value : '',
'U',
);
if (NAME.value === '') {
setNameValue(generated_name);
}
if (NAME.value !== generated_name) {
document.getElementById('<?= e($id) ?>-edit').click();
} else {
let fn = function () {
if (NAME.classList.contains("d-none") === true) {
setNameValue(webtrees.buildNameFromParts(
NPFX ? NPFX.value : '',
GIVN ? GIVN.value : '',
SPFX ? SPFX.value : '',
SURN ? SURN.value : '',
NSFX ? NSFX.value : '',
'U',
));
}
};
NPFX && NPFX.addEventListener('input', fn);
GIVN && GIVN.addEventListener('input', fn);
SPFX && SPFX.addEventListener('input', fn);
SURN && SURN.addEventListener('input', fn);
SURN && SURN.addEventListener('blur', fn); // For autocompleted entries
NSFX && NSFX.addEventListener('input', fn);
}
});
</script>
|