aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorZarino Zappia <mail@zarino.co.uk>2015-11-24 18:05:57 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-12-16 17:58:16 +0000
commitcbdfcad63e598447c318ce78738d477383f273d7 (patch)
tree3b9b8c9a807beae1d340916eee94e3083f8857ac /perllib
parent749fe96b5b987bec29fb608acfcbdb81e57aaebf (diff)
Add multiple photo upload support.
Three file inputs, progressively enhanced with dropzone. This moves the photo input higher up, so that photos can upload while you're filling out the form. It standardises and improves photo error handling. [fixmystreet.com] Guidance for what photos should and shouldn’t include.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm29
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm18
2 files changed, 35 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index bc72f4bfb..e8025e0a1 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -69,7 +69,7 @@ sub index :LocalRegex('^(c/)?(\d+)(?:\.(\d+))?(?:\.(full|tn|fp))?\.jpeg$') {
$c->detach( 'no_photo' ) if $id =~ /\D/;
($item) = $c->cobrand->problems->search( {
id => $id,
- state => [ FixMyStreet::DB::Result::Problem->visible_states(), 'partial' ],
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
photo => { '!=', undef },
} );
}
@@ -150,6 +150,33 @@ sub _crop {
return $blobs[0];
}
+sub upload : Local {
+ my ( $self, $c ) = @_;
+ my @items = (
+ ( map {
+ /^photo/ ? # photo, photo1, photo2 etc.
+ ($c->req->upload($_)) : ()
+ } sort $c->req->upload),
+ );
+ my $photoset = FixMyStreet::App::Model::PhotoSet->new({
+ c => $c,
+ data_items => \@items,
+ });
+
+ my $fileid = $photoset->data;
+ my $out;
+ if ($c->stash->{photo_error} || !$fileid) {
+ $c->res->status(500);
+ $out = { error => $c->stash->{photo_error} || _('Unknown error') };
+ } else {
+ $out = { id => $fileid };
+ }
+
+ my $body = JSON->new->utf8(1)->encode($out);
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body($body);
+}
+
=head2 process_photo
Handle the photo - either checking and storing it after an upload or retrieving
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 246facbee..4632f450d 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -426,26 +426,21 @@ sub initialize_report : Private {
for (1) { # use as pseudo flow control
- # did we find a token
- last unless $partial;
-
# is it in the database
my $token =
$c->model("DB::Token")
- ->find( { scope => 'partial', token => $partial } ) #
+ ->find( { scope => 'partial', token => $partial } )
|| last;
# can we get an id from it?
- my $id = $token->data #
- || last;
+ my $id = $token->data || last;
# load the related problem
- $report = $c->cobrand->problems #
- ->search( { id => $id, state => 'partial' } ) #
+ $report = $c->cobrand->problems
+ ->search( { id => $id, state => 'partial' } )
->first;
if ($report) {
-
# log the problem creation user in to the site
$c->authenticate( { email => $report->user->email },
'no_password' );
@@ -453,9 +448,10 @@ sub initialize_report : Private {
# save the token to delete at the end
$c->stash->{partial_token} = $token if $report;
- }
- else {
+ # Stash the photo IDs for "already got" display
+ $c->stash->{upload_fileid} = $report->get_photoset($c)->data;
+ } else {
# no point keeping it if it is done.
$token->delete;
}