App-Widget

 view release on metacpan or  search on metacpan

lib/App/Widget/DataTable.pm  view on Meta::CPAN

        $elem = " " if (!defined $elem || $elem eq "");
        $html .= "  <td$td_row_attrib$td_col_attrib>$elem_begin$elem$elem_end</td>\n";
    }
    $html .= "</tr>\n";

    $td_row_attrib = "";
    $td_row_attrib .= " bgcolor=\"$bgcolor\"" if ($bgcolor);
    #$td_row_attrib .= " align=\"$align\"" if ($align);
    $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, "font_family", $font_face)  if ($font_face);
        push(@edit_style, "color",      $font_color) if ($font_color);

        # 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, "font_size",   "100%")     if ($font_size);

        # border_style",
        # border_width",
        # border_color",
        # padding",
        # background_color",

        # 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->{column_selected}{$column}) ||
                ($self->{row_selected} && %{$self->{row_selected}})) {
                for ($row = 0; $row <= $#$data; $row++) {
                    $elem = $data->[$row][$col];
                    if (defined $elem && length($elem) > $column_length[$col]) {
                        $column_length[$col] = length($elem);
                    }
                }
            }
        }
    }

    my ($format, $scale_factor);
    for ($row = 0; $row <= $#$data; $row++) {
        $numrow = $startrow + $row;

        $html .= "<tr>\n";

        $key = "";
        if (defined $keys && defined $keys->[$row]) {
            $key = join(",", @{$keys->[$row]});   # need to HTML-escape these!
        }

        $html .= "  <td bgcolor=\"$heading_bgcolor\" align=\"right\">$elem_begin$numrow$elem_end</td>\n" if ($numbered);

        if ($row_selectable) {
            $html .= "  <td bgcolor=\"#ffaaaa\" valign=\"middle\" align=\"center\">\n";
            $html .= $context->widget("$name\{row_selected}{$key}",
                         class => "App::Widget::Checkbox",
                     )->html();
            $html .= "  </td>\n";
        }

        if ($row_single_selectable) {
            $html .= "  <td bgcolor=\"#ffaaaa\" valign=\"middle\" align=\"center\">\n";
            $html .= $context->widget("$name\{row_single_selected}",
                         class => "App::Widget::RadioButton",
                         override => 1,
                         value => $key,
                     )->html();
            $html .= "  </td>\n";
        }

        if ($#row_actions > -1) {
            my (%args);
            $html .= "  <td bgcolor=\"$heading_bgcolor\">";
            foreach $rowaction (@row_actions) {
                %args = (
                    override => 1,
                    class => "App::Widget::ImageButton",
                    image_script => 'app-button',
                    volatile => 1,
                    height => 17,
                    width => 50,
                    bevel => 2,
                );
                $rowactiondef = $rowactiondefs->{$rowaction};
                if ($rowactiondef) {
                    foreach (keys %$rowactiondef) {
                        $args{$_} = $rowactiondef->{$_};
                    }
                }
                $html .= $context->widget("$name.${rowaction}", %args, args => $key)->html();
            }
            $html .= "</td>\n";
        }

        for ($col = 0; $col < $numcols; $col++) {
            $elem = $data->[$row][$col];

            $column = "";
            $format = "";
            $scale_factor = "";
            $align = "";
            if (defined $columns && defined $columns->[$col]) {
                $column = $columns->[$col];
                $format       = $view_column_defs->{$column}{format}       || $table_column_defs->{$column}{format};
                $scale_factor = $view_column_defs->{$column}{scale_factor} || $table_column_defs->{$column}{scale_factor};
                $align        = $view_column_defs->{$column}{align}        || $table_column_defs->{$column}{align};
            }

            $elem_selected = 0;
            if ($mode eq "edit") {
                if (($self->{column_selected}{$column} && $self->{row_selected}{$key}) ||
                    ($self->{column_selected}{$column} && (!defined $self->{row_selected} || !%{$self->{row_selected}})) ||
                    ((!defined $self->{column_selected} || !%{$self->{column_selected}})  && $self->{row_selected}{$key})) {
                    $elem_selected = 1;
                }
            }

            if ($elem_selected) {
                if (!defined $elem || $elem eq "") {
                    $elem = "";
                    $td_col_attrib = " align=\"left\"";
                }
                else {
                    $elem = $elem * $scale_factor if ($scale_factor);
                    if ($align) {
                        $td_col_attrib = " align=\"$align\"";
                    }
                    elsif ($elem =~ /^[-0-9.,%]+$/) {
                        $td_col_attrib = " align=\"right\"";
                    }
                    else {
                        $td_col_attrib = " align=\"left\"";
                    }
                    $elem = sprintf($format, $elem) if ($format);
                }
                if (! defined $self->{editdata}{$key}{$column}) {
                    $self->{editdata}{$key}{$column} = $elem
                }
                $html .= "  <td $td_row_attrib$td_col_attrib>${elem_begin}";
                $html .= $context->widget("$name\{editdata}{$key}{$column}",
                             class => "App::Widget::TextField",
                             size => $column_length[$col]+2,   # add 2 just to give some visual space
                             maxlength => 99,
                             background_color => "#ffaaaa",
                             border_style => "solid",
                             border_width => "1px",
                             padding => 0,
                             @edit_style,
                         )->html();
                $html .= "$elem_end</td>\n";
            }
            else {
                $elem = $self->html_escape($elem);
                if (!defined $elem || $elem eq "") {
                    $elem = "&nbsp;";
                }
                else {
                    $elem = $elem * $scale_factor if ($scale_factor);
                    $elem = sprintf($format, $elem) if ($format);
                    if ($align) {
                        $td_col_attrib = " align=\"$align\"";
                    }
                    elsif ($elem =~ /^[-0-9.,%]+$/) {
                        $td_col_attrib = " align=\"right\"";
                    }
                    else {
                        $td_col_attrib = " align=\"left\"";
                    }
                }
                $html .= "  <td$td_row_attrib$td_col_attrib>$elem_begin$elem$elem_end</td>\n";
            }
        }
        $html .= "</tr>\n";
    }

    $html .= "</table>\n";
    if (1) {
        $html .= "<!-- SQL used in table query\n";
        $html .= $rep->{sql};
        $html .= "-->\n";
    }
    &App::sub_exit("<html ...>") if ($App::trace);
    $html;
}

1;



( run in 1.054 second using v1.01-cache-2.11-cpan-437f7b0c052 )