Bug 16424: Update default values in advanced editor when changing frameworks.

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>
This commit is contained in:
Ere Maijala 2017-11-10 08:28:01 +02:00 committed by Nick Clemens
parent b70d2bc281
commit 2074421ba3
3 changed files with 23 additions and 10 deletions

View file

@ -222,10 +222,14 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin
$.each( taginfo.subfields, function( undef, subfield ) {
var subfieldcode = subfield[0], subfieldinfo = subfield[1];
if ( subfieldinfo.mandatory != "1" && !allTags ) return;
if ( subfieldinfo.mandatory != "1" && !subfieldinfo.defaultvalue && !allTags ) return;
$.each( fields, function( undef, field ) {
if ( !field.hasSubfield(subfieldcode) ) field.addSubfieldGrouped( [ subfieldcode, subfieldinfo.defaultvalue || '' ] );
if ( !field.hasSubfield(subfieldcode) ) {
field.addSubfieldGrouped( [ subfieldcode, subfieldinfo.defaultvalue || '' ] );
} else if ( subfieldinfo.defaultvalue && field.subfield( subfieldcode ) === '' ) {
field.subfield( subfieldcode, subfieldinfo.defaultvalue );
}
} );
} );
} );

View file

@ -537,30 +537,38 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ],
this.cm.refresh();
},
setFrameworkCode: function( code, callback ) {
setFrameworkCode: function( code, updateFields, 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 );
var cm = this.cm;
KohaBackend.InitFramework( code, function ( error ) {
cm.setOption( 'mode', {
name: 'marc',
nonRepeatableTags: KohaBackend.GetTagsBy( code, 'repeatable', '0' ),
nonRepeatableSubfields: KohaBackend.GetSubfieldsBy( code, 'repeatable', '0' )
});
if ( updateFields ) {
var record = TextMARC.TextToRecord( cm.getValue() );
KohaBackend.FillRecord( code, record );
cm.setValue( TextMARC.RecordToText(record) );
}
callback( error );
} );
},
displayRecord: function( record ) {
this.cm.setValue( TextMARC.RecordToText(record) );
this.modified = false;
var cm = this.cm;
this.setFrameworkCode(
typeof record.frameworkcode !== 'undefined' ? record.frameworkcode : '',
false,
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' )
});
}
);
},

View file

@ -1098,6 +1098,7 @@ require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr
$("#loading").show();
editor.setFrameworkCode(
$(this).data( 'frameworkcode' ),
true,
function ( error ) {
if ( typeof error !== 'undefined' ) {
humanMsg.displayAlert( _("Failed to change framework"), { className: 'humanError' } );