diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-19 12:29:25 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-19 14:29:07 +0100 |
commit | e51bb2af37fbfe6efd3fad9a79e51010f6cad1aa (patch) | |
tree | 2bce3d55d7603782cdcfb53991f844948237134e | |
parent | 0d5e096bad80e2f5969c79d489edbd3996e15987 (diff) |
Get contribution state from server with map click.
This makes sure the correct dropdown is shown.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 10 | ||||
-rw-r--r-- | templates/web/base/report/new/form_user_loggedin.html | 17 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 17 |
3 files changed, 40 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 86026f8e6..6934c6d79 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -186,6 +186,15 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $extra_titles_list = $c->cobrand->title_list($c->stash->{all_areas}); + my $contribute_as = {}; + if ($c->user_exists) { + my $bodies = join(',', keys %{$c->stash->{bodies}}); + my $ca_another_user = $c->user->has_permission_to('contribute_as_another_user', $bodies); + my $ca_body = $c->user->has_permission_to('contribute_as_body', $bodies); + $contribute_as->{another_user} = $ca_another_user if $ca_another_user; + $contribute_as->{body} = $ca_body if $ca_body; + } + my $body = encode_json( { councils_text => $councils_text, @@ -193,6 +202,7 @@ sub report_form_ajax : Path('ajax') : Args(0) { extra_name_info => $extra_name_info, titles_list => $extra_titles_list, categories => $c->stash->{category_options}, + %$contribute_as ? (contribute_as => $contribute_as) : (), } ); diff --git a/templates/web/base/report/new/form_user_loggedin.html b/templates/web/base/report/new/form_user_loggedin.html index 79b8d866e..49ead784c 100644 --- a/templates/web/base/report/new/form_user_loggedin.html +++ b/templates/web/base/report/new/form_user_loggedin.html @@ -1,20 +1,29 @@ <div class="form-box" id="form-box--logged-in-name"> +[% IF js %] + <div style="display:none" id="js-contribute-as-wrapper"> + [% INCLUDE form_as %] + </div> +[% ELSE %] [% can_contribute_as_another_user = c.user.has_permission_to("contribute_as_another_user", bodies.keys.join(",")) %] [% can_contribute_as_body = c.user.from_body AND c.user.has_permission_to("contribute_as_body", bodies.keys.join(",")) %] - [% IF can_contribute_as_another_user OR can_contribute_as_body %] + [% INCLUDE form_as %] + [% END %] +[% END %] + +[% BLOCK form_as %] <label for="form_as">[% loc('Report as') %]</label> <select id="form_as" class="js-contribute-as" name="form_as"> <option value="myself" selected>[% loc('Yourself') %]</option> - [% IF can_contribute_as_another_user %] + [% IF js || can_contribute_as_another_user %] <option value="another_user">[% loc('Another user') %]</option> [% END %] - [% IF can_contribute_as_body %] + [% IF js || can_contribute_as_body %] <option value="body">[% c.user.from_body.name %]</option> [% END %] </select> - [% END %] +[% END %] <label for="form_email">[% loc('Email address') %]</label> <input id="form_email" diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index d98730b62..8935712cc 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -819,6 +819,23 @@ fixmystreet.update_pin = function(lonlat, savePushState) { if (category_select.val() != '-- Pick a category --') { category_select.change(); } + + if (data.contribute_as) { + var $select = $('.js-contribute-as'); + if (!$select.data('original')) { + $select.data('original', $select.html()); + } + $select.html($select.data('original')); + if (!data.contribute_as.another_user) { + $select.find('option[value=another_user]').remove(); + } + if (!data.contribute_as.body) { + $select.find('option[value=body]').remove(); + } + $('#js-contribute-as-wrapper').show(); + } else { + $('#js-contribute-as-wrapper').hide(); + } }); if (!$('#side-form-error').is(':visible')) { |