xref: /webtrees/resources/views/admin/fix-level-0-media.phtml (revision c532e5bbfb7e07b4bacf8fa7c4fdd95577124aae)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
4use Fisharebest\Webtrees\Http\RequestHandlers\FixLevel0MediaAction;
5use Fisharebest\Webtrees\Http\RequestHandlers\FixLevel0MediaData;
6use Fisharebest\Webtrees\I18N;
7
8?>
9<?php use Fisharebest\Webtrees\View; ?>
10
11<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), $title]]) ?>
12
13<h1><?= $title ?></h1>
14
15<p>
16    <?= I18N::translate('If a media object is linked to an individual, when it should be linked to a fact or event, then you can move it to the correct location.') ?>
17</p>
18
19<table
20    class="table table-bordered table-sm table-hover wt-fix-table datatables d-none"
21    <?= view('lists/datatables-attributes') ?>
22    data-ajax="<?= e(json_encode(['url' => route(FixLevel0MediaData::class)])) ?>"
23    data-server-side="true"
24>
25    <caption class="sr-only">
26        <?= I18N::translate('Media objects') ?>
27    </caption>
28    <thead class="thead-dark">
29        <tr>
30            <th data-sortable="false"><?= I18N::translate('Family tree') ?></th>
31            <th data-sortable="false"><?= I18N::translate('Media object') ?></th>
32            <th data-sortable="false"><?= I18N::translate('Title') ?></th>
33            <th data-sortable="false"><?= I18N::translate('Individual') ?></th>
34            <th data-sortable="false"><?= I18N::translate('Facts and events') ?></th>
35        </tr>
36    </thead>
37</table>
38
39<?php View::push('javascript') ?>
40<script>
41  'use strict';
42
43  // If we click on a button, post the request and reload the table
44  document.querySelector(".wt-fix-table").onclick = function (event) {
45    let element = event.target;
46    if (element.classList.contains("wt-fix-button")) {
47      event.stopPropagation();
48      if (confirm(element.dataset.confirm)) {
49        $.ajax({
50          data: {
51            "fact_id":   element.dataset.factId,
52            "indi_xref": element.dataset.individualXref,
53            "obje_xref": element.dataset.mediaXref,
54            "tree_id":   element.dataset.treeId
55          },
56          method: "POST",
57          url: <?= json_encode(route(FixLevel0MediaAction::class)) ?>
58        }).done(function () {
59          $(".wt-fix-table").DataTable().ajax.reload(null, false);
60        });
61      }
62    }
63  };
64</script>
65<?php View::endpush() ?>
66