aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/open311-populate-service-list14
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm7
-rw-r--r--templates/web/default/common_header_tags.html4
-rw-r--r--templates/web/default/report/new/fill_in_details.html15
-rw-r--r--web/js/fixmystreet.js14
5 files changed, 36 insertions, 18 deletions
diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list
index 2e65bf4fd..2a6733ef1 100755
--- a/bin/open311-populate-service-list
+++ b/bin/open311-populate-service-list
@@ -77,12 +77,14 @@ while ( my $council = $council_list->next ) {
my $meta_data = $open311->get_service_meta_info( $service->{service_code} );
# turn the data into something a bit more friendly to use
- my %meta = ();
- foreach my $attribute ( @{ $meta_data->{attributes}->{attribute} } ) {
- $meta{ $attribute->{code} } = $attribute;
- }
-
- $contact->extra( \%meta );
+ my @meta =
+ # remove trailing colon as we add this when we display so we don't want 2
+ map { $_->{description} =~ s/:\s*//; $_ }
+ # there is a display order and we only want to sort once
+ sort { $a->{order} <=> $b->{order} }
+ @{ $meta_data->{attributes}->{attribute} };
+
+ $contact->extra( \@meta );
$contact->update;
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 63add43ee..d418becb9 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -500,7 +500,7 @@ sub setup_categories_and_councils : Private {
unless ( $seen{$contact->category} ) {
push @category_options, $contact->category;
- $category_extras{ $contact->category } = [ values %{$contact->extra} ]
+ $category_extras{ $contact->category } = $contact->extra
if $contact->extra;
}
$seen{$contact->category} = 1;
@@ -517,7 +517,8 @@ 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;
+ $c->stash->{category_extras} = \%category_extras;
+ $c->stash->{category_extras_json} = encode_json \%category_extras;
my @missing_details_councils =
grep { !$area_ids_to_list{$_} } #
@@ -699,7 +700,7 @@ sub process_report : Private {
my @extra = ();
my $metas = $contacts[0]->extra;
- foreach my $field ( sort { $a->{order} <=> $b->{order} } values %$metas ) {
+ foreach my $field ( @$metas ) {
if ( lc( $field->{required} ) eq 'true' ) {
unless ( $c->request->param( $field->{code} ) ) {
$c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
diff --git a/templates/web/default/common_header_tags.html b/templates/web/default/common_header_tags.html
index 35218bc1c..206a0e6d4 100644
--- a/templates/web/default/common_header_tags.html
+++ b/templates/web/default/common_header_tags.html
@@ -4,9 +4,9 @@
[% map_js %]
-[% IF category_extras && category_extras != '{}' %]
+[% IF category_extras_json && category_extras_json != '{}' %]
<script type="text/javascript">
- category_extras = [% category_extras %];
+ category_extras = [% category_extras_json %];
</script>
[% END %]
diff --git a/templates/web/default/report/new/fill_in_details.html b/templates/web/default/report/new/fill_in_details.html
index df43fc254..6beb77802 100644
--- a/templates/web/default/report/new/fill_in_details.html
+++ b/templates/web/default/report/new/fill_in_details.html
@@ -105,9 +105,10 @@
[%- IF category_extras %]
<div id="category_meta">
[%- IF report_meta %]
+ [%- category = report.category %]
<h4>Additional Information</h4>
- [%- FOR meta IN report_meta %]
- [%- meta_name = meta.name -%]
+ [%- FOR meta IN category_extras.$category %]
+ [%- meta_name = meta.code -%]
[% IF field_errors.$meta_name %]
<div class='form-error'>[% field_errors.$meta_name %]</div>
@@ -115,7 +116,15 @@
<div class="form-field">
<label for="form_[% meta_name %]">[% meta.description _ ':' %]</label>
- <input type="text" value="[% meta.value | html %]" name="[% meta_name %]" id="form_[% meta_name %]">
+ [% IF meta.exists('values') %]
+ <select name="[% meta_name %]" id="form_[% meta_name %]">
+ [% FOR option IN meta.values.value.keys %]
+ <option value="[% meta.$foo.value.$option.key %]">[% option %]</option>
+ [% END %]
+ </select>
+ [% ELSE %]
+ <input type="text" value="[% report_meta.$meta_name | html %]" name="[% meta_name %]" id="form_[% meta_name %]">
+ [% END %]
</div>
[%- END %]
[%- END %]
diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js
index 3c5c56454..9fa0f948b 100644
--- a/web/js/fixmystreet.js
+++ b/web/js/fixmystreet.js
@@ -63,13 +63,19 @@ $(function(){
if ( category_extras[this.options[ this.selectedIndex ].text] ) {
var fields = category_extras[this.options[ this.selectedIndex ].text];
$('<h4>Additional information</h4>').appendTo('#category_meta');
- fields.sort( function(a,b) { return a.order - b.order } );
for ( var i in fields) {
- var field = '';
var meta = fields[i];
- field = '<div class="form-field">';
+ var 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 + '">';
+ if ( meta.values ) {
+ field += '<select name="' + meta.code + '" id="form_' + meta.code + '">';
+ for ( var j in meta.values.value ) {
+ field += '<option value="' + meta.values.value[j].key + '">' + j + '</option>';
+ }
+ field += '</select>';
+ } else {
+ field += '<input type="text" value="" name="' + meta.code + '" id="form_' + meta.code + '">';
+ }
field += '</div>';
$( field ).appendTo('#category_meta');
}