[interchange-cvs] interchange - heins modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Fri May 13 00:10:58 EDT 2005


User:      heins
Date:      2005-05-13 04:10:58 GMT
Modified:  lib/Vend Data.pm
Modified:  code/Widget imagehelper.widget
Log:
* Change imagehelper routine and its accompanying Data.pm routine to
  allow it to rename the image to match a field name.

  Noticed when showing a new user the item input that they had no
  non-manual way to get the rightly named image up there -- of
  course they had saved their image with some long quote-filled
  name.

  If you set the extended.name_from_field to "sku", it will automatically
  rename "Some very long name, it's a Windows thing.jpg" to 00001.jpg (or
  whatever the SKU is).

Revision  Changes    Path
2.50      +15 -1     interchange/lib/Vend/Data.pm


rev 2.50, prev_rev 2.49
Index: Data.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Data.pm,v
retrieving revision 2.49
retrieving revision 2.50
diff -u -r2.49 -r2.50
--- Data.pm	12 May 2005 17:54:37 -0000	2.49
+++ Data.pm	13 May 2005 04:10:58 -0000	2.50
@@ -1,6 +1,6 @@
 # Vend::Data - Interchange databases
 #
-# $Id: Data.pm,v 2.49 2005/05/12 17:54:37 mheins Exp $
+# $Id: Data.pm,v 2.50 2005/05/13 04:10:58 mheins Exp $
 # 
 # Copyright (C) 2002-2004 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -1908,6 +1908,7 @@
 
     my @file_fields = split /[\s\0,]+/, $CGI::values{mv_data_file_field};
     my @file_paths = split /\0/, $CGI::values{mv_data_file_path};
+    my @file_name_from = split /\0/, $CGI::values{mv_data_file_name_from};
     my @file_oldfiles = split /\0/, $CGI::values{mv_data_file_oldfile};
 
 	if($en_col) {
@@ -2049,6 +2050,19 @@
 			# remove path components
 			$dref->[0] =~ s:.*/::; 
 			$dref->[0] =~ s:.*\\::; 
+
+			if(my $switch = $file_name_from[$i]) {
+				my $new;
+				if($data{$switch} and $new = $data{$switch}->[0]) {
+					my $ext = $dref->[0];
+					if($ext =~ s/.*\.//) {
+						$dref->[0] = join '.', $new, $ext;
+					}
+					else {
+						$dref->[0] = $new;
+					}
+				}
+			}
 
 			if (length ($file_paths[$i])) {
 				# real file upload



1.4       +22 -2     interchange/code/Widget/imagehelper.widget


rev 1.4, prev_rev 1.3
Index: imagehelper.widget
===================================================================
RCS file: /var/cvs/interchange/code/Widget/imagehelper.widget,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- imagehelper.widget	12 Apr 2005 19:19:27 -0000	1.3
+++ imagehelper.widget	13 May 2005 04:10:58 -0000	1.4
@@ -8,6 +8,7 @@
 	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);
@@ -37,12 +38,31 @@
 	}
 	$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">
+        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">
+        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








More information about the interchange-cvs mailing list