Skip to content

Commit 58af24c

Browse files
committed
fixed filter input box to left and made it dynamic
1 parent 4721f98 commit 58af24c

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

resources/templates/footer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
</body>
2727

28-
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/filterable.js"></script>
29-
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/sortable.js"></script>
28+
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/filter.js"></script>
29+
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/sort.js"></script>
3030
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/global.js"></script>
3131
<script src="<?php echo $CONFIG["site"]["prefix"]; ?>/js/tables.js"></script>
3232

webroot/admin/pi-mgmt.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@
106106

107107
<table class="searchable longTable sortable filterable">
108108
<tr class="key">
109-
<input type="text" placeholder="Filter by Name..." class="filterSearch" id="name-filter">
109+
<input type="text" style="margin-right:5px;" placeholder="Filter by..." id="common-filter" class="filterSearch">
110110
<td id="name"><span class="filter">⫧ </span>Name</td>
111-
<input type="text" placeholder="Filter by Unity ID..." class="filterSearch" id="unityID-filter">
112111
<td id="unityID"><span class="filter">⫧ </span>Unity ID</td>
113-
<input type="text" placeholder="Filter by Mail..." class="filterSearch" id="mail-filter">
114112
<td id="mail"><span class="filter">⫧ </span>Mail</td>
115113
<td>Actions</td>
116114
</tr>

webroot/admin/user-mgmt.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727

2828
<table class="searchable longTable sortable filterable">
2929
<tr class="key">
30-
<input type="text"style="margin-right:5px;"placeholder="Filter by Name..."class="filterSearch"id="name-filter">
30+
<input type="text" style="margin-right:5px;" placeholder="Filter by..." id="common-filter" class="filterSearch">
3131
<td id="name"><span class="filter">⫧ </span>Name</td>
32-
<input type="text" placeholder="Filter by UID..." class="filterSearch" id="uid-filter">
3332
<td id="uid"><span class="filter">⫧ </span>UID</td>
34-
<input type="text" placeholder="Filter by Org..." class="filterSearch" id="org-filter">
3533
<td id="org"><span class="filter">⫧ </span>Org</td>
36-
<input type="text" placeholder="Filter by Mail..." class="filterSearch" id="mail-filter">
3734
<td id="mail"><span class="filter">⫧ </span>Mail</td>
38-
<input type="text" placeholder="Filter by Groups..." class="filterSearch" id="groups-filter">
3935
<td id="groups"><span class="filter">⫧ </span>Groups</td>
4036
<td>Actions</td>
4137
</tr>

webroot/js/filterable.js renamed to webroot/js/filter.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,52 @@ function updateQueryStringParameter(uri, key, value) {
2121
window.history.pushState("object or string", "Title", currentURL.href);
2222
}
2323

24-
function updateFilterInputs() {
25-
$(".filterSearch").each(function() {
26-
if (getQueryVariable("filter") != false) {
27-
if (this.id == getQueryVariable("filter")+"-filter") {
28-
if ($(this).css("display") == "inline-block" && $(this).css("visibility") == "visible" && getQueryVariable("value") == false) {
29-
updateQueryStringParameter(window.location.href, "filter", "");
30-
updateQueryStringParameter(window.location.href, "value", "");
31-
updateFilterInputs();
32-
return;
33-
}
34-
$(this).css("display", "inline-block");
35-
$(this).css("visibility", "visible");
36-
} else {
37-
$(this).css("display", "inline-block");
38-
$(this).css("visibility", "hidden");
39-
}
24+
function updateFilterInput() {
25+
const commonFilterInputBox = document.querySelector(".filterSearch");
26+
commonFilterInputBox.style.display = "none";
27+
commonFilterInputBox.style.visibility = "hidden";
28+
commonFilterInputBox.value = "";
29+
30+
var filter = getQueryVariable("filter");
31+
if (filter) {
32+
commonFilterInputBox.style.display = "inline-block";
33+
commonFilterInputBox.style.visibility = "visible";
34+
35+
if (filter == "uid") {
36+
commonFilterInputBox.placeholder = "Filter by " + filter.toUpperCase() + '...';
4037
} else {
41-
$(this).css("display", "none");
38+
commonFilterInputBox.placeholder = "Filter by " + filter.charAt(0).toUpperCase() + filter.slice(1) + '...';
4239
}
4340

4441
if (getQueryVariable("value") != false) {
45-
$(this).val(getQueryVariable("value"));
46-
} else {
47-
$(this).val("");
42+
commonFilterInputBox.value = getQueryVariable("value");
43+
filterRows();
4844
}
4945

50-
$(this).on("keyup", function(e) {
51-
updateQueryStringParameter(window.location.href, "value", $(this).val());
46+
commonFilterInputBox.addEventListener("keyup", function(e) {
47+
updateQueryStringParameter(window.location.href, "value", e.target.value);
5248
filterRows();
53-
})
54-
});
49+
});
50+
}
5551
}
5652

57-
updateFilterInputs();
53+
updateFilterInput();
5854

5955
var filters = document.querySelectorAll("span.filter");
6056
filters.forEach(function(filter) {
6157
filter.addEventListener("click", function(e) {
6258
e.preventDefault();
6359
e.stopPropagation();
64-
updateQueryStringParameter(window.location.href, "filter", e.target.parentElement.id);
65-
updateFilterInputs();
60+
if (e.target.parentElement.id != getQueryVariable("filter")) {
61+
updateQueryStringParameter(window.location.href, "filter", e.target.parentElement.id);
62+
updateQueryStringParameter(window.location.href, "value", "");
63+
filterRows();
64+
} else {
65+
updateQueryStringParameter(window.location.href, "filter", "");
66+
updateQueryStringParameter(window.location.href, "value", "");
67+
filterRows();
68+
}
69+
updateFilterInput();
6670
});
6771
});
6872

webroot/js/sortable.js renamed to webroot/js/sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ table.querySelectorAll("td").forEach(function(td) {
44
if (td.parentElement.classList.contains("key") && td.innerHTML != "Actions") {
55
if (e.target.classList.contains("filter")) {
66
updateQueryStringParameter(window.location.href, "filter", e.target.parentElement.id);
7-
updateFilterInputs();
7+
updateFilterInput();
88
} else {
99
var column = td.cellIndex;
1010
var rows = Array.from(table.querySelectorAll("tr:nth-child(n+2)"));

0 commit comments

Comments
 (0)