View | Details | Raw Unified | Return to bug 15766
Collapse All | Expand All

(-)a/C4/Creators/Batch.pm (-1 / +4 lines)
Lines 15-20 sub _check_params { Link Here
15
    my @valid_template_params = (
15
    my @valid_template_params = (
16
        'label_id',
16
        'label_id',
17
        'batch_id',
17
        'batch_id',
18
        'description',
18
        'item_number',
19
        'item_number',
19
        'card_number',
20
        'card_number',
20
        'branch_code',
21
        'branch_code',
Lines 43-48 sub new { Link Here
43
    my $type = ref($invocant) || $invocant;
44
    my $type = ref($invocant) || $invocant;
44
    my $self = {
45
    my $self = {
45
        batch_id        => 0,
46
        batch_id        => 0,
47
        description     => '',
46
        items           => [],
48
        items           => [],
47
        branch_code     => 'NB',
49
        branch_code     => 'NB',
48
        batch_stat      => 0,   # False if any data has changed and the db has not been updated
50
        batch_stat      => 0,   # False if any data has changed and the db has not been updated
Lines 63-69 sub add_item { Link Here
63
        my $batch_id = $sth->fetchrow_array;
65
        my $batch_id = $sth->fetchrow_array;
64
        $self->{'batch_id'}= ++$batch_id;
66
        $self->{'batch_id'}= ++$batch_id;
65
    }
67
    }
66
    my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);";
68
    my $query = "INSERT INTO creator_batches (batch_id, description, $number_type, branch_code, creator) VALUES (?,?,?,?,?);";
67
    my $sth = C4::Context->dbh->prepare($query);
69
    my $sth = C4::Context->dbh->prepare($query);
68
#    $sth->{'TraceLevel'} = 3;
70
#    $sth->{'TraceLevel'} = 3;
69
    $sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1);
71
    $sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1);
Lines 149-154 sub retrieve { Link Here
149
    while (my $record = $sth->fetchrow_hashref) {
151
    while (my $record = $sth->fetchrow_hashref) {
150
        $self->{'branch_code'} = $record->{'branch_code'};
152
        $self->{'branch_code'} = $record->{'branch_code'};
151
        $self->{'creator'} = $record->{'creator'};
153
        $self->{'creator'} = $record->{'creator'};
154
        $self->{'description'} = $record->{'description'};
152
        push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
155
        push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
153
        $record_flag = 1;       # true if one or more rows were retrieved
156
        $record_flag = 1;       # true if one or more rows were retrieved
154
    }
157
    }
(-)a/C4/Creators/Lib.pm (-1 / +1 lines)
Lines 293-299 NOTE: Do not pass in the keyword 'WHERE.' Link Here
293
sub get_batch_summary {
293
sub get_batch_summary {
294
    my ( $params ) = @_;
294
    my ( $params ) = @_;
295
    my @batches = ();
295
    my @batches = ();
296
    $params->{fields} = ['batch_id', 'count(batch_id) as _item_count'];
296
    $params->{fields} = ['batch_id', 'description', 'count(batch_id) as _item_count'];
297
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
297
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
298
    $query .= " GROUP BY batch_id";
298
    $query .= " GROUP BY batch_id";
299
    my $sth = C4::Context->dbh->prepare($query);
299
    my $sth = C4::Context->dbh->prepare($query);
(-)a/installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl (+9 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    unless( column_exists( 'creator_batches', 'description' ) ) {
4
        $dbh->do(q|ALTER TABLE creator_batches ADD description mediumtext default NULL AFTER batch_id|);
5
    }
6
7
    SetVersion( $DBversion );
8
    print "Upgrade to $DBversion done (Bug 15766: Add column creator_batches.description)\n";
9
}
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1809-1814 SET character_set_client = utf8; Link Here
1809
CREATE TABLE `creator_batches` (
1809
CREATE TABLE `creator_batches` (
1810
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1810
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1811
  `batch_id` int(10) NOT NULL DEFAULT '1',
1811
  `batch_id` int(10) NOT NULL DEFAULT '1',
1812
  `description` mediumtext DEFAULT NULL,
1812
  `item_number` int(11) DEFAULT NULL,
1813
  `item_number` int(11) DEFAULT NULL,
1813
  `borrower_number` int(11) DEFAULT NULL,
1814
  `borrower_number` int(11) DEFAULT NULL,
1814
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1815
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt (+30 lines)
Lines 63-68 Link Here
63
                                    <ol><li>
63
                                    <ol><li>
64
                                        <input type="hidden" name="op" value="add" />
64
                                        <input type="hidden" name="op" value="add" />
65
                                        <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
65
                                        <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
66
                                        <label for="description">Batch description: </label>
67
                                        <input type="text" name="description" value="[% description | html %]">
68
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id | html %]">Save description</a> <span id="change-status"></span>
66
                                    </li>
69
                                    </li>
67
                                    <li>
70
                                    <li>
68
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
71
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
Lines 319-324 Link Here
319
                var batch_id = $(this).data("batch-id");
322
                var batch_id = $(this).data("batch-id");
320
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
323
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
321
            });
324
            });
325
            $("#savedesc").click(function(event){
326
                event.preventDefault(); // prevent form submission
327
                var newdescription = $(this).siblings('input[name="description"]').val();
328
                var batch_id = $(this).data('batch_id');
329
                var ajaxData = {
330
                    'newdescription': newdescription,
331
                    'batch_id': batch_id,
332
                    'card_element': "batch",
333
                    'creator': "label",
334
                };
335
336
                $.ajax({
337
                    url: '/cgi-bin/koha/svc/creator_batches',
338
                    type: 'POST',
339
                    dataType: 'json',
340
                    data: ajaxData,
341
                })
342
343
                .done(function(data){
344
                    if (data.status == 'success') {
345
                        $("input[name='description']").text(data.newdesc);
346
                        $("#change-status").text(_("Saved"));
347
                    } else {
348
                        $("#change-status").text(_("Unable to save description"));
349
                    }
350
                });
351
            });
322
         });
