Commit 82145411 authored by joubu's avatar joubu Committed by Galen Charlton

Bug 9016: Create a message for each transport type.

This patch adds:
- a new jquery plugin : insertatcaret.
- the ability to define a notice template for each transport type.
- a new routine C4::Letters::GetMessageTransportTypes.

Test plan:
- Go on tools/letter.pl and check that all existing notices are still
  there.
- Modify one. A new empty message is present for sms, print, etc. The
  email message is filled with the existant value.
- Add a message for sms for example (don't forget the subject) and save.
- edit again and verify the sms message has been saved.
Signed-off-by: default avatarOlli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Signed-off-by: default avatarMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton's avatarGalen Charlton <gmc@esilibrary.com>
parent 160ed321
......@@ -43,7 +43,7 @@ BEGIN {
$VERSION = 3.07.00.049;
@ISA = qw(Exporter);
@EXPORT = qw(
&GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages
&GetLetters &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages &GetMessageTransportTypes
);
}
......@@ -98,20 +98,19 @@ $template->param(LETTERLOOP => \@letterloop);
sub GetLetters {
# returns a reference to a hash of references to ALL letters...
my $cat = shift;
my ( $cat, $message_transport_type ) = @_;
$message_transport_type ||= 'email';
my %letters;
my $dbh = C4::Context->dbh;
my $sth;
if (defined $cat) {
my $query = "SELECT * FROM letter WHERE module = ? ORDER BY name";
$sth = $dbh->prepare($query);
$sth->execute($cat);
}
else {
my $query = "SELECT * FROM letter ORDER BY name";
$sth = $dbh->prepare($query);
$sth->execute;
}
my $query = q{
SELECT * FROM letter WHERE
};
$query .= q{ module = ? AND } if defined $cat;
$query .= q{ message_transport_type = ? ORDER BY name};
$sth = $dbh->prepare($query);
$sth->execute((defined $cat ? $cat : ()), $message_transport_type);
while ( my $letter = $sth->fetchrow_hashref ) {
$letters{ $letter->{'code'} } = $letter->{'name'};
}
......@@ -125,7 +124,8 @@ sub GetLetters {
# short-term fix, our will work.
our %letter;
sub getletter {
my ( $module, $code, $branchcode ) = @_;
my ( $module, $code, $branchcode, $message_transport_type ) = @_;
$message_transport_type ||= 'email';
if ( C4::Context->preference('IndependentBranches')
......@@ -136,17 +136,22 @@ sub getletter {
}
$branchcode //= '';
if ( my $l = $letter{$module}{$code}{$branchcode} ) {
if ( my $l = $letter{$module}{$code}{$branchcode}{$message_transport_type} ) {
return { %$l }; # deep copy
}
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("select * from letter where module=? and code=? and (branchcode = ? or branchcode = '') order by branchcode desc limit 1");
$sth->execute( $module, $code, $branchcode );
my $sth = $dbh->prepare(q{
SELECT *
FROM letter
WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type = ?
ORDER BY branchcode DESC LIMIT 1
});
$sth->execute( $module, $code, $branchcode, $message_transport_type );
my $line = $sth->fetchrow_hashref
or return;
$line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
$letter{$module}{$code}{$branchcode} = $line;
$letter{$module}{$code}{$branchcode}{$message_transport_type} = $line;
return { %$line };
}
......@@ -448,7 +453,7 @@ sub GetPreparedLetter {
my $letter_code = $params{letter_code} or croak "No letter_code";
my $branchcode = $params{branchcode} || '';
my $letter = getletter( $module, $letter_code, $branchcode )
my $letter = getletter( $module, $letter_code, $branchcode, $params{message_transport_type} )
or warn( "No $module $letter_code letter"),
return;
......@@ -842,6 +847,28 @@ ENDSQL
return $sth->fetchall_arrayref({});
}
=head2 GetMessageTransportTypes
my @mtt = GetMessageTransportTypes();
returns a list of hashes
=cut
sub GetMessageTransportTypes {
my $dbh = C4::Context->dbh();
my $sth = $dbh->prepare("
SELECT message_transport_type
FROM message_transport_types
ORDER BY message_transport_type
");
$sth->execute;
my @mtts = map{
$_->[0]
} @{ $sth->fetchall_arrayref() };
return \@mtts;
}
=head2 _add_attachements
named parameters:
......
/*!
* jQuery insertAtCaret
* Allows inserting text where the caret is in a textarea
* Copyright (c) 2003-2010 phpMyAdmin devel team
* Version: 1.0
* Developed by the phpMyAdmin devel team. Modified by Alex King and variaas
* http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
* http://www.mail-archive.com/jquery-en@googlegroups.com/msg08708.html
* Licensed under the GPL license:
* http://www.gnu.org/licenses/gpl.html
*/
;(function($) {
$.fn.insertAtCaret = function (myValue) {
return this.each(function() {
//IE support
if (document.selection) {
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus();
} else if (this.selectionStart || this.selectionStart == '0') {
//MOZILLA / NETSCAPE support
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos)+ myValue+ this.value.substring(endPos,this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
} else {
this.value += myValue;
this.focus();
}
});
};
})(jQuery);
......@@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 4;
use Test::More tests => 5;
use C4::Context;
use C4::Letters;
......@@ -31,7 +31,9 @@ my $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
$dbh->do('DELETE FROM message_queue');
$dbh->do(q|DELETE FROM letter|);
$dbh->do(q|DELETE FROM message_queue|);
$dbh->do(q|DELETE FROM message_transport_types|);
my $borrowernumber = AddMember(
firstname => 'Jane',
......@@ -40,6 +42,13 @@ my $borrowernumber = AddMember(
branchcode => 'CPL',
);
$dbh->do(q|
INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms')
|);
my $mtts = C4::Letters::GetMessageTransportTypes();
is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes returns all values' );
my $message_id = C4::Letters::EnqueueLetter({
borrowernumber => $borrowernumber,
message_transport_type => 'sms',
......
This diff is collapsed.
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