@@ -, +, @@
---
koha-tmpl/intranet-tmpl/prog/css/cateditor.css | 7 +++
.../prog/en/includes/cateditor-widgets-marc21.inc | 51 +++++++++++++++++++
svc/cataloguing/control_num_sequences | 59 ++++++++++++++++++++++
3 files changed, 117 insertions(+)
create mode 100755 svc/cataloguing/control_num_sequences
--- a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css
+++ a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css
@@ -155,6 +155,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;
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc
@@ -112,6 +112,57 @@ require( [ 'koha-backend', 'widget' ], function( KohaBackend, Widget ) {
},
} );
+ Widget.Register( '001@', {
+ init: function() {
+ var $result = $(
+ ''
+ + _("Control number: ")
+ + ''
+ + ''
+ + ''
+ + ''
+ + ''
+ );
+
+ return $result[0];
+ },
+ setControlNumber: function( text ) {
+ if ( text ) this.setText( text );
+ $( this.node ).find('.control-number-widget-contents')
+ .html( text == '' ? ( '' + _("unset") + '' ) : 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();
+
+ $.each( sequence_list, function( undef, sequence ) {
+ $( widget.node ).find('.control-number-widget-sequence').append( '' );
+ } );
+
+ // TODO: Make Enter on select click "Assign"
+ }
+ } );
+
Widget.Register( '005@', {
init: function() {
var $result = $( '' + _("Updated: ") + '' );
--- a/svc/cataloguing/control_num_sequences
+++ a/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;
+
+my ( $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 ],
+);
--