--- /dev/null
+package Koha::Illcomment;
+
+# Copyright Magnus Enger Libriotech 2017
+#
+# 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, write to the Free Software Foundation, Inc., 51 Franklin
+# Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use Koha::Database;
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Illcomment - Koha Illcomment Object class
+
+=head2 Class methods
+
+=head3 patron
+
+=cut
+
+sub patron {
+ my ( $self ) = @_;
+ return Koha::Patron->_new_from_dbic(
+ scalar $self->_result->borrowernumber
+ );
+}
+
+=head2 Internal methods
+
+=head3 _type
+
+=cut
+
+sub _type {
+ return 'Illcomment';
+}
+
+=head1 AUTHOR
+
+Magnus Enger <magnus@libriotech.no>
+
+=cut
+
+1;
--- /dev/null
+package Koha::Illcomments;
+
+# TODO Add POD
+
+use Modern::Perl;
+use Koha::Database;
+use Koha::Illcomment;
+use base qw(Koha::Objects);
+
+sub _type {
+ return 'Illcomments';
+}
+
+sub object_class {
+ return 'Koha::Illcomment';
+}
+
+1;
use Koha::Database;
use Koha::Email;
use Koha::Exceptions::Ill;
+use Koha::Illcomments;
use Koha::Illrequestattributes;
use Koha::Patron;
);
}
+=head3 illcomments
+
+=cut
+
+sub illcomments {
+ my ( $self ) = @_;
+ return Koha::Illcomments->_new_from_dbic(
+ scalar $self->_result->illcomments
+ );
+}
+
=head3 patron
=cut
$self->branchcode
)->TO_JSON;
}
+ # Augment the request response with the number of comments if appropriate
+ if ( $embed->{comments} ) {
+ $object->{comments} = $self->illcomments->count;
+ }
}
return $object;
use C4::Auth;
use C4::Output;
use Koha::AuthorisedValues;
+use Koha::Illcomment;
use Koha::Illrequests;
use Koha::Libraries;
+use Koha::Token;
use Try::Tiny;
my $request = Koha::Illrequests->find($params->{illrequest_id});
$template->param(
- request => $request
+ request => $request,
+ csrf_token => Koha::Token->new->generate_csrf({
+ session_id => scalar $cgi->cookie('CGISESSID'),
+ }),
);
} elsif ( $op eq 'create' ) {
prefilters => $active_filters
);
}
+
+ } elsif ( $op eq "save_comment" ) {
+ die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
+ session_id => scalar $cgi->cookie('CGISESSID'),
+ token => scalar $cgi->param('csrf_token'),
+ });
+ my $comment = Koha::Illcomment->new({
+ illrequest_id => scalar $params->{illrequest_id},
+ borrowernumber => $patronnumber,
+ comment => scalar $params->{comment},
+ });
+ $comment->store();
+ # Redirect to view the whole request
+ print $cgi->redirect("/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=".
+ scalar $params->{illrequest_id}
+ );
+ exit;
+
} else {
my $request = Koha::Illrequests->find($params->{illrequest_id});
my $backend_result = $request->custom_capability($op, $params);
'status',
'updated',
'illrequest_id',
- 'action'
+ 'comments',
+ 'action' // Action should always be last
];
// Remove any fields we're ignoring
}
};
+ // Toggle request attributes in Illview
+ $('#toggle_requestattributes').on('click', function(e) {
+ e.preventDefault();
+ $('#requestattributes').toggleClass('content_hidden');
+ });
+
+ // Toggle new comment form in Illview
+ $('#toggle_addcomment').on('click', function(e) {
+ e.preventDefault();
+ $('#addcomment').toggleClass('content_hidden');
+ });
+
// Filter partner list
$('#partner_filter').keyup(function() {
var needle = $('#partner_filter').val();
// Get our data from the API and process it prior to passing
// it to datatables
var ajax = $.ajax(
- '/api/v1/illrequests?embed=metadata,patron,capabilities,library'
+ '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
).done(function() {
var data = JSON.parse(ajax.responseText);
// Make a copy, we'll be removing columns next and need
</div>
</div>
+ <div id="ill-view-panel" class="panel panel-default">
+ <div class="panel-heading">
+ <h3>[% request.illcomments.count %] comments</h3>
+ </div>
+ <div class="panel-body">
+ [% IF request.illcomments.count && request.illcomments.count > 0 %]
+ [% FOREACH comment IN request.illcomments %]
+ <div class="rows comment_[% comment.patron.categorycode %]">
+ <h5>Comment by:
+ <a href="[% borrowerlink %]" title="View borrower details">
+ [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a>
+ [% comment.timestamp | $KohaDates with_hours => 1 %]</h5>
+ <p>[% comment.comment | html %]</p>
+ </div>
+ [% END %]
+ [% END %]
+ <div class="rows">
+ <h3><a id="toggle_addcomment" href="#">Add comment</a></h3>
+ <div id="addcomment" class="content_hidden">
+ <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl">
+ <input type="hidden" value="save_comment" name="method">
+ <input type="hidden" value="[% csrf_token %]" name="csrf_token">
+ <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
+ <fieldset class="rows">
+ <ol>
+ <li>
+ <label class="required" for="comment">Comment: </label>
+ <textarea type="text" class="required" required="required" value="" cols="80" rows="10" id="comment" name="comment"></textarea>
+ <span class="required">Required</span>
+ </li>
+ </ol>
+ </fieldset>
+ <fieldset class="action">
+ <input type="submit" value="Submit">
+ </fieldset>
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+
[% ELSIF query_type == 'illlist' %]
<!-- illlist -->
<h1>View ILL requests</h1>
<th>Status</th>
<th>Updated on</th>
<th>Request number</th>
+ <th>Comments</th>
<th class="actions"></th>
</tr>
</thead>
--- /dev/null
+#!/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 File::Basename qw/basename/;
+use Koha::Database;
+use Koha::Illrequests;
+use Koha::Illrequestattributes;
+use Koha::Illrequest::Config;
+use Koha::Patrons;
+use t::lib::Mocks;
+use t::lib::TestBuilder;
+use Test::MockObject;
+use Test::MockModule;
+
+use Test::More tests => 9;
+
+my $schema = Koha::Database->new->schema;
+my $builder = t::lib::TestBuilder->new;
+use_ok('Koha::Illcomment');
+use_ok('Koha::Illcomments');
+
+$schema->storage->txn_begin;
+
+Koha::Illrequests->search->delete;
+
+# Create a patron
+my $patron = $builder->build({ source => 'Borrower' });
+
+# Create an ILL request
+my $illrq = $builder->build({
+ source => 'Illrequest',
+ value => { borrowernumber => $patron->{borrowernumber} }
+});
+my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
+isa_ok( $illrq_obj, 'Koha::Illrequest' );
+
+# Create a librarian
+my $librarian = $builder->build({ source => 'Borrower' });
+
+# Create a comment and tie it to the request and the librarian
+my $comment_text = 'xyz';
+my $illcomment = $builder->build({
+ source => 'Illcomment',
+ value => {
+ illrequest_id => $illrq_obj->illrequest_id,
+ borrowernumber => $librarian->{borrowernumber},
+ comment => $comment_text,
+ }
+});
+
+# Get all the comments
+my $comments = $illrq_obj->illcomments;
+isa_ok( $comments, 'Koha::Illcomments', "Illcomments" );
+my @comments_list = $comments->as_list();
+is( scalar @comments_list, 1, "We have 1 comment" );
+
+# Get the first (and only) comment
+my $comment = $comments->next();
+isa_ok( $comment, 'Koha::Illcomment', "Illcomment" );
+
+# Check the different data in the comment
+is( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' );
+is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works');
+is( $comment->comment, $comment_text, 'comment getter works');
+
+$illrq_obj->delete;
+
+$schema->storage->txn_rollback;