cvsuser     02/03/12 08:54:11

  Modified:    P5EEx/Blue/P5EEx/Blue/Widget/HTML DataTable.pm
  Log:
  many changes refining edit fields but it still won't save quite yet
  
  Revision  Changes    Path
  1.5       +218 -35   p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML/DataTable.pm
  
  Index: DataTable.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML/DataTable.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- DataTable.pm      6 Mar 2002 23:00:14 -0000       1.4
  +++ DataTable.pm      12 Mar 2002 16:54:10 -0000      1.5
  @@ -1,10 +1,10 @@
   
   ######################################################################
  -## $Id: DataTable.pm,v 1.4 2002/03/06 23:00:14 spadkins Exp $
  +## $Id: DataTable.pm,v 1.5 2002/03/12 16:54:10 spadkins Exp $
   ######################################################################
   
   package P5EEx::Blue::Widget::HTML::DataTable;
  -$VERSION = do { my @r=(q$Revision: 1.4 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.5 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   use P5EEx::Blue::P5EE;
   use P5EEx::Blue::Widget::HTML;
  @@ -105,6 +105,7 @@
   
       if ($wname eq "$name.view") {
           $self->set("mode","view");
  +        $self->delete("editdata");
           return 1;
       }
       elsif ($wname eq "$name.edit") {
  @@ -224,6 +225,7 @@
           if ($P5EEx::Blue::DEBUG && $self->{context}->dbg(1));
       my ($wc, $repname, $rep, $rows, $table, $columns, $sql, $error, $data);
       my ($params, $paramvalues, $ordercols, $startrow, $maxrows, $endrow, 
$directions, $keycolidx);
  +    my (%paramvalues, $filter, $column);
   
       $repname = $self->get("repository");
       $wc = $self->{context};
  @@ -234,7 +236,7 @@
       $data = $self->get("data");
   
       if ($sql) {
  -        $paramvalues = $self->get("paramvalues");
  +        $paramvalues = $self->substitute($self->get("paramvalues"));
           $sql         = $self->substitute($sql, $paramvalues);
           $startrow    = $self->get("startrow", 1, 1);
           $maxrows     = $self->get("maxrows", 25, 1);
  @@ -267,7 +269,19 @@
           }
   
           $params      = $self->get("params");
  -        $paramvalues = $self->get("paramvalues");
  +        $paramvalues = $self->get("paramvalues",{});
  +        %paramvalues = %$paramvalues;
  +        $self->substitute(\%paramvalues);
  +        $filter      = $self->get("filter",{});
  +        foreach $column (%$filter) {
  +            if (defined $filter->{$column} && $filter->{$column} ne "") {
  +                if (!defined $paramvalues{"$column.contains"} && defined $params) {
  +                    push(@$params,"$column.contains");
  +                }
  +                $paramvalues{"$column.contains"} = $filter->{$column};
  +            }
  +        }
  +
           $ordercols   = $self->get("ordercols");
           $directions  = $self->get("directions");
           $startrow    = $self->get("startrow", 1, 1);
  @@ -285,7 +299,8 @@
               $self->{context}->dbgprint("DataTable->load(): directions=[", join(",", 
@$directions), "]") if (ref($directions) eq "ARRAY");
           }
   
  -        $rows  = $rep->select_rows($table, $columns, $params, $paramvalues, 
$ordercols, $startrow, $endrow, $directions);
  +        #$rows  = $rep->select_rows($table, $columns, $params, \%paramvalues, 
$ordercols, $startrow, $endrow, $directions);
  +        $rows  = $rep->select_rows($table, $columns, undef, \%paramvalues, 
$ordercols, $startrow, $endrow, $directions);
           $error = $rep->error();
           if ($#$rows == -1 && $error) {
               $sql = $rep->{sql};
  @@ -308,12 +323,24 @@
   }
   
   sub substitute {
  -    my ($self, $sql, $values) = @_;
  -    $self->{context}->dbgprint("DataTable->substitute()")
  -        if ($P5EEx::Blue::DEBUG && $self->{context}->dbg(1));
  -    my ($phrase, $var, $value);
  -    return ($sql) if (!$values || ref($values) ne "HASH");
  -    while ( $sql =~ /\[([^\[\]]+)\]/ ) {
  +    my ($self, $text, $values) = @_;
  +    Widget->dbgprint("DataTable->substitute()")
  +        if ($Widget::DEBUG && Widget->dbg(ref($self),"substitute"));
  +    my ($phrase, $var, $value, $controller);
  +    $controller = $self->{controller};
  +    $values = {} if (! defined $values);
  +
  +    if (ref($text) eq "HASH") {
  +        my ($hash, $newhash);
  +        $hash = $text;    # oops, not text, but a hash of text values
  +        $newhash = {};    # prepare a new hash for the substituted values
  +        foreach $var (keys %$hash) {
  +            $newhash->{$var} = $self->substitute($hash->{$var}, $values);
  +        }
  +        return($newhash); # short-circuit this whole process
  +    }
  +
  +    while ( $text =~ /\[([^\[\]]+)\]/ ) {
           $phrase = $1;
           while ( $phrase =~ /\{([^\{\}]+)\}/ ) {
               $var = $1;
  @@ -322,18 +349,43 @@
                   $phrase =~ s/\{$var\}/$value/g;
               }
               else {
  +                if ($var =~ /^(.+)\.([^.]+)$/) {
  +                    $value = $controller->wget($1, $2);
  +                    if (defined $value) {
  +                        $phrase =~ s/\{$var\}/$value/g;
  +                    }
  +                    else {
                   $phrase = "";
               }
           }
  -        $sql =~ s/\[[^\[\]]+\]/$phrase/;
  +                else {
  +                    $phrase = "";
  +                }
       }
  -    while ( $sql =~ /\{([^\{\}]+)\}/ ) {
  +        }
  +        if ($phrase eq "") {
  +            $text =~ s/\[[^\[\]]+\]\n?//;  # zap it including (optional) ending 
newline
  +        }
  +        else {
  +            $text =~ s/\[[^\[\]]+\]/$phrase/;
  +        }
  +    }
  +    while ( $text =~ /\{([^\{\}]+)\}/ ) {  # vars of the form {var}
           $var = $1;
  +        if (defined $values->{$var}) {
           $value = $values->{$var};
  +            $text =~ s/\{$var\}/$value/g;
  +        }
  +        else {
  +            $value = "";
  +            if ($var =~ /^(.+)\.([^.]+)$/) {
  +                $value = $controller->wget($1, $2);
  +            }
  +        }
           $value = "" if (!defined $value);
  -        $phrase =~ s/\{$var\}/$value/g;
  +        $text =~ s/\{$var\}/$value/g;
       }
  -    $sql;
  +    $text;
   }
   
   ######################################################################
  @@ -363,9 +415,10 @@
       my ($columns, $headings, $scrollable, $sortable, $filterable, $editable);
       my ($startrow, $numrow, $numbered);
       my ($keys, $mode, $sql);
  -    my ($columnSelectable, $rowSelectable);
  +    my ($columnSelectable, $rowSelectable, $elemSelected);
  +    my (@edit_style, @column_length);
   
  -    $columns          = $self->get("columns");
  +    $columns          = $self->get("columns",[]);
       $headings         = $self->get_headings();
       $data             = $self->get_data();
       $startrow         = $self->get("startrow",         1);
  @@ -442,6 +495,7 @@
               $html .= $wc->widget("$name.view",
                            widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
                            imageScript => 'button',
  +                         #lightweight => 1,
                            label => 'View',
                            height => 17,
                            width => 50,
  @@ -452,6 +506,7 @@
                   $html .= $wc->widget("$name.edit",
                            widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
                            imageScript => 'button',
  +                         #lightweight => 1,
                            label => 'Edit',
                            height => 17,
                            width => 50,
  @@ -465,6 +520,7 @@
               $html .= $wc->widget("$name.prev",
                            widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
                            imageScript => 'button',
  +                         #lightweight => 1,
                            label => '<< Prev',
                            height => 17,
                            width => 70,
  @@ -486,6 +542,7 @@
               $html .= $wc->widget("$name.next",
                            widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
                            imageScript => 'button',
  +                         #lightweight => 1,
                            label => 'Next >>',
                            height => 17,
                            width => 70,
  @@ -495,6 +552,43 @@
               $html .= "</td></tr></table>\n";
           }
       
  +        if ($mode eq "edit") {
  +            $html .= "<table border=\"0\" cellspacing=\"0\" 
cellpadding=\"3\"><tr>\n";
  +            $html .= "<td>\n";
  +            $html .= $wc->widget("$name.save",
  +                         widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
  +                         imageScript => 'button',
  +                         #lightweight => 1,
  +                         label => 'Save',
  +                         height => 17,
  +                         width => 50,
  +                         bevel => 2,
  +                     )->display();
  +            $html .= "</td>\n";
  +            $html .= "<td>\n";
  +            $html .= $wc->widget("$name.add",
  +                         widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
  +                         imageScript => 'button',
  +                         #lightweight => 1,
  +                         label => 'Add Rows',
  +                         height => 17,
  +                         width => 70,
  +                         bevel => 2,
  +                     )->display();
  +            $html .= "</td>\n";
  +            $html .= "<td>\n";
  +            $html .= $wc->widget("$name.delete",
  +                         widgetClass => "P5EEx::Blue::Widget::HTML::ImageButton",
  +                         imageScript => 'button',
  +                         #lightweight => 1,
  +                         label => 'Delete Rows',
  +                         height => 17,
  +                         width => 70,
  +                         bevel => 2,
  +                     )->display();
  +            $html .= "</td></tr></table>\n";
  +        }
  +    
           $html .= $table_begin;
           if (!$sql) {
               if ($sortable) {
  @@ -506,6 +600,7 @@
                       $elem = $wc->widget("$name.sort$col",
                                   widgetClass => 
"P5EEx::Blue::Widget::HTML::ImageButton",
                                   imageScript => 'button',
  +                                #lightweight => 1,
                                   label => 'Up|Dn',
                                   height => 17,
                                   width => 50,
  @@ -521,7 +616,8 @@
                   $html .= "  <td>&nbsp;</td>\n" if ($mode eq "edit" && 
$rowSelectable);
                   $html .= "  <td>&nbsp;</td>\n" if ($numbered);
                   for ($col = 0; $col < $numcols; $col++) {
  -                    $elem = $wc->widget("$name\{filter}[$col]",
  +                    $column = $columns->[$col];
  +                    $elem = $wc->widget("$name\{filter}{$column}",
                                   widgetClass => 
"P5EEx::Blue::Widget::HTML::TextField",
                                   size => 5,
                                   maxwidth => 99,
  @@ -583,14 +679,56 @@
       $td_row_attrib .= " valign=\"$valign\"" if ($valign);
       $td_row_attrib .= " nowrap" if ($nowrap);
   
  +    # since we are editing, we need to prepare these two arrays...
  +    @edit_style = ();
  +    @column_length = ();
  +
  +    if ($mode eq "edit") {
  +
  +        # prepare the style attribute arrays
  +        push(@edit_style, "fontFamily", $fontFace)  if ($fontFace);
  +        push(@edit_style, "color",      $fontColor) if ($fontColor);
  +
  +        # This seems to cause <input> elements to take on the font size
  +        # currently active for text that surrounds them
  +        # i.e. <font size="-2"><input type="text" style="font-size: 100%;"></font>
  +        push(@edit_style, "fontSize",   "100%")     if ($fontSize);
  +
  +        # borderStyle",
  +        # borderWidth",
  +        # borderColor",
  +        # padding",
  +        # backgroundColor",
  +
  +        # any columns we are editing, we need to compute max width (size) for 
textfield
  +        for ($col = 0; $col < $numcols; $col++) {
  +            $column_length[$col] = 5;  # minimum length
  +            $column = "";
  +            if (defined $columns && defined $columns->[$col]) {
  +                $column = $columns->[$col];
  +            }
  +    
  +            if ($column ne "" && $self->{columnSelected}{$column}) {
  +                for ($row = 0; $row <= $#$data; $row++) {
  +                    $elem = $data->[$row][$col];
  +                    if (defined $elem && length($elem) > $column_length[$col]) {
  +                        $column_length[$col] = length($elem);
  +                    }
  +                }
  +            }
  +        }
  +    }
  +
       for ($row = 0; $row <= $#$data; $row++) {
           $numrow = $startrow + $row;
   
           $html .= "<tr>\n";
   
  -        if ($mode eq "edit" && $rowSelectable) {
  +        $key = "";
  +        if ($mode eq "edit") {
               if (defined $keys && defined $keys->[$row]) {
                   $key = join(",", @{$keys->[$row]});   # need to HTML-escape these!
  +                if ($rowSelectable) {
                   $html .= "  <td bgcolor=\"#ffaaaa\" valign=\"middle\" 
align=\"center\">\n";
                   $html .= $wc->widget("$name\{rowSelected}{$key}",
                                widgetClass => "P5EEx::Blue::Widget::HTML::Checkbox",
  @@ -601,12 +739,56 @@
                   $html .= "  <td>&nbsp;</td>\n";
               }
           }
  +        }
  +
           $html .= "  <td bgcolor=\"$headingBgcolor\" 
align=\"right\">$elem_begin$numrow$elem_end</td>\n" if ($numbered);
   
           for ($col = 0; $col < $numcols; $col++) {
               $elem = $data->[$row][$col];
  +
  +            $column = "";
  +            if ($mode eq "edit") {
  +                if (defined $columns && defined $columns->[$col]) {
  +                    $column = $columns->[$col];
  +                }
  +            }
  +
  +            $elemSelected = 0;
  +            if ($self->{columnSelected}{$column} && $self->{rowSelected}{$key}) {
  +                $elemSelected = 1;
  +            }
  +
  +            if ($elemSelected) {
  +                if (!defined $elem || $elem eq "") {
  +                    $elem = "";
  +                    $td_col_attrib = " align=\"left\"";
  +                }
  +                elsif ($elem =~ /^[-0-9.%]+$/) {
  +                    $td_col_attrib = " align=\"right\"";
  +                }
  +                else {
  +                    $td_col_attrib = " align=\"left\"";
  +                }
  +                if (! defined $self->{editdata}{$key}{$column}) {
  +                    $self->{editdata}{$key}{$column} = $elem
  +                }
  +                $html .= "  <td $td_row_attrib$td_col_attrib>${elem_begin}";
  +                $html .= $wc->widget("$name\{editdata}{$key}{$column}",
  +                             widgetClass => "P5EEx::Blue::Widget::HTML::TextField",
  +                             size => $column_length[$col]+1,   # add 1 just to give 
some visual space
  +                             maxlength => 99,
  +                             backgroundColor => "#ffaaaa",
  +                             borderStyle => "solid",
  +                             borderWidth => "1px",
  +                             padding => 0,
  +                             @edit_style,
  +                         )->display();
  +                $html .= "$elem_end</td>\n";
  +            }
  +            else {
  +                $elem = $self->html_escape($elem);
               if (!defined $elem || $elem eq "") {
  -                $elem = "&nbsp;"
  +                    $elem = "&nbsp;";
               }
               elsif ($elem =~ /^[-0-9.%]+$/) {
                   $td_col_attrib = " align=\"right\"";
  @@ -615,6 +797,7 @@
                   $td_col_attrib = " align=\"left\"";
               }
               $html .= "  
<td$td_row_attrib$td_col_attrib>$elem_begin$elem$elem_end</td>\n";
  +            }
           }
           $html .= "</tr>\n";
       }
  
  
  


Reply via email to