From 2ef5193e415c56919b412cc1a033d78168bb0d46 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 4 Sep 2017 14:03:58 +0100 Subject: [PATCH] Fixed organisaiton listing and editing in backend --- .../Controller/Admin/Organisations.pm | 6 +- lib/Pear/LocalLoop/Schema/Result/Entity.pm | 12 ++++ templates/admin/organisations/list.html.ep | 4 +- .../admin/organisations/valid_read.html.ep | 59 +++++++++++++++---- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm index dba62e0..9a9a919 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Organisations.pm @@ -6,8 +6,8 @@ use Try::Tiny; sub list { my $c = shift; - my $valid_orgs_rs = $c->schema->resultset('Organisation'); - my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation'); + my $valid_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 0 }); + my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 }); $c->stash( valid_orgs_rs => $valid_orgs_rs, @@ -85,6 +85,7 @@ sub valid_edit { $validation->required('town'); $validation->optional('sector'); $validation->required('postcode')->postcode; + $validation->optional('pending'); if ( $validation->has_error ) { $c->flash( error => 'The validation has failed' ); @@ -101,6 +102,7 @@ sub valid_edit { town => $validation->param('town'), sector => $validation->param('sector'), postcode => $validation->param('postcode'), + pending => defined $validation->param('pending') ? 0 : 1, }); } ); } finally { diff --git a/lib/Pear/LocalLoop/Schema/Result/Entity.pm b/lib/Pear/LocalLoop/Schema/Result/Entity.pm index 121d560..0321049 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Entity.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Entity.pm @@ -51,4 +51,16 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +sub name { + my $self = shift; + + if ( $self->type eq 'customer' ) { + return $self->customer->display_name; + } elsif ( $self->type eq 'organisation' ) { + return $self->organisation->name; + } else { + return "Unknown Name"; + } +} + 1; diff --git a/templates/admin/organisations/list.html.ep b/templates/admin/organisations/list.html.ep index dad10cf..4db8974 100644 --- a/templates/admin/organisations/list.html.ep +++ b/templates/admin/organisations/list.html.ep @@ -20,7 +20,7 @@
% for my $valid_org ($valid_orgs_rs->all) { - +
%= $valid_org->name
@@ -41,7 +41,7 @@
% } else { % for my $pending_org ($pending_orgs_rs->all) { - +
%= $pending_org->name
diff --git a/templates/admin/organisations/valid_read.html.ep b/templates/admin/organisations/valid_read.html.ep index 2055496..5bbe739 100644 --- a/templates/admin/organisations/valid_read.html.ep +++ b/templates/admin/organisations/valid_read.html.ep @@ -15,20 +15,53 @@

%= $valid_org->name

- +