Interchange Reference Pages: Widgets


For a complete introduction to Interchange widgets, please see the widget glossary entry.

Table of Contents

acl
check_nbsp
checkbox
combo
country_select — display country selector dropdown box
date — calendar date input widget
default
display
gpg_keys
htmlarea — rich text editor widget
imagedir
imagehelper — image upload widget
labels
links
movecombo
movecombo_replace
multiple
noyes — display a no/yes option
option_format
options
radio
radio_nbsp
realvalue — display raw, unencoded value, providing no option to change it
select
show
state_select — display state selector dropdown box
text — display value, providing HTML input box change it
textarea — display value, providing HTML textarea box change it
time — display time selector dropdown box
uploadblob
uploadhelper — display file upload widget
value — display value, providing no option to change it
yesno — display a yes/no option
ynzero — display a yes/no option

Name

acl

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

acl is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/acl.widget
Lines: 94


# 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: acl.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef acl Widget 1
CodeDef acl Description ACL Settings
CodeDef acl Routine <<EOR
sub {
my($opt) = @_;
my($name, $val) = ($opt->{name}, $opt->{value});

my $del_label = errmsg('delete');
my $n_label = errmsg('none');
my $rw_label = errmsg('read-write');
my $r_label = errmsg('read');

my $opsub = 
sub  {
my ($name, $val, $lab, $width) = @_;
my ($nsel, $rsel, $rwsel, $tsel) = ('', '', '', '');

#::logDebug("$val=$lab");
if   ($lab =~ /n/) { $nsel = ' SELECTED' }
elsif($lab =~ /w/) { $rwsel = ' SELECTED' }
elsif($lab =~ /r/) { $rsel = ' SELECTED' }
if   ($lab =~ /t/) { $tsel = ' CHECKED' }
#::logDebug("nsel=$nsel, rsel=$rsel, rwsel=$rwsel");
$val =~ s/"/&quot;/g;
$lab =~ s/"/&quot;/g;
$width = 16 if ! $width;
return qq{  <tr>
    <td>
    <input type="text" name="$name" value="$val" size="$width" style="font-size: small">
    <input type="hidden" name="$name" value="=">
  </td>

    <td>
    <select name="$name" style="font-size: small">
    <option value="n"$nsel>$n_label</option>
    <option value="r"$rsel>$r_label</option>
    <option value="rw"$rwsel>$rw_label</option>
    <option value="d">$del_label</option>
  </select>
  </td>
    <td align=center>
    <input type="checkbox" name="$name" value="t" style="font-size: small"$tsel>
    <input type="hidden" name="$name" value=",">
  </td>
</tr>};
};


my $width = $opt->{width} || 16;
$opt->{pre_filter} = 'hash2acl'
  unless length($opt->{filter});
$opt->{filter} = 'acl2hash'
  unless length($opt->{filter});
$val = Vend::Interpolate::filter_value($opt->{pre_filter}, $val);
my @opts = split /\s*,\s*/, $val;

my $out = qq{<table cellpadding="0" cellspacing="0"><tr>};
$out .= qq{<th style="font-size: small">};
$out .= errmsg('Object');
$out .= qq{</th>};
$out .= qq{<th align="left" style="font-size: small">};
$out .= errmsg('Permissions');
$out .= qq{</th>};
$out .= qq{<th align="center" style="font-size: small">};
$out .= errmsg('Allow tar');
$out .= qq{</th>};
$out .= qq{</tr>};

my $done;
my $height = $opt->{height} || 5;
$height -= 2;
for(@opts) {
  my ($v,$l) = split /\s*=\s*/, $_, 2;
  next unless length($v);
  $done++;
  $out .= $opsub->($name, $v, $l, $width);
}
while($done++ < $height) {
  $out .= $opsub->($name, '', '', '', $width);
}
$out .= $opsub->($name, '', '', '', $width);
$out .= $opsub->($name, '', '', '', $width);
$out .= "</table>";
}
EOR


Name

check_nbsp

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

check_nbsp is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/checkbox.widget
Lines: 18


# 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: checkbox.widget,v 1.5 2007-11-14 15:20:30 racke Exp $

CodeDef checkbox Widget 1
CodeDef checkbox Description Checkbox
CodeDef checkbox Help Selection of single/multiple values
CodeDef checkbox Multiple 1
CodeDef checkbox MapRoutine Vend::Form::box
CodeDef check_nbsp Widget 1
CodeDef check_nbsp Description Checkbox (nbsp)
CodeDef check_nbsp Multiple 1
CodeDef check_nbsp Help Selection of single/multiple values, &nbsp; for spaces

SEE ALSO


Name

checkbox

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

checkbox is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/checkbox.widget
Lines: 18


# 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: checkbox.widget,v 1.5 2007-11-14 15:20:30 racke Exp $

CodeDef checkbox Widget 1
CodeDef checkbox Description Checkbox
CodeDef checkbox Help Selection of single/multiple values
CodeDef checkbox Multiple 1
CodeDef checkbox MapRoutine Vend::Form::box
CodeDef check_nbsp Widget 1
CodeDef check_nbsp Description Checkbox (nbsp)
CodeDef check_nbsp Multiple 1
CodeDef check_nbsp Help Selection of single/multiple values, &nbsp; for spaces

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/"/&quot;/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 .= "&nbsp;($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/ /&nbsp;/g if $xlt;
  }
  else {
    $label =~ s/ /&nbsp;/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;
}


Name

combo

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

combo is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/combo.widget
Lines: 12


# 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: combo.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef combo Widget 1
CodeDef combo Description Combo Select
CodeDef combo MapRoutine Vend::Form::combo

Source: lib/Vend/Form.pm
Lines: 750

