# Copyright (c) 1999-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: TextArea.pm,v 2.11 2009/11/28 03:09:28 nagler Exp $ package Bivio::UI::HTML::Widget::TextArea; use strict; use Bivio::Base 'HTMLWidget.ControlBase'; # C draws a C tag with # attribute C. # # # # field : string (required) # # Name of the form field. # # form_model : array_ref (required, inherited, get_request) # # Which form are we dealing with. # # rows : int (required) # # The number of rows to show. # # cols : int (required) # # The number of character columns to show. # # readonly : boolean (optional) [0] # # Don't allow text-editing # # wrap : string (optional) [VIRTUAL] # # The text wrapping mode. our($VERSION) = sprintf('%d.%02d', q$Revision: 2.11 $ =~ /\d+/g); my($_IDI) = __PACKAGE__->instance_data_index; my($_VS) = 'Bivio::UI::HTML::ViewShortcuts'; sub control_on_render { my($self, $source, $buffer) = @_; $self->SUPER::control_on_render($source, $buffer); my($fields) = $self->[$_IDI]; my($req) = $source->get_request; my($form) = $req->get_widget_value(@{$fields->{model}}); my($field) = $fields->{field}; # need first time initialization to get field name from form model unless ($fields->{initialized}) { my($type) = $fields->{type} = $form->get_field_type($field); my($attributes) = ''; $self->unsafe_render_attr('edit_attributes', $source, \$attributes); #TODO: need get_width or is it something else? $fields->{prefix} = 'vs_html_attrs_render($self, $source) || '') . join('', map(qq{ $_="$fields->{$_}"}, qw(rows cols))); $fields->{prefix} .= ' readonly="readonly"' if $fields->{readonly}; $fields->{initialized} = 1; } my($p, $s) = Bivio::UI::Font->format_html('input_field', $req); $$buffer .= $p.$fields->{prefix} . ' name="' . $form->get_field_name_for_html($field) . '">' . $form->get_field_as_html($field) . '' . $s; return; } sub initialize { my($self) = @_; my($fields) = $self->[$_IDI]; return if $fields->{model}; $self->unsafe_initialize_attr('edit_attributes'); $fields->{model} = $self->ancestral_get('form_model'); ($fields->{field}, $fields->{rows}, $fields->{cols}) = $self->get( 'field', 'rows', 'cols'); $fields->{readonly} = $self->get_or_default('readonly', 0); return; } sub new { my($self) = shift->SUPER::new(@_); $self->[$_IDI] ||= {}; return $self; } 1;