xref: /webtrees/resources/views/modules/census-assistant.phtml (revision 08362db417156410ee02c6391bd9eb83a2df65fc)
171378461SGreg Roach<?php
271378461SGreg Roach
371378461SGreg Roachuse Fisharebest\Webtrees\I18N;
471378461SGreg Roachuse Fisharebest\Webtrees\View;
571378461SGreg Roach
671378461SGreg Roach?>
7dd6b2bfcSGreg Roach
8dd6b2bfcSGreg Roach<div id="census-assistant-link" hidden>
9dd6b2bfcSGreg Roach    <a href="#">
10dd6b2bfcSGreg Roach        <?= I18N::translate('Create a shared note using the census assistant') ?>
11dd6b2bfcSGreg Roach    </a>
12dd6b2bfcSGreg Roach</div>
13dd6b2bfcSGreg Roach
14dd6b2bfcSGreg Roach<div id="census-assistant" hidden>
15dd6b2bfcSGreg Roach    <input type="hidden" name="ca_census" id="census-assistant-class">
16dd6b2bfcSGreg Roach    <div class="form-group">
17dd6b2bfcSGreg Roach        <div class="input-group">
18dd6b2bfcSGreg Roach            <div class="input-group-prepend">
19dd6b2bfcSGreg Roach                <label class="input-group-text" for="census-assistant-title">
20dd6b2bfcSGreg Roach                    <?= I18N::translate('Title') ?>
21dd6b2bfcSGreg Roach                </label>
22dd6b2bfcSGreg Roach            </div>
23dd6b2bfcSGreg Roach            <input class="form-control" id="census-assistant-title" name="ca_title" value="">
24dd6b2bfcSGreg Roach        </div>
25dd6b2bfcSGreg Roach    </div>
26dd6b2bfcSGreg Roach
27dd6b2bfcSGreg Roach    <div class="row">
28dd6b2bfcSGreg Roach        <div class="form-group col-sm-6">
29dd6b2bfcSGreg Roach            <div class="input-group">
30dd6b2bfcSGreg Roach                <div class="input-group-prepend">
31b6c326d8SGreg Roach                    <label class="input-group-text" for="census-assistant-citation">
32dd6b2bfcSGreg Roach                        <?= I18N::translate('Citation') ?>
33dd6b2bfcSGreg Roach                    </label>
34dd6b2bfcSGreg Roach                </div>
35dd6b2bfcSGreg Roach                <input class="form-control" id="census-assistant-citation" name="ca_citation">
36dd6b2bfcSGreg Roach            </div>
37dd6b2bfcSGreg Roach        </div>
38dd6b2bfcSGreg Roach
39dd6b2bfcSGreg Roach        <div class="form-group col-sm-6">
40dd6b2bfcSGreg Roach            <div class="input-group">
41dd6b2bfcSGreg Roach                <div class="input-group-prepend">
42dd6b2bfcSGreg Roach                    <label class="input-group-text" for="census-assistant-place">
43dd6b2bfcSGreg Roach                        <?= I18N::translate('Place') ?>
44dd6b2bfcSGreg Roach                    </label>
45dd6b2bfcSGreg Roach                </div>
46dd6b2bfcSGreg Roach                <input class="form-control" id="census-assistant-place" name="ca_place">
47dd6b2bfcSGreg Roach            </div>
48dd6b2bfcSGreg Roach        </div>
49dd6b2bfcSGreg Roach    </div>
50dd6b2bfcSGreg Roach
51dd6b2bfcSGreg Roach    <div class="form-group">
52dd6b2bfcSGreg Roach        <div class="input-group">
53dd6b2bfcSGreg Roach            <div class="input-group-prepend">
54dd6b2bfcSGreg Roach                <span class="input-group-text">
55dd6b2bfcSGreg Roach                    <?= I18N::translate('Individuals') ?>
56dd6b2bfcSGreg Roach                </span>
57dd6b2bfcSGreg Roach            </div>
58b6c326d8SGreg Roach            <?= view('components/select-individual', ['name' => 'census-assistant-individual', 'individual' => $individual, 'tree' => $individual->tree()]) ?>
59b6c326d8SGreg Roach            <div class="input-group-append">
60*08362db4SGreg Roach                <button type="button" class="btn btn-primary" id="census-assistant-add" title="<?= I18N::translate('add') ?>">
616a83cfe8SGreg Roach                    <?= view('icons/add') ?>
62dd6b2bfcSGreg Roach                </button>
63b6c326d8SGreg Roach            </div>
64b6c326d8SGreg Roach            <div class="input-group-append">
65*08362db4SGreg Roach                <button type="button" class="btn btn-primary" id="census-assistant-head" title="<?= I18N::translate('Head of household') ?>">
666a83cfe8SGreg Roach                    <?= view('icons/individual') ?>
67dd6b2bfcSGreg Roach                </button>
68b6c326d8SGreg Roach            </div>
69dd6b2bfcSGreg Roach        </div>
70dd6b2bfcSGreg Roach    </div>
71dd6b2bfcSGreg Roach
72b38a7b85SGreg Roach    <div class="table-responsive">
73b38a7b85SGreg Roach        <table class="table table-bordered table-small 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>
78b38a7b85SGreg Roach    </div>
79dd6b2bfcSGreg Roach
80dd6b2bfcSGreg Roach    <div class="form-group">
81dd6b2bfcSGreg Roach        <div class="input-group">
82dd6b2bfcSGreg Roach            <div class="input-group-prepend">
83dd6b2bfcSGreg Roach                <label class="input-group-text" for="census-assistant-notes">
84dd6b2bfcSGreg Roach                    <?= I18N::translate('Notes') ?>
85dd6b2bfcSGreg Roach                </label>
86dd6b2bfcSGreg Roach            </div>
87dd6b2bfcSGreg Roach            <input class="form-control" id="census-assistant-notes" name="ca_notes">
88dd6b2bfcSGreg Roach        </div>
89dd6b2bfcSGreg Roach    </div>
90dd6b2bfcSGreg Roach</div>
91dd6b2bfcSGreg Roach
927a18bd58SGreg Roach<?php View::push('javascript') ?>
93dd6b2bfcSGreg Roach<script>
94dd6b2bfcSGreg Roach  // When a census date/place is selected, activate the census-assistant
95dd6b2bfcSGreg Roach  function censusAssistantSelect() {
96dd6b2bfcSGreg Roach    var censusAssistantLink = document.querySelector('#census-assistant-link');
97dd6b2bfcSGreg Roach    var censusAssistant     = document.querySelector('#census-assistant');
98dd6b2bfcSGreg Roach    var censusOption        = this.options[this.selectedIndex];
99dd6b2bfcSGreg Roach    var census              = censusOption.dataset.census;
100dd6b2bfcSGreg Roach    var censusPlace         = censusOption.dataset.place;
101dd6b2bfcSGreg Roach    var censusYear          = censusOption.value.substr(-4);
102dd6b2bfcSGreg Roach
103dd6b2bfcSGreg Roach    if (censusOption.value !== '') {
104dd6b2bfcSGreg Roach      censusAssistantLink.removeAttribute('hidden');
105dd6b2bfcSGreg Roach    } else {
106dd6b2bfcSGreg Roach      censusAssistantLink.setAttribute('hidden', '');
107dd6b2bfcSGreg Roach    }
108dd6b2bfcSGreg Roach
109dd6b2bfcSGreg Roach    censusAssistant.setAttribute('hidden', '');
110dd6b2bfcSGreg Roach    document.querySelector('#census-assistant-class').value = census;
11139ca88baSGreg Roach    document.querySelector('#census-assistant-title').value = censusYear + ' ' + censusPlace + ' - <?= I18N::translate('Census transcript') ?> - <?= strip_tags($individual->fullName()) ?> - <?= I18N::translate('Household') ?>';
112dd6b2bfcSGreg Roach
1137da59459SGreg Roach    let formData = new FormData();
1147da59459SGreg Roach    formData.append('census', census);
1157da59459SGreg Roach    formData.append('csrf', document.querySelector('meta[name=csrf]').content);
1167da59459SGreg Roach
1177da59459SGreg Roach    fetch(<?= json_encode(route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusHeader', 'tree' => $individual->tree()->name()])) ?>, {
1187da59459SGreg Roach        credentials: 'same-origin',
1197da59459SGreg Roach        body: formData,
1207da59459SGreg Roach        method: 'POST',
121dd6b2bfcSGreg Roach    })
1227da59459SGreg Roach    .then(response => response.text())
123dd6b2bfcSGreg Roach    .then(function (text) {
124dd6b2bfcSGreg Roach        document.querySelector('#census-assistant-table thead').innerHTML = text;
125dd6b2bfcSGreg Roach        document.querySelector('#census-assistant-table tbody').innerHTML = '';
126dd6b2bfcSGreg Roach    });
127dd6b2bfcSGreg Roach  }
128dd6b2bfcSGreg Roach
129dd6b2bfcSGreg Roach  // When the census assistant is activated, show the input fields
130dd6b2bfcSGreg Roach  function censusAssistantLink() {
131dd6b2bfcSGreg Roach    document.querySelector('#census-selector').setAttribute('hidden', '');
132dd6b2bfcSGreg Roach    this.setAttribute('hidden', '');
133dd6b2bfcSGreg Roach    document.getElementById('census-assistant').removeAttribute('hidden');
134dd6b2bfcSGreg Roach    // Set the current individual as the head of household.
135dd6b2bfcSGreg Roach    censusAssistantHead();
136dd6b2bfcSGreg Roach
137dd6b2bfcSGreg Roach    return false;
138dd6b2bfcSGreg Roach  }
139dd6b2bfcSGreg Roach
140dd6b2bfcSGreg Roach  // Add the currently selected individual to the census
141dd6b2bfcSGreg Roach  function censusAssistantAdd() {
142dd6b2bfcSGreg Roach    var censusSelector = document.querySelector('#census-selector');
143dd6b2bfcSGreg Roach    var census         = censusSelector.options[censusSelector.selectedIndex].dataset.census;
144dd6b2bfcSGreg Roach    var indi_selector  = document.querySelector('#census-assistant-individual');
145dd6b2bfcSGreg Roach    var xref           = indi_selector.options[indi_selector.selectedIndex].value;
146dd6b2bfcSGreg Roach    var headTd         = document.querySelector('#census-assistant-table td');
147dd6b2bfcSGreg Roach    var head           = headTd === null ? xref : headTd.innerHTML;
148dd6b2bfcSGreg Roach
1497da59459SGreg Roach    let formData = new FormData();
1507da59459SGreg Roach    formData.append('census', census);
1517da59459SGreg Roach    formData.append('csrf', document.querySelector('meta[name=csrf]').content);
1527da59459SGreg Roach    formData.append('head', head);
1537da59459SGreg Roach    formData.append('xref', xref);
1547da59459SGreg Roach
1557da59459SGreg Roach    fetch(<?= json_encode(route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusIndividual', 'tree' => $individual->tree()->name()])) ?>, {
1567da59459SGreg Roach        credentials: 'same-origin',
1577da59459SGreg Roach        body: formData,
1587da59459SGreg Roach        method: 'POST'
159dd6b2bfcSGreg Roach    })
1607da59459SGreg Roach    .then(response => response.text())
161dd6b2bfcSGreg Roach    .then(function (text) {
162dd6b2bfcSGreg Roach        document.querySelector('#census-assistant-table tbody').innerHTML += text;
163dd6b2bfcSGreg Roach    });
164dd6b2bfcSGreg Roach
165dd6b2bfcSGreg Roach    return false;
166dd6b2bfcSGreg Roach  }
167dd6b2bfcSGreg Roach
168dd6b2bfcSGreg Roach  // Set the currently selected individual as the head of household
169dd6b2bfcSGreg Roach  function censusAssistantHead() {
170dd6b2bfcSGreg Roach    var censusSelector = document.querySelector('#census-selector');
171dd6b2bfcSGreg Roach    var census         = censusSelector.options[censusSelector.selectedIndex].dataset.census;
172dd6b2bfcSGreg Roach    var indi_selector  = document.querySelector('#census-assistant-individual');
173dd6b2bfcSGreg Roach    var xref           = indi_selector.options[indi_selector.selectedIndex].value;
174dd6b2bfcSGreg Roach
1757da59459SGreg Roach    let formData = new FormData();
1767da59459SGreg Roach    formData.append('census', census);
1777da59459SGreg Roach    formData.append('csrf', document.querySelector('meta[name=csrf]').content);
1787da59459SGreg Roach    formData.append('head', xref);
1797da59459SGreg Roach    formData.append('xref', xref);
1807da59459SGreg Roach
1817da59459SGreg Roach    fetch(<?= json_encode(route('module', ['module' => 'GEDFact_assistant', 'action' => 'CensusIndividual', 'tree' => $individual->tree()->name()])) ?> , {
1827da59459SGreg Roach        credentials: 'same-origin',
1837da59459SGreg Roach        body: formData,
1847da59459SGreg Roach        method: 'POST',
185dd6b2bfcSGreg Roach    })
1867da59459SGreg Roach    .then(response => response.text())
187dd6b2bfcSGreg Roach    .then(function (text) {
188dd6b2bfcSGreg Roach        document.querySelector('#census-assistant-table tbody').innerHTML = text;
189dd6b2bfcSGreg Roach    });
190dd6b2bfcSGreg Roach
191dd6b2bfcSGreg Roach    return false;
192dd6b2bfcSGreg Roach  }
193dd6b2bfcSGreg Roach
1947a18bd58SGreg Roach  $('#census-selector').on('change', censusAssistantSelect);
1957a18bd58SGreg Roach  $('#census-assistant-link').on('click', censusAssistantLink);
1967a18bd58SGreg Roach  $('#census-assistant-add').on('click', censusAssistantAdd);
1977a18bd58SGreg Roach  $('#census-assistant-head').on('click', censusAssistantHead);
1987a18bd58SGreg Roach
199*08362db4SGreg Roach  $('#census-assistant-table').on('click', '.wt-icon-delete', function() {
2007a18bd58SGreg Roach    $(this).closest('tr').remove();
2017a18bd58SGreg Roach
2027a18bd58SGreg Roach    return false;
2037a18bd58SGreg Roach  })
204dd6b2bfcSGreg Roach</script>
2057a18bd58SGreg Roach<?php View::endpush() ?>
206