From 284b74472e30db0f1b1e82a4538f4bebfc0b67a5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 20 Oct 2011 18:03:34 +0100 Subject: make the additional information fields work with js update of category dropdown --- web/js/fixmystreet.js | 59 ++++++++++++++++++++++++++++-------------------- web/js/map-OpenLayers.js | 4 ++++ 2 files changed, 38 insertions(+), 25 deletions(-) (limited to 'web/js') diff --git a/web/js/fixmystreet.js b/web/js/fixmystreet.js index 3d07c61ec..a0ea02437 100644 --- a/web/js/fixmystreet.js +++ b/web/js/fixmystreet.js @@ -3,6 +3,38 @@ * FixMyStreet JavaScript */ +function form_category_onchange() { + if ( category_extras ) { + if ( $('#category_meta').size() ) { + $('#category_meta').empty(); + } else { + $('#form_category_row').after( + '
' + ); + } + if ( category_extras[this.options[ this.selectedIndex ].text] ) { + var fields = category_extras[this.options[ this.selectedIndex ].text]; + $('

Additional information

').appendTo('#category_meta'); + for ( var i in fields) { + var meta = fields[i]; + var field = '
'; + field += ''; + if ( meta.values ) { + field += ''; + } else { + field += ''; + } + field += '
'; + $( field ).appendTo('#category_meta'); + } + } + } +} + $(function(){ $('html').removeClass('no-js').addClass('js'); @@ -59,31 +91,8 @@ $(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] ) { - var fields = category_extras[this.options[ this.selectedIndex ].text]; - $('

Additional information

').appendTo('#category_meta'); - for ( var i in fields) { - var meta = fields[i]; - var field = '
'; - field += ''; - if ( meta.values ) { - field += ''; - } else { - field += ''; - } - field += '
'; - $( field ).appendTo('#category_meta'); - } - } - } - }); + + $('#form_category').change( form_category_onchange ); // Geolocation if (geo_position_js.init()) { diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 0f9974222..d754248f4 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -315,6 +315,10 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { }, function(data) { $('#councils_text').html(data.councils_text); $('#form_category_row').html(data.category); + eval( 'category_extras = ' + data.category_extras + ';'); + /* Need to reset this here as it gets removed when we replace + the HTML for the dropdown */ + $('#form_category').change( form_category_onchange ); }); $('#side-form').show(); $('#side').hide(); -- cgit v1.2.3