Bugzilla – Attachment 62063 Details for
Bug 18418
Advanced Editor - Rancor - Add a control number widget
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18418 - Advanced Editor - Rancor - Add a control number widget
Bug-18418---Advanced-Editor---Rancor---Add-a-contr.patch (text/plain), 8.38 KB, created by
Nick Clemens
on 2017-04-11 19:43:17 UTC
(
hide
)
Description:
Bug 18418 - Advanced Editor - Rancor - Add a control number widget
Filename:
MIME Type:
Creator:
Nick Clemens
Created:
2017-04-11 19:43:17 UTC
Size:
8.38 KB
patch
obsolete
>From 9274d760fe050aba7036a4fd334afcacfeeb2dff Mon Sep 17 00:00:00 2001 >From: Jesse Weaver <pianohacker@gmail.com> >Date: Tue, 10 Nov 2015 12:04:14 -0700 >Subject: [PATCH] Bug 18418 - Advanced Editor - Rancor - Add a control number > widget > >This patchset adds a control number widget - numbers are generated using >an authorised value in the CONTROL_NUM_SEQUENCES category > >Test plan: >1 - Apply patch >2 - Enable helpers for fixed and coded fields in advanced cataloging >editor >3 - Add or view 001 field >4 - You should see a 'Manually assign button >5 - Click and add control number >6 - Note the title when hovering over the button >7 - Add an authorised value in the CONTROL_NUM_SEQUENCES category with >initial value as 'authorised_value' and Description as you choose >8 - Reload the editor or load a new record >9 - note you now have an 'Assign next' button or an Override button - >test both >--- > koha-tmpl/intranet-tmpl/prog/css/cateditor.css | 7 +++ > .../prog/en/includes/cateditor-widgets-marc21.inc | 57 ++++++++++++++++++++- > svc/cataloguing/control_num_sequences | 59 ++++++++++++++++++++++ > svc/cataloguing/framework | 4 +- > 4 files changed, 124 insertions(+), 3 deletions(-) > create mode 100755 svc/cataloguing/control_num_sequences > >diff --git a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css b/koha-tmpl/intranet-tmpl/prog/css/cateditor.css >index 6840d0c..b09b3e7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css >+++ b/koha-tmpl/intranet-tmpl/prog/css/cateditor.css >@@ -128,6 +128,13 @@ body { > padding: 4px; > } > >+#editor .subfield-widget button { >+ font-family: inherit; >+ font-size: inherit; >+ margin-left: 5px; >+ vertical-align: middle; >+} >+ > #editor .subfield-widget select, #editor .subfield-widget input { > height: 1.5em; > vertical-align: middle; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >index 1761c03..ed5fc01 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc >@@ -84,7 +84,7 @@ > * single subfield, '@'. > */ > >-require( [ 'widget' ], function( Widget ) { >+require( [ 'koha-backend', 'widget' ], function( KohaBackend, Widget ) { > Widget.Register( '000@', { > makeTemplate: function() { > return ' nam a22 7a 4500'; >@@ -112,6 +112,61 @@ require( [ 'widget' ], function( Widget ) { > }, > } ); > >+ Widget.Register( '001@', { >+ init: function() { >+ var $result = $( >+ '<span class="subfield-widget">' >+ + _("Control number: ") >+ + '<span class="control-number-widget-contents"></span>' >+ + '<button class="control-number-widget-assign">' + _("Assign next") + '</button>' >+ + '<select class="control-number-widget-sequence"></select>' >+ + '<button class="control-number-widget-override">' + _("Override") + '</button>' >+ + '</span>' >+ ); >+ >+ return $result[0]; >+ }, >+ setControlNumber: function( text ) { >+ if ( text ) this.setText( text ); >+ $( this.node ).find('.control-number-widget-contents') >+ .html( text == '<empty>' ? ( '<span class="hint">' + _("unset") + '</span>' ) : text ); >+ this.mark.changed(); >+ }, >+ postCreate: function( node, mark ) { >+ var widget = this; >+ this.setControlNumber( this.text ); >+ $( this.node ) >+ .find('.control-number-widget-assign').click( function() { >+ var sequence = $( widget.node ).find('.control-number-widget-sequence').val(); >+ $.post( >+ '/cgi-bin/koha/svc/cataloguing/control_num_sequences/' + sequence >+ ).done( function( result ) { >+ if ( result.next_value ) widget.setControlNumber( result.next_value ); >+ } ); >+ } ).end() >+ .find('.control-number-widget-override').click( function() { >+ var result = prompt( _("Enter new control number") ); >+ >+ if ( result ) widget.setControlNumber( result ); >+ } ).end(); >+ var sequence_list = $.map( KohaBackend.GetAuthorisedValues( 'CONTROL_NUM_SEQUENCE' ), function( authval ) { >+ return authval.lib; >+ } ); >+ sequence_list.sort(); >+ if(sequence_list.length){ >+ $.each( sequence_list, function( undef, sequence ) { >+ $( widget.node ).find('.control-number-widget-sequence').append( '<option>' + sequence + '</option>' ); >+ } ); >+ } else { >+ $(".control-number-widget-assign").remove() >+ $(".control-number-widget-sequence").remove(); >+ $(".control-number-widget-override").text( _('Manually assign') ); >+ $(".control-number-widget-override").attr('title', _('Define a CONTROL_NUM_SEQUENCE authorised value category with value set to initial value to enable auto-generation') ); >+ } >+ // TODO: Make Enter on select click "Assign" >+ } >+ } ); >+ > Widget.Register( '005@', { > init: function() { > var $result = $( '<span class="subfield-widget fixed-widget">' + _("Updated: ") + '</span>' ); >diff --git a/svc/cataloguing/control_num_sequences b/svc/cataloguing/control_num_sequences >new file mode 100755 >index 0000000..e8a4307 >--- /dev/null >+++ b/svc/cataloguing/control_num_sequences >@@ -0,0 +1,59 @@ >+#!/usr/bin/perl >+# >+# Copyright 2015 ByWater Solutions >+# >+# 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 Modern::Perl; >+ >+use C4::Service; >+use Koha::Database; >+use MARC::Record; >+ >+our ( $query, $response ) = C4::Service->init( editcatalogue => 'edit_catalogue' ); >+ >+sub get_and_increment { >+ my ( $control_num_sequence ) = @_; >+ >+ my $schema = Koha::Database->new->schema(); >+ my $authval = $schema->resultset( 'AuthorisedValue' )->find( >+ { >+ category => 'CONTROL_NUM_SEQUENCE', >+ lib => $control_num_sequence >+ } >+ ); >+ >+ if ( !$authval ) { >+ C4::Service->return_error( 'not_found' ); >+ } >+ >+ my $value = $authval->authorised_value; >+ >+ $response->param( next_value => $value ); >+ >+ my ( $prefix, $num ) = ( $value =~ /(.+?)(\d+)$/ ); >+ >+ $value = $prefix . sprintf( '%0*d', length( $num ), $num + 1 ); >+ >+ $authval->authorised_value( $value ); >+ $authval->update(); >+ >+ C4::Service->return_success( $response ); >+} >+ >+C4::Service->dispatch( >+ [ 'POST /(.*)', [], \&get_and_increment ], >+); >diff --git a/svc/cataloguing/framework b/svc/cataloguing/framework >index 4880b8a..94356b7 100755 >--- a/svc/cataloguing/framework >+++ b/svc/cataloguing/framework >@@ -56,7 +56,7 @@ my $results; > if( $branch_limit ) { > $results = $schema->resultset( "AuthorisedValue" )->search( > { "authorised_values_branches.branchcode" => { "=", [ $branch_limit, undef ] } }, >- { join => "authorised_values_branches", order_by => "lib" } ); >+ { join => "authorised_values_branches", order_by => "lib"}); > } else { > $results = $schema->resultset( "AuthorisedValue" )->search( > undef, >@@ -65,7 +65,7 @@ if( $branch_limit ) { > > foreach my $result ( $results->all ) { > $authorised_values->{$result->category} ||= []; >- push @{ $authorised_values->{$result->category} }, { value => $result->authorised_value, lib => $result->lib }; >+ push @{ $authorised_values->{$result->category->category_name} }, { value => $result->authorised_value, lib => $result->lib }; > } > > $response->param( framework => \@tags, authorised_values => $authorised_values ); >-- >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 18418
: 62063