# Copyright (c) 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: With.pm,v 1.5 2009/03/05 12:58:18 nagler Exp $ package Bivio::UI::Widget::With; use strict; use Bivio::Base 'Widget.ControlBase'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.5 $ =~ /\d+/g); sub internal_as_string { return shift->unsafe_get('source'); } sub internal_new_args { my(undef, $source, $value, $attributes) = @_; return { source => $source, value => $value, ($attributes ? %$attributes : ()), }; } sub initialize { my($self) = @_; $self->initialize_attr('source'); $self->initialize_attr('value'); return shift->SUPER::initialize(@_); } sub control_on_render { my($self, $source, $buffer) = @_; my($object) = $self->unsafe_resolve_attr('source', $source); unless (defined($object)) { $self->control_off_render($source, $buffer); return; } $object = b_use('Model.StringArrayList')->new($source->req) ->load_from_string_array($object) if $object->isa('Bivio::Type::StringArray'); unless ($object->can('do_rows')) { $self->render_attr('value', $object, $buffer); return; } if ($object->can('get_result_set_size') && $object->get_result_set_size <= 0 ) { $self->control_off_render($source, $buffer); return; } my($cursor) = $object->has_cursor ? $object->get_cursor : undef; my($i) = 0; my($v) = $self->get('value'); $object->do_rows(sub { $self->render_value('value' . $i++, $v, $object, $buffer); return 1; }); $object->set_cursor($cursor) if defined($cursor); return; } 1;