xref: /webtrees/resources/views/modules/GEDFact_assistant/select-census.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
57c2c99faSGreg Roachuse Fisharebest\Webtrees\Census\CensusPlaceInterface;
6d70512abSGreg Roachuse Fisharebest\Webtrees\Date;
77c2c99faSGreg Roachuse Fisharebest\Webtrees\I18N;
87c2c99faSGreg Roach
97c2c99faSGreg Roach/**
107c2c99faSGreg Roach * @var array<CensusPlaceInterface> $census_places
117c2c99faSGreg Roach */
12d70512abSGreg Roach
13d70512abSGreg Roach?>
14dd6b2bfcSGreg Roach
154b9213b3SGreg Roach<select class="form-select census-selector" aria-label="<?= I18N::translate('Census date and place') ?>" autocomplete="off">
16c3f581d9SGreg Roach    <option value="" disabled="disabled" selected="selected" hidden="hidden"><?= I18N::translate('Census date') ?></option>
17dd6b2bfcSGreg Roach
18dd6b2bfcSGreg Roach    <?php foreach ($census_places as $census_place) : ?>
19d3e191dcSDavid Drury        <optgroup label="<?= $census_place->censusPlace() ?>">
20dd6b2bfcSGreg Roach          <?php foreach ($census_place->allCensusDates() as $census) : ?>
21d4786c66SGreg Roach              <option data-wt-date="<?= $census->censusDate() ?>" data-wt-place="<?= $census->censusPlace() ?>" data-wt-census="<?= get_class($census) ?>">
22dd6b2bfcSGreg Roach                  <?= (new Date($census->censusDate()))->minimumDate()->format('%Y') ?>
23f64490b2SGreg Roach24f64490b2SGreg Roach                  <?= $census->censusPlace() ?>
25dd6b2bfcSGreg Roach              </option>
26dd6b2bfcSGreg Roach          <?php endforeach ?>
27d3e191dcSDavid Drury        </optgroup>
28dd6b2bfcSGreg Roach    <?php endforeach ?>
29dd6b2bfcSGreg Roach</select>
3077b47e31SGreg Roach
3177b47e31SGreg Roach<script>
3277b47e31SGreg Roach  document.querySelectorAll('.census-selector').forEach(function (el) {
3377b47e31SGreg Roach    el.addEventListener('change', function (el) {
3477b47e31SGreg Roach      const select = el.target;
3577b47e31SGreg Roach      const option = select.options[select.selectedIndex];
3677b47e31SGreg Roach      const form = select.closest('form');
3777b47e31SGreg Roach
38d4786c66SGreg Roach      form.querySelector('[id$=CENS\\3a DATE]').value = option.dataset.wtDate;
39d4786c66SGreg Roach      form.querySelector('[id$=CENS\\3a PLAC]').value = option.dataset.wtPlace;
4077b47e31SGreg Roach    });
4177b47e31SGreg Roach  });
4277b47e31SGreg Roach</script>
43