sub combo {
my ($opt, $opts) = @_;
my $addl;
if($opt->{textarea}) {
  my $template = $opt->{o_template};
  if(! $template) {
    $template = "<br$Vend::Xtrailer>";
    if(! $opt->{rows} or $opt->{rows} > 1) {
      $template .= q(<textarea rows="{ROWS|2}" wrap="{WRAP|virtual}");
      $template .= q( cols="{COLS|60}" name="{NAME}">);
      $template .= '{ENCODED}'
        unless $opt->{conditional_text} and length($opt->{value}) < 3;
      $template .= q(</textarea>);
    }
    else {
      $template .= qq(<input type="text" size="{COLS|40}");
      $template .= qq( name="{NAME}" value=");
      $template .= '{ENCODED}'
        unless $opt->{conditional_text} and length($opt->{value}) < 3;
      $template .= qq(">);
    }
  }
  $addl = attr_list($template, $opt);
}
else {
  $addl = qq|<input type="text" name="$opt->{name}"|;
  $addl   .= qq| size="$opt->{cols}" value="">|;
}
if($opt->{reverse}) {
  $opt->{append} = length($opt->{append}) ? "$addl$opt->{append}" : $addl;
}
else {
  $opt->{prepend} = length($opt->{prepend}) ? "$opt->{prepend}$addl" : $addl;
}
return dropdown($opt, $opts);
}

SEE ALSO


Name

country_select — display country selector dropdown box

DESCRIPTION

The <widget>country_select</widget> widget displays an elegantly-formatted country selector dropdown box.

EXAMPLES

Example: Country selector

[widget name=widget_countryselect type=country_select]

NOTES

AVAILABILITY

country_select is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/country_select.widget
Lines: 386


# Copyright 2005-2009 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.

CodeDef state_select  Widget  1
CodeDef state_select  Description State (needs country_select)
CodeDef state_select  Help Requires country_select widget for country to work properly
CodeDef state_select  Routine <<EOR
sub {
my $opt = shift;
my $sel = $opt->{state_element};
if(! $sel) {
my $n = $opt->{name};
my $pre = '';
if($n =~ /^([a-z]_)/) {
  $pre = $1;
}
$sel = "${pre}state_widget_container";
}
$opt->{type} = 'hidden';
my $wid = Vend::Form::display($opt);
return qq{$wid<span id="$sel"></span>};
}
EOR

CodeDef state_select ExtraMeta <<EOM
{
_order => [ qw/
  state_element
/],
state_element => {
label => 'State element ID',
help => 'The CSS ID of the span containing the dynamic widget. The \ \

 default is usually good (state_widget_container or b_state_widget_container)',
widget => 'text_30',
},
}
EOM

CodeDef country_select  Widget  1
CodeDef country_select  Description Country
CodeDef country_select  Help Requires state_select widget for state to work properly
CodeDef country_select  Routine <<EOR
sub {
my ($opt) = @_;
my $name = $opt->{name} ||= 'country';

use vars qw/$Tag/;

my $sel = $opt->{state_element};

my $pre = '';

if(! $sel) {
my $n = $opt->{name};
if($n =~ /^([a-z]_)/) {
  $pre = $1;
}
$sel = "${pre}state_widget_container";
}

my $svar = $opt->{state_var} || $opt->{state_variable} || "${pre}state";
my $svar_in = $svar . '_cs_in';
my $size = $opt->{state_size} || $opt->{cols} || $opt->{width} || '16';
my $ctab = $opt->{country_table} || 'country';
$opt->{state_style} ||= 'font-style: italic; font-size: smaller';

my $die = sub {
my ($msg, @arg) = @_;
$msg = errmsg($msg) if @arg;
$Tag->error({ name => 'country_select widget', set => $msg});
::logError($msg);
return undef;
};

my $pr; 
my $ap;

my $stab = $opt->{state_table} || 'state';

my $csort = $opt->{country_sort} || ($opt->{no_region} ? 'name' : 'sorder,name');
my $ssort = $opt->{state_sort} || 'country,name';

my @csort = grep /\w/, split /[\s,\0]+/, $csort;

my $csort_sub = sub {
for(@csort) {
  my $so = $a->{$_} cmp $b->{$_};
  return $so if $so;
}
return 0;
};

my @ssort = grep /\w/, split /[\s,\0]+/, $ssort;

my $ssort_sub = sub {
for(@ssort) {
  my $so = $a->{$_} cmp $b->{$_};
  return $so if $so;
}
return 0;
};

my $cdb = dbref($ctab) or return $die->('country table %s not found', $ctab);
my $sdb = dbref($stab) or return $die->('state table %s not found', $stab);
$ctab = $cdb->name();
$stab = $sdb->name();
my $cq = "select * from $ctab";
my $sq = "select * from $stab";
my $cary = $cdb->query({ sql => $cq, hashref => 1});
my $sary = $sdb->query({ sql => $sq, hashref => 1});

@csort = grep exists($cary->[0]{$_}), @csort;
@ssort = grep exists($sary->[0]{$_}), @ssort;

@$cary = sort $csort_sub @$cary;
@$sary = sort $ssort_sub @$sary;

if($opt->{only_with_shipping}) {
@$cary = grep $_->{shipmodes} =~ /\w/, @$cary;
}

my %states;

for my $s (@$sary) {
my $c = $s->{country};
push @{$states{$c} ||= []}, [ $s->{state}, $s->{name} ];
}

my @copts;
my %no_state;

my $v_formv = "${pre}formv";
my $v_csval = "${pre}csval";
my $v_f = "${pre}f";
my $v_no_state = "${pre}no_state";
my $v_state_tary = "${pre}state_tary";
my $v_state_vary = "${pre}state_vary";

my $prev;
for my $c (@$cary) {
if($c->{no_state}) {
  $no_state{$c->{code}} = 1;
}
if(! $opt->{no_region} and $c->{region} and $c->{region} ne $prev) {
  push @copts, ["~~" . $c->{region} . "~~"];
  $prev = $c->{region};
}
push @copts, [ $c->{code}, $c->{name} ];
}

my @pre;
push @pre, <<EOF;
<script>
var $v_formv;
var $v_no_state = new Array;
EOF

for(keys %no_state) {
push @pre, "$v_no_state\['$_'] = 1";
}

push @pre, <<EOF;
var $v_state_vary = new Array;
var $v_state_tary = new Array;
EOF

for(keys %states) {
my $sa = $states{$_};
my @sv;
my @st;
my %seen;
@$sa = grep !$seen{$_->[0]}++, @$sa;
for my $e (@$sa) {
  push @sv, $e->[0];
  push @st, $e->[1];
}

for(@sv) { s/'/\\'/g; }
for(@st) { s/'/\\'/g; }

my $string = "$v_state_vary\['$_'] = ['";
$string .= join "','", '', @sv;
$string .= "'];";
push @pre, $string;
$string = "$v_state_tary\['$_'] = ['";
$string .= join "','", errmsg('--select state--'), @st;
$string .= "'];";
push @pre, $string;
}

my $cvar = $opt->{name};
$cvar =~ s/\W+/_/g;

my $extra = $opt->{state_extra} ? " $opt->{state_extra}" : '';
my $state_js = $opt->{state_js} ? "; $opt->{state_js}" : '';
my $state_class = $opt->{state_class} ? "$opt->{state_class}" : '';
my $country_js = $opt->{country_js} ? "; $opt->{country_js}" : '';
for ($state_js, $country_js) { s|\bthis\.form\b|$v_formv|g }

push @pre, <<EOF;
function ${cvar}_widget_adjust_state (cel,sval) {
var sbox = document.getElementById('$sel');
var country = cel.value;

if(! $v_formv) {
  $v_formv=cel.form;
}

if(! sval) {
  if($v_formv.$svar && $v_formv.$svar.value)
    sval = $v_formv.$svar.value;
  else sval = '';
}

if(! sbox) return;
if($v_no_state\[country]) {
  sbox.innerHTML = '<span style="$opt->{state_style}">No state required</span>';
  $v_formv.$svar.value = '';
  return;
}
var svary = $v_state_vary\[country];
if(! svary) {
  var val = '';
  sbox.innerHTML = '<input type="text" size="$size" name="$svar_in" \ \

 id="$svar_in" value="' + sval + '" onChange="$v_formv.$svar.value = this.value"$extra>';
  $v_formv.$svar.value=sval;

  return;
}
var stary = $v_state_tary\[country];

var str = '<select name="$svar_in" id="$svar_in" onChange="$v_formv.$svar.value \
 \
 = this.value$state_js" class="$state_class"$extra>';
for(var i = 0; i < svary.length; i++) {
  str += '<option value="' + svary[i] + '"';
  if(svary[i] == sval)
    str += ' SELECTED';
  str += '>';
  str += stary[i];
}
str += '</select>';
sbox.innerHTML = str;

return;
}
</script>
EOF

my $sval = $CGI::values{$svar} || $::Values->{$svar};
$sval = HTML::Entities::encode($sval, $ESCAPE_CHARS::std);
$sval = $Tag->jsq($sval) || "''";
my $fname = $opt->{form_name} || 'nevairbe';

my $prepend = join "\n", @pre;

if(my $sub = $opt->{callback_prescript}) {
$sub->($prepend);
}
else {
$opt->{prepend} = '' unless defined $opt->{prepend};
$opt->{prepend} .= "\n" if length $opt->{prepend};
$opt->{prepend} .= $prepend;
}


my $append = <<EOF;
<script>
var $v_f = document.$fname;
var $v_csval = $sval;
if(!$v_f) {
for(var i = 0; i < document.forms.length; i++) {
  $v_f = document.forms[i];
  if($v_f.$opt->{name}) {
    if($v_f.$svar && $v_f.$svar.value) 
      $v_csval = $v_f.$svar.value;
    ${cvar}_widget_adjust_state($v_f.$opt->{name}, $v_csval);
    break;
  }
}
}
$v_formv = $v_f;
if($v_formv.$svar) {
csval = $v_formv.$svar.value;
}
${cvar}_widget_adjust_state($v_formv.$opt->{name}, $v_csval);

</script>
EOF

if(my $sub = $opt->{callback_postscript}) {
$sub->($append);
}
else {
$opt->{append} = '' unless defined $opt->{append};
$opt->{append} .= "\n" if length $opt->{append};
$opt->{append} .= $append;
}

$opt->{js} = qq{ onLoad="${cvar}_widget_adjust_state(this)" onChange="${cvar}_widget_adjust_state \
 \
(this)$country_js"};
my @out;
#push @out, '<xmp>';
#push @out, ::uneval(\%states);
#push @out, '</xmp>';

$opt->{type} = 'select';
push @out, Vend::Form::display($opt, {}, \@copts);

return join "\n", @out;
}
EOR

CodeDef country_select ExtraMeta <<EOM
{
_order => [ qw/
  state_var
  state_style
  state_class
  country_sort
  no_region
  only_with_shipping
  form_name
  country_table
  state_table
  state_element
  state_js
/],
state_var => {
label => 'State variable',
help => 'default is <i>state</i>, might use <i>b_state</i> instead',
widget => 'text_16',
},
state_class => {
label => 'CSS class for state',
help => 'Modify look of state text',
widget => 'text_20',
},
state_style => {
label => 'CSS style for state',
help => 'Modify look of state text',
widget => 'text_60',
},
no_region => {
label => 'Region sort',
help => 'Controls country groupings',
options => '=Region sort, 1=No region sort',
widget => 'select',
},
only_with_shipping => {
label => 'Only with shipping',
help => 'Only show countries that have value in shipmodes',
options => '=All countries, 1=Only with shipping',
widget => 'select',
},
country_sort => {
label => 'Country sort order',
help => 'Should be "name" if no region sort, "sorder,name" with region',
widget => 'text_16',
},
country_table => {
label => 'Country table',
help => 'default is usually good (country)',
widget => 'text_16',
},
state_sort => {
label => 'State sort order',
help => 'Default of <i>country,name</i> is usually OK',
widget => 'text_16',
},
state_table => {
label => 'State table',
help => 'default is usually good (state)',
widget => 'text_16',
},
state_element => {
label => 'State element ID',
help => 'The CSS ID of the span containing the dynamic widget. The \ \

 default is usually good (state_widget_container or b_state_widget_container)',
widget => 'text_30',
},
state_js => {
label => 'State javascript',
help => 'Runs specified javascript under onChange. E.g. "state_js=check_tax(this.form)"',
widget => 'text_20',
},
}
EOM


Name

date — calendar date input widget

DESCRIPTION

This widget allows the user to select a calendar date.

You can adjust the year range with the year_begin and year_end options, which default to UI_DATE_BEGIN and UI_DATE_END variables respectively.

EXAMPLES

Example: Specifying year range

[display type=date name=create_date
  value="[value create_date]"
  year_begin=1975 year_end=2020]

NOTES

AVAILABILITY

date is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/date.widget
Lines: 12


# 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: date.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef date Widget 1
CodeDef date Description Date selector
CodeDef date MapRoutine Vend::Form::date_widget

Source: lib/Vend/Form.pm
Lines: 634

sub date_widget {
my($opt) = @_;

my $name = $opt->{name};
my $val  = $opt->{value};

if($val =~ /\D/) {
  $val = Vend::Interpolate::filter_value('date_change', $val);
}
my $now;
if($opt->{time} and $opt->{time_adjust} =~ /([-+]?)(\d+)/) {
  my $sign = $1 || '+';
  my $adjust = $2;
  $adjust *= 3600;
  $now = time;
  $now += $sign eq '+' ? $adjust : -$adjust;
}

my $sel_extra;
my $opt_extra;
for(qw/ class style extra /) {
  my $stag = "select_$_";
  my $otag = "option_$_";
  my $selapp;
  my $optapp;

  if($_ eq 'extra') {
    $selapp = " $opt->{$stag}";
    $optapp = " $opt->{$otag}";
  }
  else {
    $selapp = qq{ $_="$opt->{$stag}"};
    $optapp = qq{ $_="$opt->{$otag}"};
  }
  $sel_extra .= $opt->{$stag} ? $selapp : '';
  $opt_extra .= $opt->{$otag} ? $optapp : '';
}

my @t = localtime($now || time);
my $sel = 0;
my $out = qq{<select name="$name"$sel_extra>};
my $o;
if ($opt->{blank}) {
  $out .= qq{<option value="0"$opt_extra>------</option>};
} elsif (not $val) {
  # use current time with possible adjustments as default value
  $t[2]++ if $t[2] < 23;
  $val = POSIX::strftime("%Y%m%d%H00", @t);
}
for(@Months) {
  $o = qq{<option value="$_->[0]"$opt_extra>} . errmsg($_->[1]) . '</option>';
  ($out .= $o, next) unless ! $sel and $val;
  $o =~ s/>/ SELECTED>/ && $sel++
    if substr($val, 4, 2) eq $_->[0];
  $out .= $o;
}
$sel = 0;
$out .= qq{</select>};
$out .= qq{<input type="hidden" name="$name" value="/">};
$out .= qq{<select name="$name"$sel_extra>};
if ($opt->{blank}) {
  $out .= qq{<option value="0"$opt_extra>--</option>};
}
for(@Days) {
  $o = qq{<option value="$_->[0]"$opt_extra>$_->[1]} . '</option>';
  ($out .= $o, next) unless ! $sel and $val;
  $o =~ s/>/ SELECTED>/ && $sel++
    if substr($val, 6, 2) eq $_->[0];
  $out .= $o;
}
$sel = 0;
$out .= qq{</select>};
$out .= qq{<input type="hidden" name="$name" value="/">};
$out .= qq{<select name="$name"$sel_extra>};

my $cy = $t[5] + 1900;

# If year_begin or year_end are /00+/, make current year
for(qw/ year_begin year_end /) {
  if( length($opt->{$_}) > 1 and $opt->{$_} == 0) {
    $opt->{$_} = $cy;
  }
}

if(my $by = $opt->{year_begin} || $::Variable->{UI_DATE_BEGIN}) {
  my $ey = $opt->{year_end}  || $::Variable->{UI_DATE_END} || ($cy + 10);
  if($by < 100) {
    $by = $cy - abs($by);
  }
  if($ey < 100) {
    $ey += $cy;
  }
  @Years = $by <= $ey ? ($by .. $ey) : reverse ($ey .. $by);
}
if ($opt->{blank}) {
  $out .= qq{<option value="0000"$opt_extra>----</option>};
}
for(@Years) {
  $o = qq{<option$opt_extra>$_} . '</option>';
  ($out .= $o, next) unless ! $sel and $val;
  $o =~ s/>/ SELECTED>/ && $sel++
    if substr($val, 0, 4) eq $_;
  $out .= $o;
}
$out .= qq{</select>};
return $out unless $opt->{time};

$val =~ s/^(\d{8})//;
# If the date is blank (0000-00-00), treat time of 00:00 as blank,
# not midnight, in the option selection below
my $blank_time = ($opt->{blank} and $1 !~ /[1-9]/);
$val =~ s/\D+//g;
$val = round_to_fifteen($val);
$out .= qq{<input type="hidden" name="$name" value=":">};
$out .= qq{<select name="$name"$sel_extra>};
if ($opt->{blank}) {
  $out .= qq{<option value="0"$opt_extra>--:--</option>};
}

my $ampm = defined $opt->{ampm} ? $opt->{ampm} : 1;
my $mod = '';
undef $sel;
my %special = qw/ 0 midnight 12 noon /;

my @min;

$opt->{minutes} ||= '';

if($opt->{minutes} =~ /half/i) {
  @min = (0,30);
}
elsif($opt->{minutes} =~ /hourly/i) {
  @min = (0);
}
elsif($opt->{minutes} =~ /ten/i) {
  @min = (0,10,20,30,40,50);
}
elsif($opt->{minutes} =~ /[\0,]/) {
  @min = grep /^\d+$/ && $_ <= 59, split /[\0,\s]+/, $opt->{minutes};
}
else {
  @min = (0,15,30,45);
}

$opt->{start_hour} ||= 0;
for(qw/start_hour end_hour/) {
  $opt->{$_} = int(abs($opt->{$_}));
  if($opt->{$_} > 23) {
    $opt->{$_} = 0;
  }
}
$opt->{start_hour}  ||= 0;
$opt->{end_hour}  ||= 23;

for my $hr ( $opt->{start_hour} .. $opt->{end_hour} ) {
  next if defined $opt->{start_hour} and $hr < $opt->{start_hour};
  next if defined $opt->{end_hour} and $hr > $opt->{end_hour};
  for my $min ( @min ) {
    my $disp_hour = $hr;
    if($opt->{ampm}) {
      if( $hr < 12) {
        $mod = 'am';
      }
      else {
        $mod = 'pm';
        $disp_hour = $hr - 12 unless $hr == 12;
      }
      $mod = errmsg($mod);
      $mod = " $mod";
    }
    if($special{$hr} and $min == 0) {
      $disp_hour = errmsg($special{$hr});
    }
    elsif($ampm) {
      $disp_hour = sprintf("%2d:%02d%s", $disp_hour, $min, $mod);
    }
    else {
      $disp_hour = sprintf("%02d:%02d", $hr, $min);
    }
    my $time = sprintf "%02d%02d", $hr, $min;
    $o = sprintf qq{<option value="%s"$opt_extra>%s}, $time, $disp_hour;
    ($out .= $o, next) unless ! $sel and $val;
#::logDebug("prospect=$time actual=$val");
    $o =~ s/>/ SELECTED>/ && $sel++
      if ! $blank_time and $val eq $time;
    $out .= $o;
  }
}
$out .= "</select>";
return $out;
}


Name

default

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

default is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/default.widget
Lines: 13


# 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: default.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef default Widget 1
CodeDef default Description Default widget if none selected
CodeDef default Visibility private
CodeDef default MapRoutine Vend::Form::template_sub

Source: lib/Vend/Form.pm
Lines: 301

sub template_sub {
my $opt = shift;
return attr_list($Template{$opt->{type}} || $Template{default}, $opt);
}

SEE ALSO


Name

display

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

display is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/display.widget
Lines: 12


# 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: display.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef display Widget 1
CodeDef display Description Text of option
CodeDef display MapRoutine Vend::Form::current_label

Source: lib/Vend/Form.pm
Lines: 321

sub current_label {
my($opt, $data) = @_;
my $val;
my $default;
if (defined $opt->{value}) {
  $val = $opt->{value};
}
elsif(defined $opt->{default}) {
  $val = $opt->{default};
}
$val =~ s/\0//;
for(@$data) {
  my ($setting, $label) = @$_;
  $default = $label if $label =~ s/\*$//;
  return ($label || $setting) if $val eq $setting;
}
return $val || $default;
}

SEE ALSO


Name

gpg_keys

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

gpg_keys is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/gpg_keys.widget
Lines: 20


# 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: gpg_keys.widget,v 1.4 2007-03-30 23:40:58 pajamian Exp $

CodeDef gpg_keys Widget 1
CodeDef gpg_keys Description GPG key selector
CodeDef gpg_keys Routine <<EOR
sub {
my ($opt) = @_;
$opt->{passed} = $Tag->get_gpg_keys();
$opt->{type} = delete $opt->{variant} || 'combo';
$opt->{filter} = 'nullselect' if $opt->{type} eq 'combo';
return Vend::Form::display($opt);
}
EOR

SEE ALSO


Name

htmlarea — rich text editor widget

DESCRIPTION

The htmlarea widget makes calls to a rich-text editor that replaces a TEXTAREA component on supported browsers. It operates as a normal textarea otherwise.

Two flavours of rich-text editors are available, htmlarea (HTMLArea) and fckeditor (FCKeditor).

Most modern browsers are supported.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

htmlarea is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/htmlarea.widget
Lines: 241


# 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: htmlarea.widget,v 1.16 2007-09-26 19:56:56 racke Exp $

CodeDef htmlarea Widget 1
CodeDef htmlarea Description Rich text editor
CodeDef htmlarea Documentation <<EOD
=head1 NAME

HTMLArea widget for Interchange

=head1 SYNOPSIS

 [display type=htmlarea name=foo height=NN width=NNN]

or

 [table-editor
   widget.foo=htmlarea
 ...
 ]

=head1 DESCRIPTION

The C<htmlarea> widget makes calls to a rich-text editor that replaces 
a C<TEXTAREA> component on supported browsers. It operates as a normal 
textarea otherwise.

Two flavours of rich-text editors are available, htmlarea (HTMLArea) and
fckeditor (FCKeditor).

Supported browsers include at least Mozilla 1.3.1 and higher, and
MSIE 6 and higher.

=head1 INSTALLATION

The flavour can be selected by the Interchange Variable HTMLAREA_FLAVOUR
or the flavour option and defaults to htmlarea.

To install the htmlarea flavour, get HTMLArea-3.0-RC1 or later and install 
in the C<htmlarea> directory of your DocumentRoot. 
That means that routines can be accessed with a base HREF of C</htmlarea/>).

To install the fckeditor flavour, get FCKeditor 2.1 or later and install 
in the C<fckeditor> directory of your DocumentRoot. 
That means that routines can be accessed with a base HREF of C</fckeditor/>.

Alternatively, you can set the Interchange Variable HTMLAREA_PATH to
the appropriate path.

This widget requires Interchange 5.0 and higher.

If you are planning on using it outside of the Interchange UI, you must
either have the output-style of layout (the "standard" demo) with a 
[scratch meta_header] call in the <HEAD> area, or you must place the
equivalent of the following in the header of any page to use this widget:

   [tmp tmp_hpath][either]__HTMLAREA_PATH__[or]/htmlarea/[/either][/tmp]
 <script type="text/javascript">
    _editor_url = "[scratch tmp_hpath]";
    _editor_lang = "en";
 </script>
 <script type="text/javascript" src="[scratch tmp_hpath]htmlarea.js"></script>

For the fckeditor flavour:

   [tmp tmp_hpath][either]__HTMLAREA_PATH__[or]/htmlarea/[/either][/tmp]
 <script type="text/javascript">
    _editor_url = "[scratch tmp_hpath]";
 </script>
 <script type="text/javascript" src="[scratch tmp_hpath]fckeditor.js"></script>

Additionally for the fckeditor flavour, if "htmlarea_config" is set, upon
loading it will call a javascript function by the name of its value:

   [display type=htmlarea name=foo height=NN width=NNN htmlarea_config="bar"]

   <script>
   function bar (fckobj) {
       fckobj.ToolbarSet = 'Basic';
   }
   </script>

This is useful to pass fckeditor configurations, such as the above example "ToolbarSet".
Note that you must supply the Javascript function of (in this case) "bar" as shown, somewhere
on the same page for it to work. 

The "en" is the language locale to use. If you use the output-style
layout, this is automatically determined from the Interchange locale.
You can also override this with the Variable HTMLAREA_LANG. This is not
applicable for the fckeditor flavour.

=head1 BUGS

A bug in MSIE doesn't allow initialization of a textarea until the
complete document is loaded. This means that the editor toolbox will not
show up until the mouse enters the C<TEXTAREA>.

=cut
EOD

CodeDef htmlarea Routine <<EOR
sub {
 my ($opt) = @_;
#::logDebug("called kupu widget, value=$opt->{value}");
 use vars qw/$Tag/;

 my %flavours = (htmlarea => {path => '/htmlarea/',
         header => qq|
<script type="text/javascript">
  _editor_url = "{PATH}";
  _editor_lang = "{LANG}";
</script>
<script type="text/javascript" src="{PATH}htmlarea.js"></script>
|,
         area => qq|<textarea id="htmlarea_{NAME}" rows="{HEIGHT}" cols={WIDTH} \
 name="{NAME}"{ONMOUSE}>{VALUE}</textarea>|},
         fckeditor => {path => '/fckeditor/',
         header => qq|
<script type="text/javascript" src="{PATH}fckeditor.js"></script>
<script type="text/javascript">
  _editor_url = "{PATH}";

  function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
   window.onload = func;
 } else {
   window.onload = function() {
   oldonload();
   func();
   }
 }
  }
</script>|,
         pre => qq|<script>
addLoadEvent(function()
{
   var {NAME}FCKeditor = new FCKeditor( '{NAME}', '{WIDTH}', '{HEIGHT}' ) ;
   {NAME}FCKeditor.BasePath = _editor_url ;
{CONFIG?}{CONFIG}({NAME}FCKeditor);{/CONFIG?}
 {NAME}FCKeditor.ReplaceTextarea() ;
});

</script>
|,
       area => qq|<textarea id="{NAME}" rows="{HEIGHT}" cols="{WIDTH}" \
 \
 name="{NAME}">{VALUE}</textarea>|,
       post => ''
});

