Get config panel working for nutups

This commit is contained in:
Brian Read 2025-01-20 18:06:41 +00:00
parent 51a59b9696
commit e717237726
3 changed files with 39 additions and 16 deletions

View File

@ -181,7 +181,21 @@ sub create_link{
} }
sub get_model_options { sub get_model_options {
return [];
# Execute the RPM command and capture the output
my @output = qx{rpm -ql nut | grep /usr/sbin};
# Check for errors
if ($? != 0) {
warn "Error executing command: $!";
return ['Error occurred'];
} }
# Remove "/usr/sbin" from the front of each line
s{^/usr/sbin}{} for @output;
# Trim whitespace from each element and return the array
chomp(@output); # Remove newline characters from each line
return ["fred","Art"] #@output; # Return the array of modified output lines
}
1; 1;

View File

@ -85,16 +85,16 @@
<p><span class=label> <p><span class=label>
%=l('nut_UPS_Model') %=l('nut_UPS_Model')
</span><span class=data> </span><span class=data>
% my @UPS_Model_options = ; % my @UPS_Model_options = $c->get_model_options();
% param 'UPS_Model' => $nut_data->{UPS_Model} unless param 'UPS_Model'; % param 'UPS_Model' => $nut_data->{UPS_Model} unless param 'UPS_Model';
%= select_field 'UPS_Model' => @UPS_Model_options, class => 'input', id => 'UPS_Model_select' %= select_field 'UPS_Model' => \@UPS_Model_options, class => 'input', id => 'UPS_Model_select'
<br></span> </p> <br></span> </p>
<p><span class=label> <p><span class=label>
%=l('nut_UPS_Device') %=l('nut_UPS_Device')
</span><span class=data> </span><span class=data>
% param 'UPS_Device' => $nut_data->{UPS_Device} unless param 'UPS_Device'; % param 'UPS_Device' => $nut_data->{UPS_Device} unless param 'UPS_Device';
%= text_field 'UPS_Device', size => '50', class => 'textinput UPS_Device' , pattern=>'.*' , placeholder=>'UPS_Device' %= text_field 'UPS_Device', size => '50', class => 'textinput UPS_Device' , pattern=>'.*' , placeholder=>'auto (for usb)'
<br></span></p> <br></span></p>
<div class=generics> <div class=generics>
@ -122,12 +122,13 @@
% param 'UPS_gen_Model' => $nut_data->{UPS_gen_Model} unless param 'UPS_gen_Model'; % param 'UPS_gen_Model' => $nut_data->{UPS_gen_Model} unless param 'UPS_gen_Model';
%= text_field 'UPS_gen_Model', size => '50', class => 'textinput UPS_gen_Model' , pattern=>'.*' , placeholder=>'UPS_gen_Model' %= text_field 'UPS_gen_Model', size => '50', class => 'textinput UPS_gen_Model' , pattern=>'.*' , placeholder=>'UPS_gen_Model'
<br></span></p> <br></span></p>
</div>
<span class='data'> <span class='data'>
%= submit_button l('nut_Save'), class => 'action subm12' %= submit_button l('nut_Save'), class => 'action subm12'
</span> </span>
</div>
%# Probably finally by a submit. %# Probably finally by a submit.

View File

@ -1,6 +1,3 @@
//
//Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-01-20 16:09:58
//
$(document).ready(function() { $(document).ready(function() {
function toggleUPSClasses() { function toggleUPSClasses() {
var selectedOption = $('#Nutmode_select').val(); var selectedOption = $('#Nutmode_select').val();
@ -12,9 +9,20 @@ $(document).ready(function() {
$('.slaveups input').prop('disabled', selectedOption !== 'netserver'); $('.slaveups input').prop('disabled', selectedOption !== 'netserver');
} }
// Event listener for the select change function toggleGenerics() {
$('#Nutmode_select').change(toggleUPSClasses); var upsModelValue = $('#UPS_Model_select').val().toLowerCase(); // Get the current value from UPS_Model
var isGenericUps = upsModelValue === 'genericups'; // Check if it's 'genericups'
// Set the initial state // Show/Hide generics section and enable/disable inputs
$('.generics').toggle(isGenericUps);
$('.generics input').prop('disabled', !isGenericUps); // Enable/Disable inputs based on the value
}
// Event listener for the selections
$('#Nutmode_select').change(toggleUPSClasses);
$('#UPS_Model_select').change(toggleGenerics); // Listen for changes in the UPS_Model dropdown
// Set the initial state based on current selections
toggleGenerics();
toggleUPSClasses(); toggleUPSClasses();
}); });