aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-01 16:53:20 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-01 16:53:20 +0100
commit720fc7ff7f9a375389ae4ba67bb56ce55587363a (patch)
tree0d427dc8b51a52163ec91690a33af930b21484cc
parent8d841abcf6a6539344094927ffb7b82d38b70473 (diff)
display and save extra info for open311 reports
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm29
-rw-r--r--templates/web/default/common_header_tags.html6
-rw-r--r--templates/web/default/report/new/fill_in_details.html18
-rw-r--r--web/js/fixmystreet.js17
4 files changed, 68 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index ed9266632..cd943070d 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -15,6 +15,7 @@ use Path::Class;
use Utils;
use mySociety::EmailUtil;
use mySociety::TempFiles;
+use JSON;
=head1 NAME
@@ -449,6 +450,7 @@ sub setup_categories_and_councils : Private {
my %area_ids_to_list = (); # Areas with categories assigned
my @category_options = (); # categories to show
my $category_label = undef; # what to call them
+ my %category_extras = (); # extra fields to fill in for open311
# FIXME - implement in cobrand
if ( $c->cobrand->moniker eq 'emptyhomes' ) {
@@ -495,8 +497,12 @@ sub setup_categories_and_councils : Private {
next if $contact->category eq _('Other');
- push @category_options, $contact->category
- unless $seen{$contact->category};
+ unless ( $seen{$contact->category} ) {
+ push @category_options, $contact->category;
+
+ $category_extras{ $contact->category } = $contact->extra
+ if $contact->extra;
+ }
$seen{$contact->category} = 1;
}
@@ -511,6 +517,7 @@ sub setup_categories_and_councils : Private {
$c->stash->{area_ids_to_list} = [ keys %area_ids_to_list ];
$c->stash->{category_label} = $category_label;
$c->stash->{category_options} = \@category_options;
+ $c->stash->{category_extras} = encode_json \%category_extras;
my @missing_details_councils =
grep { !$area_ids_to_list{$_} } #
@@ -682,6 +689,24 @@ sub process_report : Private {
if $council_string && @{ $c->stash->{missing_details_councils} };
$report->council($council_string);
+ my @extra = ();
+ my $metas = $contacts[0]->extra;
+
+ foreach my $field ( @{ $metas->{attribute} } ) {
+ if ( lc( $field->{required} ) eq 'true' ) {
+ unless ( $c->request->param( $field->{code} ) ) {
+ $c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
+ }
+ }
+ push @extra, {
+ name => $field->{code},
+ description => $field->{description},
+ value => $c->request->param( $field->{code} ),
+ };
+ }
+
+ $c->stash->{report_meta} = \@extra if @extra;
+ $report->extra( \@extra ) if @extra;
} elsif ( @{ $c->stash->{area_ids_to_list} } ) {
# There was an area with categories, but we've not been given one. Bail.
diff --git a/templates/web/default/common_header_tags.html b/templates/web/default/common_header_tags.html
index f9048b067..35218bc1c 100644
--- a/templates/web/default/common_header_tags.html
+++ b/templates/web/default/common_header_tags.html
@@ -4,6 +4,12 @@
[% map_js %]
+[% IF category_extras && category_extras != '{}' %]
+<script type="text/javascript">
+ category_extras = [% category_extras %];
+</script>
+[% END %]
+
[% IF robots %]
<meta name="robots" content="[% robots %]">
[% ELSIF c.config.STAGING_SITE %]
diff --git a/templates/web/default/report/new/fill_in_details.html b/templates/web/default/report/new/fill_in_details.html
index 32d4a733b..8e8134c3a 100644
--- a/templates/web/default/report/new/fill_in_details.html
+++ b/templates/web/default/report/new/fill_in_details.html
@@ -100,6 +100,24 @@
<textarea name="detail" id="form_detail" rows="7" cols="26">[% report.detail | html %]</textarea>
</div>
+[% IF category_extras %]
+<div id="category_meta">
+ [% IF report_meta %]
+ [% FOR meta IN report_meta %]
+ [% meta_name = meta.name %]
+[% IF field_errors.$meta_name %]
+ <div class='form-error'>[% field_errors.$meta_name %]</div>
+[% END %]
+
+<div class="form-field">
+ <label for="form_[% meta %]">[% meta.description _ ':' %]</label>
+ <input type="text" value="[% meta.value | html %]" name="[% meta_name %]" id="form_[% meta_name %]">
+</div>
+ [% END %]
+ [% END %]
+</div>
+[% END %]
+
[% IF c.cobrand.allow_photo_upload %]
[% IF field_errors.photo %]
<div class='form-error'>[% field_errors.photo %]</div>
diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js
index 4b19dc53e..2ebf74751 100644
--- a/web/js/fixmystreet.js
+++ b/web/js/fixmystreet.js
@@ -57,4 +57,21 @@ $(function(){
timer = window.setTimeout(email_alert_close, 2000);
});
+ $('#form_category').change(function() {
+ if ( category_extras ) {
+ $('#category_meta').empty();
+ if ( category_extras[this.options[ this.selectedIndex ].text] ) {
+ extras = category_extras[this.options[ this.selectedIndex ].text].attribute;
+ for ( i in extras ) {
+ meta = extras[i];
+ field = '<div class="form-field">';
+ field += '<label for="form_' + meta.code + '">' + meta.description + '</label>';
+ field += '<input type="text" value="" name="' + meta.code + '" id="form_' + meta.code + '">';
+ field += '</div>';
+ $('<p>' + field + '</p>').appendTo('#category_meta');
+ }
+ }
+ }
+ });
+
});