3039aed35cf75e13b54aa4d7b39c925a87b92a9c
[freeside.git] / httemplate / edit / saved_search.html
1 <& elements/edit.html,
2   'name'   => 'saved search',
3   'table'  => 'saved_search',
4   'popup'  => 1,
5   'fields' => [
6     { field   => 'searchname',
7       type    => 'text',
8       size    => 40,
9     },
10     { field   => 'freq',
11       type    => 'select',
12       options => [ '', 'daily', 'weekly', 'monthly' ],
13       labels  => { '' => 'no' },
14     },
15     { field   => 'emailaddress',
16       type    => 'fixed',
17       curr_value_callback => sub {
18         $curuser->option('email_address')
19         || 'no email address configured'
20       },
21     },
22     { field   => 'last_sent',
23       type    => 'fixed-date',
24     },
25     { field   => 'format',
26       type    => 'hidden', # revisit this later
27 #      type    => 'select',
28 #      options => [ 'html', 'xls', 'csv' ],
29 #      labels => {
30 #        'html' => 'webpage',
31 #        'xls'  => 'spreadsheet',
32 #        'csv'  => 'CSV',
33 #      },
34     },
35     { field => 'disabled', # currently unused
36       type  => 'hidden',
37     },
38     { type  => 'tablebreak-tr-title' },
39     { field => 'path',
40       type  => 'fixed',
41       cell_style => 'font-size: small',
42     },
43     { field => 'params',
44       type  => 'fixed',
45       cell_style => 'font-size: small',
46     },
47   ],
48   'labels' => {
49     'searchnum'         => 'Saved search',
50     'searchname'        => 'Name this search',
51     'path'              => 'Search page',
52     'params'            => 'Parameters',
53     'freq'              => 'Subscribe by email',
54     'last_sent'         => 'Last sent on',
55     'emailaddress'      => 'Will be sent to',
56     'format'            => 'Report format',
57   },
58   'new_object_callback' => $new_object,
59   'delete_url'          => $fsurl.'misc/delete-saved_search.html',
60 &>
61 <%init>
62
63 my $curuser = $FS::CurrentUser::CurrentUser;
64
65 # prefix to the freeside document root (usually '/freeside/')
66 my $root = URI->new($fsurl)->path;
67
68 # alternatively, could do all this on the client using window.top.location
69 my $new_object = sub {
70   my $cgi = shift;
71   my $hashref = shift;
72   my $fields = shift;
73   for (grep { $_->{field} eq 'last_sent' } @$fields) {
74     $_->{type} = 'hidden';
75   }
76   my $url = $r->header_in('Referer')
77     or die "no referring page found";
78   $url = URI->new($url);
79   my $path = $url->path;
80   $path =~ s/^$root//; # path should not have a leading slash
81   my $title = $cgi->param('title');
82   return FS::saved_search->new({
83     'usernum'     => $curuser->usernum,
84     'path'        => $path,
85     'params'      => $url->query,
86     'format'      => 'html',
87     'searchname'  => $title,
88   });
89 };
90
91 </%init>