/[pxelator]/lib/PXElator/html.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 172 by dpavlin, Thu Aug 6 22:27:34 2009 UTC revision 401 by dpavlin, Tue Sep 8 20:21:25 2009 UTC
# Line 1  Line 1 
1  package html;  package html;
2    
3    use Data::Dump qw/dump/;
4    use amt;
5    
6  sub table {  sub table {
7          my $cols = shift;          my $cols = shift;
8          my $th;          my $th;
# Line 12  sub table { Line 15  sub table {
15    
16          my @td = map { "<td>$_</td>" } @_;          my @td = map { "<td>$_</td>" } @_;
17          my $html = qq{<table>\n<tr>$th};          my $html = qq{<table>\n<tr>$th};
18            my $row = 0;
19    
20          foreach ( 0 .. $#td ) {          foreach ( 0 .. $#td ) {
21                          $html .= $td[$_];                          $html .= $td[$_];
22                          $html .= qq{</tr>\n<tr>} if ( $_ + 1 ) % $cols == 0;                          if ( ( $_ + 1 ) % $cols == 0 ) {
23                                    $zebra = $row++ % 2 == 0 ? qq{ style="background: #eee"} : '';
24                                    $html .= qq{</tr>\n<tr$zebra>};
25                            };
26          }          }
27          $html .= qq{</tr>\n</table>};          $html .= qq{</tr>\n</table>};
28  }  }
# Line 32  sub tabs { Line 40  sub tabs {
40                    
41    
42  sub tt {  sub tt {
43          qq|<tt>| . join(' ', @_) . qq|</tt>|;          qq|<tt>| . join(' ', @_) . qq|</tt>| if @_;
44  }  }
45    
46  sub select {  sub select {
47          my $name = shift;          my $name = shift;
48          my $selected_option = shift;          my $selected_option = shift;
49            unshift @_, '' unless $selected_option;
50          return join("\n"                  return join("\n"        
51                  , qq|<select type=select name=$name>|                  , qq|<select type=select name=$name>|
52                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
53                  , qq|</select>|                  , qq|</select>|
                 , qq|</form>|  
54          );          );
55  }  }
56    
57    sub pre {
58            qq|<pre>| . join(' ', @_) . qq|</pre>| if @_;
59    }
60    
61    sub pre_dump {
62            my $data = shift;
63            my $dump = dump( $data );
64            $dump =~ s{"([^"]+)"(\s*=>)}{$1  $2}gs;
65            $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
66            qq|<pre>$dump</pre>|;
67    }
68    
69    sub conf {
70            my ($ip,$conf,$format) = @_;
71            my @editable = splice(@_,3);
72    
73            warn "# conf ",dump( $ip, $conf, $format, [ @editable ] );
74    
75            $format ||= 'inline';
76    
77            my @opts = map {
78                    my $name = $_;
79                    my $html = $conf->{$name};
80    
81                    if ( $format eq 'edit' && grep { m/^$name$/ } @editable ) {
82                            $size = length($html);
83                            ( $name, qq|<input name=$name value="$html" size=$size>| )
84                    } else {
85                            if ( $name eq 'amt' ) {
86                                    my $amt_ip = amt::ip($ip,$html);
87                                    $html = qq|<a title="$html" href=http://$amt_ip:16992/logon.htm target=$amt_ip>$amt_ip</a>|;
88    
89                                    if ( $format ne 'inline' ) {
90                                            my $power = amt::power_on($ip);
91                                            $html .= qq| power: |
92                                            . ( $power
93                                                    ? qq|<a href=/amt/PowerDown/$ip title="turn off">on</a>|
94                                                    : qq|<a href=/amt/PowerUp/$ip   title="turn on" >off</a>|
95                                            );
96                                            client::conf( $ip, 'power' => $power ? 'on' : 'off' );
97                                    }
98                            } elsif ( $name eq 'ssh' ) {
99                                    $html =~ s{\s(\S{16}).+(\S{16})\s}{ $1..$2 };
100                                    chomp($html);
101                            }
102                            $html = qq|<tt>$html</tt>|
103                            unless
104                            $html =~ s{\b(\S+)\t(\S+)\t(\S+)\b}{<b title="$1/$2">$3</b> }gs;
105                    
106                            if ( $format =~ /edit|table/ ) {
107                                    ( $name, $html );
108                            } else {
109                                    qq|<div class="config $name"><em>$name</em> $html</div>|
110                            }
111                    }
112            } grep { length($conf->{$_}) > 0 } sort keys %$conf;
113    
114            $format eq 'inline' ? join("\n", @opts) : @opts;
115    }
116    
117  warn "loaded";  warn "loaded";
118    
119  1;  1;

Legend:
Removed from v.172  
changed lines
  Added in v.401

  ViewVC Help
Powered by ViewVC 1.1.26