Fix contract/contact editing from within reseller.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent d050c6b3be
commit a9b68ae367

@ -99,37 +99,62 @@ sub base :Chained('list_contact') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $contact_id) = @_;
unless($contact_id && $contact_id->is_int) {
$c->flash(messages => [{type => 'error', text => 'Invalid contact id detected!'}]);
$c->flash(messages => [{type => 'error', text => 'Invalid contact id detected'}]);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contact'));
}
my $res = $c->stash->{contacts};
$c->stash(contact => $res->find($contact_id));
unless($c->stash->{contact}) {
$c->flash(messages => [{type => 'error', text => 'Contact not found'}]);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contact'));
}
}
sub edit :Chained('base') :PathPart('edit') :Args(0) {
my ($self, $c) = @_;
my ($self, $c, $no_reseller) = @_;
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::Contact->new;
my $form;
my $params = { $c->stash->{contact}->get_inflated_columns };
$params = $params->merge($c->session->{created_objects});
if($c->user->is_superuser && $no_reseller) {
$form = NGCP::Panel::Form::Contact::Reseller->new;
$params->{reseller}{id} = $c->user->reseller_id;
} elsif($c->user->is_superuser) {
$form = NGCP::Panel::Form::Contact::Admin->new;
} else {
$form = NGCP::Panel::Form::Contact::Reseller->new;
}
$form->process(
posted => $posted,
params => $c->request->params,
item => $c->stash->{contact},
action => $c->uri_for($c->stash->{contact}->id, 'edit'),
item => $params,
);
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {
'reseller.create' => $c->uri_for('/reseller/create'),
},
back_uri => $c->req->uri,
);
# TODO: use values instead of params, chain reseller creation, add check_form_buttons
if($posted && $form->validated) {
try {
delete $form->params->{submitid};
delete $form->params->{save};
$c->stash->{contact}->update($form->params);
if($c->user->is_superuser && $no_reseller) {
delete $form->values->{reseller};
} elsif($c->user->is_superuser) {
$form->values->{reseller_id} = $form->values->{reseller}{id};
}
delete $form->values->{reseller};
$c->stash->{contact}->update($form->values);
$c->flash(messages => [{type => 'success', text => 'Contact successfully changed'}]);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contact'));
delete $c->session->{created_objects}->{reseller};
} catch($e) {
$c->log->error("failed to update contact: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to update contact'}]);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contact'));
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contact'));
}
$c->stash(
@ -138,6 +163,12 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
);
}
sub edit_without_reseller :Chained('base') :PathPart('edit/noreseller') :Args(0) {
my ($self, $c) = @_;
$self->edit($c, 1);
}
sub delete :Chained('base') :PathPart('delete') :Args(0) {
my ($self, $c) = @_;

@ -141,6 +141,10 @@ sub base :Chained('list_reseller') :PathPart('') :CaptureArgs(1) {
]);
$c->stash(reseller => $c->stash->{resellers}->search_rs({ id => $reseller_id }));
unless($c->stash->{reseller}->first) {
$c->flash(messages => [{type => 'error', text => 'Reseller not found'}]);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/reseller'));
}
}
sub reseller_contacts :Chained('base') :PathPart('contacts/ajax') :Args(0) {

@ -44,7 +44,6 @@
UNLESS c.user.read_only;
helper.dt_buttons = [
{ name = 'Edit', uri = "/reseller/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
{ name = 'Terminate', uri = "/reseller/'+full.id+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-remove' },
];
END;
@ -73,6 +72,12 @@
helper.ajax_uri = c.uri_for_action('/reseller/reseller_contracts', c.req.captures );
helper.base_uri = c.uri_for_action('/contract/root');
UNLESS c.user.read_only;
helper.dt_buttons = [
{ name = 'Edit', uri = "/contract/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
];
END;
PROCESS 'helpers/datatables.tt';
-%]
</div>
@ -98,6 +103,12 @@
helper.ajax_uri = c.uri_for_action('/reseller/reseller_contacts', c.req.captures );
helper.base_uri = c.uri_for_action('/contact/root');
UNLESS c.user.read_only;
helper.dt_buttons = [
{ name = 'Edit', uri = "/contact/'+full.id+'/edit/noreseller", class = 'btn-small btn-primary', icon = 'icon-edit' },
];
END;
PROCESS 'helpers/datatables.tt';
-%]
</div>

Loading…
Cancel
Save