aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Photo.pm
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/FixMyStreet/App/Controller/Photo.pm
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/FixMyStreet/App/Controller/Photo.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm29
1 files changed, 28 insertions, 1 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