# Copyright (c) 2001 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: TableSummaryCell.pm,v 2.1 2006/10/16 21:08:05 moeller Exp $ package Bivio::UI::HTML::Widget::TableSummaryCell; use strict; $Bivio::UI::HTML::Widget::TableSummaryCell::VERSION = sprintf('%d.%02d', q$Revision: 2.1 $ =~ /\d+/g); $_ = $Bivio::UI::HTML::Widget::TableSummaryCell::VERSION; =head1 NAME Bivio::UI::HTML::Widget::TableSummaryCell - row summary cell for a table =head1 RELEASE SCOPE bOP =head1 SYNOPSIS use Bivio::UI::HTML::Widget::TableSummaryCell; =cut =head1 EXTENDS L =cut use Bivio::UI::HTML::Widget::AmountCell; @Bivio::UI::HTML::Widget::TableSummaryCell::ISA = ('Bivio::UI::HTML::Widget::AmountCell'); =head1 DESCRIPTION C =head1 ATTRIBUTES =over 4 =item list_class : string (required, inherited) The list model class. =item field : string (required) The summary field. =back =cut #=IMPORTS use Bivio::UI::HTML::Format::Amount; use Bivio::UI::HTML::Widget::AmountCell; #=VARIABLES =head1 METHODS =cut =for html =head2 initialize() Startup initialization. =cut sub initialize { my($self) = @_; my($field_name) = $self->get('field'); $self->put(field_name => $field_name); my($list) = Bivio::Biz::Model->get_instance( $self->ancestral_get('list_class')); unless ($list->has_fields($field_name)) { $list = Bivio::Biz::Model->get_instance($list->get_list_class); } my($type) = $list->get_field_type($field_name); $self->put(decimals => $type->get_decimals) unless $self->has_keys('decimals'); $self->put(field => [['->get_request'], ref($self).$field_name]); $self->SUPER::initialize; return; } =for html =head2 render(any source, string_ref buffer) Computes and displays the row summary value. =cut sub render { my($self, $source, $buffer) = @_; my($total) = 0; my($list) = $source->get_list_model; my($type) = $list->get_field_type($self->get('field_name')); $list->reset_cursor; while ($list->next_row) { $total = $type->add($total, $list->get($self->get('field_name'))); } $source->get_request->put(ref($self).$self->get('field_name') => $total); $self->SUPER::render($source, $buffer); return; } #=PRIVATE METHODS =head1 COPYRIGHT Copyright (c) 2001 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 =head1 VERSION $Id: TableSummaryCell.pm,v 2.1 2006/10/16 21:08:05 moeller Exp $ =cut 1;