1*71378461SGreg Roach<?php 2*71378461SGreg Roach 3*71378461SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ModuleAction; 4*71378461SGreg Roachuse Fisharebest\Webtrees\I18N; 5*71378461SGreg Roachuse Fisharebest\Webtrees\View; 6*71378461SGreg Roach 7*71378461SGreg Roach?> 8dd6b2bfcSGreg Roach 9dd6b2bfcSGreg Roach<div id="census-assistant-link" hidden> 10dd6b2bfcSGreg Roach <a href="#"> 11dd6b2bfcSGreg Roach <?= I18N::translate('Create a shared note using the census assistant') ?> 12dd6b2bfcSGreg Roach </a> 13dd6b2bfcSGreg Roach</div> 14dd6b2bfcSGreg Roach 15dd6b2bfcSGreg Roach<div id="census-assistant" hidden> 16dd6b2bfcSGreg Roach <input type="hidden" name="ca_census" id="census-assistant-class"> 17dd6b2bfcSGreg Roach <div class="form-group"> 18dd6b2bfcSGreg Roach <div class="input-group"> 19dd6b2bfcSGreg Roach <div class="input-group-prepend"> 20dd6b2bfcSGreg Roach <label class="input-group-text" for="census-assistant-title"> 21dd6b2bfcSGreg Roach <?= I18N::translate('Title') ?> 22dd6b2bfcSGreg Roach </label> 23dd6b2bfcSGreg Roach </div> 24dd6b2bfcSGreg Roach <input class="form-control" id="census-assistant-title" name="ca_title" value=""> 25dd6b2bfcSGreg Roach </div> 26dd6b2bfcSGreg Roach </div> 27dd6b2bfcSGreg Roach 28dd6b2bfcSGreg Roach <div class="row"> 29dd6b2bfcSGreg Roach <div class="form-group col-sm-6"> 30dd6b2bfcSGreg Roach <div class="input-group"> 31dd6b2bfcSGreg Roach <div class="input-group-prepend"> 32b6c326d8SGreg Roach <label class="input-group-text" for="census-assistant-citation"> 33dd6b2bfcSGreg Roach <?= I18N::translate('Citation') ?> 34dd6b2bfcSGreg Roach </label> 35dd6b2bfcSGreg Roach </div> 36dd6b2bfcSGreg Roach <input class="form-control" id="census-assistant-citation" name="ca_citation"> 37dd6b2bfcSGreg Roach </div> 38dd6b2bfcSGreg Roach </div> 39dd6b2bfcSGreg Roach 40dd6b2bfcSGreg Roach <div class="form-group col-sm-6"> 41dd6b2bfcSGreg Roach <div class="input-group"> 42dd6b2bfcSGreg Roach <div class="input-group-prepend"> 43dd6b2bfcSGreg Roach <label class="input-group-text" for="census-assistant-place"> 44dd6b2bfcSGreg Roach <?= I18N::translate('Place') ?> 45dd6b2bfcSGreg Roach </label> 46dd6b2bfcSGreg Roach </div> 47dd6b2bfcSGreg Roach <input class="form-control" id="census-assistant-place" name="ca_place"> 48dd6b2bfcSGreg Roach </div> 49dd6b2bfcSGreg Roach </div> 50dd6b2bfcSGreg Roach </div> 51dd6b2bfcSGreg Roach 52dd6b2bfcSGreg Roach <div class="form-group"> 53dd6b2bfcSGreg Roach <div class="input-group"> 54dd6b2bfcSGreg Roach <div class="input-group-prepend"> 55dd6b2bfcSGreg Roach <span class="input-group-text"> 56dd6b2bfcSGreg Roach <?= I18N::translate('Individuals') ?> 57dd6b2bfcSGreg Roach </span> 58dd6b2bfcSGreg Roach </div> 59b6c326d8SGreg Roach <?= view('components/select-individual', ['name' => 'census-assistant-individual', 'individual' => $individual, 'tree' => $individual->tree()]) ?> 60b6c326d8SGreg Roach <div class="input-group-append"> 616a83cfe8SGreg Roach <button type="button" class="btn btn-primary" id="census-assistant-add" aria-label="<?= I18N::translate('add') ?>"> 626a83cfe8SGreg Roach <?= view('icons/add') ?> 63dd6b2bfcSGreg Roach </button> 64b6c326d8SGreg Roach </div> 65b6c326d8SGreg Roach <div class="input-group-append"> 666a83cfe8SGreg Roach <button type="button" class="btn btn-primary" id="census-assistant-head" aria-label="<?= I18N::translate('Head of household') ?>"> 676a83cfe8SGreg Roach <?= view('icons/individual') ?> 68dd6b2bfcSGreg Roach </button> 69b6c326d8SGreg Roach </div> 70dd6b2bfcSGreg Roach </div> 71dd6b2bfcSGreg Roach </div> 72dd6b2bfcSGreg Roach 73f699d6fcSGreg Roach <table class="table table-bordered table-small table-responsive small wt-census-assistant-table" 74dd6b2bfcSGreg Roach id="census-assistant-table"> 75dd6b2bfcSGreg Roach <thead class="wt-census-assistant-header"></thead> 76dd6b2bfcSGreg Roach <tbody class="wt-census-assistant-body"></tbody> 77dd6b2bfcSGreg Roach </table> 78dd6b2bfcSGreg Roach 79dd6b2bfcSGreg Roach <div class="form-group"> 80dd6b2bfcSGreg Roach <div class="input-group"> 81dd6b2bfcSGreg Roach <div class="input-group-prepend"> 82dd6b2bfcSGreg Roach <label class="input-group-text" for="census-assistant-notes"> 83dd6b2bfcSGreg Roach <?= I18N::translate('Notes') ?> 84dd6b2bfcSGreg Roach </label> 85dd6b2bfcSGreg Roach </div> 86dd6b2bfcSGreg Roach <input class="form-control" id="census-assistant-notes" name="ca_notes"> 87dd6b2bfcSGreg Roach </div> 88dd6b2bfcSGreg Roach </div> 89dd6b2bfcSGreg Roach</div> 90dd6b2bfcSGreg Roach 917a18bd58SGreg Roach<?php View::push('javascript') ?> 92dd6b2bfcSGreg Roach<script> 93dd6b2bfcSGreg Roach // When a census date/place is selected, activate the census-assistant 94dd6b2bfcSGreg Roach function censusAssistantSelect() { 95dd6b2bfcSGreg Roach var censusAssistantLink = document.querySelector('#census-assistant-link'); 96dd6b2bfcSGreg Roach var censusAssistant = document.querySelector('#census-assistant'); 97dd6b2bfcSGreg Roach var censusOption = this.options[this.selectedIndex]; 98dd6b2bfcSGreg Roach var census = censusOption.dataset.census; 99dd6b2bfcSGreg Roach var censusPlace = censusOption.dataset.place; 100dd6b2bfcSGreg Roach var censusYear = censusOption.value.substr(-4); 101dd6b2bfcSGreg Roach 102dd6b2bfcSGreg Roach if (censusOption.value !== '') { 103dd6b2bfcSGreg Roach censusAssistantLink.removeAttribute('hidden'); 104dd6b2bfcSGreg Roach } else { 105dd6b2bfcSGreg Roach censusAssistantLink.setAttribute('hidden', ''); 106dd6b2bfcSGreg Roach } 107dd6b2bfcSGreg Roach 108dd6b2bfcSGreg Roach censusAssistant.setAttribute('hidden', ''); 109dd6b2bfcSGreg Roach document.querySelector('#census-assistant-class').value = census; 11039ca88baSGreg Roach document.querySelector('#census-assistant-title').value = censusYear + ' ' + censusPlace + ' - <?= I18N::translate('Census transcript') ?> - <?= strip_tags($individual->fullName()) ?> - <?= I18N::translate('Household') ?>'; 111dd6b2bfcSGreg Roach 112f4afa648SGreg Roach fetch('<?= route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusHeader', 'ged' => $individual->tree()->name()]) ?>&census=' + census) 113dd6b2bfcSGreg Roach .then(function (response) { 114dd6b2bfcSGreg Roach return response.text(); 115dd6b2bfcSGreg Roach }) 116dd6b2bfcSGreg Roach .then(function (text) { 117dd6b2bfcSGreg Roach document.querySelector('#census-assistant-table thead').innerHTML = text; 118dd6b2bfcSGreg Roach document.querySelector('#census-assistant-table tbody').innerHTML = ''; 119dd6b2bfcSGreg Roach }); 120dd6b2bfcSGreg Roach } 121dd6b2bfcSGreg Roach 122dd6b2bfcSGreg Roach // When the census assistant is activated, show the input fields 123dd6b2bfcSGreg Roach function censusAssistantLink() { 124dd6b2bfcSGreg Roach document.querySelector('#census-selector').setAttribute('hidden', ''); 125dd6b2bfcSGreg Roach this.setAttribute('hidden', ''); 126dd6b2bfcSGreg Roach document.getElementById('census-assistant').removeAttribute('hidden'); 127dd6b2bfcSGreg Roach // Set the current individual as the head of household. 128dd6b2bfcSGreg Roach censusAssistantHead(); 129dd6b2bfcSGreg Roach 130dd6b2bfcSGreg Roach return false; 131dd6b2bfcSGreg Roach } 132dd6b2bfcSGreg Roach 133dd6b2bfcSGreg Roach // Add the currently selected individual to the census 134dd6b2bfcSGreg Roach function censusAssistantAdd() { 135dd6b2bfcSGreg Roach var censusSelector = document.querySelector('#census-selector'); 136dd6b2bfcSGreg Roach var census = censusSelector.options[censusSelector.selectedIndex].dataset.census; 137dd6b2bfcSGreg Roach var indi_selector = document.querySelector('#census-assistant-individual'); 138dd6b2bfcSGreg Roach var xref = indi_selector.options[indi_selector.selectedIndex].value; 139dd6b2bfcSGreg Roach var headTd = document.querySelector('#census-assistant-table td'); 140dd6b2bfcSGreg Roach var head = headTd === null ? xref : headTd.innerHTML; 141dd6b2bfcSGreg Roach 142f4afa648SGreg Roach fetch('<?= route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusIndividual', 'ged' => $individual->tree()->name()]) ?>&census=' + encodeURIComponent(census) + '&xref=' + encodeURIComponent(xref) + '&head=' + encodeURIComponent(head), {credentials: 'same-origin'}) 143dd6b2bfcSGreg Roach .then(function (response) { 144dd6b2bfcSGreg Roach return response.text(); 145dd6b2bfcSGreg Roach }) 146dd6b2bfcSGreg Roach .then(function (text) { 147dd6b2bfcSGreg Roach document.querySelector('#census-assistant-table tbody').innerHTML += text; 148dd6b2bfcSGreg Roach }); 149dd6b2bfcSGreg Roach 150dd6b2bfcSGreg Roach return false; 151dd6b2bfcSGreg Roach } 152dd6b2bfcSGreg Roach 153dd6b2bfcSGreg Roach // Set the currently selected individual as the head of household 154dd6b2bfcSGreg Roach function censusAssistantHead() { 155dd6b2bfcSGreg Roach var censusSelector = document.querySelector('#census-selector'); 156dd6b2bfcSGreg Roach var census = censusSelector.options[censusSelector.selectedIndex].dataset.census; 157dd6b2bfcSGreg Roach var indi_selector = document.querySelector('#census-assistant-individual'); 158dd6b2bfcSGreg Roach var xref = indi_selector.options[indi_selector.selectedIndex].value; 159dd6b2bfcSGreg Roach 160f4afa648SGreg Roach fetch('<?= route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusIndividual', 'ged' => $individual->tree()->name()]) ?>&census=' + encodeURIComponent(census) + '&xref=' + encodeURIComponent(xref) + '&head=' + encodeURIComponent(xref), {credentials: 'same-origin'}) 161dd6b2bfcSGreg Roach .then(function (response) { 162dd6b2bfcSGreg Roach return response.text(); 163dd6b2bfcSGreg Roach }) 164dd6b2bfcSGreg Roach .then(function (text) { 165dd6b2bfcSGreg Roach document.querySelector('#census-assistant-table tbody').innerHTML = text; 166dd6b2bfcSGreg Roach }); 167dd6b2bfcSGreg Roach 168dd6b2bfcSGreg Roach return false; 169dd6b2bfcSGreg Roach } 170dd6b2bfcSGreg Roach 1717a18bd58SGreg Roach $('#census-selector').on('change', censusAssistantSelect); 1727a18bd58SGreg Roach $('#census-assistant-link').on('click', censusAssistantLink); 1737a18bd58SGreg Roach $('#census-assistant-add').on('click', censusAssistantAdd); 1747a18bd58SGreg Roach $('#census-assistant-head').on('click', censusAssistantHead); 1757a18bd58SGreg Roach 1767a18bd58SGreg Roach $('#census-assistant-table').on('click', 'a.icon-remove', function() { 1777a18bd58SGreg Roach $(this).closest('tr').remove(); 1787a18bd58SGreg Roach 1797a18bd58SGreg Roach return false; 1807a18bd58SGreg Roach }) 181dd6b2bfcSGreg Roach</script> 1827a18bd58SGreg Roach<?php View::endpush() ?> 183