View | Details | Raw Unified | Return to bug 16424
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (-2 / +6 lines)
Lines 222-231 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
222
                $.each( taginfo.subfields, function( undef, subfield ) {
222
                $.each( taginfo.subfields, function( undef, subfield ) {
223
                    var subfieldcode = subfield[0], subfieldinfo = subfield[1];
223
                    var subfieldcode = subfield[0], subfieldinfo = subfield[1];
224
224
225
                    if ( subfieldinfo.mandatory != "1" && !allTags ) return;
225
                    if ( subfieldinfo.mandatory != "1" && !subfieldinfo.defaultvalue && !allTags ) return;
226
226
227
                    $.each( fields, function( undef, field ) {
227
                    $.each( fields, function( undef, field ) {
228
                        if ( !field.hasSubfield(subfieldcode) ) field.addSubfieldGrouped( [ subfieldcode, subfieldinfo.defaultvalue || '' ] );
228
                        if ( !field.hasSubfield(subfieldcode) ) {
229
                            field.addSubfieldGrouped( [ subfieldcode, subfieldinfo.defaultvalue || '' ] );
230
                        } else if ( subfieldinfo.defaultvalue && field.subfield( subfieldcode ) === '' ) {
231
                            field.subfield( subfieldcode, subfieldinfo.defaultvalue );
232
                        }
229
                    } );
233
                    } );
230
                } );
234
                } );
231
            } );
235
            } );
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js (-8 / +16 lines)
Lines 537-566 define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], Link Here
537
            this.cm.refresh();
537
            this.cm.refresh();
538
        },
538
        },
539
539
540
        setFrameworkCode: function( code, callback ) {
540
        setFrameworkCode: function( code, updateFields, callback ) {
541
            this.frameworkcode = code;
541
            this.frameworkcode = code;
542
            $( 'a.change-framework i.selected' ).addClass( 'hidden' );
542
            $( 'a.change-framework i.selected' ).addClass( 'hidden' );
543
            $( 'a.change-framework i.unselected' ).removeClass( 'hidden' );
543
            $( 'a.change-framework i.unselected' ).removeClass( 'hidden' );
544
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.unselected' ).addClass( 'hidden' );
544
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.unselected' ).addClass( 'hidden' );
545
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.selected' ).removeClass( 'hidden ');
545
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.selected' ).removeClass( 'hidden ');
546
            KohaBackend.InitFramework( code, callback );
546
            var cm = this.cm;
547
            KohaBackend.InitFramework( code, function ( error ) {
548
                cm.setOption( 'mode', {
549
                    name: 'marc',
550
                    nonRepeatableTags: KohaBackend.GetTagsBy( code, 'repeatable', '0' ),
551
                    nonRepeatableSubfields: KohaBackend.GetSubfieldsBy( code, 'repeatable', '0' )
552
                });
553
                if ( updateFields ) {
554
                    var record = TextMARC.TextToRecord( cm.getValue() );
555
                    KohaBackend.FillRecord( code, record );
556
                    cm.setValue( TextMARC.RecordToText(record) );
557
                }
558
                callback( error );
559
            } );
547
        },
560
        },
548
561
549
        displayRecord: function( record ) {
562
        displayRecord: function( record ) {
550
            this.cm.setValue( TextMARC.RecordToText(record) );
563
            this.cm.setValue( TextMARC.RecordToText(record) );
551
            this.modified = false;
564
            this.modified = false;
552
            var cm = this.cm;
553
            this.setFrameworkCode(
565
            this.setFrameworkCode(
554
                typeof record.frameworkcode !== 'undefined' ? record.frameworkcode : '',
566
                typeof record.frameworkcode !== 'undefined' ? record.frameworkcode : '',
567
                false,
555
                function ( error ) {
568
                function ( error ) {
556
                    if ( typeof error !== 'undefined' ) {
569
                    if ( typeof error !== 'undefined' ) {
557
                        humanMsg.displayAlert( _(error), { className: 'humanError' } );
570
                        humanMsg.displayAlert( _(error), { className: 'humanError' } );
558
                    }
571
                    }
559
                    cm.setOption( 'mode', {
560
                        name: 'marc',
561
                        nonRepeatableTags: KohaBackend.GetTagsBy( this.frameworkcode, 'repeatable', '0' ),
562
                        nonRepeatableSubfields: KohaBackend.GetSubfieldsBy( this.frameworkcode, 'repeatable', '0' )
563
                    });
564
                }
572
                }
565
            );
573
            );
566
        },
574
        },
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-1 / +1 lines)
Lines 1098-1103 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1098
            $("#loading").show();
1098
            $("#loading").show();
1099
            editor.setFrameworkCode(
1099
            editor.setFrameworkCode(
1100
                $(this).data( 'frameworkcode' ),
1100
                $(this).data( 'frameworkcode' ),
1101
                true,
1101
                function ( error ) {
1102
                function ( error ) {
1102
                    if ( typeof error !== 'undefined' ) {
1103
                    if ( typeof error !== 'undefined' ) {
1103
                        humanMsg.displayAlert( _("Failed to change framework"), { className: 'humanError' } );
1104
                        humanMsg.displayAlert( _("Failed to change framework"), { className: 'humanError' } );
1104
- 

Return to bug 16424