summaryrefslogtreecommitdiff
path: root/resources/views/modules/descendancy/sidebar.phtml
blob: 46fab38967d4c929e85d92ec7ffbc7d8e5624b42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;

/**
 * @var string $individual_list
 * @var Tree   $tree
 */

?>

<form method="post" action="<?= e(route('module', ['module' => 'descendancy', 'action' => 'Descendants', 'tree' => $tree->name()])) ?>" onsubmit="return false;">
    <?= csrf_field() ?>
    <input type="search" name="sb_desc_name" id="sb_desc_name" placeholder="<?= I18N::translate('Search') ?>">
</form>

<div id="sb_desc_content">
    <ul>
        <?= $individual_list ?>
    </ul>
</div>

<?php View::push('javascript') ?>
<script>
  function dsearchQ() {
    var query = $("#sb_desc_name").val();
    if (query.length>1) {
      $("#sb_desc_content").load(<?= json_encode(route('module', ['module' => 'descendancy', 'action' => 'Search', 'tree' => $tree->name(), 'search' => ''])) ?> + encodeURIComponent(query));
    }
  }

  $("#sb_desc_name").focus(function(){this.select();});
  $("#sb_desc_name").blur(function(){if (this.value === "") this.value="<?= I18N::translate('Search') ?>";});
  var dtimerid = null;
  $("#sb_desc_name").keyup(function(e) {
    if (dtimerid) window.clearTimeout(dtimerid);
    dtimerid = window.setTimeout("dsearchQ()", 500);
  });

  $("#sb_desc_content").on("click", ".sb_desc_indi", function() {
    var self = $(this),
        state = self.children(".plusminus"),
        target = self.siblings("div");
    if(state.hasClass("icon-plus")) {
      if (jQuery.trim(target.html())) {
        target.show("fast"); // already got content so just show it
      } else if (self.attr("href") !== "#") {
        target
          .hide()
          .load(self.attr("href"), function(response, status, xhr) {
            if(status === "success" && response !== "") {
              target.show("fast");
            }
          })
      }
    } else {
      target.hide("fast");
    }
    state.toggleClass("icon-minus icon-plus");
    return false;
  });
</script>
<?php View::endpush() ?>