352
         });
323
    </script>
353
    </script>
324
[% END %]
354
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt (-7 / +37 lines)
Lines 45-56 Link Here
45
                                <div>
45
                                <div>
46
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
46
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
47
                                    <ol><li>
47
                                    <ol><li>
48
                                    <input type="hidden" name="op" value="add" />
48
                                        <input type="hidden" name="op" value="add" />
49
                                    <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
49
                                        <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
50
                                    <label for="bor_num_list">Add by borrowernumber(s):
50
                                        <label for="description">Batch description: </label>
51
                                        <br /> <span class="hint">One borrowernumber per line.</span>
51
                                        <input type="text" name="description" value="[% description | html %]">
52
                                    </label>
52
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id | html %]">Save description</a> <span id="change-status"></span>
53
                                    <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
53
                                    </li><li>
54
                                        <label for="bor_num_list">Add by borrowernumber(s):
55
                                            <br /> <span class="hint">One borrowernumber per line.</span>
56
                                        </label>
57
                                        <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
54
                                    </li></ol>
58
                                    </li></ol>
55
                                    </fieldset>
59
                                    </fieldset>
56
                                </div>
60
                                </div>
Lines 265-271 Link Here
265
                e.preventDefault();
269
                e.preventDefault();
266
                var label_id = $(this).data("label-id");
270
                var label_id = $(this).data("label-id");
267
                var batch_id = $(this).data("batch-id");
271
                var batch_id = $(this).data("batch-id");
268
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
272
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id=' + batch_id + '&label_id=' + label_id, 400, 800);
273
            });
274
            $("#savedesc").click(function(event){
275
                var newdescription = $(this).siblings('input[name="description"]').val();
276
                var batch_id = $(this).data('batch_id');
277
                var ajaxData = {
278
                    'newdescription': newdescription,
279
                    'batch_id': batch_id,
280
                    'card_element': "batch",
281
                    'creator': "patroncard",
282
                };
283
284
                $.ajax({
285
                    url: '/cgi-bin/koha/svc/creator_batches',
286
                    type: 'POST',
287
                    dataType: 'json',
288
                    data: ajaxData,
289
                })
290
291
                .done(function(data){
292
                    if (data.status == 'success') {
293
                        $("input[name='description']").text(data.newdesc);
294
                        $("#change-status").text(_("Saved"));
295
                    } else {
296
                        $("#change-status").text(_("Unable to save description"));
297
                    }
298
                });
269
            });
299
            });
270
        });
300
        });
271
    </script>
301
    </script>
(-)a/labels/label-edit-batch.pl (+3 lines)
Lines 63-68 my @item_numbers; Link Here
63
my $number_list;
63
my $number_list;
64
my $number_type = $cgi->param('number_type') || "barcode";
64
my $number_type = $cgi->param('number_type') || "barcode";
65
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
65
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
66
my $description = $cgi->param('description') || '';
66
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
67
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
67
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
68
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
68
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
69
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
Lines 99-104 elsif ($op eq 'add') { Link Here
99
    }
100
    }
100
    if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
101
    if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
101
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
102
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
103
    $template->param( description => $batch->{description} );
