Update hooks.php
Hide the SSH key field if the user isn't logged in to see them or is a new user.
This commit is contained in:
@@ -65,18 +65,20 @@ add_hook('ClientAreaFooterOutput', 1, function ($vars) {
|
|||||||
return "
|
return "
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var osTemplates = " . json_encode($dropdownOptions) . ";
|
let osTemplates = ".json_encode($dropdownOptions, JSON_THROW_ON_ERROR).";
|
||||||
var sshKeys = " . json_encode($sshKeysOptions) . ";
|
let sshKeys = ".json_encode($sshKeysOptions, JSON_THROW_ON_ERROR).";
|
||||||
|
|
||||||
var osInputField = document.querySelector('[name=\"customfield[" . ($osID[0] ?? null) . "]\"]');
|
const osInputField = document.querySelector('[name=\"customfield[".($osID[0] ?? null)."]\"]');
|
||||||
var sshInputField = document.querySelector('[name=\"customfield[" . ($sshID[0] ?? null) . "]\"]');
|
const osInputLabel = document.querySelector('[for=\"customfield".($osID[0] ?? null)."\"]');
|
||||||
|
const sshInputField = document.querySelector('[name=\"customfield[".($sshID[0] ?? null)."]\"]');
|
||||||
|
const sshInputLabel = document.querySelector('[for=\"customfield".($sshID[0] ?? null)."\"]');
|
||||||
|
|
||||||
// Create dropdown options menu, then add it to the DOM then on change, update the regular input.
|
// Create dropdown options menu, then add it to the DOM then on change, update the regular input.
|
||||||
var osSelect = document.createElement('select');
|
let osSelect = document.createElement('select');
|
||||||
osSelect.className = 'form-control';
|
osSelect.className = 'form-control';
|
||||||
|
|
||||||
osTemplates.forEach(function(template) {
|
osTemplates.forEach(function(template) {
|
||||||
var option = document.createElement('option');
|
let option = document.createElement('option');
|
||||||
option.value = template.id;
|
option.value = template.id;
|
||||||
option.text = template.name;
|
option.text = template.name;
|
||||||
osSelect.appendChild(option);
|
osSelect.appendChild(option);
|
||||||
@@ -95,11 +97,11 @@ add_hook('ClientAreaFooterOutput', 1, function ($vars) {
|
|||||||
|
|
||||||
if (sshKeys.length > 0) {
|
if (sshKeys.length > 0) {
|
||||||
// Create dropdown options menu, then add it to the DOM then on change, update the regular input.
|
// Create dropdown options menu, then add it to the DOM then on change, update the regular input.
|
||||||
var sshSelect = document.createElement('select');
|
let sshSelect = document.createElement('select');
|
||||||
sshSelect.className = 'form-control';
|
sshSelect.className = 'form-control';
|
||||||
|
|
||||||
sshKeys.forEach(function(sshkey) {
|
sshKeys.forEach(function(sshkey) {
|
||||||
var option = document.createElement('option');
|
let option = document.createElement('option');
|
||||||
option.value = sshkey.id;
|
option.value = sshkey.id;
|
||||||
option.text = sshkey.name;
|
option.text = sshkey.name;
|
||||||
sshSelect.appendChild(option);
|
sshSelect.appendChild(option);
|
||||||
@@ -116,6 +118,7 @@ add_hook('ClientAreaFooterOutput', 1, function ($vars) {
|
|||||||
sshInputField.style.display = 'none';
|
sshInputField.style.display = 'none';
|
||||||
} else {
|
} else {
|
||||||
sshInputField.style.display = 'none';
|
sshInputField.style.display = 'none';
|
||||||
|
sshInputLabel.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user