aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2016-10-19 17:46:54 +0100
committerDave Arter <davea@mysociety.org>2016-10-28 11:04:05 +0100
commit0a9c2ea426e8477ad302582e41756730965ea8c8 (patch)
treee29797d61b9c9f3264d4db04c883716d2c056827
parentbbfb600725bf6fb846291ad4f09a0451fe5cb397 (diff)
Add UI for assigning categories to a user in admin
- A user can be assigned to any number of its body's categories - The category ids are stored as a list in the user's extra field
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm27
-rw-r--r--templates/web/base/admin/user-form.html13
-rw-r--r--web/js/fixmystreet-admin.js3
3 files changed, 42 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index c4bd5c293..ca2eeb52b 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1330,6 +1330,17 @@ sub user_edit : Path('user_edit') : Args(1) {
}
$c->stash->{field_errors} = {};
+
+ # Update the categories this user operates in
+ if ( $user->from_body ) {
+ $c->stash->{body} = $user->from_body;
+ $c->forward('fetch_contacts');
+ my @live_contacts = $c->stash->{live_contacts}->all;
+ my @live_contact_ids = map { $_->id } @live_contacts;
+ my @new_contact_ids = grep { $c->get_param("contacts[$_]") } @live_contact_ids;
+ $user->set_extra_metadata('categories', \@new_contact_ids);
+ }
+
unless ($user->email) {
$c->stash->{field_errors}->{email} = _('Please enter a valid email');
}
@@ -1354,6 +1365,22 @@ sub user_edit : Path('user_edit') : Args(1) {
'<p><em>' . _('Updated!') . '</em></p>';
}
+ if ( $user->from_body ) {
+ unless ( $c->stash->{body} && $user->from_body->id eq $c->stash->{body}->id ) {
+ $c->stash->{body} = $user->from_body;
+ $c->forward('fetch_contacts');
+ }
+ my @contacts = @{$user->get_extra_metadata('categories') || []};
+ my %active_contacts = map { $_ => 1 } @contacts;
+ my @live_contacts = $c->stash->{live_contacts}->all;
+ my @all_contacts = map { {
+ id => $_->id,
+ category => $_->category,
+ active => $active_contacts{$_->id},
+ } } @live_contacts;
+ $c->stash->{contacts} = \@all_contacts;
+ }
+
return 1;
}
diff --git a/templates/web/base/admin/user-form.html b/templates/web/base/admin/user-form.html
index fb0bdd0fa..cfd85b465 100644
--- a/templates/web/base/admin/user-form.html
+++ b/templates/web/base/admin/user-form.html
@@ -71,6 +71,19 @@
</li>
[% END %]
+ [% IF contacts AND c.cobrand.moniker != 'zurich'%]
+ <li class="js-user-categories">
+ <div class="admin-hint">
+ <p>
+ [% loc(
+ "Authorised staff users can be associated with the categories in which they operate.")
+ %]
+ </p>
+ </div>
+ [% INCLUDE 'admin/category-checkboxes.html' %]
+ </li>
+ [% END %]
+
[% IF c.cobrand.moniker != 'zurich' %]
<li>
diff --git a/web/js/fixmystreet-admin.js b/web/js/fixmystreet-admin.js
index 0323b1742..884ad1c09 100644
--- a/web/js/fixmystreet-admin.js
+++ b/web/js/fixmystreet-admin.js
@@ -84,10 +84,11 @@ $(function(){
}
});
- // On user edit page, hide the area select field if body changes
+ // On user edit page, hide the area/categories fields if body changes
$("form#user_edit select#body").change(function() {
var show_area = $(this).val() == $(this).find("[data-originally-selected]").val();
$("form#user_edit select#area_id").closest("li").toggle(show_area);
+ $("form#user_edit .js-user-categories").toggle(show_area);
});
// On category edit page, hide the reputation input if inspection isn't required