-
Notifications
You must be signed in to change notification settings - Fork 27
/
imagehelper.widget
77 lines (72 loc) · 2.49 KB
/
imagehelper.widget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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/,/,/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> <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