Commit c99fc9d7 authored by joubu's avatar joubu Committed by Kyle M Hall

Bug 17762: Update the letter form interface

If the pref is on, the notice template will be translatable in different
languages

Sponsored-by: Orex Digital
Signed-off-by: default avatarHugo Agud <hagud@orex.es>
Signed-off-by: Wm. Nick Clemens's avatarNick Clemens <nick@bywatersolutions.com>
Signed-off-by: default avatarKyle M Hall <kyle@bywatersolutions.com>
parent f244dd38
......@@ -106,7 +106,6 @@ sub GetLetters {
);
Return a hashref of letter templates.
The key will be the message transport type.
=cut
......@@ -117,16 +116,15 @@ sub GetLetterTemplates {
my $code = $params->{code};
my $branchcode = $params->{branchcode} // '';
my $dbh = C4::Context->dbh;
my $letters = $dbh->selectall_hashref(
my $letters = $dbh->selectall_arrayref(
q|
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type, lang
FROM letter
WHERE module = ?
AND code = ?
and branchcode = ?
|
, 'message_transport_type'
, undef
, { Slice => {} }
, $module, $code, $branchcode
);
......@@ -249,14 +247,17 @@ sub DelLetter {
my $module = $params->{module};
my $code = $params->{code};
my $mtt = $params->{mtt};
my $lang = $params->{lang};
my $dbh = C4::Context->dbh;
$dbh->do(q|
DELETE FROM letter
WHERE branchcode = ?
AND module = ?
AND code = ?
| . ( $mtt ? q| AND message_transport_type = ?| : q|| )
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ) );
|
. ( $mtt ? q| AND message_transport_type = ?| : q|| )
. ( $lang? q| AND lang = ?| : q|| )
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
}
=head2 addalert ($borrowernumber, $type, $externalid)
......@@ -685,6 +686,7 @@ sub GetPreparedLetter {
my $letter_code = $params{letter_code} or croak "No letter_code";
my $branchcode = $params{branchcode} || '';
my $mtt = $params{message_transport_type} || 'email';
my $lang = $params{lang} || 'default';
my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
or warn( "No $module $letter_code letter transported by " . $mtt ),
......
......@@ -105,11 +105,13 @@ $(document).ready(function() {
$("#sms_counter").css("color", "black");
}
});
$( "#transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
$( ".transport-types" ).accordion({ collapsible: true, active:false, animate: 200 });
$(".insert").on("click",function(){
var containerid = $(this).data("containerid");
insertValueQuery( containerid );
})
$("#tabs").tabs();
});
[% IF add_form or copy_form %]
......@@ -374,8 +376,28 @@ $(document).ready(function() {
</li>
</ol>
</fieldset>
<div id="transport-types" style="clear:both">
[% FOREACH letter IN letters %]
[% IF Koha.Preference('TranslateNotices') %]
<div style="clear:both"></div>
<div id="tabs">
<ul>
<li><a href="#lang_default">Default</a></li>
[% FOR language IN languages %]
[% FOR sublanguage IN language.sublanguages_loop %]
[% IF language.plural %]
<li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] [% sublanguage.region_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
[% ELSE %]
<li><a href="#lang_[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] ([% sublanguage.rfc4646_subtag %])</a></li>
[% END %]
[% END %]
[% END %]
</ul>
[% END %]
[% FOREACH lang IN letters.keys %]
<div id="lang_[% lang %]">
<div class="transport-types" style="clear:both">
[% FOR mtt IN letters.$lang.templates.keys.sort %]
[% SET letter = letters.$lang.templates.$mtt %]
<h3>
[% SWITCH letter.message_transport_type %]
[% CASE 'email' %]
......@@ -404,6 +426,7 @@ $(document).ready(function() {
<ol>
<li>
<input type="hidden" name="message_transport_type" value="[% letter.message_transport_type %]" />
<input type="hidden" name="lang" value="[% lang %]" />
<label for="is_html_[% letter.message_transport_type %]">HTML message:</label>
[% IF letter.is_html %]
<input type="checkbox" name="is_html_[% letter.message_transport_type %]" id="is_html_[% letter.message_transport_type %]" value="1" checked="checked" />
......@@ -437,8 +460,13 @@ $(document).ready(function() {
</li>
</ol>
</fieldset>
[% END %]
[% END %]
</div>
</div> <!-- / #transport-types -->
[% END %]
[% IF Koha.Preference('TranslateNotices') %]
</div>
[% END %]
[% IF code.search('DGST') %] <span class="overdue">Warning, this is a template for a Digest, as such, any references to branch data ( e.g. branches.branchname ) will refer to the borrower's home branch.</span> [% END %]
<fieldset class="action"><input type="submit" id="submit_form" value="Submit" class="button" /> <a class="cancel" href="/cgi-bin/koha/tools/letter.pl">Cancel</a></fieldset>
......
......@@ -105,26 +105,26 @@ for my $l (@$letters) {
my $letter_templates;
$letter_templates = C4::Letters::GetLetterTemplates;
is_deeply( $letter_templates, {},
is_deeply( $letter_templates, [],
'GetLetterTemplates should not return templates if not param is given' );
$letter_templates = C4::Letters::GetLetterTemplates(
{ module => 'circulation', code => 'code1', branchcode => '' } );
is( scalar( keys %$letter_templates ),
is( scalar( @$letter_templates ),
2, '2 default templates should exist for circulation code1' );
is( exists( $letter_templates->{email} ),
1, 'The mtt email should exist for circulation code1' );
is( exists( $letter_templates->{sms} ),
1, 'The mtt sms should exist for circulation code1' );
my $has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
is( $has_email, 1, 'The mtt email should exist for circulation code1' );
my $has_sms = grep { $_->{message_transport_type} eq 'sms' } @$letter_templates;
is( $has_sms, 1, 'The mtt sms should exist for circulation code1' );
$letter_templates = C4::Letters::GetLetterTemplates(
{ module => 'circulation', code => 'code1', branchcode => 'CPL' } );
is( scalar( keys %$letter_templates ),
is( scalar( @$letter_templates ),
1, '1 template should exist for circulation CPL code1' );
is( exists( $letter_templates->{email} ),
1, 'The mtt should be email for circulation CPL code1' );
$has_email = grep { $_->{message_transport_type} eq 'email' } @$letter_templates;
is( $has_email, 1, 'The mtt should be email for circulation CPL code1' );
$letter_templates = C4::Letters::GetLetterTemplates(
{ module => 'circulation', code => 'code1' } );
is( scalar( keys %$letter_templates ),
is( scalar( @$letter_templates ),
2, '2 default templates should exist for circulation code1 (even if branchcode is not given)' );
......@@ -146,48 +146,70 @@ sub add_form {
}
my $message_transport_types = GetMessageTransportTypes();
my @letter_loop;
my $templates = { map { $_ => { message_transport_type => $_ } } sort @$message_transport_types };
my %letters = ( default => { templates => $templates } );
if ( C4::Context->preference('TranslateNotices') ) {
my $translated_languages =
C4::Languages::getTranslatedLanguages( 'opac',
C4::Context->preference('template') );
for my $language (@$translated_languages) {
for my $sublanguage( @{ $language->{sublanguages_loop} } ) {
if ( $language->{plural} ) {
$letters{ $sublanguage->{rfc4646_subtag} } = {
description => $sublanguage->{native_description}
. ' '
. $sublanguage->{region_description} . ' ('
. $sublanguage->{rfc4646_subtag} . ')',
templates => { %$templates },
};
}
else {
$letters{ $sublanguage->{rfc4646_subtag} } = {
description => $sublanguage->{native_description}
. ' ('
. $sublanguage->{rfc4646_subtag} . ')',
templates => { %$templates },
};
}
}
}
$template->param( languages => $translated_languages );
}
if ($letters) {
$template->param(
modify => 1,
code => $code,
branchcode => $branchcode,
);
my $first_flag = 1;
my $first_flag_name = 1;
my ( $lang, @templates );
# The letter name is contained into each mtt row.
# So we can only sent the first one to the template.
for my $mtt ( @$message_transport_types ) {
for my $letter ( @$letters ) {
# The letter_name
if ( $first_flag and $letters->{$mtt}{name} ) {
if ( $first_flag_name and $letter->{name} ) {
$template->param(
letter_name=> $letters->{$mtt}{name},
letter_name=> $letter->{name},
);
$first_flag = 0;
$first_flag_name = 0;
}
push @letter_loop, {
message_transport_type => $mtt,
is_html => $letters->{$mtt}{is_html},
title => $letters->{$mtt}{title},
content => $letters->{$mtt}{content}//'',
my $lang = $letter->{lang};
my $mtt = $letter->{message_transport_type};
$letters{ $lang }{templates}{$mtt} = {
message_transport_type => $letter->{message_transport_type},
is_html => $letter->{is_html},
title => $letter->{title},
content => $letter->{content} // '',
};
}
}
else { # initialize the new fields
for my $mtt ( @$message_transport_types ) {
push @letter_loop, {
message_transport_type => $mtt,
}
}
$template->param(
branchcode => $branchcode,
module => $module,
);
else {
$template->param( adding => 1 );
}
$template->param(
letters => \@letter_loop,
letters => \%letters,
);
my $field_selection;
......@@ -258,11 +280,13 @@ sub add_validate {
my @mtt = $input->multi_param('message_transport_type');
my @title = $input->multi_param('title');
my @content = $input->multi_param('content');
my @lang = $input->multi_param('lang');
for my $mtt ( @mtt ) {
my $is_html = $input->param("is_html_$mtt");
my $title = shift @title;
my $content = shift @content;
my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
my $lang = shift @lang;
my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt, $lang );
# getletter can return the default letter even if we pass a branchcode
# If we got the default one and we needed the specific one, we didn't get the one we needed!
......@@ -271,25 +295,25 @@ sub add_validate {
}
unless ( $title and $content ) {
# Delete this mtt if no title or content given
delete_confirmed( $branchcode, $oldmodule, $code, $mtt );
delete_confirmed( $branchcode, $oldmodule, $code, $mtt, $lang );
next;
}
elsif ( $letter and $letter->{message_transport_type} eq $mtt ) {
elsif ( $letter and $letter->{message_transport_type} eq $mtt and $letter->{lang} eq $lang ) {
$dbh->do(
q{
UPDATE letter
SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?
SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?, lang = ?
WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ?
},
undef,
$branchcode || '', $module, $name, $is_html || 0, $title, $content,
$branchcode || '', $module, $name, $is_html || 0, $title, $content, $lang,
$branchcode, $oldmodule, $code, $mtt
);
} else {
$dbh->do(
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)},
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type, lang) VALUES (?,?,?,?,?,?,?,?,?)},
undef,
$branchcode || '', $module, $code, $name, $is_html || 0, $title, $content, $mtt
$branchcode || '', $module, $code, $name, $is_html || 0, $title, $content, $mtt, $lang
);
}
}
......@@ -310,13 +334,14 @@ sub delete_confirm {
}
sub delete_confirmed {
my ($branchcode, $module, $code, $mtt) = @_;
my ($branchcode, $module, $code, $mtt, $lang) = @_;
C4::Letters::DelLetter(
{
branchcode => $branchcode || '',
module => $module,
code => $code,
mtt => $mtt
mtt => $mtt,
lang => $lang,
}
);
# setup default display for screen
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment