Fixed organisaiton listing and editing in backend

This commit is contained in:
Tom Bloor 2017-09-04 14:03:58 +01:00
parent 2594d826ef
commit 2ef5193e41
4 changed files with 64 additions and 17 deletions

View file

@ -6,8 +6,8 @@ use Try::Tiny;
sub list { sub list {
my $c = shift; my $c = shift;
my $valid_orgs_rs = $c->schema->resultset('Organisation'); my $valid_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 0 });
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation'); my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
$c->stash( $c->stash(
valid_orgs_rs => $valid_orgs_rs, valid_orgs_rs => $valid_orgs_rs,
@ -85,6 +85,7 @@ sub valid_edit {
$validation->required('town'); $validation->required('town');
$validation->optional('sector'); $validation->optional('sector');
$validation->required('postcode')->postcode; $validation->required('postcode')->postcode;
$validation->optional('pending');
if ( $validation->has_error ) { if ( $validation->has_error ) {
$c->flash( error => 'The validation has failed' ); $c->flash( error => 'The validation has failed' );
@ -101,6 +102,7 @@ sub valid_edit {
town => $validation->param('town'), town => $validation->param('town'),
sector => $validation->param('sector'), sector => $validation->param('sector'),
postcode => $validation->param('postcode'), postcode => $validation->param('postcode'),
pending => defined $validation->param('pending') ? 0 : 1,
}); });
} ); } );
} finally { } finally {

View file

@ -51,4 +51,16 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 }, { 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; 1;

View file

@ -20,7 +20,7 @@
</h3> </h3>
<div class="list-group list-group-flush"> <div class="list-group list-group-flush">
% for my $valid_org ($valid_orgs_rs->all) { % for my $valid_org ($valid_orgs_rs->all) {
<a href="<%= url_for . '/valid/' . $valid_org->id %>" class="list-group-item list-group-item-action"> <a href="<%= url_for . '/' . $valid_org->id %>" class="list-group-item list-group-item-action">
<div> <div>
%= $valid_org->name %= $valid_org->name
</div> </div>
@ -41,7 +41,7 @@
</div> </div>
% } else { % } else {
% for my $pending_org ($pending_orgs_rs->all) { % for my $pending_org ($pending_orgs_rs->all) {
<a href="<%= url_for . '/pending/' . $pending_org->id %>" class="list-group-item list-group-item-action"> <a href="<%= url_for . '/' . $pending_org->id %>" class="list-group-item list-group-item-action">
<div> <div>
%= $pending_org->name %= $pending_org->name
</div> </div>

View file

@ -15,20 +15,53 @@
<h3 class="card-header"> <h3 class="card-header">
%= $valid_org->name %= $valid_org->name
</h3> </h3>
<ul class="list-group list-group-flush"> <div class="card-block">
<form action="<%= url_for . '/edit' %>" method="post"> <form action="<%= url_for %>" method="post">
<li class="list-group-item"><input id="name" type="text" class="form-control" placeholder="Organisation Name" name="name" value="<%= $valid_org->name %>"></li> <div class="form-group row">
<li class="list-group-item"><input id="street_name" type="text" class="form-control" placeholder="Street Name" name="street_name" value="<%= $valid_org->street_name %>"></li> <label for="name" class="col-sm-2 col-form-label">Organisation Name</label>
<li class="list-group-item"><input id="town" type="text" class="form-control" placeholder="Town" name="town" value="<%= $valid_org->town %>"></li> <div class="col-sm-10">
<li class="list-group-item"> <input id="name" type="text" class="form-control" placeholder="Organisation Name" name="name" value="<%= $valid_org->name %>">
<select class="form-control" name="sector"> </div>
%= include 'partials/sector_options', selected_sector => $valid_org->sector || ''; </div>
</select> <div class="form-group row">
</li> <label for="name" class="col-sm-2 col-form-label">Street Name</label>
<li class="list-group-item"><input id="postcode" type="text" class="form-control" placeholder="Postcode" name="postcode" value="<%= $valid_org->postcode %>"></li> <div class="col-sm-10">
<li class="list-group-item"><button class="btn btn-success" type="submit">Edit Organisation</button></li> <input id="street_name" type="text" class="form-control" placeholder="Street Name" name="street_name" value="<%= $valid_org->street_name %>">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Town/City</label>
<div class="col-sm-10">
<input id="town" type="text" class="form-control" placeholder="Town" name="town" value="<%= $valid_org->town %>">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Sector</label>
<div class="col-sm-10">
<select class="form-control" name="sector">
%= include 'partials/sector_options', selected_sector => $valid_org->sector || '';
</select>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Postcode</label>
<div class="col-sm-10">
<input id="postcode" type="text" class="form-control" placeholder="Postcode" name="postcode" value="<%= $valid_org->postcode %>">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Validated</label>
<div class="col-sm-10">
<input id="pending" type="checkbox" name="pending" value="0"<%= $valid_org->pending ? '' : ' checked' %>>
</div>
</div>
<div class="form-group row">
<div class="ml-auto col-sm-10">
<button class="btn btn-success" type="submit">Save Changes To Organisation</button>
</div>
</div>
</form> </form>
</ul> </div>
</div> </div>
<div class="card mb-3"> <div class="card mb-3">
<h3 class="card-header"> <h3 class="card-header">