[Koha-patches] [PATCH] bug 14803: KOHA.Checkouts js object
Srdjan
srdjan at catalyst.net.nz
Fri Jun 17 04:13:32 CEST 2016
* Use javascript to:
- update fines/checkouts info
- show/hide checkouts form and messages
* Created svc/patron/fines
---
circ/circulation.pl | 14 -----
.../prog/en/includes/blocked-fines.inc | 16 ++---
.../prog/en/modules/circ/circulation.tt | 72 ++++++++--------------
.../prog/en/modules/members/moremember.tt | 6 +-
koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 36 +++++++++++
members/moremember.pl | 3 -
svc/patron/fines | 40 ++++++++++++
7 files changed, 110 insertions(+), 77 deletions(-)
create mode 100755 svc/patron/fines
diff --git a/circ/circulation.pl b/circ/circulation.pl
index b2201cf..11bc8dd 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -261,7 +261,6 @@ if ($findborrower) {
# get the borrower information.....
if ($borrowernumber) {
$borrower = GetMemberDetails( $borrowernumber, 0 );
- my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
# Warningdate is the date that the warning starts appearing
my ( $today_year, $today_month, $today_day) = Today();
@@ -291,12 +290,6 @@ if ($borrowernumber) {
$template->param("returnbeforeexpiry" => 1);
}
}
- $template->param(
- overduecount => $od,
- issuecount => $issue,
- finetotal => $fines
- );
-
if ( IsDebarred($borrowernumber) ) {
$template->param(
'userdebarred' => $borrower->{debarred},
@@ -411,9 +404,6 @@ if (@$barcodes) {
}
}
- # FIXME If the issue is confirmed, we launch another time GetMemberIssuesAndFines, now display the issue count after issue
- my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
-
if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
$template->param(
reserveborrowernumber => $question->{'resborrowernumber'}
@@ -424,10 +414,6 @@ if (@$barcodes) {
itembiblionumber => $getmessageiteminfo->{'biblionumber'}
);
-
-
- $template_params->{issuecount} = $issue;
-
if ( $iteminfo ) {
$iteminfo->{subtitle} = GetRecordValue('subtitle', GetMarcBiblio($iteminfo->{biblionumber}), GetFrameworkCode($iteminfo->{biblionumber}));
$template_params->{item} = $iteminfo;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc
index 596c0c7..547fa7f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/blocked-fines.inc
@@ -1,14 +1,11 @@
-[% USE Price %]
-[% SET NoIssuesCharge = Koha.Preference('noissuescharge') %]
-
-[% IF NoIssuesCharge && fines > NoIssuesCharge %]
- <li>
+<script type="text/javascript">
+KOHA.Checkouts.BorrowerNumber = [% borrowernumber %];
+KOHA.Checkouts.NoIssuesCharge = [% Koha.Preference('noissuescharge') || "null" %];
+</script>
+ <li id="outstanding-fees" style="display: none;">
<span class="circ-hlt">Fees & Charges:</span>
Patron has <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">
- Outstanding fees & charges
- [% IF ( fines ) %]
- of [% fines | $Price %]
- [% END %]
+ Outstanding fees & charges of <span id="outstanding-fees-amount"></span>
</a>.
[% IF !Koha.Preference('AllowFineOverride') %]
@@ -19,4 +16,3 @@
or
<a href="/cgi-bin/koha/members/paycollect.pl?borrowernumber=[% borrowernumber %]">Pay all fines</a></li>
</li>
-[% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
index f8666bd..fd9ce38 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
@@ -23,6 +23,9 @@
[% INCLUDE 'strings.inc' %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
+<style>
+.issue-allow, .issue-disallow, #mainform {display: none;}
+</style>
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery-ui-timepicker-addon.min.js"></script>
[% INCLUDE 'timepicker.inc' %]
@@ -82,6 +85,10 @@ function toggle_onsite_checkout(){
function Dopop(link) {
var newin = window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
}
+
+KOHA.Checkouts.DisallowIssue = [% noissues ? "true" : "false" %];
+KOHA.Checkouts.ForceAllowIssue = [% forceallow ? "true" : "false" %];
+KOHA.Checkouts.ForceOnSiteCheckouts = [% Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ? "true" : "false" %];
$(document).ready(function() {
$('#mainform').on('submit',function() {
if ($("#barcode") && $("#barcode").val()) {
@@ -424,9 +431,7 @@ $(document).ready(function() {
</form>
[% IF ( RESERVED || ISSUED_TO_ANOTHER ) && (CAN_user_reserveforothers_place_holds ) %]
- [% UNLESS noissues %]
- <button type="submit" onclick="window.location.href='/cgi-bin/koha/reserve/request.pl?biblionumber=[% itembiblionumber %]&borrowernumber=[% borrowernumber %]'"><i class="fa fa-sticky-note-o"></i> Cancel checkout and place a hold for [% INCLUDE 'patron-title.inc' %]</button>
- [% END %]
+ <button class="issue-allow" type="submit" onclick="window.location.href='/cgi-bin/koha/reserve/request.pl?biblionumber=[% itembiblionumber %]&borrowernumber=[% borrowernumber %]'"><i class="fa fa-sticky-note-o"></i> Cancel checkout and place a hold for [% INCLUDE 'patron-title.inc' %]</button>
[% END %]
</div></div>
[% END %] <!-- NEEDSCONFIRMATION -->
@@ -589,7 +594,6 @@ No patron matched <span class="ex">[% message %]</span>
<div class="dialog alert"><strong>Error:</strong> This patron has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or incorrect.</div>
[% END %]
-[% IF ( !noissues ) || ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') )%]
<div class="yui-u first">
<form method="post" action="/cgi-bin/koha/circ/circulation.pl" id="mainform" name="mainform" autocomplete="off">
@@ -622,7 +626,6 @@ No patron matched <span class="ex">[% message %]</span>
<div class="checkout-settings">
- [% UNLESS ( noissues && Koha.Preference('OnSiteCheckoutsForce') ) %]
[% IF ( SpecifyDueDate ) %]
<div id="specify-due-date" class="checkout-setting">
<div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
@@ -640,10 +643,8 @@ No patron matched <span class="ex">[% message %]</span>
<button class="btn btn-small action" id="cleardate" name="cleardate" onclick="this.checked = false; this.form.duedatespec.value = ''; this.form.stickyduedate.checked = false; this.form.barcode.focus(); return false;" >Clear</button>
</div>
[% END %]
- [% END %]
- [% UNLESS ( noissues ) %]
- <div id="set-automatic-renewal" class="checkout-setting">
+ <div id="set-automatic-renewal" class="checkout-setting issue-allow">
[% IF NEEDSCONFIRMATION %]
<input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
[% ELSE %]
@@ -670,19 +671,17 @@ No patron matched <span class="ex">[% message %]</span>
<label for="override_high_holds">Don't decrease checkout length based on holds</label>
</div>
[% END %]
- [% END %]
[% IF Koha.Preference('OnSiteCheckouts') %]
<div id="onsite_checkout-select" class="checkout-setting">
- [% IF noissues %]
- <div class="onsite-checkout-only">
+ <div class="onsite-checkout-only issue-disallow">
<input type="checkbox" id="onsite_checkout" name="onsite_checkout_forced" checked="checked" disabled="disabled" /> <label for="onsite_checkout">On-site checkouts only. Automatic due date: </label>
<input type="text" name="duedatespec" id="duedatespec" readonly="readonly" />
<input type="hidden" name="onsite_checkout" checked="checked" value="1" />
</div>
- [% ELSE %]
+ <div class="issue-allow">
<input type="checkbox" id="onsite_checkout" name="onsite_checkout" /> <label for="onsite_checkout">On-site checkout</label>
- [% END %]
+ </div>
</div>
[% END %]
@@ -704,35 +703,20 @@ No patron matched <span class="ex">[% message %]</span>
[% END %]
</form></div>
-[% END %]<!-- /unless noissues -->
-
-[% IF ( noissues ) %]
- [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %]
- <div class="yui-u">
- [% ELSE %]
- <div>
- [% END %]
-[% ELSE %]
<div class="yui-u">
-[% END %]
-
- [% IF ( noissues ) %]
- [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %]
- <div id="circmessages" class="circmessage attention">
- [% ELSE %]
+ <div id="circmessages" class="circmessage attention">
+ <h3>Attention:</h3>
+ <div class="issue-disallow">
+ [% IF !( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %]
<h4>Checking out to [% INCLUDE 'patron-title.inc' %]</h4>
- <div id="circmessages" class="circmessage warning">
[% END %]
- <h3>
- Cannot check out!
- [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %]
- <span class="circ-hlt">Only on-site checkouts are allowed</span>
- [% END %]
- </h3>
- [% ELSE %]
- <div id="circmessages" class="circmessage attention">
- <h3>Attention:</h3>
- [% END %]
+ <h3>
+ Cannot check out!
+ [% IF ( Koha.Preference('OnSiteCheckouts') && Koha.Preference('OnSiteCheckoutsForce') ) %]
+ <span class="circ-hlt">Only on-site checkouts are allowed</span>
+ [% END %]
+ </h3>
+ </div>
<ul>
@@ -786,8 +770,8 @@ No patron matched <span class="ex">[% message %]</span>
<br/>
<a class="btn btn-small" href="#reldebarments" onclick="$('#debarments-tab-link').click()"><i class="fa fa-ban"></i> View restrictions</a>
- [% IF (noissues && borrowernumber && CAN_user_circulate_force_checkout) %]
- <span class="override_debarment">
+ [% IF (borrowernumber && CAN_user_circulate_force_checkout) %]
+ <span class="override_debarment issue-disallow">
<a href="/cgi-bin/koha/circ/circulation.pl?forceallow=1&borrowernumber=[% borrowernumber %]" class="btn btn-small">Override restriction temporarily</a>
</span>
[% END %]
@@ -885,11 +869,7 @@ No patron matched <span class="ex">[% message %]</span>
<ul>
<li>
- [% IF ( issuecount ) %]
- <a href="#checkouts">[% issuecount %] Checkout(s)</a>
- [% ELSE %]
- <a href="#checkouts">0 Checkouts</a>
- [% END %]
+ <a href="#checkouts"><span id="issuecount">0</span> Checkout(s)</a>
</li>
[% IF relatives_issues_count %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
index 80a80a9..c092aa2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
@@ -173,9 +173,7 @@ function validate1(date) {
[% ELSE %]
[% IF ( was_renewed ) %]<div class="dialog message">Patron's account has been renewed until [% dateexpiry | $KohaDates %]</div>[% END %]
- [% IF fines %]
- [% INCLUDE 'blocked-fines.inc' %]
- [% END %]
+ [% INCLUDE 'blocked-fines.inc' %]
[% IF ( flagged ) %]
<div id="circmessages" class="circmessage attention">
@@ -447,7 +445,7 @@ function validate1(date) {
<div id="finesholdsissues" class="toptabs">
<ul>
- <li><a href="#checkouts">[% issuecount %] Checkout(s)</a></li>
+ <li><a href="#checkouts"><span id="issuecount">0</span> Checkout(s)</a></li>
[% IF relatives_issues_count %]
<li><a href="#relatives-issues" id="relatives-issues-tab">Relatives' checkouts</a></li>
[% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
index 9643d0e..e26970e 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
@@ -1,6 +1,40 @@
+if ( KOHA === undefined ) var KOHA = {};
+KOHA.Checkouts = {
+ NoIssuesCharge: null,
+ BorrowerNumber: null,
+ DisallowIssue: false,
+ ForceAllowIssue: false,
+ ForceOnSiteCheckouts: false,
+ ToggleInput: function( allow_issue ) {
+ if (KOHA.Checkouts.DisallowIssue) allow_issue = false;
+ if (KOHA.Checkouts.ForceAllowIssue) allow_issue = true;
+
+ $(".issue-allow").toggle(allow_issue);
+ $(".issue-disallow").toggle(!allow_issue);
+ $("#mainform").toggle(allow_issue || KOHA.Checkouts.ForceOnSiteCheckouts);
+
+ if (!allow_issue) {
+ $(".circmessage.attention").removeClass("attention").addClass("warning");
+ }
+ },
+ UpdateCheckoutsAndFees: function(checkouts_only=false) {
+ $.get( "/cgi-bin/koha/svc/patron/fines", {borrowernumber: KOHA.Checkouts.BorrowerNumber}, function( data ) {
+ $("#issuecount").text(data.issuecount);
+ if (checkouts_only) return;
+
+ var noissue = KOHA.Checkouts.NoIssuesCharge && data.owing >= KOHA.Checkouts.NoIssuesCharge;
+ $("#outstanding-fees").toggle(noissue);
+ $("#outstanding-fees-amount").text(data.owing_formatted);
+ KOHA.Checkouts.ToggleInput(!noissue);
+ } );
+ }
+}
+
$(document).ready(function() {
$.ajaxSetup ({ cache: false });
+ KOHA.Checkouts.UpdateCheckoutsAndFees();
+
var barcodefield = $("#barcode");
var issuesTable;
@@ -65,6 +99,7 @@ $(document).ready(function() {
content = "";
if ( data.returned ) {
+ KOHA.Checkouts.UpdateCheckoutsAndFees(true);
content = CIRCULATION_RETURNED;
$(id).parent().parent().addClass('ok');
$('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
@@ -97,6 +132,7 @@ $(document).ready(function() {
var content = "";
if ( data.renew_okay ) {
+ KOHA.Checkouts.UpdateCheckoutsAndFees();
issuesTable.api().ajax.reload();
content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
$('#date_due_' + data.itemnumber).replaceWith( data.date_due );
diff --git a/members/moremember.pl b/members/moremember.pl
index e7c54f4..c6fe21d 100755
--- a/members/moremember.pl
+++ b/members/moremember.pl
@@ -115,9 +115,6 @@ my $borrowernumber = $input->param('borrowernumber');
my $error = $input->param('error');
$template->param( error => $error ) if ( $error );
-my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
-$template->param( issuecount => $issue, fines => $fines );
-
my $data = GetMember( 'borrowernumber' => $borrowernumber );
if ( not defined $data ) {
diff --git a/svc/patron/fines b/svc/patron/fines
new file mode 100755
index 0000000..d61df9c
--- /dev/null
+++ b/svc/patron/fines
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+# Copyright 2016 CatalystIT
+#
+# 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 strict;
+use warnings;
+
+use C4::Service;
+use C4::Members qw/GetMemberIssuesAndFines/;
+use Koha::Number::Price;
+
+my ( $query, $response ) = C4::Service->init( borrowers => '*' );
+
+my $borrowernumber = $query->param('borrowernumber');
+
+my ( $od, $issue, $owing ) = GetMemberIssuesAndFines( $borrowernumber );
+
+$response->param(
+ overduecount => $od,
+ issuecount => $issue,
+ owing => $owing || 0.00,
+ owing_formatted => Koha::Number::Price->new( $owing )->format,
+);
+
+C4::Service->return_success( $response );
--
2.7.4
More information about the Koha-patches
mailing list