diff options
author | Mark Wells <mark@freeside.biz> | 2016-09-08 11:25:59 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2016-09-08 11:25:59 -0700 |
commit | 87194c546606205e78e36f99ec1f2ae6f0a9cafc (patch) | |
tree | 08fe22e3bf25a0ffbde7257675c617db9a55e42d /httemplate/edit | |
parent | 4b75f33fd6c2d0fecf8714f588f2d6d200aa4d47 (diff) |
add UI to manage saved searches, #72101
Diffstat (limited to 'httemplate/edit')
-rw-r--r-- | httemplate/edit/process/saved_search.html | 15 | ||||
-rw-r--r-- | httemplate/edit/saved_search.html | 91 |
2 files changed, 106 insertions, 0 deletions
diff --git a/httemplate/edit/process/saved_search.html b/httemplate/edit/process/saved_search.html new file mode 100644 index 000000000..7ae7e0d78 --- /dev/null +++ b/httemplate/edit/process/saved_search.html @@ -0,0 +1,15 @@ +<& elements/process.html, + 'table' => 'saved_search', + 'popup_reload' => 'Saving', + 'post_new_object_callback' => $callback, +&> +<%init> + +my $callback = sub { + my ($cgi, $obj) = @_; + $obj->usernum( $FS::CurrentUser::CurrentUser->usernum ); + # if this would change it from its existing owner, replace_check + # will refuse +}; + +</%init> diff --git a/httemplate/edit/saved_search.html b/httemplate/edit/saved_search.html new file mode 100644 index 000000000..3039aed35 --- /dev/null +++ b/httemplate/edit/saved_search.html @@ -0,0 +1,91 @@ +<& elements/edit.html, + 'name' => 'saved search', + 'table' => 'saved_search', + 'popup' => 1, + 'fields' => [ + { field => 'searchname', + type => 'text', + size => 40, + }, + { field => 'freq', + type => 'select', + options => [ '', 'daily', 'weekly', 'monthly' ], + labels => { '' => 'no' }, + }, + { field => 'emailaddress', + type => 'fixed', + curr_value_callback => sub { + $curuser->option('email_address') + || 'no email address configured' + }, + }, + { field => 'last_sent', + type => 'fixed-date', + }, + { field => 'format', + type => 'hidden', # revisit this later +# type => 'select', +# options => [ 'html', 'xls', 'csv' ], +# labels => { +# 'html' => 'webpage', +# 'xls' => 'spreadsheet', +# 'csv' => 'CSV', +# }, + }, + { field => 'disabled', # currently unused + type => 'hidden', + }, + { type => 'tablebreak-tr-title' }, + { field => 'path', + type => 'fixed', + cell_style => 'font-size: small', + }, + { field => 'params', + type => 'fixed', + cell_style => 'font-size: small', + }, + ], + 'labels' => { + 'searchnum' => 'Saved search', + 'searchname' => 'Name this search', + 'path' => 'Search page', + 'params' => 'Parameters', + 'freq' => 'Subscribe by email', + 'last_sent' => 'Last sent on', + 'emailaddress' => 'Will be sent to', + 'format' => 'Report format', + }, + 'new_object_callback' => $new_object, + 'delete_url' => $fsurl.'misc/delete-saved_search.html', +&> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +# prefix to the freeside document root (usually '/freeside/') +my $root = URI->new($fsurl)->path; + +# alternatively, could do all this on the client using window.top.location +my $new_object = sub { + my $cgi = shift; + my $hashref = shift; + my $fields = shift; + for (grep { $_->{field} eq 'last_sent' } @$fields) { + $_->{type} = 'hidden'; + } + my $url = $r->header_in('Referer') + or die "no referring page found"; + $url = URI->new($url); + my $path = $url->path; + $path =~ s/^$root//; # path should not have a leading slash + my $title = $cgi->param('title'); + return FS::saved_search->new({ + 'usernum' => $curuser->usernum, + 'path' => $path, + 'params' => $url->query, + 'format' => 'html', + 'searchname' => $title, + }); +}; + +</%init> |