diff options
-rwxr-xr-x | bin/update-schema | 1 | ||||
-rw-r--r-- | db/downgrade_0044---0043.sql | 7 | ||||
-rw-r--r-- | db/schema.sql | 7 | ||||
-rw-r--r-- | db/schema_0044-contact_response_templates.sql | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 102 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm | 46 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ResponseTemplate.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 11 | ||||
-rw-r--r-- | t/app/controller/admin.t | 44 | ||||
-rw-r--r-- | templates/web/base/admin/response_templates_select.html (renamed from templates/web/zurich/admin/response_templates_select.html) | 2 | ||||
-rw-r--r-- | templates/web/base/admin/template_edit.html | 50 | ||||
-rw-r--r-- | templates/web/base/admin/templates.html (renamed from templates/web/zurich/admin/templates.html) | 4 | ||||
-rw-r--r-- | templates/web/base/admin/templates_index.html | 11 | ||||
-rw-r--r-- | templates/web/base/report/update/form_update.html | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 8 |
17 files changed, 296 insertions, 48 deletions
diff --git a/bin/update-schema b/bin/update-schema index e8f2e2cbd..eb44e4dda 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -194,6 +194,7 @@ else { # By querying the database schema, we can see where we're currently at # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { + return '0044' if table_exists('contact_response_templates'); return '0043' if column_exists('users', 'area_id'); return '0042' if table_exists('user_planned_reports'); return '0041' if column_exists('users', 'is_superuser') && ! constraint_exists('user_body_permissions_permission_type_check'); diff --git a/db/downgrade_0044---0043.sql b/db/downgrade_0044---0043.sql new file mode 100644 index 000000000..d3a7642ad --- /dev/null +++ b/db/downgrade_0044---0043.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE response_templates DROP COLUMN auto_response; + +DROP TABLE contact_response_templates; + +COMMIT; diff --git a/db/schema.sql b/db/schema.sql index b11bb30b7..c96059fb1 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -473,5 +473,12 @@ create table response_templates ( title text not null, text text not null, created timestamp not null default current_timestamp, + auto_response boolean NOT NULL DEFAULT 'f', unique(body_id, title) ); + +CREATE TABLE contact_response_templates ( + id serial NOT NULL PRIMARY KEY, + contact_id int REFERENCES contacts(id) NOT NULL, + response_template_id int REFERENCES response_templates(id) NOT NULL +); diff --git a/db/schema_0044-contact_response_templates.sql b/db/schema_0044-contact_response_templates.sql new file mode 100644 index 000000000..e85d99fb8 --- /dev/null +++ b/db/schema_0044-contact_response_templates.sql @@ -0,0 +1,12 @@ +BEGIN; + +CREATE TABLE contact_response_templates ( + id serial NOT NULL PRIMARY KEY, + contact_id int REFERENCES contacts(id) NOT NULL, + response_template_id int REFERENCES response_templates(id) NOT NULL +); + +ALTER TABLE response_templates + ADD COLUMN auto_response boolean NOT NULL DEFAULT 'f'; + +COMMIT; diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 652113734..3c02c1318 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -309,7 +309,7 @@ sub body : Path('body') : Args(1) { $c->forward('update_contacts'); } - $c->forward('display_contacts'); + $c->forward('fetch_contacts'); return 1; } @@ -457,14 +457,14 @@ sub check_body_params : Private { } } -sub display_contacts : Private { +sub fetch_contacts : Private { my ( $self, $c ) = @_; my $contacts = $c->stash->{body}->contacts->search(undef, { order_by => [ 'category' ] } ); $c->stash->{contacts} = $contacts; $c->stash->{live_contacts} = $contacts->search({ deleted => 0 }); - if ( $c->get_param('text') && $c->get_param('text') == 1 ) { + if ( $c->get_param('text') && $c->get_param('text') eq '1' ) { $c->stash->{template} = 'admin/council_contacts.txt'; $c->res->content_type('text/plain; charset=utf-8'); return 1; @@ -893,57 +893,84 @@ sub categories_for_point : Private { sub templates : Path('templates') : Args(0) { my ( $self, $c ) = @_; - $c->detach( '/page_error_404_not_found' ) - unless $c->cobrand->moniker eq 'zurich'; - my $user = $c->user; - $self->templates_for_body($c, $user->from_body ); + if ($user->is_superuser) { + $c->forward('fetch_all_bodies'); + $c->stash->{template} = 'admin/templates_index.html'; + } elsif ( $user->from_body ) { + $c->forward('load_template_body', [ $user->from_body->id ]); + $c->res->redirect( $c->uri_for( 'templates', $c->stash->{body}->id ) ); + } else { + $c->detach( '/page_error_404_not_found' ); + } } sub templates_view : Path('templates') : Args(1) { my ($self, $c, $body_id) = @_; - $c->detach( '/page_error_404_not_found' ) - unless $c->cobrand->moniker eq 'zurich'; + $c->forward('load_template_body', [ $body_id ]); - # e.g. for admin + my @templates = $c->stash->{body}->response_templates->search( + undef, + { + order_by => 'title' + } + ); - my $body = $c->model('DB::Body')->find($body_id) - or $c->detach( '/page_error_404_not_found' ); + $c->stash->{response_templates} = \@templates; - $self->templates_for_body($c, $body); + $c->stash->{template} = 'admin/templates.html'; } sub template_edit : Path('templates') : Args(2) { my ( $self, $c, $body_id, $template_id ) = @_; - $c->detach( '/page_error_404_not_found' ) - unless $c->cobrand->moniker eq 'zurich'; - - my $body = $c->model('DB::Body')->find($body_id) - or $c->detach( '/page_error_404_not_found' ); - $c->stash->{body} = $body; + $c->forward('load_template_body', [ $body_id ]); my $template; if ($template_id eq 'new') { - $template = $body->response_templates->new({}); + $template = $c->stash->{body}->response_templates->new({}); } else { - $template = $body->response_templates->find( $template_id ) + $template = $c->stash->{body}->response_templates->find( $template_id ) or $c->detach( '/page_error_404_not_found' ); } + $c->forward('fetch_contacts'); + my @contacts = $template->contacts->all; + my @live_contacts = $c->stash->{live_contacts}->all; + my %active_contacts = map { $_->id => 1 } @contacts; + my @all_contacts = map { { + id => $_->id, + category => $_->category, + active => $active_contacts{$_->id}, + } } @live_contacts; + $c->stash->{contacts} = \@all_contacts; + if ($c->req->method eq 'POST') { - if ($c->get_param('delete_template') eq _("Delete template")) { + if ($c->get_param('delete_template') && $c->get_param('delete_template') eq _("Delete template")) { + $template->contact_response_templates->delete_all; $template->delete; } else { $template->title( $c->get_param('title') ); - $template->text ( $c->get_param('text') ); + $template->text( $c->get_param('text') ); + $template->auto_response( $c->get_param('auto_response') ? 1 : 0 ); $template->update_or_insert; + + my @live_contact_ids = map { $_->id } @live_contacts; + my @new_contact_ids = grep { $c->get_param("contacts[$_]") } @live_contact_ids; + $template->contact_response_templates->search({ + contact_id => { '!=' => \@new_contact_ids }, + })->delete; + foreach my $contact_id (@new_contact_ids) { + $template->contact_response_templates->find_or_create({ + contact_id => $contact_id, + }); + } } - $c->res->redirect( $c->uri_for( 'templates', $body->id ) ); + $c->res->redirect( $c->uri_for( 'templates', $c->stash->{body}->id ) ); } $c->stash->{response_template} = $template; @@ -951,22 +978,25 @@ sub template_edit : Path('templates') : Args(2) { $c->stash->{template} = 'admin/template_edit.html'; } +sub load_template_body : Private { + my ($self, $c, $body_id) = @_; -sub templates_for_body { - my ( $self, $c, $body ) = @_; - - $c->stash->{body} = $body; + my $zurich_user = $c->user->from_body && $c->cobrand->moniker eq 'zurich'; + my $has_permission = $c->user->from_body && + $c->user->from_body->id eq $body_id && + $c->user->has_permission_to('template_edit', $body_id); - my @templates = $body->response_templates->search( - undef, - { - order_by => 'title' - } - ); + unless ( $c->user->is_superuser || $zurich_user || $has_permission ) { + $c->detach( '/page_error_404_not_found' ); + } - $c->stash->{response_templates} = \@templates; + # Regular users can only view their own body's templates + if ( !$c->user->is_superuser && $body_id ne $c->user->from_body->id ) { + $c->res->redirect( $c->uri_for( 'templates', $c->user->from_body->id ) ); + } - $c->stash->{template} = 'admin/templates.html'; + $c->stash->{body} = $c->model('DB::Body')->find($body_id) + or $c->detach( '/page_error_404_not_found' ); } sub users: Path('users') : Args(0) { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index ee110a18b..a58f50b18 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -646,7 +646,7 @@ sub admin_pages { 'summary' => [_('Summary'), 0], 'bodies' => [_('Bodies'), 1], 'reports' => [_('Reports'), 2], - 'timeline' => [_('Timeline'), 3], + 'timeline' => [_('Timeline'), 4], 'users' => [_('Users'), 5], 'flagged' => [_('Flagged'), 6], 'stats' => [_('Stats'), 7], @@ -661,6 +661,12 @@ sub admin_pages { if ( $user->is_superuser ) { $pages->{config} = [ _('Configuration'), 8]; }; + # And some that need special permissions + if ( $user->is_superuser || $user->has_body_permission_to('template_edit') ) { + $pages->{templates} = [_('Templates'), 3], + $pages->{template_edit} = [undef, undef], + }; + return $pages; } @@ -711,6 +717,9 @@ sub available_permissions { user_assign_body => _("Grant access to the admin"), user_assign_areas => _("Assign users to areas"), # future use }, + _("Bodies") => { + template_edit => _("Add/edit response templates"), + }, }; } diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index 58d8e58de..ea9b656aa 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -55,10 +55,16 @@ __PACKAGE__->belongs_to( { id => "body_id" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, ); +__PACKAGE__->has_many( + "contact_response_templates", + "FixMyStreet::DB::Result::ContactResponseTemplate", + { "foreign.contact_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hq/BFHDEu4OUI4MSy3OyHg +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CXUabm3Yd11OoIYJceSPag __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); @@ -68,6 +74,8 @@ use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Extra'; +__PACKAGE__->many_to_many( response_templates => 'contact_response_templates', 'response_template' ); + sub get_metadata_for_input { my $self = shift; my $id_field = $self->id_field; diff --git a/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm new file mode 100644 index 000000000..3c777533c --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/ContactResponseTemplate.pm @@ -0,0 +1,46 @@ +use utf8; +package FixMyStreet::DB::Result::ContactResponseTemplate; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); +__PACKAGE__->table("contact_response_templates"); +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "contact_response_templates_id_seq", + }, + "contact_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "response_template_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, +); +__PACKAGE__->set_primary_key("id"); +__PACKAGE__->belongs_to( + "contact", + "FixMyStreet::DB::Result::Contact", + { id => "contact_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); +__PACKAGE__->belongs_to( + "response_template", + "FixMyStreet::DB::Result::ResponseTemplate", + { id => "response_template_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d6niNsxi2AsijhvJSuQeKw + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm index d189bf3ec..0d4377dba 100644 --- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm +++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm @@ -31,6 +31,8 @@ __PACKAGE__->add_columns( is_nullable => 0, original => { default_value => \"now()" }, }, + "auto_response", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("response_templates_body_id_title_key", ["body_id", "title"]); @@ -40,11 +42,18 @@ __PACKAGE__->belongs_to( { id => "body_id" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, ); +__PACKAGE__->has_many( + "contact_response_templates", + "FixMyStreet::DB::Result::ContactResponseTemplate", + { "foreign.response_template_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ECFQLMxOFGwv7cwfHLlszw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-08-24 11:29:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KRm0RHbtrzuxzH0S/UAsdw +__PACKAGE__->many_to_many( contacts => 'contact_response_templates', 'contact' ); # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index c3583bb3e..ee9631bdf 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -600,12 +600,21 @@ sub delete_body { my $body = shift; $mech->delete_problems_for_body($body->id); - $body->contacts->delete; + $mech->delete_contact($_) for $body->contacts; $mech->delete_user($_) for $body->users; + $_->delete for $body->response_templates; $body->body_areas->delete; $body->delete; } +sub delete_contact { + my $mech = shift; + my $contact = shift; + + $contact->contact_response_templates->delete_all; + $contact->delete; +} + sub delete_problems_for_body { my $mech = shift; my $body = shift; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 94a8d28f2..f7dcd4023 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -15,6 +15,7 @@ my $user2 = $mech->create_user_ok('test2@example.com', name => 'Test User 2'); my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); +my $oxfordshirecontact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire); my $bromley = $mech->create_body_ok(2482, 'Bromley Council', id => 2482); @@ -1175,6 +1176,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { name => 'Changed User', @@ -1205,6 +1207,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { email => 'changed@example.com', @@ -1235,6 +1238,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { body => $southend->id, @@ -1265,6 +1269,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { flagged => 'on', @@ -1295,6 +1300,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { flagged => undef, @@ -1325,6 +1331,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, changes => { is_superuser => 'on', @@ -1343,6 +1350,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]", "permissions[user_assign_body]", "permissions[user_assign_areas]", + "permissions[template_edit]", ], log_count => 5, log_entries => [qw/edit edit edit edit edit/], @@ -1375,6 +1383,7 @@ FixMyStreet::override_config { "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, "permissions[user_assign_areas]" => undef, + "permissions[template_edit]" => undef, }, log_count => 5, log_entries => [qw/edit edit edit edit edit/], @@ -1490,16 +1499,43 @@ subtest "Users with from_body can't access fixmystreet.com admin" => sub { }; }; -$mech->log_out_ok; -$user2->user_body_permissions->delete_all; -$oxfordshireuser->user_body_permissions->delete_all; +subtest "response templates can be added" => sub { + is $oxfordshire->response_templates->count, 0, "No response templates yet"; + $mech->log_in_ok( $superuser->email ); + $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" ); + + my $fields = { + title => "Report acknowledgement", + text => "Thank you for your report. We will respond shortly.", + auto_response => undef, + "contacts[".$oxfordshirecontact->id."]" => 1, + }; + $mech->submit_form_ok( { with_fields => $fields } ); + + is $oxfordshire->response_templates->count, 1, "Response template was added"; +}; + +subtest "response templates are included on page" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'oxfordshire' ], + }, sub { + $report->update({ category => $oxfordshirecontact->category, bodies_str => $oxfordshire->id }); + $mech->log_in_ok( $oxfordshireuser->email ); + $mech->get_ok("/report/" . $report->id); + $mech->content_contains( $oxfordshire->response_templates->first->text ); + + $mech->log_out_ok; + }; +}; + +$mech->log_out_ok; $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); $mech->delete_user( $superuser ); -$mech->delete_user( $oxfordshireuser ); $mech->delete_user( 'test4@example.com' ); +$mech->delete_body( $oxfordshire ); done_testing(); diff --git a/templates/web/zurich/admin/response_templates_select.html b/templates/web/base/admin/response_templates_select.html index 853956a0d..664d1d20a 100644 --- a/templates/web/zurich/admin/response_templates_select.html +++ b/templates/web/base/admin/response_templates_select.html @@ -1,6 +1,6 @@ <div class="response_templates_select"> <select id="templates_for_[% for %]" class="js-template-name" data-for="[% for %]"> - <option value="">[% loc('Choose a template') %]</option> + <option value="">[% loc('--Choose a template--') %]</option> [% FOR t IN problem.response_templates %] <option value="[% t.text | html %]"> [% t.title | html %] </option> [% END %] diff --git a/templates/web/base/admin/template_edit.html b/templates/web/base/admin/template_edit.html new file mode 100644 index 000000000..54058a04c --- /dev/null +++ b/templates/web/base/admin/template_edit.html @@ -0,0 +1,50 @@ +[% INCLUDE 'admin/header.html' title=tprintf(loc('Response Template for %s'), body.name) -%] +[% rt = response_template %] + +[% UNLESS rt.id %]<h3>[% loc('New template') %]</h3>[% END %] + +<form method="post" + action="[% c.uri_for('templates', body.id, rt.id || 'new' ) %]" + enctype="application/x-www-form-urlencoded" + accept-charset="utf-8" + class="validate"> + + <p> + <strong>[% loc('Title:') %] </strong> + <input type="text" name="title" class="required" size="30" value="[% rt.title| html %]"> + </p> + <p> + <strong>[% loc('Text:') %] </strong> + <textarea name="text" class="required">[% rt.text |html %]</textarea> + </p> + <p> + <label> + <strong>[% loc('Auto-response:') %]</strong> + <input type="checkbox" name="auto_response" [% 'checked' IF rt.auto_response %] /> + </label> + </p> + <p> + <strong>[% loc('Categories:') %]</strong> + <ul> + [% FOR contact IN contacts %] + <li> + <label> + <input type="checkbox" name="contacts[[% contact.id %]]" [% 'checked' IF contact.active %]/> + [% contact.category %] + </label> + </li> + [% END %] + </ul> + </p> + <p> + <input type="hidden" name="token" value="[% csrf_token %]" > + <input type="submit" name="Edit templates" value="[% rt.id ? loc('Save changes') : loc('Create template') %]" > + </p> + [% IF rt.id %] + <p> + <input class="delete" type="submit" name="delete_template" value="[% loc('Delete template') %]"> + </p> + [% END %] +</form> + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/zurich/admin/templates.html b/templates/web/base/admin/templates.html index d3b334022..25cd181aa 100644 --- a/templates/web/zurich/admin/templates.html +++ b/templates/web/base/admin/templates.html @@ -1,6 +1,8 @@ [% INCLUDE 'admin/header.html' title=tprintf(loc('Response Templates for %s'), body.name) -%] -<h2> [% tprintf(loc('Response Templates for %s'), body.name) %] </h2> +[% IF c.cobrand.moniker == 'zurich' %] + <h2> [% tprintf(loc('Response Templates for %s'), body.name) %] </h2> +[% END %] <table> <thead> diff --git a/templates/web/base/admin/templates_index.html b/templates/web/base/admin/templates_index.html new file mode 100644 index 000000000..1f45b84de --- /dev/null +++ b/templates/web/base/admin/templates_index.html @@ -0,0 +1,11 @@ +[% INCLUDE 'admin/header.html' title=loc('Response Templates') -%] + +<ul> + [% FOR body IN bodies %] + <li> + <a href="/admin/templates/[% body.id %]">[% body.name %]</a> + </li> + [% END %] +</ul> + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/report/update/form_update.html b/templates/web/base/report/update/form_update.html index 007bd68d8..ef87d9de0 100644 --- a/templates/web/base/report/update/form_update.html +++ b/templates/web/base/report/update/form_update.html @@ -25,6 +25,9 @@ [% END %] <label for="form_update">[% loc( 'Update' ) %]</label> +[% IF c.user && c.user.belongs_to_body( problem.bodies_str ) %] + [% INCLUDE 'admin/response_templates_select.html' for='form_update' %] +[% END %] [% IF field_errors.update %] <div class='form-error'>[% field_errors.update %]</div> [% END %] diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 5ab750679..2b55983bc 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -856,6 +856,13 @@ $.extend(fixmystreet.set_up, { } add_handlers( $('.problem-header'), 'problem' ); add_handlers( $('.item-list__item--updates'), 'update' ); + }, + + response_templates: function() { + $('.js-template-name').change(function() { + var $this = $(this); + $('#' + $this.data('for')).val($this.val()); + }); } }); @@ -1079,6 +1086,7 @@ fixmystreet.display = { fixmystreet.set_up.dropzone($sideReport); fixmystreet.set_up.form_focus_triggers(); fixmystreet.set_up.moderation(); + fixmystreet.set_up.response_templates(); window.selected_problem_id = reportId; var marker = fixmystreet.maps.get_marker_by_id(reportId); |