--- /dev/null
+package fileSelector;
+
+use warnings;
+use strict;
+
+
+
+sub new {
+ my $class=shift;
+ my %options = @_;
+ my $self = {
+ id => '',
+ name => 'fileSelectionDropdown',
+ class => '',
+ onchange => '',
+ items => [],
+ selected => '',
+ %options
+ };
+ bless($self, $class);
+ return $self;
+}
+
+sub add_item {
+ my $self = shift;
+ my %entry = @_;
+
+ push(@{$self->{items}},{%entry});
+}
+
+sub print_items {
+ my $self = shift;
+ for my $href (@{$self->{items}}) {
+ for my $key (keys %$href) {
+ print "$key:\t".$href->{$key}."\n";
+ }
+ }
+}
+
+sub add_items_from_dir{
+ my $self = shift;
+ my %options = @_;
+ my $ext = $options{ext};
+ my @files;
+
+ opendir( DIR, $options{dir}) or die $!;
+
+ while ( my $file = readdir(DIR) ) {
+
+ # Use a regular expression to ignore files beginning with a period
+ next if ( $file =~ m/^\./ );
+ push(@files, $file);
+
+ }
+
+ for my $file (sort @files) {
+ if (defined($ext)) {
+ if ( $file =~ m/\.$ext$/ ) {
+# push( @xmlfiles, $file );
+ $self->add_item(value=>$file);
+ }
+ } else {
+ $self->add_item(value=>$file);
+ }
+ }
+
+ closedir(DIR);
+
+}
+
+sub print_html {
+
+ my $self = shift;
+
+ print q%<select name='%.$self->{name}.q%' %
+ .q%id='%.$self->{id}.q%' %
+ .q%onchange='%.$self->{onchange}.q%' %
+ .q%class='%.$self->{class}.q%' %
+ .q%>%;
+ print "\n";
+
+# print "<option value='...'>...</option>";
+
+ for my $item ( sort @{$self->{items}} ) {
+ print q%<option value='%.$item->{value}.q%' %;
+ if(defined($item->{selected}) or ($self->{selected} eq $item->{value})){
+ print q%selected%;
+ }
+ print q%>%.$item->{value}.q%</option>%;
+ print "\n";
+ }
+
+ print q%</select>%;
+
+ print "\n";
+}
+
+1;
\ No newline at end of file
use FindBin;
use lib "$FindBin::Bin/..";
use Environment;
+use Widgets;
my %cgiHash = &read_input;
## subs generating html output
###############################
-sub print_fileSelector {
-
- my $configFile = $_[0];
- my $elementId = $_[1];
- my $action = $_[2];
- opendir( DIR, $confDir ) or die $!;
-
- print '<select name="fileSelectionDropdown" id="'
- . $elementId
- . '" onchange="'
- . $action . '">';
-
- print "<option value='...'>...</option>";
- my @xmlfiles;
- while ( my $file = readdir(DIR) ) {
-
- # Use a regular expression to ignore files beginning with a period
- next if ( $file =~ m/^\./ );
-
- if ( $file =~ m/\.xml$/ ) {
- push( @xmlfiles, $file );
- }
- }
- for my $file ( sort @xmlfiles ) {
- print '<option value="' . $file . '"';
- if ( $file eq $configFile ) {
- print ' selected ';
- }
- print '>' . $file . '</option>';
- }
- closedir(DIR);
-
- print '</select>';
-}
-
-sub print_specSelector {
-
- my $configFile = $_[0];
- opendir( DIR, $specDir ) or die $!;
-
- print '<select name="specSelectionDropdown" id="specSelector" >';
-
- my @xmlfiles;
- while ( my $file = readdir(DIR) ) {
-
- # Use a regular expression to ignore files beginning with a period
- next if ( $file =~ m/^\./ );
-
- if ( $file =~ m/\.xml$/ ) {
- push( @xmlfiles, $file );
- }
- }
- for my $file ( sort @xmlfiles ) {
- print '<option value="' . $file . '"';
- if ( $file eq $configFile ) {
- print ' selected ';
- }
- print '>' . $file . '</option>';
- }
- closedir(DIR);
-
- print '</select>';
-}
-
sub print_fileSelection {
my $configFile = $_[0];
print "<h3>selected config file</h3>";
print "<p>";
- print_fileSelector( $configFile, "fileSelector", "loadFile()" );
+# print_fileSelector( $configFile, "fileSelector", "loadFile()" );
+ my $config_selector = fileSelector->new(
+ selected=>$configFile,
+ id=>"fileSelector",
+ name=>"fileSelectionDropdown",
+ onchange=>"loadFile()"
+ );
+ $config_selector->add_item(value=>'...');
+ $config_selector->add_items_from_dir(dir=>$confDir,ext=>"xml");
+ $config_selector->print_html();
print
"<input type='button' onclick='loadFile()' value='reload file' class='stdbutton'>";
print
print "<td>";
print "<input type='text' value='' id='newFileName'>";
print "</td><td>";
- print_specSelector();
+ my $spec_selector = fileSelector->new(
+ id=>"specSelector",
+ name=>"specSelectonDropdown"
+ );
+ $spec_selector->add_items_from_dir(dir=>$specDir,ext=>"xml");
+ $spec_selector->print_html();
+# print_specSelector();
print "</td><td>";
print
"<input type='button' onclick='createFile(selectedSpecFile(),newFileName());reloadFileSelection(newFileName());loadFile()' value='create file' class='stdbutton'>";