Skip to content

Commit 6d23cca

Browse files
author
wrongecho
committed
Assets: Suggest operating systems when adding an asset
1 parent 0ffb399 commit 6d23cca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

client_asset_add_modal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
1313
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
1414

15-
<div class="modal-body bg-white">
15+
<div class="modal-body bg-white ui-front">
1616

1717
<ul class="nav nav-pills nav-justified mb-3">
1818
<li class="nav-item">
@@ -116,7 +116,7 @@
116116
<div class="input-group-prepend">
117117
<span class="input-group-text"><i class="fab fa-fw fa-windows"></i></span>
118118
</div>
119-
<input type="text" class="form-control" name="os" placeholder="ex Windows 10 Pro">
119+
<input type="text" class="form-control" name="os" id="os" placeholder="ex Windows 10 Pro">
120120
</div>
121121
</div>
122122
<?php } ?>

client_assets.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@
9191

9292
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
9393

94+
95+
// OS typeahead suggestions
96+
$os_sql = mysqli_query($mysqli, "SELECT DISTINCT asset_os AS label FROM assets WHERE asset_archived_at IS NULL");
97+
if (mysqli_num_rows($os_sql) > 0) {
98+
while ($row = mysqli_fetch_array($os_sql)) {
99+
$os_arr[] = $row;
100+
}
101+
$json_os = json_encode($os_arr);
102+
}
103+
94104
?>
95105

96106
<div class="col-sm-12 mb-3">
@@ -619,3 +629,20 @@ class="btn btn-<?php if($archived == 1){ echo "primary"; } else { echo "default"
619629

620630
require_once "footer.php";
621631

632+
?>
633+
634+
<!-- JSON Autocomplete / type ahead -->
635+
<link rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css">
636+
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
637+
<script>
638+
$(function() {
639+
var operatingSystems = <?php echo $json_os; ?>;
640+
$("#os").autocomplete({
641+
source: operatingSystems, // Should be an array of objects with 'label' and 'value'
642+
select: function(event, ui) {
643+
$("#os").val(ui.item.label); // Set the input field value to the selected label
644+
return false;
645+
}
646+
});
647+
});
648+
</script>

0 commit comments

Comments
 (0)