my $flavour = $opt->{flavour} || $::Variable->{HTMLAREA_FLAVOUR} || 'htmlarea';

my $fname = $opt->{form_name} || 'editor';

my $callpage = $opt->{append} || 'special/kupu';

 my $pname = $opt->{name};

 my $wname = $opt->{window_name} || "ic_kupu_$pname";

$pname =~ s/\W/_/g;

unless(defined $opt->{close_window}) {
$opt->{close_window} = 1;
}

if(! $::Scratch->{htmlarea_added}) {
$Tag->tmp({ name => 'htmlarea_added', body => 1 });
$::Scratch->{meta_header} ||= '';
my $path = $::Variable->{HTMLAREA_PATH} || $flavours{$flavour}->{path};
my $lang = $::Variable->{HTMLAREA_LANG} || $::Scratch->{mv_locale} || 'en';
$lang = substr($lang, 0, 2);
$path =~ s:/*$:/:;
$::Scratch->{meta_header} .= $Tag->uc_attr_list({hash => {path => $path, \
 \
 \
 lang => $lang}}, $flavours{$flavour}->{header});
}

 my $val;
 if($opt->{value} =~ /</) {
   $val = HTML::Entities::encode($opt->{value});
 }
 else {
   $val = $opt->{value};
 }
 my $pre_scr = '';
 my $post_scr = '';
 my $onmouse = '';
 my $htmlarea_config = '';
 
 if ($opt->{htmlarea_config}) {
   $htmlarea_config = ", $opt->{htmlarea_config}";
 }

 if($Session->{browser} =~ /MSIE/) {
   if ($flavour eq 'htmlarea') {
       $pre_scr = qq{
<script>
var htmlarea_needinit_$pname = true;
</script>
};
     $onmouse = qq{ onMouseOver="if(htmlarea_needinit_$pname) { HTMLArea.replace \
('htmlarea_$pname'$htmlarea_config); htmlarea_needinit_$pname=false }"};
   }
 }
 else {
   if ($flavour eq 'fckeditor') {
     $post_scr = <<EOF;

EOF
   } else {
     $post_scr = <<EOF;
<script>
 HTMLArea.replace('htmlarea_$pname'$htmlarea_config);
</script>
EOF
   }
 }

   $opt->{height} =~ s/\D+//;
   $opt->{width} =~ s/\D+//;

 $pre_scr .= $Tag->uc_attr_list({hash => {name => $pname, width => $opt->{width}, \
 height => $opt->{height},
                                 config => $flavour eq 'fckeditor' ? $opt->{htmlarea_config} \
 : undef },
                 body => $flavours{$flavour}->{pre}});
 
 $opt->{anchor_style} ||= 'font-size: smaller';

 my $extra = $opt->{anchor_class} ? qq{ class="$opt->{anchor_class}"} : '';
 $extra .= qq{ style="$opt->{anchor_style}"} if $opt->{anchor_style};
 my $textra = $opt->{text_class} ? qq{ class="$opt->{text_class}"} : '';
 $textra .= qq{ style="$opt->{text_style}"} if $opt->{text_style};

 my $wid = $pre_scr . $Tag->uc_attr_list({hash => {name => $pname,
   height => $opt->{height}, width => $opt->{width}, onmouse => $onmouse,
   value => $val}, body => $flavours{$flavour}->{area}}) . $post_scr;
 
 return $wid;
}
EOR


Name

imagedir

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

imagedir is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/imagedir.widget
Lines: 57


# 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: imagedir.widget,v 1.7 2007-03-30 23:40:58 pajamian Exp $

CodeDef imagedir Widget 1
CodeDef imagedir Description Image listing
CodeDef imagedir ExtraMeta <<EOM
{
_order => [ qw/ follow_symlinks / ],
follow_symlinks => {
  widget => 'yesno',
  label => 'Follow Symlinks',
  help => 'Set to yes if you want to list all files, even following symbolic links',
},
}
EOM

CodeDef imagedir Routine <<EOR
use File::Find;
sub {
my ($opt) = @_;
my $dir = delete $opt->{dir}  || delete $opt->{outboard};
my $suf = delete $opt->{suffix} || delete $opt->{options};
return undef unless -d $dir;
#::logDebug("passed suf=$suf");
$suf = '\.(GIF|gif|JPG|JPEG|jpg|jpeg|png|PNG)'
  unless $suf;

if($suf and $suf !~ /[\.|]/) {
  my @types = grep /\S/, split /[,\s\0]+/, $suf;
  $suf = '\.(' . join("|", @types) . ')';
}

my @names;
my $regex;
eval {
  $regex = qr{$suf$};
};
return undef if $@;
my $wanted = sub {
        return undef unless -f $_;
        return undef unless $_ =~ $regex;
        my $n = $File::Find::name;
        $n =~ s:^$dir/?::;
        push(@names, $n);
      };
find({ wanted => $wanted, follow => $opt->{follow_symlinks} }, $dir);
$opt->{passed} = [ '=None', sort @names ];
$opt->{type} = delete $opt->{variant} || 'combo';
return Vend::Form::display($opt);
}
EOR

SEE ALSO


Name

imagehelper — image upload widget

DESCRIPTION

This widget allows image upload and selection for a specific directory.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

File upload has to be enabled in the HTML form containing this widget. Also this widget depends on the process_filter form profile.

AVAILABILITY

imagehelper is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/imagehelper.widget
Lines: 77


# 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: imagehelper.widget,v 1.6 2007-03-30 23:40:58 pajamian Exp $

CodeDef imagehelper  Widget  1
CodeDef imagehelper  Description Image upload
CodeDef imagehelper  Routine <<EOR
sub  {
  my ($opt) = @_;

my $name = $opt->{name};
my $size = $opt->{cols} || $opt->{width};
my $val  = $opt->{value};
my $path = $opt->{image_path} || $opt->{outboard};
my $name_from = $opt->{name_from_field} || '';
my $imagebase = $opt->{image_base} || $opt->{prepend};

Vend::Interpolate::vars_and_comments(\$path);
Vend::Interpolate::vars_and_comments(\$imagebase);
if ($imagebase ||= '') {
  $imagebase =~ s/^\s+//;
  $imagebase =~ s:[\s/]*$:/:;
}

my $of_widget;
if($path =~ s!/\*(?:\.([^/]+))?$!!) {
  my $spec = $1;
  my @files = UI::Primitive::list_images($path, $spec);
  unshift(@files, "=(none)");
  my $passed = join ",", map { s/,/&#44;/g; $_} @files;
  my $opt = {
    type => 'select',
    default => $val,
    attribute => 'mv_data_file_oldfile',
    passed => $passed,
  };
  $of_widget = Vend::Interpolate::tag_accessories(
      undef, undef, $opt, { 'mv_data_file_oldfile' => $val } );
}
else {
  $of_widget = qq{<INPUT TYPE=hidden NAME=mv_data_file_oldfile VALUE="$val">};
}
$size = qq{ SIZE="$size"} if $size > 0;
  if ($val) {
      qq{<A HREF="$imagebase$path/$val">$val</A>&nbsp;<INPUT TYPE=hidden \
 NAME=mv_data_file_field VALUE="$name"><INPUT TYPE=hidden NAME=mv_data_file_name_from \
 VALUE="$name_from">
<INPUT TYPE=hidden NAME=mv_data_file_path VALUE="$path">$of_widget<INPUT \
 TYPE=file NAME="$name" VALUE="$val">};      
  } else {
      qq{<INPUT TYPE=hidden NAME=mv_data_file_field VALUE="$name"><INPUT \
 TYPE=hidden NAME=mv_data_file_name_from VALUE="$name_from">
<INPUT TYPE=hidden NAME=mv_data_file_path VALUE="$path">$of_widget<INPUT \
 TYPE=file NAME="$name"$size>};
  }
}
EOR

CodeDef imagehelper ExtraMeta <<EOM
{
_order => [ qw/
    image_path
    name_from_field
  /],
image_path => {
  label => 'Image Path',
  help => 'default is <b>images/items</b> in <i>standard catalog</i>',
  widget => 'text_30',
},
name_from_field => {
  label => 'Name from field',
  help => 'Usually named from products SKU',
  widget => 'select',
  options => 'columns::',
},
}
EOM


Name

labels

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

labels is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/labels.widget
Lines: 12


# 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: labels.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef labels Widget 1
CodeDef labels Description Show labels
CodeDef labels MapRoutine Vend::Form::show_labels

Source: lib/Vend/Form.pm
Lines: 296

sub show_labels {
return show_options($_[0], $_[1], 1);
}

SEE ALSO


Name

links

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

links is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/links.widget
Lines: 12


# 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: links.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef links Widget 1
CodeDef links Description Build links
CodeDef links MapRoutine Vend::Form::links

Source: lib/Vend/Form.pm
Lines: 387

sub links {
my($opt, $opts) = @_;

$opt->{joiner} = Vend::Interpolate::get_joiner($opt->{joiner}, "<br$Vend::Xtrailer>");
my $name = $opt->{name};
my $default = defined $opt->{value} ? $opt->{value} : $opt->{default};

$opt->{extra} = " $opt->{extra}" if $opt->{extra};

my $template = $opt->{template} || <<EOF;
<a href="{URL}"{EXTRA}>{SELECTED <b>}{LABEL}{SELECTED </b>}</a>
EOF

my $o_template = $opt->{o_template} || <<EOF;
<b>{TVALUE}</b>
EOF

my $href = $opt->{href} || $Global::Variable->{MV_PAGE};
$opt->{form} = "mv_action=return" unless $opt->{form};

my $no_encode = $opt->{pre_filter} eq 'decode_entities' ? 1 : 0;

my @out;
for(@$opts) {
#warn "iterating links opt $_ = " . uneval_it($_) . "\n";
  my $attr = { extra => $opt->{extra}};
  
  s/\*$// and $attr->{selected} = 1;

  ($attr->{value},$attr->{label}) = @$_;
  encode($attr->{label}, $ESCAPE_CHARS::std) unless $no_encode;
  if($attr->{value} =~ /^\s*\~\~(.*)\~\~\s*$/) {
    my $lab = $1;
    $lab =~ s/"/&quot;/g;
    $opt->{tvalue} = $lab;
    $opt->{tlabel} = $lab;
    push @out, attr_list($o_template, $opt);
    next;
  }

  next if ! $attr->{value} and ! $opt->{empty};
  if( ! length($attr->{label}) ) {
    $attr->{label} = $attr->{value} or next;
  }

  if ($default) {
    $attr->{selected} = $default eq $attr->{value} ? 1 : '';
  }

  my $form = $opt->{form};

  $attr->{label} =~ s/\s/&nbsp;/g if $opt->{nbsp};

  $attr->{url} = Vend::Interpolate::tag_area(
          $href,
          undef,
          {
            form => "$name=$attr->{value}\n$opt->{form}",
            secure => $opt->{secure},
          },
          );
  push @out, attr_list($template, $attr);
}
return join $opt->{joiner}, @out;
}

SEE ALSO


Name

movecombo

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

movecombo is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/movecombo.widget
Lines: 17


# 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: movecombo.widget,v 1.4 2007-11-14 04:50:19 pajamian Exp $

CodeDef movecombo Widget 1
CodeDef movecombo Description Combo move
CodeDef movecombo Help Selects any/all of many options, puts in text box
CodeDef movecombo Multiple 1
CodeDef movecombo MapRoutine Vend::Form::movecombo
CodeDef movecombo_replace Widget 1
CodeDef movecombo_replace Description Combo move (one value)
CodeDef movecombo_replace Help Selects one of many options, puts in text box

Source: lib/Vend/Form.pm
Lines: 713

sub movecombo {
my ($opt, $opts) = @_;
my $name = $opt->{name};
$opt->{name} = "X$name";
my $usenl = $opt->{rows} > 1 ? 1 : 0;
my $only = $opt->{replace} ? 1 : 0;
$opt->{extra} .= qq{ onChange="addItem(this.form['X$name'],this.form['$name'],$usenl,$only)"}
          unless $opt->{extra} =~ m/\bonchange\s*=/i;

$opt->{rows} = $opt->{height} unless length($opt->{rows});
$opt->{cols} = $opt->{width} unless length($opt->{cols});

my $tbox = '';
my $out = dropdown($opt, $opts);

my $template = $opt->{o_template} || '';
if(! $template) {
  if($opt->{rows} > 1) {
    $template .= q(<textarea rows="{ROWS|4}" wrap="{WRAP|virtual}");
    $template .= q( cols="{COLS|20}" name="{NAME}">{ENCODED}</textarea>);
  }
  else {
    $template .= qq(<input type="text" size="{COLS||40}");
    $template .= qq( name="{NAME}" value="{ENCODED}">);
  }
}
$opt->{name} = $name;
$tbox = attr_list($template, $opt);

return $opt->{reverse} ? $tbox . $out : $out . $tbox;
}

SEE ALSO


Name

movecombo_replace

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

movecombo_replace is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/movecombo.widget
Lines: 17


# 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: movecombo.widget,v 1.4 2007-11-14 04:50:19 pajamian Exp $

CodeDef movecombo Widget 1
CodeDef movecombo Description Combo move
CodeDef movecombo Help Selects any/all of many options, puts in text box
CodeDef movecombo Multiple 1
CodeDef movecombo MapRoutine Vend::Form::movecombo
CodeDef movecombo_replace Widget 1
CodeDef movecombo_replace Description Combo move (one value)
CodeDef movecombo_replace Help Selects one of many options, puts in text box

SEE ALSO


Name

multiple

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

multiple is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/multiple.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: multiple.widget,v 1.4 2007-11-14 04:50:19 pajamian Exp $

CodeDef multiple Widget 1
CodeDef multiple Description Select multiple
CodeDef multiple Help Dropdown list with all options shown 
CodeDef multiple Multiple 1
CodeDef multiple MapRoutine Vend::Form::dropdown

Source: lib/Vend/Form.pm
Lines: 863

sub dropdown {
my($opt, $opts) = @_;
#::logDebug("called select opt=" . ::uneval($opt) . "\nopts=" . ::uneval($opts));
$opt->{multiple} = 1 if $opt->{type} eq 'multiple';

$opts ||= [];

my $price = $opt->{price} || {};

my $select;
#::logDebug("template for selecthead: $Template{selecthead}");
#::logDebug("opt is " . ::uneval($opt));
my $run = attr_list($Template{selecthead}, $opt);
#::logDebug("run is now: $run");
my ($multi, $re_b, $re_e, $regex);
#::logDebug("select multiple=$opt->{multiple}");
if($opt->{multiple}) {
  $multi = 1;
  if($opt->{rawvalue}) {
    $re_b = '(?:\0|^)';
    $re_e = '(?:\0|$)';
  }
  else {
    $re_b = '(?:[\0,\s]|^)';
    $re_e = '(?:[\0,\s]|$)';
  }
}
else {
  $re_b = '^';
  $re_e = '$';
}

my $limit;
if($opt->{cols}) {
  my $cols = $opt->{cols};
  $limit = sub {
    return $_[0] if length($_[0]) <= $cols;
    return substr($_[0], 0, $cols - 2) . '..';
  };
}
else {
  $limit = sub { return $_[0] };
}

my $default = $opt->{value};

my $optgroup_one;
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 $label = $1;
    if($optgroup_one++) {
      $run .= "</optgroup>";
    }
    $run .= qq{<optgroup label="$label">};
    next;
  }
  $run .= '<option';
  $select = '';

  if($label) {
    $label =~ s/\*$// and $select = 1;
  }
  else {
    $value =~ s/\*$// and $select = 1;
  }

  $select = '' if defined $default;

  my $extra = '';
  my $attr = {};
  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);
    $extra = " ($extra)";
  }

  my $vvalue = $value;
  encode($vvalue, $ESCAPE_CHARS::std);
  $run .= qq| value="$vvalue"|;
  $run .= qq| title="$help"| if $help;
  if (length($default)) {
    $regex  = qr/$re_b\Q$value\E$re_e/;
    $default =~ $regex and $select = 1;
  } elsif (defined($default) && length($value) == 0) {
    $select = 1;
  }
  $run .= ' SELECTED' if $select;
  $run .= '>';
  if($opt->{option_template}) {
    $attr->{label} = $label || $value;
    $attr->{value} = $value;
    $run .= attr_list($opt->{option_template}, $attr);
  }
  elsif($label) {
    $run .= $limit->($label);
    $run .= $extra;
  }
  else {
    $run .= $limit->($value);
    $run .= $extra;
  }
}
$run .= "</optgroup>" if $optgroup_one++;
$run .= attr_list($Template{selecttail}, $opt);
}

SEE ALSO


Name

noyes — display a no/yes option

DESCRIPTION

The <widget>noyes</widget> widget creates a simple "Yes or No" option. This widget is exactly the same as <widget>yesno</widget> with the return values for Yes and No inverted.

The actual widget titles, "Yes" and "No", are locale-aware so adding their translated versions to the locale database will be enough to have them adjusted to visitors' language settings.

A negative answer will return value 1 (true) to the application.
A positive answer will return a blank (false) value to the application.

EXAMPLES

Example: 'Yes or No' widget, rendered as a dropdown list

[display name=example type=noyes]

NOTES

See very similar widget <widget>yesno</widget> for additional examples.

AVAILABILITY

noyes is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/noyes.widget
Lines: 13


# 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: noyes.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef noyes Widget 1
CodeDef noyes Description No/Yes (No=1)
CodeDef noyes Help Default is 1 for No
CodeDef noyes MapRoutine Vend::Form::noyes

Source: lib/Vend/Form.pm
Lines: 927

sub noyes {
my $opt = shift;
$opt->{value} = is_no($opt->{value});
my @opts = (
        ['1', errmsg('No')],
        ['', errmsg('Yes')],
      );
my $routine = $opt->{subwidget} || \&dropdown;
return $routine->($opt, \@opts);
}

SEE ALSO

yesno(7ic)


Name

option_format

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

option_format is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/option_format.widget
Lines: 12


# 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: option_format.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef option_format Widget 1
CodeDef option_format Description Option formatter
CodeDef option_format MapRoutine Vend::Form::option_widget

Source: lib/Vend/Form.pm
Lines: 680

sub option_widget {
my($opt) = @_;
my($name, $val) = ($opt->{name}, $opt->{value});

my $width = $opt->{width} || 16;
$opt->{filter} = 'option_format'
  unless length($opt->{filter});
$val = Vend::Interpolate::filter_value($opt->{filter}, $val);
my @opts = split /\s*,\s*/, $val;

my $out = qq{<table cellpadding="0" cellspacing="0"><tr><th><small>};
$out .= errmsg('Value');
$out .= qq{</small></th><th align="left" colspan="2"><small>};
$out .= errmsg('Label');
$out .= qq{</small></th></tr>};

my $done;
my $height = $opt->{height} || 5;
$height -= 2;
for(@opts) {
  my ($v,$l) = split /\s*=\s*/, $_, 2;
  next unless $l || length($v);
  $done++;
  my $default;
  ($l =~ s/\*$// or ! $l && $v =~ s/\*$//)
    and $default = 1;
  $out .= option_widget_box($name, $v, $l, $default, $width);
}
while($done++ < $height) {
  $out .= option_widget_box($name, '', '', '', $width);
}
$out .= option_widget_box($name, '', '', '', $width);
$out .= option_widget_box($name, '', '', '', $width);
$out .= "</table>";
}

SEE ALSO


Name

options

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

options is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/options.widget
Lines: 12


# 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: options.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef options Widget 1
CodeDef options Description Show all options
CodeDef options MapRoutine Vend::Form::show_options

Source: lib/Vend/Form.pm
Lines: 292

sub show_options {
my $opt = shift;
my $ary = shift;
my $idx = shift || 0;
return undef if ! $ary;
my @out;
eval {
  @out = map {$_->[$idx]} @$ary;
};
my $delim = Vend::Interpolate::get_joiner($opt->{delimiter}, ',');
return join $delim, @out;
}


Name

radio

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

radio is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

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/"/&quot;/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 .= "&nbsp;($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/ /&nbsp;/g if $xlt;
  }
  else {
    $label =~ s/ /&nbsp;/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;
}

SEE ALSO


Name

radio_nbsp

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

radio_nbsp is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

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)

