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