radio —
Interchange 5.9.0:
Source: code/Widget/radio.widget
Lines: 14
# Copyright 2005-2007 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # # $Id: radio.widget,v 1.4 2007-03-30 23:40:58 pajamian Exp $ CodeDef radio Widget 1 CodeDef radio Description Radio box CodeDef radio MapRoutine Vend::Form::box CodeDef radio_nbsp Widget 1 CodeDef radio_nbsp Description Radio box (nbsp)
Source: lib/Vend/Form.pm
Lines: 1042
sub box {
my($opt, $opts) = @_;
#::logDebug("Called box type=$opt->{type}");
my $inc = $opt->{breakmod};
my ($xlt, $template, $o_template, $header, $footer, $row_hdr, $row_ftr);
$opt->{variant} ||= $opt->{type};
$header = $template = $footer = $row_hdr = $row_ftr = '';
if($opt->{nbsp}) {
$xlt = 1;
$template = $Template{boxnbsp};
}
elsif ($opt->{left}) {
$header = '<table>';
$footer = '</table>';
$template = '<tr>' unless $inc;
$template .= $Template{boxvalue};
$template .= $Template{boxlabel};
$template .= '</tr>' unless $inc;
$o_template = $Template{boxgroup};
}
elsif ($opt->{right}) {
$header = '<table>';
$footer = '</table>';
$template = '<tr>' unless $inc;
$template .= $Template{boxlabel};
$template .= $Template{boxvalue};
$template .= '</tr>' unless $inc;
$o_template = $Template{boxgroup};
}
else {
$template = $Template{boxstd};
}
$o_template ||= "<br$Vend::Xtrailer><b>{TVALUE}</b><br$Vend::Xtrailer>";
my $run = $header;
my $price = $opt->{price} || {};
my $i = 0;
my $default = $opt->{value};
my $no_encode = $opt->{pre_filter} eq 'decode_entities' ? 1 : 0;
for(@$opts) {
my($value,$label,$help) = @$_;
encode($label, $ESCAPE_CHARS::std) unless $no_encode;
encode($help, $ESCAPE_CHARS::std) if $help;
if($value =~ /^\s*\~\~(.*)\~\~\s*$/) {
my $lab = $1;
$lab =~ s/"/"/g;
$opt->{tvalue} = $lab;
$opt->{tlabel} = $lab;
$run .= attr_list($o_template, $opt);
$i = 0;
next;
}
$value = '' if ! length($value);
$label = $value if ! length($label);
$run .= '<tr>' if $inc && ! ($i % $inc);
$i++;
undef $opt->{selected};
$label =~ s/\*$//
and $opt->{selected} = 1;
$opt->{selected} = '' if defined $opt->{value};
my $extra;
my $attr = { label => $label, value => $value };
if(my $p = $price->{$value}) {
$attr->{negative} = $p < 0 ? 1 : 0;
$attr->{price_noformat} = $p;
$attr->{absolute} = currency(abs($p), undef, 1);
$attr->{price} = $extra = currency($p, undef, 1);
$label .= " ($attr->{price})";
}
$value eq ''
and defined $default
and $default eq ''
and $opt->{selected} = 1;
if(length $value) {
my $regex = $opt->{contains}
? qr/\Q$value\E/
: qr/\b\Q$value\E\b/;
$default =~ $regex and $opt->{selected} = 1;
}
$opt->{tvalue} = encode($value, $ESCAPE_CHARS::std);
if($opt->{option_template}) {
$opt->{tlabel} = attr_list($opt->{option_template}, $attr);
$opt->{tlabel} =~ s/ / /g if $xlt;
}
else {
$label =~ s/ / /g if $xlt;
$opt->{tlabel} = $label;
}
$opt->{ttitle} = $help;
if($opt->{id}) {
$opt->{textid} = $opt->{id} . ($value eq '' ? 0 : $value);
$opt->{textid} =~ s/[^-\w]+//g;
}
$run .= attr_list($template, $opt);
$run .= '</tr>' if $inc && ! ($i % $inc);
}
$run .= $footer;
}