SEE ALSO


Name

realvalue — display raw, unencoded value, providing no option to change it

DESCRIPTION

The <widget>realvalue</widget> widget simply displays variables from the values space and does not create any HTML form element that would allow changing them.

It is similar to <widget>value</widget>, but more dangerous. It does not perform any encoding on the value before display, allowing for possible untrusted data (including both HTML and ITL!) to be injected into the HTML stream.

Use this widget with caution and always only on data you absolutely trust.

EXAMPLES

Example: Basic value initialization and display

[value name=widget_testrealvalue set="Test Widget Value" hide=1]

[widget name=widget_testrealvalue type=realvalue]

Example: Basic value initialization and display, showing arbitrary HTML and ITL code insertion

[set widget_testrealvalue_input]
Test <i>Widget<i> <b>Value</b>. The time is: [time]
[/set]

[value name=widget_testrealvalue
  set="[scratch widget_testrealvalue_input]"
  hide=1]

[widget name=widget_testrealvalue type=realvalue]

NOTES

The variable value is not encoded before display; to enabled recommended processing before display, use widget <widget>value</widget>.

AVAILABILITY

realvalue is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/realvalue.widget
Lines: 13


# 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: realvalue.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef realvalue Widget 1
CodeDef realvalue Description Unencoded value
CodeDef realvalue Help Skips HTML::Entities encode process
CodeDef realvalue Routine sub { my $opt = shift; return $opt->{value} }


