Add customer mock.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent c6f18db41c
commit 3b0119e603

@ -38,150 +38,25 @@ sub root :Chained('list_customer') :PathPart('') :Args(0) {
my ($self, $c) = @_;
}
sub ajax :Chained('list_customer') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $customers = $c->stash->{customers};
$c->forward(
'/ajax_process_resultset', [
$customers,
[qw(id contract_id name status)],
[ 1, 2, 3 ]
]
);
$c->detach($c->view('JSON'));
return;
}
sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $contract_id) = @_;
sub create :Chained('list_customer') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
# TODO: check in session if contract has just been created, and set it
# as default value
my $posted = $c->request->method eq 'POST';
my $form = NGCP::Panel::Form::Reseller->new;
$form->process(
posted => $posted,
params => $c->request->params,
action => $c->uri_for('create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
c => $c,
form => $form,
fields => [qw/contract.create/],
back_uri => $c->uri_for('create')
);
# TODO: preserve the current "customer" object for continuing editing
# when coming back from /contract/create
if($form->validated) {
try {
delete $form->params->{save};
$form->params->{contract_id} = delete $form->params->{contract}->{id};
delete $form->params->{contract};
$c->model('billing')->resultset('resellers')->create($form->params);
$c->flash(messages => [{type => 'success', text => 'Reseller successfully created.'}]);
} catch($e) {
$c->log->error($e);
$c->flash(messages => [{type => 'error', text => 'Creating reseller failed.'}]);
}
$c->response->redirect($c->uri_for());
return;
unless($contract_id && $contract_id->is_integer) {
$c->flash(messages => [{type => 'error', text => 'Invalid contract id detected!'}]);
$c->response->redirect($c->uri_for());
return;
}
$c->stash(create_flag => 1);
$c->stash(close_target => $c->uri_for());
$c->stash(form => $form);
}
sub base :Chained('list_reseller') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $reseller_id) = @_;
my $contract = $c->model('billing')->resultset('contracts')
->find($contract_id);
unless($reseller_id && $reseller_id =~ /^\d+$/) {
$c->flash(messages => [{type => 'error', text => 'Invalid reseller id detected.'}]);
$c->response->redirect($c->uri_for());
return;
}
$c->stash(reseller => $c->stash->{resellers}->find({id => $reseller_id}));
$c->stash(contract => $contract);
}
sub edit :Chained('base') :PathPart('edit') :Args(0) {
sub details :Chained('base') :PathPart('details') :Args(0) {
my ($self, $c) = @_;
my $posted = $c->request->method eq 'POST';
my $form = NGCP::Panel::Form::Reseller->new;
$form->process(
posted => 1,
params => $posted ? $c->request->params : {$c->stash->{reseller}->get_inflated_columns},
action => $c->uri_for($c->stash->{reseller}->get_column('id'), 'edit'),
);
return if NGCP::Panel::Utils::check_form_buttons(
c => $c, form => $form, fields => [qw/contract.create/],
back_uri => $c->uri_for($c->stash->{reseller}->get_column('id'), 'edit')
);
if($posted && $form->validated) {
try {
my $form_values = $form->value;
$form_values->{contract_id} = delete $form_values->{contract}{id};
delete $form_values->{contract};
$c->stash->{reseller}->update($form_values);
$c->flash(messages => [{type => 'success', text => 'Reseller successfully changed.'}]);
delete $c->session->{contract_id};
} catch($e) {
$c->log->error($e);
$c->flash(messages => [{type => 'error', text => 'Updating reseller failed.'}]);
}
$c->response->redirect($c->uri_for());
}
$c->stash(close_target => $c->uri_for());
$c->stash(form => $form);
$c->stash(edit_flag => 1);
$c->session(contract_id => $c->stash->{reseller}->get_column('contract_id'));
return;
}
sub delete :Chained('base') :PathPart('delete') :Args(0) {
my ($self, $c) = @_;
try {
$c->stash->{reseller}->delete;
$c->flash(messages => [{type => 'success', text => 'Reseller successfully deleted.'}]);
} catch($e) {
$c->log->error($e);
$c->flash(messages => [{type => 'error', text => 'Deleting reseller failed.'}]);
}
$c->response->redirect($c->uri_for());
}
sub ajax_contract :Chained('list_reseller') :PathPart('ajax_contract') :Args(0) {
my ($self, $c) = @_;
my $contract_id = $c->session->{contract_id};
my @used_contracts = map {
$_->get_column('contract_id') unless(
$contract_id &&
$contract_id == $_->get_column('contract_id')
)
} $c->stash->{resellers}->all;
my $free_contracts = $c->model('billing')
->resultset('contracts')
->search_rs({
id => { 'not in' => \@used_contracts }
});
$c->forward("/ajax_process_resultset", [
$free_contracts,
["id","contact_id","external_id","status"],
[1,2,3]
]);
$c->detach( $c->view("JSON") );
$c->stash(template => 'customer/details.tt');
}
=head1 AUTHOR

@ -0,0 +1,110 @@
[% site_config.title = 'Account Details' -%]
<div class="row">
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for() %]"><i class="icon-arrow-left"></i> Back</a>
</span>
</div>
[% IF messages -%]
<div class="row">
[% FOREACH m IN messages -%]
<div class="alert alert-[% m.type %]">[% m.text %]</div>
[% END -%]
</div>
[% END -%]
<div class="ngcp-separator"></div>
<h3>Subscribers</h3>
<table class="table table-bordered table-striped table-highlight table-hover">
<thead>
<tr>
<th>SIP URI</th>
<th>Primary Number</th>
<th>Registered Devices</th>
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
<tr>
<td>testuser1@example.org</td>
<td>4312345</td>
<td>Fooagent 1/0 something very long in version 20130702 foooooooooo</td>
<td class="ngcp-actions-column"></th>
</tr>
<tr>
<td>testuser2@example.org</td>
<td>4312346</td>
<td>Fooagent 1/0 something very long in version 20130702 foooooooooo</td>
<td class="ngcp-actions-column"></th>
</tr>
<tr>
<td>testuser1@example.org</td>
<td>4312345</td>
<td>Baragent</td>
<td class="ngcp-actions-column"></th>
</tr>
</tbody>
</table>
<h3>Account Balance</h3>
<table class="table table-bordered table-striped table-highlight table-hover">
<thead>
<tr>
<th></th>
<th>Cash</th>
<th>Free time</th>
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Current totals</td>
<td>0</td>
<td>0</td>
<td class="ngcp-actions-column"></th>
</tr>
<tr>
<td>Spent this interval</td>
<td>0</td>
<td>0</td>
<td class="ngcp-actions-column"></th>
</tr>
</tbody>
</table>
<h3>Fraud Limits</h3>
<table class="table table-bordered table-striped table-highlight table-hover">
<thead>
<tr>
<th></th>
<th>Limit</th>
<th>Lock Level</th>
<th>Notify</th>
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Monthly Settings</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td class="ngcp-actions-column"></th>
</tr>
<tr>
<td>Daily Settings</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td>billing profile default</td>
<td class="ngcp-actions-column"></th>
</tr>
</tbody>
</table>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -15,7 +15,7 @@
helper.dt_buttons = [
{ name = 'Edit', uri = "/contract/'+full[0]+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
{ name = 'Delete', uri = "/contract/'+full[0]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
{ name = 'Details', uri = "/customer/'+full[0]+'/details", class = 'btn-small btn-tertiary' },
{ name = 'Details', uri = "/customer/'+full[0]+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' },
];
helper.top_buttons = [
{ name = 'Create Customer', uri = c.uri_for('/customer/create'), icon = 'icon-star' },

Loading…
Cancel
Save