Skip to content

Commit

Permalink
* Move several widgets outboard into code/Widget.
Browse files Browse the repository at this point in the history
	* These are widgets that have some dependency on foundation/UI
	  setup and are not really generic.

	* Corresponding code removed from UI::Primitive.
  • Loading branch information
perusionmike committed Feb 3, 2002
1 parent bcc80b8 commit 4e9405e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 102 deletions.
36 changes: 36 additions & 0 deletions code/Widget/imagedir.widget
@@ -0,0 +1,36 @@
CodeDef imagedir Widget 1
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$}o;
};
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, $dir);
$opt->{passed} = [ sort @names ];
$opt->{type} = delete $opt->{variant} || 'combo';
return Vend::Form::display($opt);
}
EOR
47 changes: 47 additions & 0 deletions code/Widget/imagehelper.widget
@@ -0,0 +1,47 @@
CodeDef imagehelper Widget 1
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 $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 = 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_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_path VALUE="$path">$of_widget<INPUT TYPE=file NAME="$name"$size>};
}
}
EOR

34 changes: 34 additions & 0 deletions code/Widget/uploadhelper.widget
@@ -0,0 +1,34 @@
CodeDef uploadhelper Widget 1
CodeDef uploadhelper Routine <<EOR
sub {
# $column, $value, $record->{outboard}, $record->{width}
my ($opt) = @_;
my $name = $opt->{name};
my $val = $opt->{value};
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;
$out .= "</A>" if $path;
$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">};
}
else {
$out = qq{<INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
<INPUT TYPE=file NAME="$name"$size>};
}
return $out;
}
EOR

104 changes: 2 additions & 102 deletions dist/lib/UI/Primitive.pm
@@ -1,6 +1,6 @@
# UI::Primitive - Interchange configuration manager primitives

# $Id: Primitive.pm,v 2.13 2002-02-02 17:25:47 mheins Exp $
# $Id: Primitive.pm,v 2.14 2002-02-03 22:01:57 mheins Exp $

# Copyright (C) 1998-2001 Red Hat, Inc. <interchange@redhat.com>

Expand All @@ -25,7 +25,7 @@ my($order, $label, %terms) = @_;

package UI::Primitive;

$VERSION = substr(q$Revision: 2.13 $, 10);
$VERSION = substr(q$Revision: 2.14 $, 10);

$DEBUG = 0;

Expand Down Expand Up @@ -622,70 +622,6 @@ sub rotate {
return 1;
}

sub uploadhelper_widget {
# $column, $value, $record->{outboard}, $record->{width}
my ($name, $val, $path, $size) = @_;

$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;
$out .= "</A>" if $path;
$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">};
}
else {
$out = qq{<INPUT TYPE=hidden NAME="ui_upload_file_path:$name" VALUE="$path">
<INPUT TYPE=file NAME="$name"$size>};
}
return $out;
}

sub imagehelper_widget {
my ($name, $val, $path, $imagebase, $size) = @_;

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 = 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_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_path VALUE="$path">$of_widget<INPUT TYPE=file NAME="$name"$size>};
}
}

sub meta_record {
my ($item, $view, $mtable) = @_;
Expand Down Expand Up @@ -882,42 +818,6 @@ sub meta_display {
return $w unless $o->{template};
return ($w, $record->{label}, $record->{help}, $record->{help_url});
}
elsif ($record->{type} eq 'imagedir') {
my $dir = $record->{'outboard'} || $column;
my $suf;
if($record->{options}) {
$suf = $record->{options};;
if($suf !~ /[\.|]/) {
my @types = grep /\S/, split /[,\s\0]+/, $suf;
$suf = '\.(' . join("|", @types) . ')';
}
}
my @files = list_images($dir, $suf);
$record->{type} = 'combo';
$record->{passed} = join ",",
map { s/,/&#44;/g; $_} @files;
}
elsif ($record->{type} eq 'imagehelper') {
my $w = imagehelper_widget(
$record->{name},
$value,
$record->{outboard},
$record->{prepend},
$record->{width},
);
return $w unless $o->{template};
return ($w, $record->{label}, $record->{help}, $record->{help_url});
}
elsif ($record->{type} eq 'uploadhelper') {
my $w = uploadhelper_widget(
$record->{name},
$value,
$record->{outboard},
$record->{width},
);
return $w unless $o->{template};
return ($w, $record->{label}, $record->{help}, $record->{help_url});
}

for(qw/append prepend/) {
next unless $record->{$_};
Expand Down

0 comments on commit 4e9405e

Please sign in to comment.