diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-13 12:06:57 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-13 12:06:57 +0100 |
commit | 959acf33e06ea8ea3bae7fa89e800dfd8c45621e (patch) | |
tree | 0398c64f904a2befa07cac899c388f7a03c9fdd3 | |
parent | acec961ab9961b69e43a7cc95616577021bbd47d (diff) |
display problem and update information as appropriate
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 86 | ||||
-rw-r--r-- | t/app/controller/contact.t | 34 | ||||
-rw-r--r-- | templates/web/default/contact/index.html | 51 |
3 files changed, 171 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 6054dd326..2980b3811 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -26,6 +26,92 @@ sub index :Path :Args(0) { $c->stash->{contact_email} = $c->cobrand->contact_email; $c->stash->{contact_email} =~ s/\@/@/; + + $c->forward('determine_contact_type'); + +# my ($q, $errors, $field_errors) = @_; +# my @errors = @$errors; +# my %field_errors = %{$field_errors}; +# push @errors, _('There were problems with your report. Please see below.') if (scalar keys %field_errors); +# my @vars = qw(name em subject message); +# my %input = map { $_ => $q->param($_) || '' } @vars; +# my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; +# my $out = ''; + +# my $cobrand = Page::get_cobrand($q); +# my $form_action = Cobrand::url($cobrand, '/contact', $q); +# +# my $intro = ''; +# my $item_title = ''; +# my $item_body = ''; +# my $item_meta = ''; +# my $hidden_vals = ''; + +# my $cobrand_form_elements = Cobrand::form_elements(Page::get_cobrand($q), 'contactForm', $q); +# my %vars = ( +# header => $header, +# errors => $errors, +# intro => $intro, +# item_title => $item_title, +# item_meta => $item_meta, +# item_body => $item_body, +# hidden_vals => $hidden_vals, +# form_action => $form_action, +# input_h => \%input_h, +# field_errors => \%field_errors, +# label_name => _('Your name:'), +# label_email => _('Your email:'), +# label_subject => _('Subject:'), +# label_message => _('Message:'), +# label_submit => _('Post'), +# contact_details => contact_details($q), +# cobrand_form_elements => $cobrand_form_elements +# ); +# $out .= Page::template_include('contact', $q, Page::template_root($q), %vars); +# return $out; +} + +sub determine_contact_type : Private { + my ( $self, $c ) = @_; + + my $id = $c->req->param('id'); + my $update_id = $c->req->param('update_id'); + $id = undef unless $id && $id =~ /^[1-9]\d*$/; + $update_id = undef unless $update_id && $update_id =~ /^[1-9]\d*$/; + + if ($id) { + my $problem = $c->model('DB::Problem')->find( { id => $id } ); + + if ( $update_id ) { +# my $u = dbh()->selectrow_hashref( +# 'select comment.text, comment.name, problem.title, extract(epoch from comment.confirmed) as confirmed +# from comment, problem where comment.id=? +# and comment.problem_id = problem.id +# and comment.problem_id=?', {}, $update_id ,$id); +# if (! $u) { +# $intro = generic_contact_text($q); +# } else { +# $intro .= $q->p(_('You are reporting the following update for being abusive, containing personal information, or similar:')); +# $item_title = ent($u->{title}); +# $item_meta = $q->em( 'Update below added ', (!$u->{name}) ? 'anonymously' : "by " . ent($u->{name}), +# ' at ' . Page::prettify_epoch($q, $u->{confirmed})); +# $item_body = ent($u->{text}); +# $hidden_vals .= '<input type="hidden" name="update_id" value="' . $update_id . '">'; +# } + } elsif ( $problem ) { + $c->stash->{problem} = $problem; +# $intro .= $q->p(_('You are reporting the following problem report for being abusive, containing personal information, or similar:')); +# $item_title = ent($p->{title}); +# my $date_time = Page::prettify_epoch($q, $p->{confirmed}); +# $item_meta = $q->em( +# $p->{anonymous} +# ? sprintf(_('Reported anonymously at %s'), $date_time) +# : sprintf(_('Reported by %s at %s'), ent($p->{name}), $date_time) +# ); +# $item_body = ent($p->{detail}); + } +# $hidden_vals .= '<input type="hidden" name="id" value="' . $id . '">'; + } } diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 2ddc279bc..60e330776 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -11,4 +11,38 @@ $mech->get_ok( '/contact' ); $mech->title_like( qr/Contact Us/ ); $mech->content_contains( "We'd love to hear what you think about this site" ); +subtest 'check reporting a problem displays correctly' => sub { + my $user = FixMyStreet::App->model('DB::User')->find_or_create( + { + name => 'A User', + email => 'problem_report_rest@example.com' + } + ); + + my $problem = FixMyStreet::App->model('DB::Problem')->create( + { + title => 'Some problem or other', + detail => 'More detail on the problem', + postcode => 'EH99 1SP', + latitude => 0, + longitude => 0, + areas => 0, + used_map => 0, + name => 'Problem User', + anonymous => 0, + state => 'confirmed', + user => $user + } + ); + + ok $problem, 'succesfully create a problem'; + + $mech->get_ok( '/contact?id=' . $problem->id ); + $mech->content_contains( 'reporting the following problem' ); + $mech->content_contains( 'Some problem or other' ); + $mech->content_contains( 'Reported by A User' ); + + $problem->delete; +}; + done_testing(); diff --git a/templates/web/default/contact/index.html b/templates/web/default/contact/index.html index 5d7dfea7d..5ab5bad8c 100644 --- a/templates/web/default/contact/index.html +++ b/templates/web/default/contact/index.html @@ -6,13 +6,64 @@ <input type="hidden" name="submit_form" value="1"> + [% INCLUDE 'errors.html' %] +[% IF update %] + <p> + [% loc('You are reporting the following update for being abusive, containing personal information, or similar:') %] + </p> + + [% IF update.title %] + <blockquote> + <h2>[% update.title | html %]</h2> + + <p> + [% IF update.anonymous %] + [% tprintf( loc('Update below added anonymously at %s'), update.confirmed ) %] + [% ELSE %] + [% tprintf( loc('Update below added by %s at %s'), update.name, problem.confirmed ) | html %] + [% END %] + </p> + + <p> + [% update.detail | html %] + </p> + + </blockquote> + [% END %] + <input type="hidden" name="id" value="[% update.id %]"> +[% ELSIF problem %] + <p> + [% loc('You are reporting the following problem report for being abusive, containing personal information, or similar:') %] + </p> + + [% IF problem.title %] + <blockquote> + <h2>[% problem.title | html %]</h2> + + <p> + [% IF problem.anonymous %] + [% tprintf( loc('Reported anonymously at %s'), problem.confirmed ) %] + [% ELSE %] + [% tprintf( loc('Reported by %s at %s'), problem.user.name, problem.confirmed ) | html %] + [% END %] + </p> + + <p> + [% problem.detail | html %] + </p> + + </blockquote> + <input type="hidden" name="id" value="[% problem.id %]"> + [% END %] +[% ELSE %] <p> [% loc('Please do <strong>not</strong> report problems through this form; messages go to the team behind FixMyStreet, not a council. To report a problem, please <a href="/">go to the front page</a> and follow the instructions.') %] </p> +[% END %] <p> [% tprintf( loc("We'd love to hear what you think about this site. Just fill in the form, or send an email to <a href='mailto:%s'>%s</a>:"), contact_email, contact_email) %] |