my @valid_template_params = (
'label_id',
'batch_id',
+ 'description',
'item_number',
'card_number',
'branch_code',
my $type = ref($invocant) || $invocant;
my $self = {
batch_id => 0,
+ description => '',
items => [],
branch_code => 'NB',
batch_stat => 0, # False if any data has changed and the db has not been updated
my $batch_id = $sth->fetchrow_array;
$self->{'batch_id'}= ++$batch_id;
}
- my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);";
+ my $query = "INSERT INTO creator_batches (batch_id, description, $number_type, branch_code, creator) VALUES (?,?,?,?,?);";
my $sth = C4::Context->dbh->prepare($query);
# $sth->{'TraceLevel'} = 3;
$sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1);
while (my $record = $sth->fetchrow_hashref) {
$self->{'branch_code'} = $record->{'branch_code'};
$self->{'creator'} = $record->{'creator'};
+ $self->{'description'} = $record->{'description'};
push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
$record_flag = 1; # true if one or more rows were retrieved
}
sub get_batch_summary {
my ( $params ) = @_;
my @batches = ();
- $params->{fields} = ['batch_id', 'count(batch_id) as _item_count'];
+ $params->{fields} = ['batch_id', 'description', 'count(batch_id) as _item_count'];
my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
$query .= " GROUP BY batch_id";
my $sth = C4::Context->dbh->prepare($query);
--- /dev/null
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+ unless( column_exists( 'creator_batches', 'description' ) ) {
+ $dbh->do(q|ALTER TABLE creator_batches ADD description mediumtext default NULL AFTER batch_id|);
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15766: Add column creator_batches.description)\n";
+}
CREATE TABLE `creator_batches` (
`label_id` int(11) NOT NULL AUTO_INCREMENT,
`batch_id` int(10) NOT NULL DEFAULT '1',
+ `description` mediumtext DEFAULT NULL,
`item_number` int(11) DEFAULT NULL,
`borrower_number` int(11) DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
<ol><li>
<input type="hidden" name="op" value="add" />
<input type="hidden" name="batch_id" value="[% batch_id | html %]" />
+ <label for="description">Batch description: </label>
+ <input type="text" name="description" value="[% description | html %]">
+ <a href="#" id="savedesc" data-batch_id="[% batch_id | html %]">Save description</a> <span id="change-status"></span>
</li>
<li>
<input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
var batch_id = $(this).data("batch-id");
GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
});
+ $("#savedesc").click(function(event){
+ event.preventDefault(); // prevent form submission
+ var newdescription = $(this).siblings('input[name="description"]').val();
+ var batch_id = $(this).data('batch_id');
+ var ajaxData = {
+ 'newdescription': newdescription,
+ 'batch_id': batch_id,
+ 'card_element': "batch",
+ 'creator': "label",
+ };
+
+ $.ajax({
+ url: '/cgi-bin/koha/svc/creator_batches',
+ type: 'POST',
+ dataType: 'json',
+ data: ajaxData,
+ })
+
+ .done(function(data){
+ if (data.status == 'success') {
+ $("input[name='description']").text(data.newdesc);
+ $("#change-status").text(_("Saved"));
+ } else {
+ $("#change-status").text(_("Unable to save description"));
+ }
+ });
+ });
});
</script>
[% END %]
<div>
<fieldset class="rows" style="border-bottom: 0px; border: 0px;">
<ol><li>
- <input type="hidden" name="op" value="add" />
- <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
- <label for="bor_num_list">Add by borrowernumber(s):
- <br /> <span class="hint">One borrowernumber per line.</span>
- </label>
- <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
+ <input type="hidden" name="op" value="add" />
+ <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
+ <label for="description">Batch description: </label>
+ <input type="text" name="description" value="[% description | html %]">
+ <a href="#" id="savedesc" data-batch_id="[% batch_id | html %]">Save description</a> <span id="change-status"></span>
+ </li><li>
+ <label for="bor_num_list">Add by borrowernumber(s):
+ <br /> <span class="hint">One borrowernumber per line.</span>
+ </label>
+ <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
</li></ol>
</fieldset>
</div>
e.preventDefault();
var label_id = $(this).data("label-id");
var batch_id = $(this).data("batch-id");
- GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
+ GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id=' + batch_id + '&label_id=' + label_id, 400, 800);
+ });
+ $("#savedesc").click(function(event){
+ var newdescription = $(this).siblings('input[name="description"]').val();
+ var batch_id = $(this).data('batch_id');
+ var ajaxData = {
+ 'newdescription': newdescription,
+ 'batch_id': batch_id,
+ 'card_element': "batch",
+ 'creator': "patroncard",
+ };
+
+ $.ajax({
+ url: '/cgi-bin/koha/svc/creator_batches',
+ type: 'POST',
+ dataType: 'json',
+ data: ajaxData,
+ })
+
+ .done(function(data){
+ if (data.status == 'success') {
+ $("input[name='description']").text(data.newdesc);
+ $("#change-status").text(_("Saved"));
+ } else {
+ $("#change-status").text(_("Unable to save description"));
+ }
+ });
});
});
</script>
my $number_list;
my $number_type = $cgi->param('number_type') || "barcode";
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
+my $description = $cgi->param('description') || '';
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
}
if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
+ $template->param( description => $batch->{description} );
if ($branch_code){
foreach my $item_number (@item_numbers) {
$err = $batch->add_item($item_number);
}
else { # edit
$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
+ $template->param( description => $batch->{description} );
}
my $items = $batch->get_attr('items');
],
batch => [
{batch_id => {label => 'Batch ID', link_field => 0}},
+ {description => {label => 'Description', link_field => 0}},
{_item_count => {label => 'Item Count', link_field => 0}},
{select => {label => 'Actions', value => 'batch_id'}},
{select1 => {label => ' ', link_field => 'batch_id'}},
];
my $op = $cgi->param('op') || 'new';
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
+my $description = $cgi->param('description') || '';
my ( @label_ids, @item_numbers, @borrower_numbers );
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
}
if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
+ $template->param( description => $batch->{'description'} );
if ($branch_code){
foreach my $borrower_number (@borrower_numbers) {
$err = $batch->add_item($borrower_number);
}
elsif ($op eq 'edit') {
$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
+ $template->param( description => $batch->{'description'} );
}
elsif ($op eq 'new') {
if ($branch_code eq '') {
{select => {label => 'Select', value => 'profile_id'}},
],
batch => [ {batch_id => {label => 'Batch ID', link_field => 0}},
+ {description => {label => 'Description', link_field => 0}},
{_item_count => {label => 'Patron Count', link_field => 0}},
{_action => {label => 'Actions', link_field => 0}},
{select => {label => 'Select', value => 'batch_id'}},
--- /dev/null
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz>
+#
+# 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 JSON qw( encode_json );
+use CGI;
+use C4::Service;
+use C4::Context;
+use C4::Auth qw /check_cookie_auth/;
+use C4::Output qw(:DEFAULT :ajax);
+use C4::Patroncards::Batch;
+use C4::Labels::Batch;
+
+=head1 NAME
+
+svc/creator_batches - Web service for managing AJAX functionality for patroncards and label batches
+
+=head1 DESCRIPTION
+
+=cut
+
+# AJAX requests
+my $is_ajax = is_ajax();
+my $cgi = new CGI;
+my ( $auth_status, $sessionID ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
+if ( $auth_status ne "ok" ) {
+ exit 0;
+}
+
+if ($is_ajax) {
+ my $batch_id = $cgi->param('batch_id');
+ my $description = $cgi->param('newdescription');
+ my $status = '';
+ my $dbh = C4::Context->dbh;
+ my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($description, $batch_id);
+
+ # Check for success
+ my $creator = $cgi->param('creator');
+ if ( $creator eq 'patroncard' ) {
+ my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
+ if ( $batch->{description} eq $description ) {
+ $status = 'success';
+ }
+ } elsif ( $creator eq 'label' ) {
+ my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
+ if ( $batch->{description} eq $description ) {
+ $status = 'success';
+ }
+ }
+
+ my $json = encode_json ( { status => $status, newdesc => $description } );
+ output_with_http_headers $cgi, undef, $json, 'js';
+ exit;
+}