]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
removed ugly code for configFile and specFile selectors and replaced it with a modula...
authorMichael Wiebusch <stratomaster@gmx.net>
Mon, 2 Dec 2013 17:58:15 +0000 (18:58 +0100)
committerMichael Wiebusch <stratomaster@gmx.net>
Mon, 2 Dec 2013 17:58:15 +0000 (18:58 +0100)
tools/Widgets.pm [new file with mode: 0644]
tools/jtageditor.pl
tools/testgui.pl

diff --git a/tools/Widgets.pm b/tools/Widgets.pm
new file mode 100644 (file)
index 0000000..9efe195
--- /dev/null
@@ -0,0 +1,98 @@
+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
index 02576e9ff9c9df55495a0c1744434bafc237a940..7e4345a2087e0c5ff3a0a0b5211c200d7dbcbd97 100755 (executable)
@@ -69,6 +69,7 @@ require xmlRendering;
 use FindBin;
 use lib "$FindBin::Bin/..";
 use Environment;
+use Widgets;
 
 
 my %cgiHash = &read_input;
@@ -145,70 +146,6 @@ if ( defined $cgiHash{'debuginput'} ) {
 ## 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];
@@ -216,7 +153,16 @@ sub print_fileSelection {
   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
@@ -233,7 +179,13 @@ sub print_fileSelection {
   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'>";
index 8bdf96f644a6c9b58b4899105847eb49d8a6768e..eee8e857dcf8b89b750427b76859936bb6ce3c06 100755 (executable)
@@ -113,17 +113,6 @@ sub parse_setupFile {
   }
   $setupTree = $parser->parse_file($setupFile);
 }
-  
-  
-# sub parse_quickEditMaskFile {
-#   my $parser       = XML::LibXML->new();
-#   unless( -e $quickEditMaskFile) { 
-#     die "quickEditMaskFile $quickEditMaskFile does not exist!\n";
-#   }
-#   $quickEditMaskTree = $parser->parse_file($quickEditMaskFile);
-# }
-
-
 
 sub init_html{