[interchange-cvs] interchange - heins modified 3 files
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Thu Sep 12 01:34:01 2002
User: heins
Date: 2002-09-12 05:33:29 GMT
Modified: code/UI_Tag row_edit.coretag table_editor.coretag
Modified: scripts interchange.PL
Log:
* Optimize [row_edit] to only do one fetch per row.
* Add general multiple-table update feature to main::update_data.
* Add the suggested feature from Dan Browning -- a great idea --
a spreadsheet of a linked table within the table editor.
Adds the options:
link_table Table to link in
link_key Key field to link to
link_fields Columns to display
link_sort How to order the linked rows
(probably should add link_query here)
link_view The view for spreasheet meta
link_label How to label the thing (default
is something like "Settings in
link_table linked by link_key"
link_before Where to plop the thing, input
a column name in the main table to
put it before
link_extra Class, style, or other data for
the table cells in the spreadsheet
To make it even better, multiple link tables are allowed,
so you could do:
[table-editor
link-table.0=3Doptions
link-table.1=3Dpricing
link-key.0=3Dsku
link-key.1=3Dprice_group
]
To test, try this little test-snippet in a default foundation
from the latest CVS.
[table-editor
table=3Dproducts
item_id=3D"os28004"
link-table=3Doptions
link-key=3Dsku
link-fields=3D"sku price description"
link-sort=3D"price desc"
link-before=3D"weight"
]
Revision Changes Path
1.4 +20 -5 interchange/code/UI_Tag/row_edit.coretag
rev 1.4, prev_rev 1.3
Index: row_edit.coretag
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/code/UI_Tag/row_edit.coretag,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- row_edit.coretag 11 Sep 2002 23:22:55 -0000 1.3
+++ row_edit.coretag 12 Sep 2002 05:33:29 -0000 1.4
@@ -38,12 +38,19 @@
$prependor =3D $prependor ? $prependor . '_' : '';
#::logDebug("setting prependor to $prependor");
}
+
+ my $appendor =3D '';
+ if($opt->{stacker}) {
+ $appendor =3D "__$opt->{stacker}";
+#::logDebug("setting appendor to $appendor");
+ }
return errmsg("non-existent table '%s' for row-edit", $table)
unless $db;
$db =3D $db->ref();
=20
my $acl =3D UI::Primitive::get_ui_table_acl();
=20
+ my $record;
my $bad;
if ($key) {
eval {
@@ -51,12 +58,20 @@
$bad =3D errmsg('DELETED') if $bad;
};
$bad =3D errmsg('ERROR') if $@;
- if(! $bad and $acl) {
+ if($bad) {
+ # Do nothing, we are already bad
+ }
+ elsif($acl) {
$bad =3D errmsg('Not available')
if ! UI::Primitive::ui_acl_atom($acl, 'keys', $key);
}
+ else {
+ $record =3D $db->row_hash($key);
+ }
}
=20
+ $record ||=3D {};
+
my @cols;
=20
if($columns ||=3D $view->{spread_cols} || $view->{attribute}) {
@@ -108,13 +123,13 @@
}
elsif($key or $opt->{blank}) {
for(@cols) {
- my $text =3D $opt->{blank} ? '' : $db->field($key, $_);
+ my $text =3D $opt->{blank} ? '' : $record->{$_} || '';
my $msg =3D '';
if($do_meta{$_}) {
my $tmp =3D Vend::Tags->display( {
table =3D> $table,
column =3D> $_,
- name =3D> "$prependor$_",
+ name =3D> "$prependor$_$appendor",
value =3D> $text,
template =3D> ' $WIDGET$ ',
});
@@ -125,13 +140,13 @@
my $rows =3D $opt->{height} || 4;
HTML::Entities::encode($text, $ESCAPE_CHARS::std);
$out .=3D <<EOF;
-<TD$ta_extra><TEXTAREA NAME=3D"$prependor$_" COLS=3D"$size" ROWS=3D"$rows"=
>$text</TEXTAREA>$msg</TD>
+<TD$ta_extra><TEXTAREA NAME=3D"$prependor$_$appendor" COLS=3D"$size" ROWS=
=3D"$rows">$text</TEXTAREA>$msg</TD>
EOF
}
else {
$text =3D~ s/"/"/g;
$out .=3D <<EOF;
-<TD$tf_extra><INPUT NAME=3D"$prependor$_" SIZE=3D$size VALUE=3D"$text">$ms=
g</TD>
+<TD$tf_extra><INPUT NAME=3D"$prependor$_$appendor" SIZE=3D$size VALUE=3D"$=
text">$msg</TD>
EOF
}
}
1.12 +153 -3 interchange/code/UI_Tag/table_editor.coretag
rev 1.12, prev_rev 1.11
Index: table_editor.coretag
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/code/UI_Tag/table_editor.coretag,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- table_editor.coretag 12 Aug 2002 17:39:39 -0000 1.11
+++ table_editor.coretag 12 Sep 2002 05:33:29 -0000 1.12
@@ -123,7 +123,7 @@
show_times("begin table editor call item_id=3D$key") if $Global::ShowTimes;
=20
package Vend::Interpolate;
- use vars qw/$Values $Scratch $Db $Tag $Config $CGI $Variable $safe_safe/;
+ use vars qw/$Values $Scratch $Db $Tag $Config $CGI $safe_safe $Session/;
=20
if(ref($opt->{all_opts}) eq 'HASH') {
my $o =3D $opt->{all_opts};
@@ -400,9 +400,9 @@
$key =3D $opt->{item_id};
}
=20
- $opt->{color_success} =3D $Variable->{UI_C_SUCCESS} || '#00FF00'
+ $opt->{color_success} =3D $::Variable->{UI_C_SUCCESS} || '#00FF00'
if ! $opt->{color_success};
- $opt->{color_fail} =3D $Variable->{UI_CONTRAST} || '#FF0000'
+ $opt->{color_fail} =3D $::Variable->{UI_CONTRAST} || '#FF0000'
if ! $opt->{color_fail};
### Build the error checking
my $error_show_var =3D 1;
@@ -1271,7 +1271,153 @@
: $::Variable->{UI_META_LINK};
}
=20
+ my %link_row;
+ my %link_before;
+ if($opt->{link_table} and $key) {
+ my @ltable;
+ my @lfields;
+ my @lkey;
+ my @lview;
+ my @llab;
+ my @ltpl;
+ my @lbefore;
+ my @lsort;
+ my $tcount =3D 1;
+ if(ref($opt->{link_table}) eq 'ARRAY') {
+ @ltable =3D @{$opt->{link_table}};
+ @lfields =3D @{$opt->{link_fields}};
+ @lview =3D @{$opt->{link_view}};
+ @lkey =3D @{$opt->{link_key}};
+ @llab =3D @{$opt->{link_label}};
+ @ltpl =3D @{$opt->{link_template}};
+ @lbefore =3D @{$opt->{link_before}};
+ @lsort =3D @{$opt->{link_sort}};
+ }
+ else {
+ @ltable =3D $opt->{link_table};
+ @lfields =3D $opt->{link_fields};
+ @lview =3D $opt->{link_view};
+ @lkey =3D $opt->{link_key};
+ @llab =3D $opt->{link_label};
+ @ltpl =3D $opt->{link_template};
+ @lbefore =3D $opt->{link_before};
+ @lsort =3D $opt->{link_sort};
+ }
+ while(my $lt =3D shift @ltable) {
+ my $lf =3D shift @lfields;
+ my $lv =3D shift @lview;
+ my $lk =3D shift @lkey;
+ my $ll =3D shift @lkey;
+ my $lb =3D shift @lbefore;
+ my $ls =3D shift @lsort;
+
+ my $rcount =3D 0;
+
+ $ll ||=3D errmsg("Settings in table %s linked by %s", $lt, $lk);
+
+ my $tpl =3D $row_template;
+ my $ldb =3D database_exists_ref($lt)
+ or do {
+ logError("Bad table editor link table: %s", $lt);
+ next;
+ };
+
+ my $lmeta =3D Vend::Tags->meta_record($lt, $lv);
+ $lf ||=3D $lmeta->{spread_fields};
+
+ my $l_pkey =3D $ldb->config('KEY');
+
+ my @cf =3D grep /\S/, split /[\s,\0]+/, $lf;
+ @cf =3D grep $_ ne $l_pkey, @cf;
+ $lf =3D join " ", @cf;
+ my $lextra =3D $opt->{link_extra} || '';
+ $lextra =3D " $lextra" if $lextra;
+ my $labside =3D <<EOF;
+<input type=3Dhidden name=3D"mv_data_table__$tcount" value=3D"$lt">
+<input type=3Dhidden name=3D"mv_data_fields__$tcount" value=3D"$lf">
+<input type=3Dhidden name=3D"mv_data_multiple__$tcount" value=3D"1">
+<input type=3Dhidden name=3D"mv_data_key__$tcount" value=3D"$l_pkey">
+$ll
+EOF
+
+ my @lout =3D q{<table cellspacing=3D0 cellpadding=3D1>};
+ push @lout, qq{<tr><td$lextra>$l_pkey</td>};
+ push @lout, Vend::Tags->row_edit({ table =3D> $lt, columns =3D> $lf });
+ push @lout, '</tr>';
+
+ my $tname =3D $ldb->name();
+ my $lfor =3D $key;
+ $lfor =3D $ldb->quote($key, $lk);
+ my $q =3D "SELECT $l_pkey FROM $tname WHERE $lk =3D $lfor";
+ $q .=3D " ORDER BY $ls" if $ls;
+ my $ary =3D $ldb->query($q);
+ for(@$ary) {
+ my $rk =3D $_->[0];
+ my $pp =3D $rcount ? "${rcount}_" : '';
+ my $hid =3D qq{<input type=3Dhidden name=3D"$pp${l_pkey}__$tcount" val=
ue=3D"};
+ $hid .=3D HTML::Entities::encode($rk);
+ $hid .=3D qq{">};
+ push @lout, qq{<tr><td$lextra>$rk$hid</td>};
+ my %o =3D (
+ table =3D> $lt,
+ key =3D> $_->[0],
+ extra =3D> $opt->{link_extra},
+ pointer =3D> $rcount,
+ stacker =3D> $tcount,
+ columns =3D> $lf,
+ extra =3D> $opt->{link_extra},
+ );
+ $rcount++;
+ push @lout, Vend::Tags->row_edit(\%o);
+ push @lout, "</tr>";
+ }
+ my %o =3D (
+ table =3D> $lt,
+ blank =3D> 1,
+ extra =3D> $opt->{link_extra},
+ pointer =3D> 999999,
+ stacker =3D> $tcount,
+ columns =3D> $lf,
+ extra =3D> $opt->{link_extra},
+ );
+ push @lout, qq{<tr><td$lextra>};
+ push @lout, qq{<input size=3D8 name=3D"999999_${l_pkey}__$tcount" value=
=3D"">};
+ push @lout, '</td>';
+ push @lout, Vend::Tags->row_edit(\%o);
+ push @lout, '</tr>';
+ push @lout, "</table>";
+ $tpl =3D~ s{\$LABEL\$}{$labside}g;
+ $tpl =3D~ s{\$WIDGET\$}{join "", @lout}ge;
+ my $murl =3D '';
+ if($show_meta) {
+ $murl =3D $Tag->page({
+ href =3D> 'admin/db_metaconfig_spread',
+ form =3D> qq(
+ ui_table=3D$lt
+ ui_view=3D$lv
+ ),
+ });
+ $murl .=3D errmsg('meta');
+ $murl .=3D '</a>';
+ }
+ $tpl =3D~ s{\~META\~}{$murl}g;
+ $tpl =3D~ s{\$HELP\$}{}g;
+ $tpl =3D~ s{\~TKEY\~}{}g;
+ $tpl =3D~ s!{HELP_URL}.*?{/HELP_URL}!!gs;
+ $link_row{$lt} =3D $tpl;
+ if($lb) {
+ $link_before{$lb} =3D $lt;
+ }
+ my $mde_key =3D "mv_data_enable__$tcount";
+ $Scratch->{$mde_key} =3D "$lt:" . join(",", $l_pkey, @cf) . ':';
+ $tcount++;
+ }
+ }
+
foreach my $col (@cols) {
+ if($link_before{$col}) {
+ push @controls, delete $link_row{$link_before{$col}};
+ }
my $t;
my $c;
my $k;
@@ -1506,6 +1652,10 @@
$w .=3D $display;
$w .=3D "</TR>\n" unless $rowcount % $rowdiv;
push @controls, $w;
+ }
+
+ for(sort keys %link_row) {
+ push @controls, delete $link_row{$_};
}
=20
my @firstout =3D splice @out, 0;
2.57 +35 -2 interchange/scripts/interchange.PL
rev 2.57, prev_rev 2.56
Index: interchange.PL
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/scripts/interchange.PL,v
retrieving revision 2.56
retrieving revision 2.57
diff -u -r2.56 -r2.57
--- interchange.PL 11 Sep 2002 23:22:55 -0000 2.56
+++ interchange.PL 12 Sep 2002 05:33:29 -0000 2.57
@@ -3,7 +3,7 @@
#
# Interchange version 4.9.3
#
-# $Id: interchange.PL,v 2.56 2002/09/11 23:22:55 mheins Exp $
+# $Id: interchange.PL,v 2.57 2002/09/12 05:33:29 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. and others.
# http://www.icdevgroup.org/
@@ -507,6 +507,7 @@
## Update the user-entered fields.
sub update_data {
my($key,$value);
+ my @cgi_keys =3D keys %CGI::values;
# Update a database record
# Check to see if this is allowed
#::logDebug("mv_data_enable=3D$::Scratch->{mv_data_enable}");
@@ -807,7 +808,7 @@
my @multis;
if($CGI::values{mv_data_multiple}) {
my $re =3D qr/^\d+_$prikey$/;
- @multis =3D grep $_ =3D~ $re, keys %CGI::values;
+ @multis =3D grep $_ =3D~ $re, @cgi_keys;
for(@multis) {
s/_.*//;
}
@@ -973,6 +974,38 @@
if($CGI::values{mv_return_table}) {
$CGI::values{mv_data_table} =3D $CGI::values{mv_return_table};
}
+
+ my @reloads =3D grep /^mv_data_table__\d+$/, keys %CGI::values;
+ if(@reloads) {
+ @reloads =3D map { m/.*__(\d+)$/; $1 } @reloads;
+ @reloads =3D sort { $a <=3D> $b } @reloads;
+ my $new =3D shift @reloads;
+ my $this =3D qr{__$new$};
+ my $some =3D qr{__\d+$};
+#::logDebug("Reloading, new=3D$new this=3D$this some=3D$some");
+ my %cgiset;
+ my @death_row;
+ for(@cgi_keys) {
+ push(@death_row, $_), next unless $_ =3D~ $some;
+ if($_ =3D~ $this) {
+ my $k =3D $_;
+ $k =3D~ s/$this//;
+ $cgiset{$k} =3D delete $CGI::values{$_};
+ }
+ }
+
+ $::Scratch->{mv_data_enable} =3D delete $::Scratch->{"mv_data_enable__$n=
ew"};
+ delete $::Scratch->{mv_data_enable_key};
+
+ for(@death_row) {
+ next unless /^mv_(data|blob|update)_/ or $data{$_}; # Reprieve!
+ delete $CGI::values{$_};
+ }
+
+ @CGI::values{keys %cgiset} =3D values %cgiset;
+ update_data();
+ }
+
return;
}
=20