Properly carry back new objects in nav-chain.

If you create something (e.g. a contract) and have a sub-field
you create on-the-go (e.g. contact and billing profile), then
properly pre-select them once you get back to the original view
(the contract form in this example).
agranig/1_0_subfix
Andreas Granig 13 years ago
parent 9350d4258e
commit 5e0c8faa0a

@ -135,7 +135,9 @@ sub create :Chained('profile_list') :PathPart('create') :Args(0) {
$form->values->{reseller_id} = $c->user->reseller_id;
}
delete $form->values->{reseller};
$c->model('DB')->resultset('billing_profiles')->create($form->values);
my $profile = $c->model('DB')->resultset('billing_profiles')->create($form->values);
$c->session->{created_objects}->{billing_profile} = { id => $profile->id };
$c->flash(messages => [{type => 'success', text => 'Billing profile successfully created'}]);
} catch($e) {
$c->log->error("failed to create billing profile: $e");

@ -64,7 +64,7 @@ sub create :Chained('list_contact') :PathPart('create') :Args(0) {
if($posted && $form->validated) {
try {
my $contact = $c->stash->{contacts}->create($form->values);
$c->session->{created_object} = { contact => { id => $contact->id } };
$c->session->{created_objects}->{contact} = { id => $contact->id };
$c->flash(messages => [{type => 'success', text => 'Contact successfully created'}]);
} catch($e) {
$c->log->error("failed to create contact: $e");

@ -81,8 +81,7 @@ sub create :Chained('contract_list') :PathPart('create') :Args(0) {
my $posted = ($c->request->method eq 'POST');
my $params = {};
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, delete $c->session->{created_object});
# TODO: where to store created contact and billing profile?
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, $c->session->{created_objects});
my $form;
$form = NGCP::Panel::Form::Contract->new;
$form->process(
@ -116,6 +115,8 @@ sub create :Chained('contract_list') :PathPart('create') :Args(0) {
profile => $billing_profile,
contract => $contract,
);
delete $c->session->{created_objects}->{contact};
delete $c->session->{created_objects}->{billing_profile};
$c->flash(messages => [{type => 'success', text => 'Contract successfully created!'}]);
});
} catch($e) {
@ -163,6 +164,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
my $contract = $c->stash->{contract_result};
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
my $params = {};
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, $c->session->{created_objects});
unless($posted) {
$params->{billing_profile}{id} = $billing_mapping->billing_profile->id;
$params->{contact}{id} = $contract->contact_id;
@ -199,6 +201,8 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$form->values->{contact_id} = $form->values->{contact}{id};
delete $form->values->{contact};
$contract->update($form->values);
delete $c->session->{created_objects}->{contact};
delete $c->session->{created_objects}->{billing_profile};
});
$c->flash(messages => [{type => 'success', text => 'Contract successfully changed!'}]);
} catch($e) {
@ -281,7 +285,7 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) {
my $posted = ($c->request->method eq 'POST');
my $params = {};
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, delete $c->session->{created_object});
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, $c->session->{created_objects});
# TODO: where to store created contact and billing profile?
say ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ";
use Data::Printer; p $params;
@ -319,9 +323,9 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) {
profile => $billing_profile,
contract => $contract,
);
$c->session->{created_object} = { contract => { id => $contract->id }};
say ">>>>>>>>>>>>>>>>>> setting created contract object:";
use Data::Printer; p $c->session->{created_object};
$c->session->{created_objects}->{contract} = { id => $contract->id };
delete $c->session->{created_objects}->{contact};
delete $c->session->{created_objects}->{billing_profile};
$c->flash(messages => [{type => 'success', text => 'Contract successfully created'}]);
});
} catch($e) {

@ -36,6 +36,7 @@ sub index :Path :Args(0) {
$c->stash(template => 'dashboard.tt');
delete $c->session->{redirect_targets};
delete $c->session->{created_objects};
}
=head1 AUTHOR

@ -72,10 +72,12 @@ sub edit :Chained('base') :PathPart('edit') {
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::PeeringGroup->new;
my $params = {};
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, $c->session->{created_objects});
$form->process(
posted => 1,
params => $posted ? $c->request->params : $c->stash->{group},
action => $c->uri_for_action('/peering/edit', [$c->req->captures->[0]])
posted => $posted,
params => $c->request->params,
item => $params,
);
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form,
@ -86,6 +88,7 @@ sub edit :Chained('base') :PathPart('edit') {
try {
$c->stash->{group_result}->update($form->custom_get_values);
$self->_sip_lcr_reload;
delete $c->session->{created_objects}->{contract};
$c->flash(messages => [{type => 'success', text => 'Peering Group successfully changed!'}]);
} catch (DBIx::Class::Exception $e) {
$c->flash(messages => [{type => 'error', text => 'Update of peering group failed.'}]);
@ -119,9 +122,7 @@ sub create :Chained('group_list') :PathPart('create') :Args(0) {
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::PeeringGroup->new;
my $params = {};
say ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> created objects in peering/create is:";
use Data::Printer; p $c->session->{created_object};
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, delete $c->session->{created_object});
$params = Hash::Merge->new('RIGHT_PRECEDENT')->merge($params, $c->session->{created_objects});
say ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> got new contract:";
use Data::Printer; p $params;
$form->process(
@ -140,6 +141,7 @@ sub create :Chained('group_list') :PathPart('create') :Args(0) {
$c->model('DB')->resultset('voip_peer_groups')->create(
$formdata );
$self->_sip_lcr_reload;
delete $c->session->{created_objects}->{contract};
$c->flash(messages => [{type => 'success', text => 'Peering group successfully created!'}]);
} catch (DBIx::Class::Exception $e) {
$c->flash(rules_messages => [{type => 'error', text => 'Creation of peering group failed.'}]);

Loading…
Cancel
Save