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 279-285 NOTE: Do not pass in the keyword 'WHERE.' Link Here
279
sub get_batch_summary {
279
sub get_batch_summary {
280
    my ( $params ) = @_;
280
    my ( $params ) = @_;
281
    my @batches = ();
281
    my @batches = ();
282
    $params->{fields} = ['batch_id', 'count(batch_id) as _item_count'];
282
    $params->{fields} = ['batch_id', 'description', 'count(batch_id) as _item_count'];
283
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
283
    my ( $query, @where_args ) = _build_query( $params, 'creator_batches' );
284
    $query .= " GROUP BY batch_id";
284
    $query .= " GROUP BY batch_id";
285
    my $sth = C4::Context->dbh->prepare($query);
285
    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 1841-1846 SET character_set_client = utf8; Link Here
1841
CREATE TABLE `creator_batches` (
1841
CREATE TABLE `creator_batches` (
1842
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1842
  `label_id` int(11) NOT NULL AUTO_INCREMENT,
1843
  `batch_id` int(10) NOT NULL DEFAULT '1',
1843
  `batch_id` int(10) NOT NULL DEFAULT '1',
1844
  `description` mediumtext DEFAULT NULL,
1844
  `item_number` int(11) DEFAULT NULL,
1845
  `item_number` int(11) DEFAULT NULL,
1845
  `borrower_number` int(11) DEFAULT NULL,
1846
  `borrower_number` int(11) DEFAULT NULL,
1846
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1847
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt (-2 / +32 lines)
Lines 124-130 Link Here
124
                return (-1);
124
                return (-1);
125
            };
125
            };
126
126
127
         $(document).ready(function() {
127
        $(document).ready(function() {
128
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
128
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
129
                "autoWidth": false,
129
                "autoWidth": false,
130
                "aoColumnDefs": [
130
                "aoColumnDefs": [
Lines 167-173 Link Here
167
                var batch_id = $(this).data("batch-id");
167
                var batch_id = $(this).data("batch-id");
168
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
168
                GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
169
            });
169
            });
170
         });
170
            $("#savedesc").click(function(event){
171
                event.preventDefault(); // prevent form submission
172
                var newdescription = $(this).siblings('input[name="description"]').val();
173
                var batch_id = $(this).data('batch_id');
174
                var ajaxData = {
175
                    'newdescription': newdescription,
176
                    'batch_id': batch_id,
177
                    'card_element': "batch",
178
                    'creator': "label",
179
                };
180
181
                $.ajax({
182
                    url: '/cgi-bin/koha/svc/creator_batches',
183
                    type: 'POST',
184
                    dataType: 'json',
185
                    data: ajaxData,
186
                })
187
188
                .done(function(data){
189
                    if (data.status == 'success') {
190
                        $("input[name='description']").text(data.newdesc);
191
                        $("#change-status").text(_("Saved"));
192
                    } else {
193
                        $("#change-status").text(_("Unable to save description"));
194
                    }
195
                });
196
            });
197
        });
171
    //]]>
198
    //]]>
172
    </script>
199
    </script>
173
</head>
200
</head>
Lines 208-213 Link Here
208
                                    <ol><li>
235
                                    <ol><li>
209
                                        <input type="hidden" name="op" value="add" />
236
                                        <input type="hidden" name="op" value="add" />
210
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
237
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
238
                                        <label for="description">Batch description: </label>
239
                                        <input type="text" name="description" value="[% description %]">
240
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id %]">Save description</a> <span id="change-status"></span>
211
                                    </li>
241
                                    </li>
212
                                    <li>
242
                                    <li>
213
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
243
                                        <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt (-9 / +39 lines)
Lines 94-100 Link Here
94
                    // some pass-thru error trapping just in case...
94
                    // some pass-thru error trapping just in case...
95
                }
95
                }
96
            };
96
            };
