@ -1542,15 +1542,6 @@ sub sanity_check_fence_agent_form
{
my ($anvil, $fence_agent) = @_;
### TODO: Left off here. Make the confirm form a table;
### Any set options that matches the default gets set to 'subtle'.
=cut
Fence Agent: $fence_agent
Devices:
| option | default | 1 | 2 | ...
+--------+---------+-------+-------+-----
| foo | bar | bar | baz |
=cut
my $sane = 1;
my $confirn_form = "";
foreach my $i (1..$anvil->data->{cgi}{fence_count}{value})
@ -1568,13 +1559,14 @@ Devices:
my $description = $anvil->data->{fences}{$fence_agent}{parameters}{$name}{description};
my $type = $anvil->data->{fences}{$fence_agent}{parameters}{$name}{content_type};
my $default = exists $anvil->data->{fences}{$fence_agent}{parameters}{$name}{'default'} ? $anvil->data->{fences}{$fence_agent}{parameters}{$name}{'default'} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
option_key => $option_key,
unique => $unique,
required => $required,
description => $description,
type => $type,
'default' => $default,
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:name' => $name,
's2:option_key' => $option_key,
's3:unique' => $unique,
's4:required' => $required,
's5:description' => $description,
's6:type' => $type,
's7:default' => $default,
}});
# If this is 'boolean' and the default is '1', change the default to 'on' so that
@ -1585,16 +1577,40 @@ Devices:
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'default' => $default }});
}
my $is_default = 1;
my $passed_parameter_key = $name."_".$i;
my $passed_value = defined $anvil->data->{cgi}{$passed_parameter_key}{value} ? $anvil->data->{cgi}{$passed_parameter_key}{value} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
my $say_value = $passed_value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
passed_parameter_key => $passed_parameter_key,
passed_value => $passed_value,
'default' => $default,
}});
if ($type eq "boolean")
{
$say_value = "";
if (defined $passed_value)
{
# Yes No
$say_value = $passed_value ? "#!string!unit_0001!#" : "#!string!unit_0002!#";
}
else
{
# Yes No
$say_value = $default ? "#!string!unit_0001!#" : "#!string!unit_0002!#";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_value => $say_value }});
}
elsif ((($type eq "string") or ($type eq "select")) && ($passed_value eq ""))
{
$say_value = "--";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_value => $say_value }});
}
if ($passed_value ne $default)
{
# Something changed. Is it sane?
$is_default = 0;
if (($type eq "integer") or ($type eq "second"))
{
# Make sure the value is a bare integer
@ -1603,7 +1619,7 @@ Devices:
# Problem.
$sane = 0;
$anvil->data->{cgi}{$passed_parameter_key}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3 , list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2 , list => {
"cgi::${passed_parameter_key}::alert" => $anvil->data->{cgi}{$passed_parameter_key}{alert},
sane => $sane,
}});
@ -1616,9 +1632,16 @@ Devices:
"fence::${fence_agent}::set::${i}::parameter::${name}::set" => $anvil->data->{fence}{$fence_agent}{set}{$i}{parameter}{$name}{set},
}});
}
$anvil->data->{fence}{confirm_table}{data}{$name}{$i}{'default'} = $is_default;
$anvil->data->{fence}{confirm_table}{data}{$name}{$i}{value} = $say_value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"fence::confirm_table::data::${name}::${i}::default" => $anvil->data->{fence}{confirm_table}{data}{$name}{$i}{'default'},
"fence::confirm_table::data::${name}::${i}::value" => $anvil->data->{fence}{confirm_table}{data}{$name}{$i}{value},
}});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sane => $sane }});
return($sane);
}
@ -1643,11 +1666,80 @@ sub process_fences
my $fence_agent = $anvil->data->{cgi}{fence_agent}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { fence_agent => $fence_agent }});
# Are we going back to the form?
if ($anvil->data->{cgi}{back}{value})
{
$anvil->data->{cgi}{save}{value} = "";
$anvil->data->{cgi}{confirm}{value} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::save::value" => $anvil->data->{cgi}{save}{value},
"cgi::confirm::value" => $anvil->data->{cgi}{confirm}{value},
}});
}
# Are we saving?
if ($anvil->data->{cgi}{save}{value})
{
# Sanity check
my $sane = sanity_check_fence_agent_form($anvil, $fence_agent);
if ($sane)
{
# Build the table and ask the user to confirm.
#print $anvil->Template->get({file => "shared.html", name => "http_headers"})."\n";
#print "<pre>\n";
#print Dumper $anvil->data->{fence}{confirm_table};
#print "</pre>\n";
my $header_columns = $anvil->Template->get({file => "anvil.html", name => "fence-agent-column", variables => {
class => "column_header",
value => " ",
}});
foreach my $i (1..$anvil->data->{cgi}{fence_count}{value})
{
$header_columns .= $anvil->Template->get({file => "anvil.html", name => "fence-agent-column", variables => {
class => "column_header",
value => $anvil->Words->string({key => "striker_0220", variables => { number => $i }}),
}});
}
my $confirm_table = $anvil->Template->get({file => "anvil.html", name => "fence-agent-row", variables => {
columns => $header_columns,
}});
foreach my $name (sort {$a cmp $b} keys %{$anvil->data->{fence}{confirm_table}{data}})
{
my $entry_row = $anvil->Template->get({file => "anvil.html", name => "fence-agent-column", variables => {
class => "column_header",
value => $name,
}});
foreach my $i (sort {$a cmp $b} keys %{$anvil->data->{fence}{confirm_table}{data}{$name}})
{
my $is_default = $anvil->data->{fence}{confirm_table}{data}{$name}{$i}{'default'};
my $value = $anvil->data->{fence}{confirm_table}{data}{$name}{$i}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:name' => $name,
's2:i' => $i,
's3:is_default' => $is_default,
's4:value' => $value,
}});
$entry_row .= $anvil->Template->get({file => "anvil.html", name => "fence-agent-column-hidden-value", variables => {
class => $is_default ? "default_value" : "changed_value",
name => $name."_".$i,
value => $value,
}});
}
$confirm_table .= $anvil->Template->get({file => "anvil.html", name => "fence-agent-row", variables => {
columns => $entry_row,
}});
}
$anvil->data->{form}{back_link} = "?anvil=true&task=fences";
$anvil->data->{form}{body} = $anvil->Template->get({file => "anvil.html", name => "fence-agent-confirm", variables => {
table => $confirm_table,
span_count => $anvil->data->{cgi}{fence_count}{value},
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'form::body' => $anvil->data->{form}{body} }});
return(0);
}
}
my $agent_description = format_fence_description($anvil, $fence_agent, $anvil->data->{fences}{$fence_agent}{description});