Name

select

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

select is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/select.widget
Lines: 13


# 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: select.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef select Widget 1
CodeDef select Description Select box
CodeDef select Help AKA dropdown menu
CodeDef select MapRoutine Vend::Form::dropdown

Source: lib/Vend/Form.pm
Lines: 863

sub dropdown {
my($opt, $opts) = @_;
#::logDebug("called select opt=" . ::uneval($opt) . "\nopts=" . ::uneval($opts));
$opt->{multiple} = 1 if $opt->{type} eq 'multiple';

$opts ||= [];

my $price = $opt->{price} || {};

my $select;
#::logDebug("template for selecthead: $Template{selecthead}");
#::logDebug("opt is " . ::uneval($opt));
my $run = attr_list($Template{selecthead}, $opt);
#::logDebug("run is now: $run");
my ($multi, $re_b, $re_e, $regex);
#::logDebug("select multiple=$opt->{multiple}");
if($opt->{multiple}) {
  $multi = 1;
  if($opt->{rawvalue}) {
    $re_b = '(?:\0|^)';
    $re_e = '(?:\0|$)';
  }
  else {
    $re_b = '(?:[\0,\s]|^)';
    $re_e = '(?:[\0,\s]|$)';
  }
}
else {
  $re_b = '^';
  $re_e = '$';
}

my $limit;
if($opt->{cols}) {
  my $cols = $opt->{cols};
  $limit = sub {
    return $_[0] if length($_[0]) <= $cols;
    return substr($_[0], 0, $cols - 2) . '..';
  };
}
else {
  $limit = sub { return $_[0] };
}

my $default = $opt->{value};

my $optgroup_one;
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 $label = $1;
    if($optgroup_one++) {
      $run .= "</optgroup>";
    }
    $run .= qq{<optgroup label="$label">};
    next;
  }
  $run .= '<option';
  $select = '';

  if($label) {
    $label =~ s/\*$// and $select = 1;
  }
  else {
    $value =~ s/\*$// and $select = 1;
  }

  $select = '' if defined $default;

  my $extra = '';
  my $attr = {};
  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);
    $extra = " ($extra)";
  }

  my $vvalue = $value;
  encode($vvalue, $ESCAPE_CHARS::std);
  $run .= qq| value="$vvalue"|;
  $run .= qq| title="$help"| if $help;
  if (length($default)) {
    $regex  = qr/$re_b\Q$value\E$re_e/;
    $default =~ $regex and $select = 1;
  } elsif (defined($default) && length($value) == 0) {
    $select = 1;
  }
  $run .= ' SELECTED' if $select;
  $run .= '>';
  if($opt->{option_template}) {
    $attr->{label} = $label || $value;
    $attr->{value} = $value;
    $run .= attr_list($opt->{option_template}, $attr);
  }
  elsif($label) {
    $run .= $limit->($label);
    $run .= $extra;
  }
  else {
    $run .= $limit->($value);
    $run .= $extra;
  }
}
$run .= "</optgroup>" if $optgroup_one++;
$run .= attr_list($Template{selecttail}, $opt);
}

