Reverted menu-left-example.png back to original and cleaned up menu-top-example to...
[freeside.git] / httemplate / edit / upload_target.html
1 <& elements/edit.html,
2   'post_url'    => popurl(1).'process/upload_target.html',
3   'name'        => 'Upload target',
4   'table'       => 'upload_target',
5   'viewall_url' => "${p}browse/upload_target.html",
6   'labels'      => { targetnum => 'Target',
7                      protocol  => 'Protocol',
8                      handling  => 'Special handling',
9                    },
10   'fields'      => [
11                      { field    => 'protocol',
12                        type     => 'selectlayers',
13                        options  => [ '', 'sftp', 'ftp', 'email' ],
14                        labels   => { ''      => '',
15                                      'email' => 'Email',
16                                      'sftp'  => 'SFTP',
17                                      'ftp'   => 'FTP',
18                                    },
19                        layer_fields => \%protocol_fields,
20                        layer_values_callback => \&values_callback,
21                      },
22                      { field => 'handling', 
23                        type => 'select',
24                        options => [ FS::upload_target->handling_types ],
25                      },
26                    ],
27   'menubar'     => \@menubar,
28   'edit_callback' => $edit_callback,
29 &>
30 <%init>
31
32 my $curuser = $FS::CurrentUser::CurrentUser;
33
34 die "access denied"
35   unless $curuser->access_right('Configuration');
36
37 my @menubar = ('View all FTP targets' => $p.'browse/upload_target.html');
38 my $edit_callback = sub {
39   my ($cgi, $object) = @_;
40   if ( $object->targetnum ) {
41     push @menubar, 'Delete this target', 
42                    $p.'misc/delete-upload_target.html?'.$object->targetnum;
43   }
44 };
45
46 my %protocol_fields = (
47   '' => [],
48   'sftp'   => [
49     'hostname' => { label => 'Server' },
50     'username' => { label => 'Username' },
51     'password' => { label => 'Password' },
52     'port'     => { label => 'Port', size => 8 },
53     'path'     => { label => 'Path', size => 30 },
54   ],
55   'email' => [
56     'username' => { label => 'To:' },
57     'hostname' => { label => '@' },
58     'subject'  => { label => 'Subject:' },
59   ],
60 );
61 $protocol_fields{'ftp'} = [ @{ $protocol_fields{'sftp'} } ];
62 foreach my $k (keys %protocol_fields) {
63   # disambiguate the field names
64   foreach (@{ $protocol_fields{$k} }) {
65     $_ = $k.'_'.$_ unless ref $_;
66   }
67 }
68
69 sub values_callback {
70   my ($cgi, $object) = @_;
71   my $layer_values;
72   # really simple, the interpretation of the fields is the same for all 
73   # three layers
74   foreach my $l (qw(email ftp sftp)) {
75     $layer_values->{$l} = { map { $l.'_'.$_ => ($cgi->param($l.'_'.$_) || 
76                                                 $object->get($_) ) }
77                             $object->fields };
78   }
79   $layer_values;
80 }
81
82 </%init>