[interchange-cvs] interchange - heins modified 2 files
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Tue Apr 12 23:14:48 EDT 2005
User: heins
Date: 2005-04-13 03:14:48 GMT
Modified: code/Widget country_select.widget
Modified: lib/Vend/Table Editor.pm
Log:
* The variable names in country_select were not necessarily unique. Though
testing worked with two country variables (country and b_country) this
would not necessarily be the case with all browsers/javascript implentations.
Rename all variables to make the code pretty much unique. It could be conflict
with non_standard variable names, so it may take more thought. This should
be at least better.
* Add a callback_prescript and callback_postscript hook for widgets to
use. This allows sending code to an area before the form (prescript)
or after the form (postscript). To begin with, only country_select
uses this.
* Add calls to callback_prescript and callback_postscript to
country_select (if routine is present). This puts the script
code in a better place and removes the necessity for state_select
being before country_select.
* Callbacks could be used like:
[display
name=country
type=country_select
callback_prescript=`sub {
my $val = shift;
$Scratch->{meta_header} .= "\n$val";
return;
}
`
callback_postscript=`sub {
my $val = shift;
$Scratch->{some_footer} .= "\n$val";
return;
}
`
]
Revision Changes Path
1.6 +67 -41 interchange/code/Widget/country_select.widget
rev 1.6, prev_rev 1.5
Index: country_select.widget
===================================================================
RCS file: /var/cvs/interchange/code/Widget/country_select.widget,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- country_select.widget 12 Apr 2005 19:19:27 -0000 1.5
+++ country_select.widget 13 Apr 2005 03:14:47 -0000 1.6
@@ -37,8 +37,12 @@
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]_)/) {
@@ -53,8 +57,6 @@
my $ctab = $opt->{country_table} || 'country';
$opt->{state_style} ||= 'font-style: italic; font-size: smaller';
- use vars qw/$Tag/;
-
my $die = sub {
my ($msg, @arg) = @_;
$msg = errmsg($msg) if @arg;
@@ -63,9 +65,8 @@
return undef;
};
- my $pre = $opt->{prepend} || '';
- my $app = $opt->{append} || '';
- my $out = $pre;
+ my $pr;
+ my $ap;
my $stab = $opt->{state_table} || 'state';
@@ -121,6 +122,13 @@
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}) {
@@ -136,17 +144,17 @@
my @pre;
push @pre, <<EOF;
<script>
- var formv;
- var no_state = new Array;
+ var $v_formv;
+ var $v_no_state = new Array;
EOF
for(keys %no_state) {
- push @pre, "no_state['$_'] = 1";
+ push @pre, "$v_no_state\['$_'] = 1";
}
push @pre, <<EOF;
- var state_vary = new Array;
- var state_tary = new Array;
+ var $v_state_vary = new Array;
+ var $v_state_tary = new Array;
EOF
for(keys %states) {
@@ -163,11 +171,11 @@
for(@sv) { s/'/\\'/g; }
for(@st) { s/'/\\'/g; }
- my $string = "state_vary['$_'] = ['";
+ my $string = "$v_state_vary\['$_'] = ['";
$string .= join "','", '', @sv;
$string .= "'];";
push @pre, $string;
- $string = "state_tary['$_'] = ['";
+ $string = "$v_state_tary\['$_'] = ['";
$string .= join "','", errmsg('--select state--'), @st;
$string .= "'];";
push @pre, $string;
@@ -180,33 +188,33 @@
var sbox = document.getElementById('$sel');
var country = cel.value;
- if(! formv) {
- formv=cel.form;
+ if(! $v_formv) {
+ $v_formv=cel.form;
}
if(! sval) {
- if(formv.$svar && formv.$svar.value)
- sval = formv.$svar.value;
+ if($v_formv.$svar && $v_formv.$svar.value)
+ sval = $v_formv.$svar.value;
else sval = '';
}
if(! sbox) return;
- if(no_state[country]) {
+ if($v_no_state\[country]) {
sbox.innerHTML = '<span style="$opt->{state_style}">No state required</span>';
- formv.$svar.value = '';
+ $v_formv.$svar.value = '';
return;
}
- var svary = state_vary[country];
+ var svary = $v_state_vary\[country];
if(! svary) {
var val = '';
- sbox.innerHTML = '<input type="text" size="$size" name="$svar_in" value="' + sval + '" onChange="formv.$svar.value = this.value">';
- formv.$svar.value=sval;
+ sbox.innerHTML = '<input type="text" size="$size" name="$svar_in" value="' + sval + '" onChange="$v_formv.$svar.value = this.value">';
+ $v_formv.$svar.value=sval;
return;
}
- var stary = state_tary[country];
+ var stary = $v_state_tary\[country];
- var str = '<select name="$svar_in" onChange="formv.$svar.value = this.value">';
+ var str = '<select name="$svar_in" onChange="$v_formv.$svar.value = this.value">';
for(var i = 0; i < svary.length; i++) {
str += '<option value="' + svary[i] + '"';
if(svary[i] == sval)
@@ -222,36 +230,54 @@
</script>
EOF
- my $sval = $CGI->{$svar} || $Values->{$svar};
+ my $sval = $CGI::values{$svar} || $::Values->{$svar};
$sval = $Tag->jsq($sval) || "''";
my $fname = $opt->{form_name} || 'nevairbe';
- $opt->{prepend} = join "\n", @pre;
- $opt->{append} = <<EOF;
+
+ 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 f = document.$fname;
- var csval = $sval;
- if(!f) {
- var str = '';
+ var $v_f = document.$fname;
+ var $v_csval = $sval;
+ if(!$v_f) {
for(var i = 0; i < document.forms.length; i++) {
- f = document.forms[i];
- str += 'checking form ' + i + ', country=' + f.$opt->{name};
- if(f.$opt->{name}) {
- if(f.$svar && f.$svar.value)
- csval = f.$svar.value;
- ${cvar}_widget_adjust_state(f.$opt->{name}, csval);
- str += 'SELECTING FORM ' + 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;
}
}
}
- formv = f;
- if(formv.$svar) {
- csval = formv.$svar.value;
+ $v_formv = $v_f;
+ if($v_formv.$svar) {
+ csval = $v_formv.$svar.value;
}
- ${cvar}_widget_adjust_state(formv.$opt->{name}, csval);
+ ${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)"};
my @out;
1.68 +24 -7 interchange/lib/Vend/Table/Editor.pm
rev 1.68, prev_rev 1.67
Index: Editor.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/Editor.pm,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- Editor.pm 12 Apr 2005 15:14:39 -0000 1.67
+++ Editor.pm 13 Apr 2005 03:14:47 -0000 1.68
@@ -1,6 +1,6 @@
# Vend::Table::Editor - Swiss-army-knife table editor for Interchange
#
-# $Id: Editor.pm,v 1.67 2005/04/12 15:14:39 mheins Exp $
+# $Id: Editor.pm,v 1.68 2005/04/13 03:14:47 mheins Exp $
#
# Copyright (C) 2002-2003 Interchange Development Group
# Copyright (C) 2002 Mike Heins <mike at perusion.net>
@@ -26,7 +26,7 @@
package Vend::Table::Editor;
use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.67 $, 10);
+$VERSION = substr(q$Revision: 1.68 $, 10);
use Vend::Util;
use Vend::Interpolate;
@@ -553,6 +553,8 @@
append
attribute
db
+ callback_prescript
+ callback_postscript
class
extra
disabled
@@ -2617,9 +2619,6 @@
no strict 'subs';
chunk ttag(), $restrict_begin;
- chunk 'FORM_BEGIN', 'OUTPUT_MAP', <<EOF; # unless $wo;
-<FORM METHOD=$opt->{method} ACTION="$opt->{href}"$opt->{enctype}$opt->{form_extra}>
-EOF
$hidden->{mv_click} = $opt->{process_filter};
$hidden->{mv_todo} = $opt->{action};
@@ -3397,6 +3396,14 @@
$reload = 1 unless $opt->{no_reload};
}
+ my @prescript;
+ my @postscript;
+ my $callback_prescript = sub {
+ push @prescript, @_;
+ };
+ my $callback_postscript = sub {
+ push @postscript, @_;
+ };
foreach my $col (@cols) {
my $t;
my $c;
@@ -3636,6 +3643,8 @@
append => $append->{$c},
applylocale => 1,
arbitrary => $opt->{ui_meta_view},
+ callback_prescript => $callback_prescript,
+ callback_postscript => $callback_postscript,
class => $class->{$c},
column => $c,
db => $database->{$c},
@@ -3974,9 +3983,17 @@
</script>
EOF
}
- chunk 'FORM_END', 'OUTPUT_MAP', <<EOF;
-</form>$end_script
+
+ push @prescript, <<EOF;
+<form method="$opt->{method}" ACTION="$opt->{href}"$opt->{enctype}$opt->{form_extra}>
EOF
+
+ chunk 'FORM_BEGIN', 'OUTPUT_MAP', join("\n", @prescript);
+
+ unshift @postscript, qq{</form>$end_script};
+
+ chunk 'FORM_END', 'OUTPUT_MAP', join("\n", @postscript);
+
chunk ttag(), $restrict_end;
chunk_alias 'BOTTOM_OF_FORM', qw/ FORM_END /;
More information about the interchange-cvs
mailing list