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