97
           function selected_layout() {
97
            function selected_layout() {
98
                if (document.items.action.length) {
98
                if (document.items.action.length) {
99
                for (i=0;i<document.items.action.length;i++){
99
                for (i=0;i<document.items.action.length;i++){
100
                    if (document.items.action[i].checked==true){
100
                    if (document.items.action[i].checked==true){
Lines 111-117 Link Here
111
                return (-1);
111
                return (-1);
112
            };
112
            };
113
113
114
         $(document).ready(function() {
114
            $(document).ready(function() {
115
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
115
            $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
116
                "aoColumnDefs": [
116
                "aoColumnDefs": [
117
                    { "aTargets": [ -2, -1 ], "bSortable": false, "bSearchable": false }
117
                    { "aTargets": [ -2, -1 ], "bSortable": false, "bSearchable": false }
Lines 153-159 Link Here
153
                var batch_id = $(this).data("batch-id");
153
                var batch_id = $(this).data("batch-id");
154
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
154
                GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id='+batch_id+'&label_id='+label_id, 400, 800);
155
            });
155
            });
156
         });
156
            $("#savedesc").click(function(event){
157
                var newdescription = $(this).siblings('input[name="description"]').val();
158
                var batch_id = $(this).data('batch_id');
159
                var ajaxData = {
160
                    'newdescription': newdescription,
161
                    'batch_id': batch_id,
162
                    'card_element': "batch",
163
                    'creator': "patroncard",
164
                };
165
166
                $.ajax({
167
                    url: '/cgi-bin/koha/svc/creator_batches',
168
                    type: 'POST',
169
                    dataType: 'json',
170
                    data: ajaxData,
171
                })
172
173
                .done(function(data){
174
                    if (data.status == 'success') {
175
                        $("input[name='description']").text(data.newdesc);
176
                        $("#change-status").text(_("Saved"));
177
                    } else {
178
                        $("#change-status").text(_("Unable to save description"));
179
                    }
180
                });
181
            });
182
            });
157
        //]]>
183
        //]]>
158
    </script>
184
    </script>
159
</head>
185
</head>
Lines 195-206 Link Here
195
                                <div>
221
                                <div>
196
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
222
                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
197
                                    <ol><li>
223
                                    <ol><li>
198
                                    <input type="hidden" name="op" value="add" />
224
                                        <input type="hidden" name="op" value="add" />
199
                                    <input type="hidden" name="batch_id" value="[% batch_id %]" />
225
                                        <input type="hidden" name="batch_id" value="[% batch_id %]" />
200
                                    <label for="bor_num_list">Add by borrowernumber(s):
226
                                        <label for="description">Batch description: </label>
201
                                        <br /> <span class="hint">One borrowernumber per line.</span>
227
                                        <input type="text" name="description" value="[% description %]">
202
                                    </label>
228
                                        <a href="#" id="savedesc" data-batch_id="[% batch_id %]">Save description</a> <span id="change-status"></span>
203
                                    <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
229
                                    </li><li>
230
                                        <label for="bor_num_list">Add by borrowernumber(s):
231
                                            <br /> <span class="hint">One borrowernumber per line.</span>
232
                                        </label>
233
                                        <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
204
                                    </li></ol>
234
                                    </li></ol>
205
                                    </fieldset>
235
                                    </fieldset>
206
                                </div>
236
                                </div>
(-)a/labels/label-edit-batch.pl (+3 lines)
Lines 62-67 my @item_numbers; Link Here
62
my $number_list;
62
my $number_list;
63
my $number_type = $cgi->param('number_type') || "barcode";
63
my $number_type = $cgi->param('number_type') || "barcode";
64
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
64
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
65
my $description = $cgi->param('description') || '';
65
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
66
@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
66
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
67
@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
67
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
68
$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 70-75 my $display_columns = { layout => [ # db column => {col label Link Here
70
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
70
                                        {select          => {label => 'Select',         value           => 'profile_id'}},
71
                                    ],
71
                                    ],
72
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
72
                        batch =>    [   {batch_id        => {label => 'Batch ID',       link_field      => 0}},
73
                                        {description     => {label => 'Description',    link_field      => 0}},
73
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
74
                                        {_item_count     => {label => 'Patron Count',   link_field      => 0}},
74
                                        {_action         => {label => 'Actions',        link_field      => 0}},
75
                                        {_action         => {label => 'Actions',        link_field      => 0}},
75
                                        {select          => {label => 'Select',         value           => 'batch_id'}},
76
                                        {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