xref: /webtrees/resources/views/edit/input-addon-edit-name.phtml (revision a45ad69d9fe14e475a431f9eb0e7184dab266144)
1*a45ad69dSGreg Roach<?php
2*a45ad69dSGreg Roach
3*a45ad69dSGreg Roachuse Fisharebest\Webtrees\I18N;
4*a45ad69dSGreg Roach
5*a45ad69dSGreg Roach?>
6*a45ad69dSGreg Roach
7*a45ad69dSGreg Roach<div class="input-group-prepend">
8*a45ad69dSGreg Roach    <span class="input-group-text">
9*a45ad69dSGreg Roach        <a id="<?= e($id) ?>-edit" href="#" title="<?= I18N::translate('Edit the name') ?>">
10*a45ad69dSGreg Roach            <?= view('icons/edit') ?>
11*a45ad69dSGreg Roach            <span class="sr-only">
12*a45ad69dSGreg Roach                <?= I18N::translate('Edit the name') ?>
13*a45ad69dSGreg Roach            </span>
14*a45ad69dSGreg Roach        </a>
15*a45ad69dSGreg Roach    </span>
16*a45ad69dSGreg Roach</div>
17*a45ad69dSGreg Roach<script>
18*a45ad69dSGreg Roach    document.getElementById('<?= e($id) ?>-edit').addEventListener('click', function (event) {
19*a45ad69dSGreg Roach        event.preventDefault();
20*a45ad69dSGreg Roach        let element = document.getElementById('<?= e($id) ?>');
21*a45ad69dSGreg Roach        element.readOnly = false;
22*a45ad69dSGreg Roach        element.focus();
23*a45ad69dSGreg Roach
24*a45ad69dSGreg Roach        let input_addon = this.parentNode.parentNode;
25*a45ad69dSGreg Roach        input_addon.parentNode.removeChild(input_addon);
26*a45ad69dSGreg Roach    });
27*a45ad69dSGreg Roach    document.addEventListener('DOMContentLoaded', function () {
28*a45ad69dSGreg Roach        let container = document.getElementById('<?= e($id) ?>').parentNode.parentNode.parentNode.parentNode;
29*a45ad69dSGreg Roach        let NAME = container.querySelector('[id$="INDI:NAME"]');
30*a45ad69dSGreg Roach        let NPFX = container.querySelector('[id$="INDI:NAME:NPFX"]');
31*a45ad69dSGreg Roach        let GIVN = container.querySelector('[id$="INDI:NAME:GIVN"]');
32*a45ad69dSGreg Roach        let SPFX = container.querySelector('[id$="INDI:NAME:SPFX"]');
33*a45ad69dSGreg Roach        let SURN = container.querySelector('[id$="INDI:NAME:SURN"]');
34*a45ad69dSGreg Roach        let NSFX = container.querySelector('[id$="INDI:NAME:NSFX"]');
35*a45ad69dSGreg Roach
36*a45ad69dSGreg Roach        if (NAME.value !== webtrees.buildNameFromParts(
37*a45ad69dSGreg Roach            NPFX ? NPFX.value : '',
38*a45ad69dSGreg Roach            GIVN ? GIVN.value : '',
39*a45ad69dSGreg Roach            SPFX ? SPFX.value : '',
40*a45ad69dSGreg Roach            SURN ? SURN.value : '',
41*a45ad69dSGreg Roach            NSFX ? NSFX.value : '',
42*a45ad69dSGreg Roach            'U'
43*a45ad69dSGreg Roach        )) {
44*a45ad69dSGreg Roach            document.getElementById('<?= e($id) ?>-edit').click();
45*a45ad69dSGreg Roach        } else {
46*a45ad69dSGreg Roach            let fn = function () {
47*a45ad69dSGreg Roach                if (NAME.readOnly === true) {
48*a45ad69dSGreg Roach                    NAME.value = webtrees.buildNameFromParts(
49*a45ad69dSGreg Roach                        NPFX ? NPFX.value : '',
50*a45ad69dSGreg Roach                        GIVN ? GIVN.value : '',
51*a45ad69dSGreg Roach                        SPFX ? SPFX.value : '',
52*a45ad69dSGreg Roach                        SURN ? SURN.value : '',
53*a45ad69dSGreg Roach                        NSFX ? NSFX.value : '',
54*a45ad69dSGreg Roach                        'U'
55*a45ad69dSGreg Roach                    );
56*a45ad69dSGreg Roach                }
57*a45ad69dSGreg Roach            }
58*a45ad69dSGreg Roach            NPFX.addEventListener('input', fn);
59*a45ad69dSGreg Roach            GIVN.addEventListener('input', fn);
60*a45ad69dSGreg Roach            SPFX.addEventListener('input', fn);
61*a45ad69dSGreg Roach            SURN.addEventListener('input', fn);
62*a45ad69dSGreg Roach            SURN.addEventListener('blur', fn); // For autocompleted entries
63*a45ad69dSGreg Roach            NSFX.addEventListener('input', fn);
64*a45ad69dSGreg Roach        }
65*a45ad69dSGreg Roach    });
66*a45ad69dSGreg Roach</script>