# Copyright (c) 2007-2009 bivio Software, Inc. All Rights Reserved.
#
# Visit http://www.bivio.biz for more info.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; If not, you may get a copy from:
# http://www.opensource.org/licenses/lgpl-license.html
#
# $Id: Table.bunit,v 1.13 2009/12/17 13:56:40 nagler Exp $
Widget({
setup_render => sub {
req()->put(task_id => Bivio::Agent::TaskId->PRODUCTS);
model('ProductList', {parent_id => 'REPTILES'})
unless req()->unsafe_get('Model.ProductList');
return;
},
new_params => sub {
my($case, $params) = @_;
if (@$params == 1) {
$case->put(_expect_args => $params->[0]);
return [ProductList => ['Product.product_id', 'Product.name'],
@$params];
}
else {
return [ProductList => @$params];
}
},
check_return => sub {
my($case, $actual, $expect) = @_;
my($expect_args) = $case->unsafe_get('_expect_args');
return defined($expect->[0])
? $expect
: [_t($expect_args)];
},
});
[
map(([$_] => undef),
{},
{cellpadding => 2},
{cellspacing => 3},
{width => '100%'},
{border => 1},
),
map({
my($left, $right) = @$_;
([$left] => _t($right));
}
[{align => 'n'}, {class => 'b_align_n'}],
[{expand => 1}, {width => '95%', class => 'b_align_left'}],
[{title => 'Reptiles'}, {title => qq{\n
Reptiles | \n
}, class => 'b_align_left'}],
),
[{class => 'reptiles'}] => _chomp(<<'EOF'),
EOF
[{class => 'reptiles', before_row =>
class('HTMLWidget.String')->new('FOO', 0)}] => _chomp(<<'EOF'),
EOF
[[
{
column_widget => class('HTMLWidget.Join')->new([' ']),
column_data_class => 'ping',
},
{field => 'Product.name', column_data_class => 'zing'}
], {class => 'reptiles', show_headings => 0}] => _chomp(<<'EOF'),
EOF
];
sub _chomp {
my($x) = @_;
chomp($x);
return $x;
}
sub _t {
my($exp) = @_;
my($x) = _chomp(<<'EOF');
EOF
$exp ||= {};
while (my($k, $v) = each(%$exp)) {
$x =~ s/(?<=\b$k=)("?)[^"\s>]+("?)/$1$v$2/;
}
$x =~ s/ \w+="?NOP"?//g;
$x =~ s/ title=//g;
return $x;
}