MT#6789 Choose email template for customer - WIP

Select an email template for subscriber creation and for password reset
when creating or editing a customer.

WIP, not compiling yet by intention.
ipeshinskaya/InvoiceTemplate5
Andreas Granig 12 years ago
parent 02610faa68
commit 507402c561

@ -111,9 +111,9 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) {
my $params = {};
$params = $params->merge($c->session->{created_objects});
if($c->config->{features}->{cloudpbx}) {
$form = NGCP::Panel::Form::Contract::ProductSelect->new;
$form = NGCP::Panel::Form::Contract::ProductSelect->new(ctx => $c);
} else {
$form = NGCP::Panel::Form::Contract::Basic->new;
$form = NGCP::Panel::Form::Contract::Basic->new(ctx => $c);
}
$form->process(
posted => $posted,
@ -342,6 +342,17 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
sub edit :Chained('base') :PathPart('edit') :Args(0) {
my ($self, $c) = @_;
$fooo = breakme;
# We now optionally get email templates via the form for subscriber creation
# and for password reset. Change DB schema to store those ids, and if they are
# not null, hide webpassword field and let user change pass on first login, and
# also provide a way to reset a lost password.
#
# also provide config option for password policy
#
# also provide option whether or not passwords are completely hidden (at least
# from subscriber(admin)) and let them be generated automatically
my $contract = $c->stash->{contract};
my $billing_mapping = $c->stash->{billing_mapping};
my $posted = ($c->request->method eq 'POST');
@ -352,9 +363,9 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$params->{billing_profile}{id} = $billing_mapping->billing_profile_id;
$params = $params->merge($c->session->{created_objects});
if($c->config->{features}->{cloudpbx}) {
$form = NGCP::Panel::Form::Contract::ProductSelect->new;
$form = NGCP::Panel::Form::Contract::ProductSelect->new(ctx => $c);
} else {
$form = NGCP::Panel::Form::Contract::Basic->new;
$form = NGCP::Panel::Form::Contract::Basic->new(ctx => $c);
}
$form->process(
posted => $posted,
@ -925,7 +936,7 @@ sub pbx_group_create :Chained('base') :PathPart('pbx/group/create') :Args(0) {
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', $c->req->captures));
}
my $form;
$form = NGCP::Panel::Form::Customer::PbxGroup->new;
$form = NGCP::Panel::Form::Customer::PbxGroup->new(ctx => $c);
my $params = {};
$params = $params->merge($c->session->{created_objects});
$form->process(

@ -52,6 +52,17 @@ sub tmpl_ajax :Chained('tmpl_list') :PathPart('ajax') :Args(0) {
$c->detach( $c->view("JSON") );
}
sub tmpl_ajax_reseller :Chained('tmpl_list') :PathPart('ajax') :Args(1) {
my ($self, $c, $reseller_id) = @_;
my $rs = $c->stash->{tmpl_rs}->search({
reseller_id => $reseller_id,
});
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{template_dt_columns});
$c->detach( $c->view("JSON") );
}
sub tmpl_create :Chained('tmpl_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
@ -145,7 +156,16 @@ sub tmpl_delete :Chained('tmpl_base') :PathPart('delete') {
my ($self, $c) = @_;
try {
# manually delete hosts in group to let triggers hit in
$c->model('DB')->resultset('contracts')->search({
subscriber_email_template_id => $c->stash->{tmpl}->id,
})->update({
subscriber_email_template_id => undef,
});
$c->model('DB')->resultset('contracts')->search({
passreset_email_template_id => $c->stash->{tmpl}->id,
})->update({
passreset_email_template_id => undef,
});
$c->stash->{tmpl}->delete;
$c->flash(messages => [{type => 'success', text => $c->loc('Email template successfully deleted') }]);
} catch ($e) {

@ -0,0 +1,24 @@
package NGCP::Panel::Field::EmailTemplate;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
#label => 'Email Template',
do_label => 0,
do_wrapper => 0,
required => 1,
template => 'helpers/datatables_field.tt',
ajax_src => '/emailtemplate/ajax',
table_titles => ['#', 'Reseller', 'Name', 'Subject'],
table_fields => ['id', 'reseller_name', 'name', 'subject'],
);
has_field 'create' => (
type => 'Button',
do_label => 0,
value => 'Create Email Template',
element_class => [qw/btn btn-tertiary pull-right/],
);
1;

@ -56,6 +56,22 @@ has_field 'external_id' => (
},
);
has_field 'subscriber_email_template' => (
type => '+NGCP::Panel::Field::EmailTemplate',
label => 'Subscriber Creation Email Template',
do_label => 1,
required => 0,
);
has_field 'passreset_email_template' => (
type => '+NGCP::Panel::Field::EmailTemplate',
label => 'Password Reset Email Template',
do_label => 1,
required => 0,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -66,7 +82,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile status external_id/],
render_list => [qw/contact billing_profile status external_id subscriber_email_template passreset_email_template/],
);
has_block 'actions' => (
@ -75,5 +91,20 @@ has_block 'actions' => (
render_list => [qw/save/],
);
sub update_fields {
my $self = shift;
my $c = $self->ctx;
return unless $c;
foreach my $field(qw/subscriber_email_template passreset_email_template/) {
my $email = $self->field($field);
if($email && $c->stash->{contract}) {
$email->field('id')->ajax_src(
$c->uri_for_action('/emailtemplate/tmpl_ajax_reseller', [$c->stash->{contract}->contact->reseller_id])->as_string
);
}
}
}
1;
# vim: set tabstop=4 expandtab:

@ -19,11 +19,10 @@ has_field 'max_subscribers' => (
},
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile product max_subscribers status external_id/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template/],
);
1;

@ -19,11 +19,10 @@ has_field 'max_subscribers' => (
},
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile product max_subscribers status external_id/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template/],
);
1;

Loading…
Cancel
Save