SEE ALSO


Name

show

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

show is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/show.widget
Lines: 12


# 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: show.widget,v 1.4 2007-03-30 23:40:58 pajamian Exp $

CodeDef show Widget 1
CodeDef show Description Show options (value=label)
CodeDef show MapRoutine Vend::Form::show_data

Source: lib/Vend/Form.pm
Lines: 279

sub show_data {
my $opt = shift;
my $ary = shift;
return undef if ! $ary;
my @out;
for(@$ary) {
  push @out, join "=", @$_;
}
my $delim = Vend::Interpolate::get_joiner($opt->{delimiter}, ',');
return join $delim, @out;
}

SEE ALSO


Name

state_select — display state selector dropdown box

DESCRIPTION

The <widget>state_select</widget> widget displays a state selector dropdown box.

EXAMPLES

Example: State selector

[widget name=widget_stateselect type=state_select]

NOTES

AVAILABILITY

state_select is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/country_select.widget
Lines: 386


# Copyright 2005-2009 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.

CodeDef state_select  Widget  1
CodeDef state_select  Description State (needs country_select)
CodeDef state_select  Help Requires country_select widget for country to work properly
CodeDef state_select  Routine <<EOR
sub {
my $opt = shift;
my $sel = $opt->{state_element};
if(! $sel) {
  my $n = $opt->{name};
  my $pre = '';
  if($n =~ /^([a-z]_)/) {
    $pre = $1;
  }
  $sel = "${pre}state_widget_container";
}
$opt->{type} = 'hidden';
my $wid = Vend::Form::display($opt);
return qq{$wid<span id="$sel"></span>};
}
EOR

CodeDef state_select ExtraMeta <<EOM
{
_order => [ qw/
    state_element
  /],
state_element => {
  label => 'State element ID',
  help => 'The CSS ID of the span containing the dynamic widget. The \
 default is usually good (state_widget_container or b_state_widget_container)',
  widget => 'text_30',
},
}
EOM

