Keeps the selected framework, allows selecting another and validates the record using the correct framework. Contains additional minor tweaks to display proper error messages.
To test:
1. Add a record with a non-default framework in the basic editor.
2. Switch to advanced editor and make sure the settings menu displays the correct framework.
3. Save the record and confirm that the framework code did not change.
4. Change the framework and save the record again.
5. Verify that the framework code changed.
6. Change one framework to make an extra field mandatory.
7. Make sure that the field is required in the editor when the framework above is selected but not when another framework is selected.
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
use DBIx::Class::ResultClass::HashRefInflator;
use Koha::Database;
use Koha::MarcSubfieldStructures;
+use Koha::BiblioFrameworks;
my $input = CGI->new;
my $authtags = Koha::MarcSubfieldStructures->search({ authtypecode => { '!=' => '' }, 'frameworkcode' => '' });
$template->{VARS}->{authtags} = $authtags;
+my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
+$template->{VARS}->{frameworks} = $frameworks;
+
# Z39.50 servers
my $dbh = C4::Context->dbh;
$template->{VARS}->{z3950_servers} = $dbh->selectall_arrayref( q{
while ( record.removeField(bibnumTag) );
}
+ function initFramework( frameworkcode, callback ) {
+ if ( typeof _frameworks[frameworkcode] === 'undefined' ) {
+ $.get(
+ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=' + frameworkcode
+ ).done( function( framework ) {
+ _importFramework( frameworkcode, framework.framework );
+ callback();
+ } ).fail( function( data ) {
+ callback( 'Could not fetch framework settings' );
+ } );
+ } else {
+ callback();
+ }
+ }
+
var KohaBackend = {
NOT_EMPTY: {}, // Sentinel value
+ InitFramework: initFramework,
+
GetAllTagsInfo: function( frameworkcode, tagnumber ) {
return _framework_mappings[frameworkcode];
},
GetRecord: function( id, callback ) {
$.get(
'/cgi-bin/koha/svc/bib/' + id
- ).done( function( data ) {
- var record = new MARC.Record();
- record.loadMARCXML(data);
- callback(record);
- } ).fail( function( data ) {
- callback( { error: data } );
+ ).done( function( metadata ) {
+ $.get(
+ '/cgi-bin/koha/svc/bib_framework/' + id
+ ).done( function( frameworkcode ) {
+ var record = new MARC.Record();
+ record.loadMARCXML(metadata);
+ record.frameworkcode = $(frameworkcode).find('frameworkcode').text();
+ initFramework( record.frameworkcode, function( error ) {
+ if ( typeof error === 'undefined' ) {
+ callback( record );
+ } else {
+ callback( { error: error } );
+ }
+ });
+ } ).fail( function( data ) {
+ callback( { error: _('Could not fetch frameworkcode for record') } );
+ } );
} );
},
} ).done( function( data ) {
callback( _fromXMLStruct( data ) );
} ).fail( function( data ) {
- callback( { error: data } );
+ callback( { error: _('Could not save record') } );
} );
},
SaveRecord: function( id, record, callback ) {
+ var frameworkcode = record.frameworkcode;
record = record.clone();
_removeBiblionumberFields( record );
$.ajax( {
type: 'POST',
- url: '/cgi-bin/koha/svc/bib/' + id,
+ url: '/cgi-bin/koha/svc/bib/' + id + '?frameworkcode=' + encodeURIComponent(frameworkcode),
data: record.toXML(),
contentType: 'text/xml'
} ).done( function( data ) {
- callback( _fromXMLStruct( data ) );
+ var record = _fromXMLStruct( data );
+ if ( record.marcxml ) {
+ record.marcxml[0].frameworkcode = frameworkcode;
+ }
+ callback( record );
} ).fail( function( data ) {
callback( { data: { error: data } } );
} );
ValidateRecord: function( frameworkcode, record ) {
var errors = [];
- var mandatoryTags = KohaBackend.GetTagsBy( '', 'mandatory', '1' );
- var mandatorySubfields = KohaBackend.GetSubfieldsBy( '', 'mandatory', '1' );
- var nonRepeatableTags = KohaBackend.GetTagsBy( '', 'repeatable', '0' );
- var nonRepeatableSubfields = KohaBackend.GetSubfieldsBy( '', 'repeatable', '0' );
+ var mandatoryTags = KohaBackend.GetTagsBy( record.frameworkcode, 'mandatory', '1' );
+ var mandatorySubfields = KohaBackend.GetSubfieldsBy( record.frameworkcode, 'mandatory', '1' );
+ var nonRepeatableTags = KohaBackend.GetTagsBy( record.frameworkcode, 'repeatable', '0' );
+ var nonRepeatableSubfields = KohaBackend.GetSubfieldsBy( record.frameworkcode, 'repeatable', '0' );
$.each( mandatoryTags, function( tag ) {
if ( !record.hasField( tag ) ) errors.push( { type: 'missingTag', tag: tag } );
} );
function MARCEditor( options ) {
+ this.frameworkcode = '';
+
this.cm = CodeMirror(
options.position,
{
this.cm.refresh();
},
+ setFrameworkCode: function( code, callback ) {
+ this.frameworkcode = code;
+ $( 'a.change-framework i.selected' ).addClass( 'hidden' );
+ $( 'a.change-framework i.unselected' ).removeClass( 'hidden' );
+ $( 'a.change-framework[data-frameworkcode="' + code + '"] i.unselected' ).addClass( 'hidden' );
+ $( 'a.change-framework[data-frameworkcode="' + code + '"] i.selected' ).removeClass( 'hidden ');
+ KohaBackend.InitFramework( code, callback );
+ },
+
displayRecord: function( record ) {
this.cm.setValue( TextMARC.RecordToText(record) );
this.modified = false;
+ var cm = this.cm;
+ this.setFrameworkCode(
+ typeof record.frameworkcode !== 'undefined' ? record.frameworkcode : '',
+ function ( error ) {
+ if ( typeof error !== 'undefined' ) {
+ humanMsg.displayAlert( _(error), { className: 'humanError' } );
+ }
+ cm.setOption( 'mode', {
+ name: 'marc',
+ nonRepeatableTags: KohaBackend.GetTagsBy( this.frameworkcode, 'repeatable', '0' ),
+ nonRepeatableSubfields: KohaBackend.GetSubfieldsBy( this.frameworkcode, 'repeatable', '0' )
+ });
+ }
+ );
},
getRecord: function() {
this.textMode = false;
+ record.frameworkcode = this.frameworkcode;
return record;
},
padding-bottom: 0;
}
+.humanMsg.humanSuccess {
+ left: 75%;
+ width: 20%;
+ top: 160px;
+}
+
#shortcuts-container {
font-size: 12px;
}
width: 14em;
}
-.fa.fa-spinner {
- display: inline-block;
- height: 16px;
- width: 16px;
- background: transparent url("../img/spinner-small.gif") top left no-repeat;
- padding: -1px;
- vertical-align: text-top;
-}
/*> Search results */
if (data.newRecord) {
var record = new MARC.Record();
record.loadMARCXML(data.newRecord);
+ record.frameworkcode = data.newRecord.frameworkcode;
editor.displayRecord( record );
}
// Click bindings
$( '#save-record, #save-dropdown a' ).click( function() {
- $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner' ).siblings( 'span' ).text( _("Saving...") );
+ $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner fa-spin' ).siblings( 'span' ).text( _("Saving...") );
function finishCb(result) {
if ( result.error == 'syntax' ) {
{ return undefined; }
};
+ $('a.change-framework').click( function() {
+ $("#loading").show();
+ editor.setFrameworkCode(
+ $(this).data( 'frameworkcode' ),
+ function ( error ) {
+ if ( typeof error !== 'undefined' ) {
+ humanMsg.displayAlert( _("Failed to change framework"), { className: 'humanError' } );
+ }
+ $('#loading').hide();
+ }
+ );
+ } );
+
// Start editor
Preferences.Load( [% logged_in_user.borrowernumber || 0 | html %] );
displayPreferences(editor);
} );
function finishCb( data ) {
- if ( data.error ) openRecord( 'new/', editor, finishCb );
+ if ( data.error ) {
+ humanMsg.displayAlert( data.error );
+ openRecord( 'new/', editor, finishCb );
+ }
Resources.GetAll().done( function() {
$("#loading").hide();
<ul id="prefs-menu" class="dropdown-menu">
<li><a id="switch-editor" href="#">Switch to basic editor</a></li>
<li><a id="set-field-widgets" href="#"></a></li>
+ <li class="nav-header">Change framework</li>
+ <li>
+ <a class="change-framework" data-frameworkcode="">
+ <i class="fa fa-fw unselected"> </i>
+ <i class="fa fa-fw fa-check selected"> </i>
+ Default
+ </a>
+ </li>
+ [% FOREACH framework IN frameworks %]
+ <li>
+ <a class="change-framework" data-frameworkcode="[% framework.frameworkcode | html %]">
+ <i class="fa fa-fw fa-check selected"></i>
+ <i class="fa fa-fw unselected"> </i>
+ [% framework.frameworktext | html %]
+ </a>
+ </li>
+ [% END %]
<li class="divider"></li>
<li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
<li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
my $query = shift;
my $biblionumber = shift;
my $old_record = GetMarcBiblio({ biblionumber => $biblionumber });
+ my $frameworkcode = $query->url_param('frameworkcode') // '';
unless (defined $old_record) {
print $query->header(-type => 'text/xml', -status => '404 Not Found');
return;
}
}
- ModBiblio( $record, $biblionumber, '' );
+ ModBiblio( $record, $biblionumber, $frameworkcode );
my $new_record = GetMarcBiblio({
biblionumber => $biblionumber,
embed_items => scalar $query->url_param('items') });
--- /dev/null
+#!/usr/bin/perl
+# Copyright 2007 LibLime
+# Copyright 2012 software.coop and MJ Ray
+#
+# 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, see <http://www.gnu.org/licenses>.
+#
+use strict;
+use warnings;
+use CGI qw ( -utf8 );
+use C4::Auth qw/check_api_auth/;
+use C4::Biblio;
+use C4::Items;
+use XML::Simple;
+
+binmode STDOUT, ':encoding(UTF-8)';
+
+my $query = new CGI;
+my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 'edit_catalogue'} );
+unless ($status eq 'ok') {
+ print $query->header(-type => 'text/xml', -status => '403 Forbidden');
+ print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
+ exit 0;
+}
+
+# do initial validation
+my $path_info = $query->path_info();
+my $biblionumber = undef;
+if ($path_info =~ m!^/(\d+)$!) {
+ $biblionumber = $1;
+} else {
+ print $query->header(-type => 'text/xml', -status => '400 Bad Request');
+}
+if ($query->request_method eq 'GET') {
+ fetch_bib_framework($query, $biblionumber);
+} else {
+ print $query->header(-type => 'text/xml', -status => '405 Method not allowed');
+ print XMLout({ error => 'Method not allowed' }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
+ exit 0;
+}
+exit 0;
+
+sub fetch_bib_framework {
+ my $query = shift;
+ my $biblionumber = shift;
+ my $frameworkcode = GetFrameworkCode( $biblionumber );
+ my $result = {
+ 'frameworkcode' => $frameworkcode
+ };
+ print $query->header(-type => 'text/xml',-charset => 'utf-8',);
+ print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => 0);
+}