App-Widget
view release on metacpan or search on metacpan
lib/App/Widget/DataTable.pm view on Meta::CPAN
package App::Widget::DataTable;
$VERSION = (q$Revision: 12437 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn
use App;
use App::Widget;
@ISA = ( "App::Widget" );
use strict;
=head1 NAME
App::Widget::DataTable - An HTML table which serves as a repository table viewer/editor
=head1 SYNOPSIS
use App::Widget::DataTable;
$name = "get_data";
$w = App::Widget::DataTable->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});
$self->{context}->dbgprint("DataTable->init()")
if ($App::DEBUG && $self->{context}->dbg(1));
}
######################################################################
# EVENTS
######################################################################
# Usage: $widget->handle_event($event, @args);
sub handle_event {
&App::sub_entry if ($App::trace);
my ($self, $wname, $event, @args) = @_;
my ($name, $context, $colnum, $x, $y, $startrow, $maxrows, $width, $direction);
#$self->clear_messages();
$name = $self->{name};
$self->{context}->dbgprint("DataTable($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");
$self->delete("editdata");
$handled = 1;
}
elsif ($wname eq "$name-edit") {
$self->set("mode","edit");
$handled = 1;
}
elsif ($wname eq "$name-next") {
$startrow = $self->get("startrow",1,1);
$maxrows = $self->get("maxrows",20,1);
$startrow += $maxrows;
$self->set("startrow",$startrow);
$handled = 1;
}
elsif ($wname eq "$name-prev") {
$startrow = $self->get("startrow",1,1);
$maxrows = $self->get("maxrows",20,1);
$startrow -= $maxrows;
$startrow = 1 if ($startrow < 1);
lib/App/Widget/DataTable.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::DataTable::html(@_);
}
sub html {
&App::sub_entry if ($App::trace);
my $self = shift;
$self->{context}->dbgprint("DataTable->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->get("table");
return "No table defined." if (!$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();
$startrow = $self->get("startrow", 1);
$title = $self->get("title");
$width = $self->get("width");
$bgcolor = $self->get("bgcolor");
$font_color = $self->get("font_color");
$border = $self->get("border", 0);
$cellspacing = $self->get("cellspacing", 2);
$cellpadding = $self->get("cellpadding", 2);
$align = $self->get("align", "");
$valign = $self->get("valign", "top");
$nowrap = $self->get("nowrap", 1);
$font_face = $self->get("font_face", "verdana,geneva,arial,sans-serif");
$font_size = $self->get("font_size", -2);
$heading_bgcolor = $self->get("heading_bgcolor", "#cccccc");
$heading_align = $self->get("heading_align", $align);
$heading_valign = $self->get("heading_valign", "bottom");
$heading_nowrap = $self->get("heading_nowrap", $nowrap);
$mode = $self->get("mode", "view");
$scrollable = $self->get("scrollable", 0);
$sortable = $self->get("sortable", 0);
$filterable = $self->get("filterable", 0);
$editable = $self->get("editable", 0);
$numbered = $self->get("numbered", 1);
( run in 0.317 second using v1.01-cache-2.11-cpan-39bf76dae61 )