Bugzilla – Attachment 63204 Details for
Bug 17762
Ability to translate notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17762: Update the letter form interface
Bug-17762-Update-the-letter-form-interface.patch (text/plain), 15.24 KB, created by
Nick Clemens (kidclamp)
on 2017-05-05 20:21:48 UTC
(
hide
)
Description:
Bug 17762: Update the letter form interface
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-05-05 20:21:48 UTC
Size:
15.24 KB
patch
obsolete
>From d5ca11241b37684a1e70d8f73d6ab443792f7a34 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 8 Dec 2016 15:01:37 +0000 >Subject: [PATCH] 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: Hugo Agud <hagud@orex.es> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > C4/Letters.pm | 16 ++-- > .../intranet-tmpl/prog/en/modules/tools/letter.tt | 36 ++++++++- > t/db_dependent/Letters/GetLetterTemplates.t | 20 ++--- > tools/letter.pl | 89 ++++++++++++++-------- > 4 files changed, 108 insertions(+), 53 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index de7e04a..5542010 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -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 ), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >index 129e1bf..08c6076 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt >@@ -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> >diff --git a/t/db_dependent/Letters/GetLetterTemplates.t b/t/db_dependent/Letters/GetLetterTemplates.t >index 5beb658..fd74285 100644 >--- a/t/db_dependent/Letters/GetLetterTemplates.t >+++ b/t/db_dependent/Letters/GetLetterTemplates.t >@@ -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)' ); >diff --git a/tools/letter.pl b/tools/letter.pl >index 351e87c..5920a84 100755 >--- a/tools/letter.pl >+++ b/tools/letter.pl >@@ -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 >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17762
:
58133
|
58134
|
58135
|
58136
|
58137
|
58138
|
58139
|
58140
|
58141
|
58525
|
59452
|
59453
|
59454
|
59455
|
59456
|
59457
|
59458
|
59459
|
59460
|
59461
|
61614
|
61615
|
61616
|
61617
|
61618
|
61619
|
61620
|
61621
|
61622
|
61623
|
61624
|
63199
|
63200
|
63201
|
63202
|
63203
| 63204 |
63205
|
63206
|
63207
|
63208
|
63209
|
63210
|
63211