Skip to content

Commit

Permalink
Assets: Suggest operating systems when adding an asset
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongecho committed Dec 14, 2024
1 parent 0ffb399 commit 6d23cca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions client_asset_add_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">

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

<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
Expand Down Expand Up @@ -116,7 +116,7 @@
<div class="input-group-prepend">
<span class="input-group-text"><i class="fab fa-fw fa-windows"></i></span>
</div>
<input type="text" class="form-control" name="os" placeholder="ex Windows 10 Pro">
<input type="text" class="form-control" name="os" id="os" placeholder="ex Windows 10 Pro">
</div>
</div>
<?php } ?>
Expand Down
27 changes: 27 additions & 0 deletions client_assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@

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


// OS typeahead suggestions
$os_sql = mysqli_query($mysqli, "SELECT DISTINCT asset_os AS label FROM assets WHERE asset_archived_at IS NULL");
if (mysqli_num_rows($os_sql) > 0) {
while ($row = mysqli_fetch_array($os_sql)) {
$os_arr[] = $row;
}
$json_os = json_encode($os_arr);
}

?>

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

require_once "footer.php";

?>

<!-- JSON Autocomplete / type ahead -->
<link rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css">
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<script>
$(function() {
var operatingSystems = <?php echo $json_os; ?>;
$("#os").autocomplete({
source: operatingSystems, // Should be an array of objects with 'label' and 'value'
select: function(event, ui) {
$("#os").val(ui.item.label); // Set the input field value to the selected label
return false;
}
});
});
</script>

0 comments on commit 6d23cca

Please sign in to comment.