Bugzilla – Attachment 63221 Details for
Bug 15766
Give label and patron card batches a description
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15766: Adding descriptions to patron card batches
Bug-15766-Adding-descriptions-to-patron-card-batch.patch (text/plain), 13.61 KB, created by
Marc Véron
on 2017-05-07 11:51:41 UTC
(
hide
)
Description:
Bug 15766: Adding descriptions to patron card batches
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2017-05-07 11:51:41 UTC
Size:
13.61 KB
patch
obsolete
>From bb4565548085c744c049bb8fa212bbfeec27bba9 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Wed, 8 Feb 2017 00:18:42 +0000 >Subject: [PATCH] Bug 15766: Adding descriptions to patron card batches >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds a 'description' column to the creator_batches table. The >description for a batch can be added and updated using ajax. > >To test: >1) Apply patch and update database (you will have to restart memcached) >2) Go to Tools -> Patron card creator -> Manage batches >3) There should now be a Description column next to Batch ID. This will >be empty (as none of the batches have descriptions yet) >4) Click Edit for any batch >5) Notice new Batch description text field. Enter a description for the >batch in here and click Save description. Some text should show saying >the description was saved. >6) If you go back to the manage batches page, the description should now >show under the Description column. > >Sponsored-by: Catalyst IT > >Signed-off-by: Eric Gosselin <eric.gosselin@inlibro.com> > >Tested on current master, works as expected. >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Creators/Batch.pm | 7 ++- > C4/Creators/Lib.pm | 2 +- > ..._15766_-_add_description_column_to_batches.perl | 9 +++ > installer/data/mysql/kohastructure.sql | 1 + > .../prog/en/modules/patroncards/edit-batch.tt | 42 ++++++++++++-- > patroncards/edit-batch.pl | 3 + > patroncards/manage.pl | 1 + > svc/patroncards | 67 ++++++++++++++++++++++ > 8 files changed, 123 insertions(+), 9 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl > create mode 100644 svc/patroncards > >diff --git a/C4/Creators/Batch.pm b/C4/Creators/Batch.pm >index 1191b96..9b9a0f2 100644 >--- a/C4/Creators/Batch.pm >+++ b/C4/Creators/Batch.pm >@@ -15,6 +15,7 @@ sub _check_params { > my @valid_template_params = ( > 'label_id', > 'batch_id', >+ 'description', > 'item_number', > 'card_number', > 'branch_code', >@@ -43,6 +44,7 @@ sub new { > 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 >@@ -63,10 +65,10 @@ sub add_item { > 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); >+ $sth->execute($self->{'batch_id'}, $self->{'description'}, $number, $self->{'branch_code'}, $1); > if ($sth->err) { > warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr); > return -1; >@@ -149,6 +151,7 @@ sub retrieve { > 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 > } >diff --git a/C4/Creators/Lib.pm b/C4/Creators/Lib.pm >index 3c53498..9373ae1 100644 >--- a/C4/Creators/Lib.pm >+++ b/C4/Creators/Lib.pm >@@ -279,7 +279,7 @@ NOTE: Do not pass in the keyword 'WHERE.' > 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); >diff --git a/installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl b/installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl >new file mode 100644 >index 0000000..1eb2c4a >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_15766_-_add_description_column_to_batches.perl >@@ -0,0 +1,9 @@ >+$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"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 94ef125..e2ead40 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1823,6 +1823,7 @@ SET character_set_client = utf8; > 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, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt >index 3909fd8..c18cafc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt >@@ -153,6 +153,32 @@ > 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); > }); >+ $("#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", >+ }; >+ >+ $.ajax({ >+ url: '/cgi-bin/koha/svc/patroncards', >+ 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> >@@ -195,12 +221,16 @@ > <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 %]" /> >- <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 %]" /> >+ <label for="description">Batch description: </label> >+ <input type="text" name="description" value="[% description %]"> >+ <a href="#" id="savedesc" data-batch_id="[% batch_id %]">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> >diff --git a/patroncards/edit-batch.pl b/patroncards/edit-batch.pl >index cd1f774..a80fe3a 100755 >--- a/patroncards/edit-batch.pl >+++ b/patroncards/edit-batch.pl >@@ -54,6 +54,7 @@ my $display_columns = [ {_summary => {label => 'Summary', link_field => 0} > ]; > 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'); >@@ -92,6 +93,7 @@ if ($bor_num_list) { > } > 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); >@@ -118,6 +120,7 @@ elsif ($op eq 'de_duplicate') { > } > 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 '') { >diff --git a/patroncards/manage.pl b/patroncards/manage.pl >index 837fccd..13c3d60 100755 >--- a/patroncards/manage.pl >+++ b/patroncards/manage.pl >@@ -70,6 +70,7 @@ my $display_columns = { layout => [ # db column => {col label > {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'}}, >diff --git a/svc/patroncards b/svc/patroncards >new file mode 100644 >index 0000000..3766cca >--- /dev/null >+++ b/svc/patroncards >@@ -0,0 +1,67 @@ >+#!/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( to_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 Data::Dumper; >+ >+=head1 NAME >+ >+svc/patroncards - Web service for managing AJAX functionality for patroncards >+ >+=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 $card_element = $cgi->param('card_element'); >+ if ( $card_element eq 'batch' ) { >+ 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 $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id); >+ if ( $batch->{description} eq $description ) { >+ $status = 'success'; >+ } >+ >+ my $json = to_json ( { status => $status, newdesc => $description } ); >+ output_with_http_headers $cgi, undef, $json, 'js'; >+ exit; >+ } >+} >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15766
:
59994
|
59998
|
59999
|
61462
|
61463
|
61464
|
63221
|
63222
|
63223
|
66515
|
67305
|
67862
|
68282
|
68359
|
68360
|
68361
|
68362
|
75213
|
75214
|
75215
|
75216
|
75715
|
75843
|
79839
|
79840
|
79841
|
79842
|
79843
|
79844
|
79845
|
79846
|
80446
|
80447
|
80448
|
80449
|
80450
|
80451
|
81070
|
81084
|
81086