Bug 29393: Ability to send emails from patron details page
Test plan - apply Bug 12802 - go to a patron's details page - click on "Add message" in tools bar - choose "Email" in "Add a message for" - Select a notice (module members) or manualy fill the message - Save - Check the message is saved in message_queue table Signed-off-by: Matthias Le Gac <matthias.le-gac@inlibro.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
4c2f58d5db
commit
ba3f704493
5 changed files with 224 additions and 8 deletions
55
Koha/Template/Plugin/NoticeTemplates.pm
Normal file
55
Koha/Template/Plugin/NoticeTemplates.pm
Normal file
|
@ -0,0 +1,55 @@
|
|||
package Koha::Template::Plugin::NoticeTemplates;
|
||||
|
||||
# Copyright 2021 BibLibre
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Template::Plugin;
|
||||
use base qw( Template::Plugin );
|
||||
|
||||
use Koha::Notice::Templates;
|
||||
|
||||
sub GetByModule {
|
||||
my ( $self, $module ) = @_;
|
||||
|
||||
return Koha::Notice::Templates->search({ module => $module });
|
||||
}
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::Template::Plugin::NoticeTemplates - TT Plugin for notice templates
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
[% USE NoticeTemplates %]
|
||||
|
||||
[% NoticeTemplates.GetByModule('members') %]
|
||||
|
||||
=head1 ROUTINES
|
||||
|
||||
=head2 GetByModule
|
||||
|
||||
In a template, you can get notice templates by module with
|
||||
[% letters = NoticeTemplates.GetByModule( 'members' ) %]
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Alex Arnaud <alex.arnaud@biblibre.com>
|
||||
|
||||
=cut
|
||||
1;
|
|
@ -23,6 +23,7 @@ use CGI qw ( -utf8 );
|
|||
|
||||
use C4::Auth qw( get_template_and_user );
|
||||
use C4::Output;
|
||||
use C4::Letters;
|
||||
use Koha::Patron::Message;
|
||||
|
||||
my $input = CGI->new;
|
||||
|
@ -41,6 +42,8 @@ my $borrowernumber = $input->param('borrowernumber');
|
|||
my $branchcode = $input->param('branchcode');
|
||||
my $message_type = $input->param('message_type');
|
||||
my $borrower_message = $input->param('borrower_message');
|
||||
my $borrower_subject = $input->param('borrower_subject');
|
||||
my $letter_code = $input->param('select_patron_notice');
|
||||
my $batch = $input->param('batch');
|
||||
|
||||
if ( $op eq 'cud-edit_message' && $message_id) {
|
||||
|
@ -48,14 +51,41 @@ if ( $op eq 'cud-edit_message' && $message_id) {
|
|||
$message->update( { message => $borrower_message } ) if $message;
|
||||
}
|
||||
elsif( $op eq 'cud-add_message' ) {
|
||||
Koha::Patron::Message->new(
|
||||
{
|
||||
borrowernumber => $borrowernumber,
|
||||
branchcode => $branchcode,
|
||||
message_type => $message_type,
|
||||
message => $borrower_message,
|
||||
if ( $message_type eq 'L' or $message_type eq 'B' ) {
|
||||
Koha::Patron::Message->new(
|
||||
{
|
||||
borrowernumber => $borrowernumber,
|
||||
branchcode => $branchcode,
|
||||
message_type => $message_type,
|
||||
message => $borrower_message,
|
||||
}
|
||||
)->store;
|
||||
}
|
||||
|
||||
if ( $message_type eq 'E' ) {
|
||||
my $letter = {
|
||||
title => $borrower_subject,
|
||||
content => $borrower_message
|
||||
};
|
||||
|
||||
if ( $letter_code ) {
|
||||
$letter = C4::Letters::GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => $letter_code,
|
||||
tables => {
|
||||
'borrowers' => $borrowernumber
|
||||
},
|
||||
);
|
||||
}
|
||||
)->store;
|
||||
|
||||
C4::Letters::EnqueueLetter(
|
||||
{
|
||||
letter => $letter,
|
||||
borrowernumber => $borrowernumber,
|
||||
message_transport_type => 'email',
|
||||
}
|
||||
) or warn "can't enqueue letter";
|
||||
}
|
||||
}
|
||||
|
||||
my $url = $input->referer;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[% USE Categories %]
|
||||
[% USE Notices %]
|
||||
[% USE AuthorisedValues %]
|
||||
[% USE NoticeTemplates %]
|
||||
[% USE scalar %]
|
||||
<div id="toolbar" class="btn-toolbar">
|
||||
[% IF CAN_user_borrowers_edit_borrowers %]
|
||||
|
@ -136,6 +137,7 @@
|
|||
<select name="message_type" id="message_type">
|
||||
<option value="L">Staff - Internal note</option>
|
||||
<option value="B">OPAC - [% patron.firstname | html %] [% patron.surname | html %]</option>
|
||||
<option value="E">Email - email addresses of patron</option>
|
||||
</select>
|
||||
</div>
|
||||
[% bor_notes = AuthorisedValues.Get( 'BOR_NOTES' ) %]
|
||||
|
@ -150,8 +152,33 @@
|
|||
</select>
|
||||
</div>
|
||||
[% END %]
|
||||
|
||||
[% patron_letters = NoticeTemplates.GetByModule( 'members' ) %]
|
||||
[% IF patron_letters %]
|
||||
<div class="form-group">
|
||||
<label for="select_patron_notice" style="display:none;">Patron notice: </label>
|
||||
<select name="select_patron_notice" id="select_patron_notice" style="display:none;">
|
||||
<option value="">Select notice</option>
|
||||
[% FOREACH letter IN patron_letters %]
|
||||
<option value="[% letter.code | html %]">[% letter.name | html %]</option>
|
||||
[% END %]
|
||||
</select>
|
||||
</div>
|
||||
[% END %]
|
||||
|
||||
<div class="form-group">
|
||||
<textarea rows="3" class="modal-textarea" name="borrower_message" id="borrower_message" ></textarea>
|
||||
<fieldset class="rows">
|
||||
<ol>
|
||||
<li id="subject_form" style="display: none;">
|
||||
<label for="borrower_subject">Subject:</label>
|
||||
<input type="text" size="60" name="borrower_subject" id="borrower_subject"/>
|
||||
</li>
|
||||
<li>
|
||||
<label for="borrower_message" style="display: none;">Body:</label>
|
||||
<textarea cols="65" rows="5" name="borrower_message" id="borrower_message" ></textarea>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
</div>
|
||||
<input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
|
||||
<input type="hidden" name="batch" value="[% batch | html %]" />
|
||||
|
|
|
@ -77,6 +77,39 @@ $(document).ready(function(){
|
|||
startup();
|
||||
});
|
||||
|
||||
$("#message_type").on("change",function(){
|
||||
if ($(this).val() == 'E') {
|
||||
$("label[for='borrower_message']").show();
|
||||
$('#subject_form').show();
|
||||
$("label[for='select_patron_notice']").show();
|
||||
$('#select_patron_notice').show();
|
||||
$("label[for='select_patron_messages']").hide();
|
||||
$('#select_patron_messages').hide();
|
||||
$('#borrower_message').val('');
|
||||
$('#select_patron_notice').val('');
|
||||
} else {
|
||||
$('#subject_form').hide();
|
||||
$("label[for='borrower_message']").hide();
|
||||
$("label[for='select_patron_notice']").hide();
|
||||
$('#select_patron_notice').hide();
|
||||
$("label[for='select_patron_messages']").show();
|
||||
$('#select_patron_messages').show();
|
||||
$('#borrower_subject').prop( "disabled", false );
|
||||
$('#borrower_message').prop( "disabled", false );
|
||||
$('#select_patron_messages').val('');
|
||||
}
|
||||
});
|
||||
|
||||
$("#select_patron_notice").on("change",function(){
|
||||
if ($(this).val()) {
|
||||
$('#borrower_subject').prop( "disabled", true );
|
||||
$('#borrower_message').prop( "disabled", true );
|
||||
} else {
|
||||
$('#borrower_subject').prop( "disabled", false );
|
||||
$('#borrower_message').prop( "disabled", false );
|
||||
}
|
||||
});
|
||||
|
||||
$(".edit-patronimage").on("click", function(e){
|
||||
e.preventDefault();
|
||||
var borrowernumber = $(this).data("borrowernumber");
|
||||
|
|
71
t/db_dependent/Template/Plugin/NoticeTemplates.t
Normal file
71
t/db_dependent/Template/Plugin/NoticeTemplates.t
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::Notice::Templates;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
BEGIN {
|
||||
use_ok('Koha::Template::Plugin::NoticeTemplates');
|
||||
}
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
Koha::Notice::Templates->delete();
|
||||
|
||||
my $notice_templates = Koha::Notice::Templates->search({ module => 'members'});
|
||||
|
||||
$builder->build({
|
||||
source => 'Letter',
|
||||
value => {
|
||||
name => 'Hold cancellation',
|
||||
module => 'reserves'
|
||||
}
|
||||
});
|
||||
|
||||
$builder->build({
|
||||
source => 'Letter',
|
||||
value => {
|
||||
name => 'Account expiration',
|
||||
module => 'members'
|
||||
}
|
||||
});
|
||||
|
||||
$builder->build({
|
||||
source => 'Letter',
|
||||
value => {
|
||||
name => 'Discharge',
|
||||
module => 'members'
|
||||
}
|
||||
});
|
||||
|
||||
my $plugin = Koha::Template::Plugin::NoticeTemplates->new();
|
||||
ok($plugin, "initialized notice templates plugin");
|
||||
|
||||
my $notices = $plugin->GetByModule('members');
|
||||
is( $notices->count, 2, 'returns 2 defined members letters' );
|
||||
|
||||
$notices = $plugin->GetByModule('reserves');
|
||||
is( $notices->count, 1, 'returns 2 defined reserves letters' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
Loading…
Reference in a new issue