CodeDef country_select  Widget  1
CodeDef country_select  Description Country
CodeDef country_select  Help Requires state_select widget for state to work properly
CodeDef country_select  Routine <<EOR
sub {
  my ($opt) = @_;
my $name = $opt->{name} ||= 'country';

use vars qw/$Tag/;

my $sel = $opt->{state_element};

my $pre = '';

if(! $sel) {
  my $n = $opt->{name};
  if($n =~ /^([a-z]_)/) {
    $pre = $1;
  }
  $sel = "${pre}state_widget_container";
}

my $svar = $opt->{state_var} || $opt->{state_variable} || "${pre}state";
my $svar_in = $svar . '_cs_in';
my $size = $opt->{state_size} || $opt->{cols} || $opt->{width} || '16';
my $ctab = $opt->{country_table} || 'country';
$opt->{state_style} ||= 'font-style: italic; font-size: smaller';

my $die = sub {
  my ($msg, @arg) = @_;
  $msg = errmsg($msg) if @arg;
  $Tag->error({ name => 'country_select widget', set => $msg});
  ::logError($msg);
  return undef;
};

my $pr; 
my $ap;

my $stab = $opt->{state_table} || 'state';

my $csort = $opt->{country_sort} || ($opt->{no_region} ? 'name' : 'sorder,name');
my $ssort = $opt->{state_sort} || 'country,name';

my @csort = grep /\w/, split /[\s,\0]+/, $csort;

my $csort_sub = sub {
  for(@csort) {
    my $so = $a->{$_} cmp $b->{$_};
    return $so if $so;
  }
  return 0;
};

my @ssort = grep /\w/, split /[\s,\0]+/, $ssort;

my $ssort_sub = sub {
  for(@ssort) {
    my $so = $a->{$_} cmp $b->{$_};
    return $so if $so;
  }
  return 0;
};

my $cdb = dbref($ctab) or return $die->('country table %s not found', $ctab);
my $sdb = dbref($stab) or return $die->('state table %s not found', $stab);
$ctab = $cdb->name();
$stab = $sdb->name();
my $cq = "select * from $ctab";
my $sq = "select * from $stab";
my $cary = $cdb->query({ sql => $cq, hashref => 1});
my $sary = $sdb->query({ sql => $sq, hashref => 1});

@csort = grep exists($cary->[0]{$_}), @csort;
@ssort = grep exists($sary->[0]{$_}), @ssort;

@$cary = sort $csort_sub @$cary;
@$sary = sort $ssort_sub @$sary;

if($opt->{only_with_shipping}) {
  @$cary = grep $_->{shipmodes} =~ /\w/, @$cary;
}

my %states;

for my $s (@$sary) {
  my $c = $s->{country};
  push @{$states{$c} ||= []}, [ $s->{state}, $s->{name} ];
}

my @copts;
my %no_state;

my $v_formv = "${pre}formv";
my $v_csval = "${pre}csval";
my $v_f = "${pre}f";
my $v_no_state = "${pre}no_state";
my $v_state_tary = "${pre}state_tary";
my $v_state_vary = "${pre}state_vary";

my $prev;
for my $c (@$cary) {
  if($c->{no_state}) {
    $no_state{$c->{code}} = 1;
  }
  if(! $opt->{no_region} and $c->{region} and $c->{region} ne $prev) {
    push @copts, ["~~" . $c->{region} . "~~"];
    $prev = $c->{region};
  }
  push @copts, [ $c->{code}, $c->{name} ];
}

my @pre;
push @pre, <<EOF;
<script>
var $v_formv;
var $v_no_state = new Array;
EOF

for(keys %no_state) {
  push @pre, "$v_no_state\['$_'] = 1";
}

push @pre, <<EOF;
var $v_state_vary = new Array;
var $v_state_tary = new Array;
EOF

for(keys %states) {
  my $sa = $states{$_};
  my @sv;
  my @st;
  my %seen;
  @$sa = grep !$seen{$_->[0]}++, @$sa;
  for my $e (@$sa) {
    push @sv, $e->[0];
    push @st, $e->[1];
  }

  for(@sv) { s/'/\\'/g; }
  for(@st) { s/'/\\'/g; }

  my $string = "$v_state_vary\['$_'] = ['";
  $string .= join "','", '', @sv;
  $string .= "'];";
  push @pre, $string;
  $string = "$v_state_tary\['$_'] = ['";
  $string .= join "','", errmsg('--select state--'), @st;
  $string .= "'];";
  push @pre, $string;
}

my $cvar = $opt->{name};
$cvar =~ s/\W+/_/g;

my $extra = $opt->{state_extra} ? " $opt->{state_extra}" : '';
my $state_js = $opt->{state_js} ? "; $opt->{state_js}" : '';
my $state_class = $opt->{state_class} ? "$opt->{state_class}" : '';
my $country_js = $opt->{country_js} ? "; $opt->{country_js}" : '';
for ($state_js, $country_js) { s|\bthis\.form\b|$v_formv|g }

push @pre, <<EOF;
function ${cvar}_widget_adjust_state (cel,sval) {
  var sbox = document.getElementById('$sel');
  var country = cel.value;

  if(! $v_formv) {
    $v_formv=cel.form;
  }

  if(! sval) {
    if($v_formv.$svar && $v_formv.$svar.value)
      sval = $v_formv.$svar.value;
    else sval = '';
  }

  if(! sbox) return;
  if($v_no_state\[country]) {
    sbox.innerHTML = '<span style="$opt->{state_style}">No state required</span>';
    $v_formv.$svar.value = '';
    return;
  }
  var svary = $v_state_vary\[country];
  if(! svary) {
    var val = '';
    sbox.innerHTML = '<input type="text" size="$size" name="$svar_in" \
 id="$svar_in" value="' + sval + '" onChange="$v_formv.$svar.value = this.value"$extra>';
    $v_formv.$svar.value=sval;

    return;
  }
  var stary = $v_state_tary\[country];

  var str = '<select name="$svar_in" id="$svar_in" onChange="$v_formv.$svar.value \
 = this.value$state_js" class="$state_class"$extra>';
  for(var i = 0; i < svary.length; i++) {
    str += '<option value="' + svary[i] + '"';
    if(svary[i] == sval)
      str += ' SELECTED';
    str += '>';
    str += stary[i];
  }
  str += '</select>';
  sbox.innerHTML = str;

  return;
}
</script>
EOF

my $sval = $CGI::values{$svar} || $::Values->{$svar};
$sval = HTML::Entities::encode($sval, $ESCAPE_CHARS::std);
$sval = $Tag->jsq($sval) || "''";
my $fname = $opt->{form_name} || 'nevairbe';

my $prepend = join "\n", @pre;

if(my $sub = $opt->{callback_prescript}) {
  $sub->($prepend);
}
else {
  $opt->{prepend} = '' unless defined $opt->{prepend};
  $opt->{prepend} .= "\n" if length $opt->{prepend};
  $opt->{prepend} .= $prepend;
}


my $append = <<EOF;
<script>
var $v_f = document.$fname;
var $v_csval = $sval;
if(!$v_f) {
  for(var i = 0; i < document.forms.length; i++) {
    $v_f = document.forms[i];
    if($v_f.$opt->{name}) {
      if($v_f.$svar && $v_f.$svar.value) 
        $v_csval = $v_f.$svar.value;
      ${cvar}_widget_adjust_state($v_f.$opt->{name}, $v_csval);
      break;
    }
  }
}
$v_formv = $v_f;
if($v_formv.$svar) {
  csval = $v_formv.$svar.value;
}
${cvar}_widget_adjust_state($v_formv.$opt->{name}, $v_csval);

</script>
EOF

if(my $sub = $opt->{callback_postscript}) {
  $sub->($append);
}
else {
  $opt->{append} = '' unless defined $opt->{append};
  $opt->{append} .= "\n" if length $opt->{append};
  $opt->{append} .= $append;
}

$opt->{js} = qq{ onLoad="${cvar}_widget_adjust_state(this)" onChange="${cvar}_widget_adjust_state \
(this)$country_js"};
my @out;
#push @out, '<xmp>';
#push @out, ::uneval(\%states);
#push @out, '</xmp>';

$opt->{type} = 'select';
push @out, Vend::Form::display($opt, {}, \@copts);

return join "\n", @out;
}
EOR

CodeDef country_select ExtraMeta <<EOM
{
_order => [ qw/
    state_var
    state_style
    state_class
    country_sort
    no_region
    only_with_shipping
    form_name
    country_table
    state_table
    state_element
    state_js
  /],
state_var => {
  label => 'State variable',
  help => 'default is <i>state</i>, might use <i>b_state</i> instead',
  widget => 'text_16',
},
state_class => {
  label => 'CSS class for state',
  help => 'Modify look of state text',
  widget => 'text_20',
},
state_style => {
  label => 'CSS style for state',
  help => 'Modify look of state text',
  widget => 'text_60',
},
no_region => {
  label => 'Region sort',
  help => 'Controls country groupings',
  options => '=Region sort, 1=No region sort',
  widget => 'select',
},
only_with_shipping => {
  label => 'Only with shipping',
  help => 'Only show countries that have value in shipmodes',
  options => '=All countries, 1=Only with shipping',
  widget => 'select',
},
country_sort => {
  label => 'Country sort order',
  help => 'Should be "name" if no region sort, "sorder,name" with region',
  widget => 'text_16',
},
country_table => {
  label => 'Country table',
  help => 'default is usually good (country)',
  widget => 'text_16',
},
state_sort => {
  label => 'State sort order',
  help => 'Default of <i>country,name</i> is usually OK',
  widget => 'text_16',
},
state_table => {
  label => 'State table',
  help => 'default is usually good (state)',
  widget => 'text_16',
},
state_element => {
  label => 'State element ID',
  help => 'The CSS ID of the span containing the dynamic widget. The \
 default is usually good (state_widget_container or b_state_widget_container)',
  widget => 'text_30',
},
state_js => {
  label => 'State javascript',
  help => 'Runs specified javascript under onChange. E.g. "state_js=check_tax(this.form)"',
  widget => 'text_20',
},
}
EOM


Name

text — display value, providing HTML input box change it

DESCRIPTION

The <widget>text</widget> widget displays variables from the values space in a HTML text input box.

EXAMPLES

Example: Value initialization and display

[value name=widget_testtext set="Test Widget Value" hide=1]

[widget name=widget_testtext type=text]

NOTES

AVAILABILITY

text is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/text.widget
Lines: 15


# 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: text.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef text Widget 1
CodeDef text Description Text entry*
CodeDef text Help Default HTML input widget
CodeDef textarea Widget 1
CodeDef textarea Description Text box (textarea)
CodeDef textarea Help Size defined by height and width


Name

textarea — display value, providing HTML textarea box change it

DESCRIPTION

The <widget>textarea</widget> widget displays variables from the values space in a HTML textarea box.

EXAMPLES

Example: Value initialization and display

[value name=widget_testtextarea set="Test Widget Value" hide=1]

[widget name=widget_testtextarea type=textarea]

NOTES

AVAILABILITY

textarea is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/text.widget
Lines: 15


# 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: text.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef text Widget 1
CodeDef text Description Text entry*
CodeDef text Help Default HTML input widget
CodeDef textarea Widget 1
CodeDef textarea Description Text box (textarea)
CodeDef textarea Help Size defined by height and width


Name

time — display time selector dropdown box

DESCRIPTION

The <widget>time</widget> widget displays a 24-hour time span in a day as a series of 15-minute increments in a dropdown list.

EXAMPLES

Example: Basic time selector

[widget name=widget_testtime type=time]

NOTES

AVAILABILITY

time is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/time.widget
Lines: 139


# 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: time.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef time Widget 1
CodeDef time Description Time selector
CodeDef time Routine <<EOR
sub {
my($opt) = @_;

my $name = $opt->{name};
my $val  = $opt->{value};

my $now;
if($opt->{time} and $opt->{time_adjust} =~ /([-+]?)(\d+)/) {
  my $sign = $1 || '+';
  my $adjust = $2;
  $adjust *= 3600;
  $now = time;
  $now += $sign eq '+' ? $adjust : -$adjust;
}

my $sel_extra;
my $opt_extra;
for(qw/ class style extra /) {
  my $stag = "select_$_";
  my $otag = "option_$_";
  my $selapp;
  my $optapp;

  if($_ eq 'extra') {
    $selapp = " $opt->{$stag}";
    $optapp = " $opt->{$otag}";
  }
  else {
    $selapp = qq{ $_="$opt->{$stag}"};
    $optapp = qq{ $_="$opt->{$otag}"};
  }
  $sel_extra .= $opt->{$stag} ? $selapp : '';
  $opt_extra .= $opt->{$otag} ? $optapp : '';
}

my @t = localtime($now || time);
if (not $val) {
  $t[2]++ if $t[2] < 23;
  $val = POSIX::strftime("%H00", @t);
}

my $sel = 0;
my $out = qq{<SELECT NAME="$name"$sel_extra>};
my $o;
if ($opt->{blank}) {
  $out .= '<OPTION VALUE="0"$opt_extra>------</OPTION>';
}

$val = Vend::Form::round_to_fifteen($val);

if ($opt->{blank}) {
  $out .= '<OPTION VALUE="0"$opt_extra>--:--</OPTION>';
}

my $ampm = defined $opt->{ampm} ? $opt->{ampm} : 1;
my $mod = '';
undef $sel;
my %special = qw/ 0 midnight 12 noon /;

my @min;

$opt->{minutes} ||= '';

if($opt->{minutes} =~ /half/i) {
  @min = (0,30);
}
elsif($opt->{minutes} =~ /hourly/i) {
  @min = (0);
}
elsif($opt->{minutes} =~ /ten/i) {
  @min = (0,10,20,30,40,50);
}
elsif($opt->{minutes} =~ /[\0,]/) {
  @min = grep /^\d+$/ && $_ <= 59, split /[\0,\s]+/, $opt->{minutes};
}
else {
  @min = (0,15,30,45);
}

$opt->{start_hour} ||= 0;
for(qw/start_hour end_hour/) {
  $opt->{$_} = int(abs($opt->{$_}));
  if($opt->{$_} > 23) {
    $opt->{$_} = 0;
  }
}
$opt->{start_hour}  ||= 0;
$opt->{end_hour}  ||= 23;

for my $hr ( $opt->{start_hour} .. $opt->{end_hour} ) {
  next if defined $opt->{start_hour} and $hr < $opt->{start_hour};
  next if defined $opt->{end_hour} and $hr > $opt->{end_hour};
  for my $min ( @min ) {
    my $disp_hour = $hr;
    if($opt->{ampm}) {
      if( $hr < 12) {
        $mod = 'am';
      }
      else {
        $mod = 'pm';
        $disp_hour = $hr - 12 unless $hr == 12;
      }
      $mod = errmsg($mod);
      $mod = " $mod";
    }
    if($special{$hr} and $min == 0) {
      $disp_hour = errmsg($special{$hr});
    }
    elsif($ampm) {
      $disp_hour = sprintf("%2d:%02d%s", $disp_hour, $min, $mod);
    }
    else {
      $disp_hour = sprintf("%02d:%02d", $hr, $min);
    }
    my $time = sprintf "%02d%02d", $hr, $min;
    $o = sprintf qq{<OPTION VALUE="%s"$opt_extra>%s}, $time, $disp_hour;
    ($out .= $o, next) unless ! $sel and $val;
#::logDebug("prospect=$time actual=$val");
    $o =~ s/>/ SELECTED>/ && $sel++
      if $val eq $time;
    $out .= $o;
  }
}
$out .= "</SELECT>";
return $out;
}
EOR


