# Copyright (c) 1999-2007 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: AmountCell.pm,v 2.12 2010/10/17 22:17:47 nagler Exp $ package Bivio::UI::HTML::Widget::AmountCell; use strict; use Bivio::Base 'HTMLWidget.String'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.12 $ =~ /\d+/g); my($_C) = b_use('IO.Config'); $_C->register(my $_CFG = { $_C->if_version( 1 => sub { return ( column_align => 0, column_nowrap => 0, pad_left => 0, string_font => 0, want_parens => 0, ); }, sub { return ( column_align => 'E', column_nowrap => 1, pad_left => 1, string_font => 'number_cell', want_parens => 1, ); }, ), zero_as_blank => 0, decimals => 2, map(($_ => 'amount_cell'), qw(column_data_class cell_class column_footer_class)), }); my($_CFG_KEYS) = [sort(keys(%$_CFG))]; sub NEW_ARGS { return ['field']; } sub handle_config { my(undef, $cfg) = @_; $_CFG = $cfg; return; } sub initialize { my($self) = @_; $self->put( value => [sub { my($source, $amount) = @_; return $self->render_simple_attr('undef_value', $source) unless defined($amount); return $self->render_simple_attr('html_format', $source) ->get_widget_value( $amount, map($self->render_simple_attr($_, $source), qw( decimals want_parens zero_as_blank ), ), ); }, [$self->get('field')]], ); $self->map_invoke(initialize_attr => [ map([$_ => $_CFG->{$_}], @$_CFG_KEYS), [html_format => b_use('HTMLFormat.Amount')], ]); return $self->SUPER::initialize(@_); } 1;