xref: /webtrees/resources/views/modules/descendancy/sidebar.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Tree;
7use Fisharebest\Webtrees\View;
8
9/**
10 * @var string $individual_list
11 * @var Tree   $tree
12 */
13
14?>
15
16<form method="post" action="<?= e(route('module', ['module' => 'descendancy', 'action' => 'Descendants', 'tree' => $tree->name()])) ?>" onsubmit="return false;">
17    <input type="search" name="sb_desc_name" id="sb_desc_name" placeholder="<?= I18N::translate('Search') ?>">
18
19    <?= csrf_field() ?>
20</form>
21
22<div id="sb_desc_content">
23    <ul>
24        <?= $individual_list ?>
25    </ul>
26</div>
27
28<?php View::push('javascript') ?>
29<script>
30  function dsearchQ() {
31    var query = $("#sb_desc_name").val();
32    if (query.length>1) {
33      $("#sb_desc_content").load(<?= json_encode(route('module', ['module' => 'descendancy', 'action' => 'Search', 'tree' => $tree->name(), 'search' => '']), JSON_THROW_ON_ERROR) ?> + encodeURIComponent(query));
34    }
35  }
36
37  $("#sb_desc_name").focus(function(){this.select();});
38  $("#sb_desc_name").blur(function(){if (this.value === "") this.value="<?= I18N::translate('Search') ?>";});
39  var dtimerid = null;
40  $("#sb_desc_name").keyup(function(e) {
41    if (dtimerid) window.clearTimeout(dtimerid);
42    dtimerid = window.setTimeout("dsearchQ()", 500);
43  });
44
45  $("#sb_desc_content").on("click", ".sb_desc_indi", function() {
46    var self = $(this),
47        state = self.children(".plusminus"),
48        target = self.siblings("div");
49    if(state.hasClass("icon-plus")) {
50      if (jQuery.trim(target.html())) {
51        target.show("fast"); // already got content so just show it
52      } else if (this.dataset.wtHref !== "#") {
53        target
54          .hide()
55          .load(this.dataset.wtHref, function(response, status, xhr) {
56            if(status === "success" && response !== "") {
57              target.show("fast");
58            }
59          })
60      }
61    } else {
62      target.hide("fast");
63    }
64    state.toggleClass("icon-minus icon-plus");
65    return false;
66  });
67</script>
68<?php View::endpush() ?>
69