102
    if ($branch_code){
104
    if ($branch_code){
103
        foreach my $item_number (@item_numbers) {
105
        foreach my $item_number (@item_numbers) {
104
            $err = $batch->add_item($item_number);
106
            $err = $batch->add_item($item_number);
Lines 123-128 elsif ($op eq 'de_duplicate') { Link Here
123
}
125
}
124
else { # edit
126
else { # edit
125
    $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
127
    $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
128
    $template->param( description => $batch->{description} );
126
}
129
}
127
130
128
my $items = $batch->get_attr('items');
131
my $items = $batch->get_attr('items');
(-)a/labels/label-manage.pl (+1 lines)
Lines 66-71 my $display_columns = { layout => [ # db column => {col label Link Here
66
                                    ],
66
                                    ],
67
                        batch =>    [
67
                        batch =>    [
68
                                        {batch_id        => {label => 'Batch ID',       link_field      => 0}},
68
                                        {batch_id        => {label => 'Batch ID',       link_field      => 0}},
69
                                        {description     => {label => 'Description',    link_field      => 0}},
69
                                        {_item_count     => {label => 'Item Count',     link_field      => 0}},
70
                                        {_item_count     => {label => 'Item Count',     link_field      => 0}},
70
                                        {select          => {label => 'Actions',         value           => 'batch_id'}},
71
                                        {select          => {label => 'Actions',         value           => 'batch_id'}},
71
                                        {select1         => {label => ' ',           link_field       => 'batch_id'}},
72
                                        {select1         => {label => ' ',           link_field       => 'batch_id'}},
(-)a/patroncards/edit-batch.pl (+3 lines)
Lines 55-60 my $display_columns = [ {_summary => {label => 'Summary', link_field => 0} Link Here
55
                      ];
55
                      ];
56
my $op = $cgi->param('op') || 'new';
56
my $op = $cgi->param('op') || 'new';
57
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
57
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
58
my $description = $cgi->param('description') || '';
58
my ( @label_ids, @item_numbers, @borrower_numbers );
59
my ( @label_ids, @item_numbers, @borrower_numbers );
59
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
60
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
60
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
61
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
Lines 93-98 if ($bor_num_list) { Link Here
93
    }
94
    }
94
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
95
    if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);}
95
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
96
    if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);}
97
    $template->param( description => $batch->{'description'} );
96
    if ($branch_code){
98
    if ($branch_code){
97
        foreach my $borrower_number (@borrower_numbers) {
99
        foreach my $borrower_number (@borrower_numbers) {
98
            $err = $batch->add_item($borrower_number);
100
            $err = $batch->add_item($borrower_number);
Lines 119-124 elsif ($op eq 'de_duplicate') { Link Here
119
}
121
}
120
elsif ($op eq 'edit') {
122
elsif ($op eq 'edit') {
121
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
123
    $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
124
    $template->param( description => $batch->{'description'} );
122
}
125
}
123
elsif ($op eq 'new') {
126
elsif ($op eq 'new') {
124
    if ($branch_code eq '') {
127
    if ($branch_code eq '') {
(-)a/patroncards/manage.pl (+1 lines)
Lines 69-74 my $display_columns = { layout => [ # db column => {col label Link Here
69
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
69
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
70
                                    ],
70
                                    ],
71
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
71
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
72
                                        {description     => {label => 'Description',    link_field      => 0}},
72
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
73
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
73
                                        {_action         => {label => 'Actions',        link_field      => 0}},
74
                                        {_action         => {label => 'Actions',        link_field      => 0}},
74
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
75
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
(-)a/svc/creator_batches (-1 / +73 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz>
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use JSON qw( encode_json );
23
use CGI;
24
use C4::Service;
25
use C4::Context;
26
use C4::Auth qw /check_cookie_auth/;
27
use C4::Output qw(:DEFAULT :ajax);
28
use C4::Patroncards::Batch;
29
use C4::Labels::Batch;
30
31
=head1 NAME
32
33
svc/creator_batches - Web service for managing AJAX functionality for patroncards and label batches
34
35
=head1 DESCRIPTION
36
37
=cut
38
39
# AJAX requests
40
my $is_ajax = is_ajax();
41
my $cgi = new CGI;
42
my ( $auth_status, $sessionID ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
43
if ( $auth_status ne "ok" ) {
44
    exit 0;
45
}
46
47
if ($is_ajax) {
48
    my $batch_id = $cgi->param('batch_id');
49
    my $description = $cgi->param('newdescription');
50
    my $status = '';
51
    my $dbh = C4::Context->dbh;
52
    my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
53
    my $sth = $dbh->prepare($query);
54
    $sth->execute($description, $batch_id);
55
56
    # Check for success
57
    my $creator = $cgi->param('creator');
58
    if ( $creator eq 'patroncard' ) {
59
        my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
60
        if ( $batch->{description} eq $description ) {
61
            $status = 'success';
62
        }
63
    } elsif ( $creator eq 'label' ) {
64
        my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
65
        if ( $batch->{description} eq $description ) {
66
            $status = 'success';
67
        }
68
    }
69
70
    my $json = encode_json ( { status => $status, newdesc => $description } );
71
    output_with_http_headers $cgi, undef, $json, 'js';
72
    exit;
73
}

Return to bug 15766