App-Widget
view release on metacpan or search on metacpan
lib/App/Widget/DataTable2.pm view on Meta::CPAN
package App::Widget::DataTable2;
$VERSION = (q$Revision: 13207 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn
use App;
use App::Widget;
@ISA = ( "App::Widget" );
use strict;
=head1 NAME
App::Widget::DataTable2 - An HTML table which serves as a repository table viewer/editor
=head1 SYNOPSIS
use App::Widget::DataTable2;
$name = "get_data";
$w = App::Widget::DataTable2->new($name);
print $w->html();
=cut
######################################################################
# CONSTANTS
######################################################################
######################################################################
# ATTRIBUTES
######################################################################
# {border} = 0;
# {cellspacing} = 2;
# {cellpadding} = 0;
# {width} = "";
# {bgcolor} = "";
# {nowrap} = "1";
# {font_face} = "verdana,geneva,arial,sans-serif";
# {font_size} = "-2";
# {font_color} = "";
# {heading_bgcolor} = "#cccccc";
# {heading_nowrap} = 0;
# {heading_align} = 0;
# {heading_valign} = 0;
# {column_selectable} = 1;
# {row_selectable} = 0;
# {row_single_selectable} = 0;
# {columns} = [ "Name", "Address", "City", "State", "Country", "Home Phone" ];
# {headings} = [ "Name", "Address", "City", "State", "Country", "Home Phone" ];
# {data} = [ [ "Smith, Harold", "1215 Interloke Pass", "Jonesboro", "GA", "US", "770-603-1810" ],
# [ "Smith, Mike", "1215 Interloke Pass", "Jonesboro", "GA", "US", "770-603-1811" ],
# [ "Smith, Sarah", "1215 Interloke Pass", "Jonesboro", "GA", "US", "770-603-1812" ],
# [ "Smith, Ken", "1215 Interloke Pass", "Jonesboro", "GA", "US", "770-603-1813" ],
# [ "Smith, Mary", "1215 Interloke Pass", "Jonesboro", "GA", "US", "770-603-1814" ], ];
# {startrow} = 1
# {maxrows} = 20
# {scrollable} = 0;
# {sortable} = 0;
# {filterable} = 0;
# {editable} = 0;
# INPUTS FROM THE ENVIRONMENT
=head1 DESCRIPTION
This class is a <input type=submit> HTML element.
In the advanced configurations, it is rendered as an image button.
=cut
######################################################################
# INITIALIZATION
######################################################################
sub _init {
&App::sub_entry if ($App::trace);
my $self = shift;
$self->SUPER::_init(@_);
$self->{table} = $self->{name} if (!$self->{table});
if (!$self->{keycolidx}) {
my $context = $self->{context};
my $table = $self->{table};
my $rep = $self->{repository};
my $r = $context->repository($rep);
$r->_load_table_metadata($table);
my $primary_key = $r->{table}{$table}{primary_key};
if ($primary_key && ref($primary_key) eq "ARRAY" && $#$primary_key > -1) {
my (@keycolidx, %colidx);
my $columns = $self->get_columns();
for (my $col = 0; $col <= $#$columns; $col++) {
$colidx{$columns->[$col]} = $col;
}
for (my $col = 0; $col <= $#$primary_key; $col++) {
if (defined $colidx{$primary_key->[$col]}) {
push(@keycolidx, $colidx{$primary_key->[$col]});
}
}
$self->{keycolidx} = \@keycolidx if ($#keycolidx == $#$primary_key);
}
}
}
######################################################################
# EVENTS
######################################################################
# Usage: $widget->handle_event($event, @args);
sub handle_event {
&App::sub_entry if ($App::trace);
my ($self, $wname, $event, @args) = @_;
my ($name, $context, $column, $x, $y, $startrow, $maxrows, $width, $dir);
#$self->clear_messages();
$name = $self->{name};
$self->{context}->dbgprint("DataTable2($name)->handle_event($wname,$event,@args)")
if ($App::DEBUG && $self->{context}->dbg(1));
my $handled = 0;
if ($wname eq "$name-view") {
$self->set("mode","view");
lib/App/Widget/DataTable2.pm view on Meta::CPAN
$context = $self->{context};
$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);
}
&App::sub_exit($newhash) if ($App::trace);
return($newhash); # short-circuit this whole process
}
while ( $text =~ /^\[([^\[\]]+)\]$/ ) {
$phrase = $1;
while ( $phrase =~ /\{([^\{\}]+)\}/ ) {
$var = $1;
if (defined $values->{$var}) {
$value = $values->{$var};
$value = join(",", @$value) if (ref($value) eq "ARRAY");
$phrase =~ s/\{$var\}/$value/g;
}
else {
$value = $context->so_get($var);
$value = join(",", @$value) if (ref($value) eq "ARRAY");
if (defined $value) {
$phrase =~ s/\{$var\}/$value/g;
}
else {
$phrase = "";
}
}
}
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};
$value = join(",", @$value) if (ref($value) eq "ARRAY");
$text =~ s/\{$var\}/$value/g;
}
else {
$value = $context->so_get($var);
$value = join(",", @$value) if (ref($value) eq "ARRAY");
}
$value = "" if (!defined $value);
$text =~ s/\{$var\}/$value/g;
}
&App::sub_exit($text) if ($App::trace);
$text;
}
######################################################################
# OUTPUT METHODS
######################################################################
sub table_html {
&App::Widget::DataTable2::html(@_);
}
sub html {
&App::sub_entry if ($App::trace);
my $self = shift;
$self->{context}->dbgprint("DataTable2->html()")
if ($App::DEBUG && $self->{context}->dbg(1));
my ($context, $name, $data);
$context = $self->{context};
$name = $self->{name};
my ($key, $column);
my ($numcols, $table, $title);
my ($width, $border, $cellspacing, $cellpadding);
my ($bgcolor, $align, $valign, $nowrap);
my ($font_face, $font_size, $font_color);
my ($heading_bgcolor, $heading_align, $heading_valign, $heading_nowrap);
my ($columns, $headings, $scrollable, $sortable, $filterable, $editable);
my ($startrow, $numrow, $numbered);
my ($keys, $mode, $sql);
my ($column_selectable, $row_selectable, $row_single_selectable, $elem_selected, $single_row_select);
my (@edit_style, @column_length);
my ($rowactions, $rowactiondefs, $rowaction, $rowactiondef);
my (@select_actions, @single_select_actions, @row_actions);
$table = $self->{table};
$columns = $self->get_columns();
return "No columns defined for table [$table]. (maybe it doesn't exist)" if (!$columns || $#$columns == -1);
$headings = $self->get_headings();
$data = $self->get_data();
my $compatibility = $self->{compatibility} || ""; # values: [HTML32]
$startrow = $self->{startrow} || 1;
$title = $self->{title};
$width = $self->{width};
$bgcolor = $self->{bgcolor};
$font_color = $self->{font_color};
$border = $self->{border} || 0;
$cellspacing = $self->{cellspacing} || 2;
$cellpadding = $self->{cellpadding} || 2;
$align = $self->{align} || "";
$valign = $self->{valign} || "top";
$nowrap = (defined $self->{nowrap}) ? $self->{nowrap} : 1;
$font_face = $self->{font_face} || "verdana,geneva,arial,sans-serif";
$font_size = $self->{font_size} || -2;
$heading_bgcolor = $self->{heading_bgcolor} || "#cccccc";
$heading_align = $self->{heading_align} || $align;
$heading_valign = $self->{heading_valign} || "bottom";
$heading_nowrap = $self->{heading_nowrap} || $nowrap;
$mode = $self->{mode} || "view";
$scrollable = $self->{scrollable} || 0;
$sortable = $self->{sortable} || 0;
$filterable = $self->{filterable} || 0;
$editable = $self->{editable} || 0;
my $deletable = $self->{deletable};
( run in 0.615 second using v1.01-cache-2.11-cpan-39bf76dae61 )