Name

uploadblob

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

uploadblob is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/uploadblob.widget
Lines: 55


# 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: uploadblob.widget,v 1.5 2007-03-30 23:40:58 pajamian Exp $

CodeDef uploadblob  Widget  1
CodeDef uploadblob  Description File upload to BLOB
CodeDef uploadblob  Routine <<EOR
sub {
# $column, $value, $record->{outboard}, $record->{width}
  my ($opt) = @_;
my $name = $opt->{name};
my $size = $opt->{cols} || $opt->{width};

my $pre = $opt->{prepend} || '';
my $app = $opt->{append} || '';
my $out = $pre;

if(my $n = $opt->{name_to}) {
  $out .= qq{<INPUT TYPE=hidden NAME="mv_data_file_name_to_$name" VALUE="$n">};
}
if(my $s = $opt->{size_to}) {
  $out .= qq{<INPUT TYPE=hidden NAME="mv_data_file_size_to_$name" VALUE="$s">};
}

$size = qq{ SIZE="$size"} if $size > 0;
  $out .= qq{<INPUT TYPE=hidden NAME="mv_data_file_field" VALUE="$name">
<INPUT TYPE=hidden NAME="mv_data_file_path" VALUE="">
<INPUT TYPE=hidden NAME="mv_data_file_oldfile" VALUE="">
<INPUT TYPE=file NAME="$name"$size>$app};
return $out;
}
EOR

CodeDef uploadblob ExtraMeta <<EOM
{
_order => [ qw/ name_to size_to /],
name_to => {
  options => 'columns::',
  label => 'Field to store uploadblob file name in',
  help => 'if any -- must be in fields of table editor',
  widget => 'select',
},
size_to => {
  options => 'columns::',
  label => 'Field to store uploadblob size in',
  help => 'if any -- must be in fields of table editor',
  widget => 'select',
},
}
EOM


Name

uploadhelper — display file upload widget

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

File upload has to be enabled in the HTML form containing this widget. Also this widget depends on the process_filter form profile.

AVAILABILITY

uploadhelper is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/uploadhelper.widget
Lines: 51


# 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: uploadhelper.widget,v 1.7 2009-05-20 09:39:19 racke Exp $

CodeDef uploadhelper  Widget  1
CodeDef uploadhelper  Description File upload
CodeDef uploadhelper  Routine <<EOR
sub {
# $column, $value, $record->{outboard}, $record->{width}
  my ($opt) = @_;

my $name = $opt->{name};
my $val  = $opt->{value};
my $umask = $opt->{umask} || '022';
my $path = $opt->{path} || $opt->{outboard};
my $size = $opt->{cols} || $opt->{width};

$path =~ s:^/+::;
my $view_url;
$size = qq{ SIZE="$size"} if $size > 0;
my $out = '';
if ($val) {
if($path) {
  my $base = $::Variable->{UI_BASE} || 'admin';
  my $view_url = Vend::Interpolate::tag_area("$base/do_view", "$path/$val");
  $out .= qq{<A HREF="$view_url">};
}
$out .= $val;
  if ($path) {
    $out .= "</A>";
    $out .= qq{<input type="checkbox" name="ui_upload_file_delete:$name" value="1">};
    $out .= errmsg('Delete');
  }
  $out .= qq{&nbsp;<INPUT TYPE=file NAME="$name" VALUE="$val">
<INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
<INPUT TYPE=hidden NAME="$name" VALUE="$val">
<INPUT TYPE=hidden NAME="ui_upload_umask:$name" VALUE="$umask">};      
  }
else {
      $out = qq{<INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
<INPUT TYPE=file NAME="$name"$size>
<INPUT TYPE=hidden NAME="ui_upload_umask:$name" VALUE="$umask">};
  }
return $out;
}
EOR


Name

value — display value, providing no option to change it

DESCRIPTION

The <widget>value</widget> widget simply displays variables from the values space and does not create any HTML form element that would allow changing them.

EXAMPLES

Example: Basic value initialization and display

[value name=widget_testvalue set="Test Widget Value" hide=1]

[widget name=widget_testvalue type=value]

NOTES

The variable value is automatically encoded before display; to avoid any processing before display, use widget <widget>realvalue</widget>.

AVAILABILITY

value is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/value.widget
Lines: 13


# 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: value.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef value Widget 1
CodeDef value Description Show value
CodeDef value Help Encoded with HTML::Entities::encode
CodeDef value Routine sub { my $opt = shift; return $opt->{encoded} }


Name

yesno — display a yes/no option

DESCRIPTION

The <widget>yesno</widget> widget creates a simple "Yes or No" option.

The actual widget titles, "Yes" and "No", are locale-aware so adding their translated versions to the locale database will be enough to have them adjusted to visitors' language settings.

A negative answer will return a blank (false) value to the application.
A positive answer will return value 1 (true) to the application.

EXAMPLES

Example: 'Yes or No' widget, rendered as a dropdown list

[display name=example type=yesno]

Example: 'Yes or No' widget, rendered as a "radio" button

[display name=example type=yesno variant=radio]

Example: 'Yes or No' widget, created in an alternative way

A similar (eventually more flexible) "Yes or No" button can be created using the general-purpose display tag:
[display name=example type=select passed="=No,1=Yes"]

NOTES

The widget is created by Interchange's Vend::Form::yesno function. Passing attribute type="yesno radio" to it is equivalent to passing attributes type=yesno variant=radio. However, only method type="yesno radio" is available if the widget is invoked through the widget tag and ITL.

AVAILABILITY

yesno is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/yesno.widget
Lines: 12


# 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: yesno.widget,v 1.3 2007-03-30 23:40:58 pajamian Exp $

CodeDef yesno Widget 1
CodeDef yesno Description Yes/No (Yes=1)
CodeDef yesno MapRoutine Vend::Form::yesno

Source: lib/Vend/Form.pm
Lines: 909

sub yesno {
my $opt = shift;
$opt->{value} = is_yes($opt->{value});
my $yes = defined $opt->{yes_value} ? $opt->{yes_value} : 1;
my $no  = defined $opt->{no_value} ? $opt->{no_value} : '';
my $yes_title = defined $opt->{yes_title} ? $opt->{yes_title} : errmsg('Yes');
my $no_title  = defined $opt->{no_title} ? $opt->{no_title} : errmsg('No');
my @opts;
my $routine = $opt->{subwidget} || \&dropdown;
if($opt->{variant} eq 'checkbox') {
  @opts = [$yes, ' '];
}
else {
  @opts = (
        [$no, $no_title],
        [$yes, $yes_title],
      );
}
return $routine->($opt, \@opts);
}


Name

ynzero — display a yes/no option

DESCRIPTION

The <widget>ynzero</widget> widget creates a simple "Yes or No" option.

The actual widget titles, "Yes" and "No", are locale-aware so adding their translated versions to the locale database will be enough to have them adjusted to visitors' language settings.

A negative answer will return value 0 (false) to the application.
A positive answer will return value 1 (true) to the application.

EXAMPLES

Example: 'Yes or No' widget, rendered as a dropdown list

[display name=example type=ynzero]

Example: 'Yes or No' widget, rendered as a "radio" button

[display name=example type=ynzero variant=radio]

NOTES

The widget is created by Interchange's Vend::Form::yesno function. Passing attribute type="yesno radio" to it is equivalent to passing attributes type=yesno variant=radio. However, only method type="yesno radio" is available if the widget is invoked through the widget tag and ITL.

AVAILABILITY

ynzero is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/Widget/ynzero.widget
Lines: 13


# 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: ynzero.widget,v 1.1 2007-12-02 15:45:04 mheins Exp $

CodeDef ynzero Widget 1
CodeDef ynzero attrDefault no_value 0
CodeDef ynzero Description Yes/No (Yes=1, No=0 -- default=No)
CodeDef ynzero MapRoutine Vend::Form::yesno

Source: lib/Vend/Form.pm
Lines: 909

sub yesno {
my $opt = shift;
$opt->{value} = is_yes($opt->{value});
my $yes = defined $opt->{yes_value} ? $opt->{yes_value} : 1;
my $no  = defined $opt->{no_value} ? $opt->{no_value} : '';
my $yes_title = defined $opt->{yes_title} ? $opt->{yes_title} : errmsg('Yes');
my $no_title  = defined $opt->{no_title} ? $opt->{no_title} : errmsg('No');
my @opts;
my $routine = $opt->{subwidget} || \&dropdown;
if($opt->{variant} eq 'checkbox') {
  @opts = [$yes, ' '];
}
else {
  @opts = (
        [$no, $no_title],
        [$yes, $yes_title],
      );
}
return $routine->($opt, \@opts);
}

SEE ALSO

yesno(7ic)

DocBook!Interchange!