aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-14 13:14:54 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-15 00:11:06 +0000
commit2d16a64009e3bd512bfe69dbf58f6091ab826049 (patch)
treecd9cbfe55e0341019d45b98cc0c6aebed7f719dd
parentff06783c6dc50321100a54b4d4a624fde2212689 (diff)
Add admin editing/adding of body name/area ID.
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm51
-rw-r--r--templates/web/default/admin/bodies.html3
-rw-r--r--templates/web/default/admin/body-form.html69
-rw-r--r--templates/web/default/admin/body.html55
4 files changed, 110 insertions, 68 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 56789b81c..e64db0135 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -208,6 +208,7 @@ sub bodies : Path('bodies') : Args(0) {
my ( $self, $c ) = @_;
$c->forward('check_page_allowed');
+ $c->forward( 'get_token' );
my $edit_activity = $c->model('DB::ContactsHistory')->search(
undef,
@@ -221,6 +222,16 @@ sub bodies : Path('bodies') : Args(0) {
$c->stash->{edit_activity} = $edit_activity;
+ my $posted = $c->req->param('posted');
+ if ( $posted eq 'body' ) {
+ $c->forward('check_token');
+
+ my $params = $c->forward('body_params');
+ $c->model('DB::Body')->create( $params );
+
+ $c->stash->{updated} = _('New body added');
+ }
+
$c->forward( 'fetch_all_bodies' );
# XXX For fixmystreet.com, need to exclude bodies that are covering London.
@@ -241,6 +252,9 @@ sub bodies : Path('bodies') : Args(0) {
$c->stash->{counts} = \%council_info;
+ my $areas = mySociety::MaPit::call('areas', $c->cobrand->area_types);
+ $c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$areas ];
+
return 1;
}
@@ -253,6 +267,9 @@ sub body : Path('body') : Args(1) {
$c->forward( 'get_token' );
$c->forward( 'lookup_body' );
+ my $areas = mySociety::MaPit::call('areas', $c->cobrand->area_types);
+ $c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$areas ];
+
if ( $c->req->param('posted') ) {
$c->log->debug( 'posted' );
$c->forward('update_contacts');
@@ -328,28 +345,32 @@ sub update_contacts : Private {
);
$c->stash->{updated} = _('Values updated');
- } elsif ( $posted eq 'open311' ) {
+ } elsif ( $posted eq 'body' ) {
$c->forward('check_token');
- my %params = map { $_ => $c->req->param($_) || '' } qw/endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id devolved/;
-
- my $body = $c->stash->{body};
-
- $body->endpoint( $params{endpoint} );
- $body->jurisdiction( $params{jurisdiction} );
- $body->api_key( $params{api_key} );
- $body->send_method( $params{send_method} );
- $body->send_comments( $params{send_comments} || 0);
- $body->suppress_alerts( $params{suppress_alerts} || 0);
- $body->comment_user_id( $params{comment_user_id} || undef );
- $body->can_be_devolved( $params{devolved} || 0 );
-
- $body->update();
+ my $params = $c->forward( 'body_params' );
+ $c->stash->{body}->update( $params );
$c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later');
}
}
+sub body_params : Private {
+ my ( $self, $c ) = @_;
+
+ my @fields = qw/name area_id endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/;
+ my %defaults = map { $_ => '' } @fields;
+ %defaults = ( %defaults,
+ area_id => undef,
+ send_comments => 0,
+ suppress_alerts => 0,
+ comment_user_id => undef,
+ can_be_devolved => 0,
+ );
+ my %params = map { $_ => $c->req->param($_) || $defaults{$_} } @fields;
+ return \%params;
+}
+
sub display_contacts : Private {
my ( $self, $c ) = @_;
diff --git a/templates/web/default/admin/bodies.html b/templates/web/default/admin/bodies.html
index 522bbf956..74adfa836 100644
--- a/templates/web/default/admin/bodies.html
+++ b/templates/web/default/admin/bodies.html
@@ -41,4 +41,7 @@
[%- '</ul>' IF loop.last %]
[%- END %]
+<h2>[% loc('Add body') %]</h2>
+[% INCLUDE 'admin/body-form.html', body='' %]
+
[% INCLUDE 'admin/footer.html' %]
diff --git a/templates/web/default/admin/body-form.html b/templates/web/default/admin/body-form.html
new file mode 100644
index 000000000..405309d93
--- /dev/null
+++ b/templates/web/default/admin/body-form.html
@@ -0,0 +1,69 @@
+ <form method="post" action="[% body ? c.uri_for('body', body.id) : c.uri_for('bodies') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8">
+
+ <p>
+ <label for="name">Name</label>
+ <input type="text" name="name" id="name" value="[% body.name %]" size="50">
+ </p>
+
+ <p>
+ <label for="area_id">Area covered</label>
+ <select name="area_id">
+ <option value=""> -- Select an area -- </option>
+ [% FOR area IN areas %]
+ <option value="[% area.id %]"[% ' selected' IF body.area_id == area.id %]>[% area.name %]</option>
+ [% END %]
+ </select>
+ </p>
+
+ <p>
+ <label for="send_method">Send Method</label>
+ <select name="send_method">
+ <option value=""> -- Select a method -- </option>
+ [% FOR method IN send_methods %]
+ <option value="[% method %]"[% ' selected' IF body.send_method == method %]>[% method %]</option>
+ [% END %]
+ </select>
+ </p>
+
+ <p>
+ <label for="endpoint">Open311 Endpoint</label>
+ <input type="text" name="endpoint" id="endpoint" value="[% body.endpoint %]" size="50">
+ </p>
+
+ <p>
+ <label for="jurisdiction">Open311 Jurisdiction</label>
+ <input type="text" name="jurisdiction" id="jurisdiction" value="[% body.jurisdiction %]" size="50">
+ </p>
+
+ <p>
+ <label for="api_key">Open311 API Key</label>
+ <input type="text" name="api_key" id="api_key" value="[% body.api_key %]" size="25">
+ </p>
+
+ <p>
+ <input type="checkbox" id="send_comments" name="send_comments"[% ' checked' IF body.send_comments %]>
+ <label for="send_comments" class="inline">Use Open311 comment sending extension</label>
+ </p>
+
+ <p>
+ <label for"comment_user_id">User ID to attribute fetched comments to</label>
+ <input type="text" name="comment_user_id" value="[% body.comment_user_id %]">
+ </p>
+
+ <p>
+ <input type="checkbox" id="suppress_alerts" name="suppress_alerts"[% ' checked' IF body.suppress_alerts %]>
+ <label for="suppress_alerts" class="inline">Do not send email alerts on fetched comments to problem creator</label>
+ </p>
+
+ <p>
+ <input type="checkbox" id="can_be_devolved" name="can_be_devolved"[% ' checked' IF body.can_be_devolved %]>
+ <label for="can_be_devolved" class="inline">Endpoint lookup can be devolved to contacts</label>
+ </p>
+
+ <p>
+ <input type="hidden" name="posted" value="body">
+ <input type="hidden" name="token" value="[% token %]">
+ <input type="submit" value="[% body ? loc('Update body') : loc('Add body') %]">
+ </p>
+ </form>
+
diff --git a/templates/web/default/admin/body.html b/templates/web/default/admin/body.html
index 80cd32fef..120a07da9 100644
--- a/templates/web/default/admin/body.html
+++ b/templates/web/default/admin/body.html
@@ -109,58 +109,7 @@
</div>
</form>
- <h2>[% loc('Configure Open311 integration') %]</h2>
- <form method="post" action="[% c.uri_for('body', body_id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8">
- <p>
- <label for="endpoint">Endpoint</label>
- <input type="text" name="endpoint" id="endpoint" value="[% body.endpoint %]" size="50">
- </p>
-
- <p>
- <label for="jurisdiction">Jurisdiction</label>
- <input type="text" name="jurisdiction" id="jurisdiction" value="[% body.jurisdiction %]" size="50">
- </p>
-
- <p>
- <label for="api_key">Api Key</label>
- <input type="text" name="api_key" id="api_key" value="[% body.api_key %]" size="25">
- </p>
-
- <p>
- <label for="send_method">Send Method</label>
- <select name="send_method">
- <option value=""> -- Select a method -- </option>
- [% FOR method IN send_methods %]
- <option value="[% method %]"[% ' selected' IF body.send_method == method %]>[% method %]</option>
- [% END %]
- </select>
- </p>
-
- <p>
- <input type="checkbox" name="send_comments"[% ' checked' IF body.send_comments %]>
- <label for="send_comments" class="inline">Use Open311 comment sending extension</label>
- </p>
-
- <p>
- <label for"comment_user_id">User to attribute fetched comments to</label>
- <input type="text" name="comment_user_id" value="[% body.comment_user_id %]">
- </p>
-
- <p>
- <input type="checkbox" name="suppress_alerts"[% ' checked' IF body.suppress_alerts %]>
- <label for="suppress_alerts" class="inline">Do not send email alerts on fetched comments to problem creator</label>
- </p>
-
- <p>
- <input type="checkbox" name="devolved"[% ' checked' IF body.can_be_devolved %]>
- <label for="devolved" class="inline">Endpoint lookup can be devolved to contacts</label>
- </p>
-
- <p>
- <input type="hidden" name="posted" value="open311">
- <input type="hidden" name="token" value="[% token %]">
- <input type="submit" name="Configure Open311" value="[% loc('Configure Open311') %]">
- </p>
- </form>
+ <h2>[% loc('Edit body details') %]</h2>
+ [% INCLUDE 'admin/body-form.html' %]
[% INCLUDE 'admin/footer.html' %]