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

(-)a/cataloguing/editor.pl (+4 lines)
Lines 30-35 use C4::Output; Link Here
30
use DBIx::Class::ResultClass::HashRefInflator;
30
use DBIx::Class::ResultClass::HashRefInflator;
31
use Koha::Database;
31
use Koha::Database;
32
use Koha::MarcSubfieldStructures;
32
use Koha::MarcSubfieldStructures;
33
use Koha::BiblioFrameworks;
33
34
34
my $input = CGI->new;
35
my $input = CGI->new;
35
36
Lines 60-65 $template->{VARS}->{DefaultLanguageField008} = pack( 'A3', C4::Context->preferen Link Here
60
my $authtags = Koha::MarcSubfieldStructures->search({ authtypecode => { '!=' => '' }, 'frameworkcode' => '' });
61
my $authtags = Koha::MarcSubfieldStructures->search({ authtypecode => { '!=' => '' }, 'frameworkcode' => '' });
61
$template->{VARS}->{authtags} = $authtags;
62
$template->{VARS}->{authtags} = $authtags;
62
63
64
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
65
$template->{VARS}->{frameworks} = $frameworks;
66
63
# Z39.50 servers
67
# Z39.50 servers
64
my $dbh = C4::Context->dbh;
68
my $dbh = C4::Context->dbh;
65
$template->{VARS}->{z3950_servers} = $dbh->selectall_arrayref( q{
69
$template->{VARS}->{z3950_servers} = $dbh->selectall_arrayref( q{
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (-13 / +46 lines)
Lines 66-74 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
66
        while ( record.removeField(bibnumTag) );
66
        while ( record.removeField(bibnumTag) );
67
    }
67
    }
68
68
69
    function initFramework( frameworkcode, callback ) {
70
        if ( typeof _frameworks[frameworkcode] === 'undefined' ) {
71
            $.get(
72
                '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=' + frameworkcode
73
            ).done( function( framework ) {
74
                _importFramework( frameworkcode, framework.framework );
75
                callback();
76
            } ).fail( function( data ) {
77
                callback( 'Could not fetch framework settings' );
78
            } );
79
        } else {
80
            callback();
81
        }
82
    }
83
69
    var KohaBackend = {
84
    var KohaBackend = {
70
        NOT_EMPTY: {}, // Sentinel value
85
        NOT_EMPTY: {}, // Sentinel value
71
86
87
        InitFramework: initFramework,
88
72
        GetAllTagsInfo: function( frameworkcode, tagnumber ) {
89
        GetAllTagsInfo: function( frameworkcode, tagnumber ) {
73
            return _framework_mappings[frameworkcode];
90
            return _framework_mappings[frameworkcode];
74
        },
91
        },
Lines 89-100 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
89
        GetRecord: function( id, callback ) {
106
        GetRecord: function( id, callback ) {
90
            $.get(
107
            $.get(
91
                '/cgi-bin/koha/svc/bib/' + id
108
                '/cgi-bin/koha/svc/bib/' + id
92
            ).done( function( data ) {
109
            ).done( function( metadata ) {
93
                var record = new MARC.Record();
110
                $.get(
94
                record.loadMARCXML(data);
111
                    '/cgi-bin/koha/svc/bib_framework/' + id
95
                callback(record);
112
                ).done( function( frameworkcode ) {
96
            } ).fail( function( data ) {
113
                    var record = new MARC.Record();
97
                callback( { error: data } );
114
                    record.loadMARCXML(metadata);
115
                    record.frameworkcode = $(frameworkcode).find('frameworkcode').text();
116
                    initFramework( record.frameworkcode, function( error ) {
117
                        if ( typeof error === 'undefined' ) {
118
                            callback( record );
119
                        } else {
120
                            callback( { error: error } );
121
                        }
122
                    });
123
                } ).fail( function( data ) {
124
                    callback( { error: _('Could not fetch frameworkcode for record') } );
125
                } );
98
            } );
126
            } );
99
        },
127
        },
100
128
Lines 110-130 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
110
            } ).done( function( data ) {
138
            } ).done( function( data ) {
111
                callback( _fromXMLStruct( data ) );
139
                callback( _fromXMLStruct( data ) );
112
            } ).fail( function( data ) {
140
            } ).fail( function( data ) {
113
                callback( { error: data } );
141
                callback( { error: _('Could not save record') } );
114
            } );
142
            } );
115
        },
143
        },
116
144
117
        SaveRecord: function( id, record, callback ) {
145
        SaveRecord: function( id, record, callback ) {
146
            var frameworkcode = record.frameworkcode;
118
            record = record.clone();
147
            record = record.clone();
119
            _removeBiblionumberFields( record );
148
            _removeBiblionumberFields( record );
120
149
121
            $.ajax( {
150
            $.ajax( {
122
                type: 'POST',
151
                type: 'POST',
123
                url: '/cgi-bin/koha/svc/bib/' + id,
152
                url: '/cgi-bin/koha/svc/bib/' + id + '?frameworkcode=' + encodeURIComponent(frameworkcode),
124
                data: record.toXML(),
153
                data: record.toXML(),
125
                contentType: 'text/xml'
154
                contentType: 'text/xml'
126
            } ).done( function( data ) {
155
            } ).done( function( data ) {
127
                callback( _fromXMLStruct( data ) );
156
                var record = _fromXMLStruct( data );
157
                if ( record.marcxml ) {
158
                    record.marcxml[0].frameworkcode = frameworkcode;
159
                }
160
                callback( record );
128
            } ).fail( function( data ) {
161
            } ).fail( function( data ) {
129
                callback( { data: { error: data } } );
162
                callback( { data: { error: data } } );
130
            } );
163
            } );
Lines 196-205 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
196
        ValidateRecord: function( frameworkcode, record ) {
229
        ValidateRecord: function( frameworkcode, record ) {
197
            var errors = [];
230
            var errors = [];
198
231
199
            var mandatoryTags = KohaBackend.GetTagsBy( '', 'mandatory', '1' );
232
            var mandatoryTags = KohaBackend.GetTagsBy( record.frameworkcode, 'mandatory', '1' );
200
            var mandatorySubfields = KohaBackend.GetSubfieldsBy( '', 'mandatory', '1' );
233
            var mandatorySubfields = KohaBackend.GetSubfieldsBy( record.frameworkcode, 'mandatory', '1' );
201
            var nonRepeatableTags = KohaBackend.GetTagsBy( '', 'repeatable', '0' );
234
            var nonRepeatableTags = KohaBackend.GetTagsBy( record.frameworkcode, 'repeatable', '0' );
202
            var nonRepeatableSubfields = KohaBackend.GetSubfieldsBy( '', 'repeatable', '0' );
235
            var nonRepeatableSubfields = KohaBackend.GetSubfieldsBy( record.frameworkcode, 'repeatable', '0' );
203
236
204
            $.each( mandatoryTags, function( tag ) {
237
            $.each( mandatoryTags, function( tag ) {
205
                if ( !record.hasField( tag ) ) errors.push( { type: 'missingTag', tag: tag } );
238
                if ( !record.hasField( tag ) ) errors.push( { type: 'missingTag', tag: tag } );
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js (+26 lines)
Lines 478-483 define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], Link Here
478
    } );
478
    } );
479
479
480
    function MARCEditor( options ) {
480
    function MARCEditor( options ) {
481
        this.frameworkcode = '';
482
481
        this.cm = CodeMirror(
483
        this.cm = CodeMirror(
482
            options.position,
484
            options.position,
483
            {
485
            {
Lines 535-543 define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], Link Here
535
            this.cm.refresh();
537
            this.cm.refresh();
536
        },
538
        },
537
539
540
        setFrameworkCode: function( code, callback ) {
541
            this.frameworkcode = code;
542
            $( 'a.change-framework i.selected' ).addClass( 'hidden' );
543
            $( 'a.change-framework i.unselected' ).removeClass( 'hidden' );
544
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.unselected' ).addClass( 'hidden' );
545
            $( 'a.change-framework[data-frameworkcode="' + code + '"] i.selected' ).removeClass( 'hidden ');
546
            KohaBackend.InitFramework( code, callback );
547
        },
548
538
        displayRecord: function( record ) {
549
        displayRecord: function( record ) {
539
            this.cm.setValue( TextMARC.RecordToText(record) );
550
            this.cm.setValue( TextMARC.RecordToText(record) );
540
            this.modified = false;
551
            this.modified = false;
552
            var cm = this.cm;
553
            this.setFrameworkCode(
554
                typeof record.frameworkcode !== 'undefined' ? record.frameworkcode : '',
555
                function ( error ) {
556
                    if ( typeof error !== 'undefined' ) {
557
                        humanMsg.displayAlert( _(error), { className: 'humanError' } );
558
                    }
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
                }
565
            );
541
        },
566
        },
542
567
543
        getRecord: function() {
568
        getRecord: function() {
Lines 553-558 define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], Link Here
553
578
554
            this.textMode = false;
579
            this.textMode = false;
555
580
581
            record.frameworkcode = this.frameworkcode;
556
            return record;
582
            return record;
557
        },
583
        },
558
584
(-)a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css (-8 / +6 lines)
Lines 55-60 body { Link Here
55
    padding-bottom: 0;
55
    padding-bottom: 0;
56
}
56
}
57
57
58
.humanMsg.humanSuccess {
59
	left: 75%;
60
    width: 20%;
61
    top: 160px;
62
}
63
58
#shortcuts-container {
64
#shortcuts-container {
59
    font-size: 12px;
65
    font-size: 12px;
60
}
66
}
Lines 283-296 body { Link Here
283
    width: 14em;
289
    width: 14em;
284
}
290
}
285
291
286
.fa.fa-spinner {
287
    display: inline-block;
288
    height: 16px;
289
    width: 16px;
290
    background: transparent url("../img/spinner-small.gif") top left no-repeat;
291
    padding: -1px;
292
    vertical-align: text-top;
293
}
294
292
295
/*> Search results */
293
/*> Search results */
296
294
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-2 / +19 lines)
Lines 329-334 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
329
            if (data.newRecord) {
329
            if (data.newRecord) {
330
                var record = new MARC.Record();
330
                var record = new MARC.Record();
331
                record.loadMARCXML(data.newRecord);
331
                record.loadMARCXML(data.newRecord);
332
                record.frameworkcode = data.newRecord.frameworkcode;
332
                editor.displayRecord( record );
333
                editor.displayRecord( record );
333
            }
334
            }
334
335
Lines 841-847 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
841
842
842
        // Click bindings
843
        // Click bindings
843
        $( '#save-record, #save-dropdown a' ).click( function() {
844
        $( '#save-record, #save-dropdown a' ).click( function() {
844
            $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner' ).siblings( 'span' ).text( _("Saving...") );
845
             $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner fa-spin' ).siblings( 'span' ).text( _("Saving...") );
845
846
846
            function finishCb(result) {
847
            function finishCb(result) {
847
                if ( result.error == 'syntax' ) {
848
                if ( result.error == 'syntax' ) {
Lines 1093-1098 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1093
                { return undefined; }
1094
                { return undefined; }
1094
        };
1095
        };
1095
1096
1097
        $('a.change-framework').click( function() {
1098
            $("#loading").show();
1099
            editor.setFrameworkCode(
1100
                $(this).data( 'frameworkcode' ),
1101
                function ( error ) {
1102
                    if ( typeof error !== 'undefined' ) {
1103
                        humanMsg.displayAlert( _("Failed to change framework"), { className: 'humanError' } );
1104
                    }
1105
                    $('#loading').hide();
1106
                }
1107
            );
1108
        } );
1109
1096
        // Start editor
1110
        // Start editor
1097
        Preferences.Load( [% logged_in_user.borrowernumber || 0 | html %] );
1111
        Preferences.Load( [% logged_in_user.borrowernumber || 0 | html %] );
1098
        displayPreferences(editor);
1112
        displayPreferences(editor);
Lines 1104-1110 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1104
        } );
1118
        } );
1105
1119
1106
        function finishCb( data ) {
1120
        function finishCb( data ) {
1107
            if ( data.error ) openRecord( 'new/', editor, finishCb );
1121
            if ( data.error ) {
1122
                humanMsg.displayAlert( data.error );
1123
                openRecord( 'new/', editor, finishCb );
1124
            }
1108
1125
1109
            Resources.GetAll().done( function() {
1126
            Resources.GetAll().done( function() {
1110
                $("#loading").hide();
1127
                $("#loading").hide();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt (+17 lines)
Lines 49-54 Link Here
49
            <ul id="prefs-menu" class="dropdown-menu">
49
            <ul id="prefs-menu" class="dropdown-menu">
50
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
50
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
51
                <li><a id="set-field-widgets" href="#"></a></li>
51
                <li><a id="set-field-widgets" href="#"></a></li>
52
                <li class="nav-header">Change framework</li>
53
                <li>
54
                    <a class="change-framework" data-frameworkcode="">
55
                        <i class="fa fa-fw unselected">&nbsp;</i>
56
                        <i class="fa fa-fw fa-check selected">&nbsp;</i>
57
                        Default
58
                    </a>
59
                </li>
60
                [% FOREACH framework IN frameworks %]
61
                    <li>
62
                        <a class="change-framework" data-frameworkcode="[% framework.frameworkcode | html %]">
63
                            <i class="fa fa-fw fa-check selected"></i>
64
                            <i class="fa fa-fw unselected">&nbsp;</i>
65
                            [% framework.frameworktext | html %]
66
                        </a>
67
                    </li>
68
                [% END %]
52
                <li class="divider"></li>
69
                <li class="divider"></li>
53
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
70
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
54
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
71
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
(-)a/svc/bib (-1 / +2 lines)
Lines 80-85 sub update_bib { Link Here
80
    my $query = shift;
80
    my $query = shift;
81
    my $biblionumber = shift;
81
    my $biblionumber = shift;
82
    my $old_record = GetMarcBiblio({ biblionumber => $biblionumber });
82
    my $old_record = GetMarcBiblio({ biblionumber => $biblionumber });
83
    my $frameworkcode = $query->url_param('frameworkcode') // '';
83
    unless  (defined $old_record) {
84
    unless  (defined $old_record) {
84
        print $query->header(-type => 'text/xml', -status => '404 Not Found');
85
        print $query->header(-type => 'text/xml', -status => '404 Not Found');
85
        return;
86
        return;
Lines 113-119 sub update_bib { Link Here
113
            }
114
            }
114
        }
115
        }
115
116
116
        ModBiblio( $record, $biblionumber, '' );
117
        ModBiblio( $record, $biblionumber, $frameworkcode );
117
        my $new_record = GetMarcBiblio({
118
        my $new_record = GetMarcBiblio({
118
            biblionumber => $biblionumber,
119
            biblionumber => $biblionumber,
119
            embed_items  => scalar $query->url_param('items') });
120
            embed_items  => scalar $query->url_param('items') });
(-)a/svc/bib_framework (-1 / +64 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
# Copyright 2007 LibLime
3
# Copyright 2012 software.coop and MJ Ray
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
#
20
use strict;
21
use warnings;
22
use CGI qw ( -utf8 );
23
use C4::Auth qw/check_api_auth/;
24
use C4::Biblio;
25
use C4::Items;
26
use XML::Simple;
27
28
binmode STDOUT, ':encoding(UTF-8)';
29
30
my $query = new CGI;
31
my ($status, $cookie, $sessionID) = check_api_auth($query, { editcatalogue => 'edit_catalogue'} );
32
unless ($status eq 'ok') {
33
    print $query->header(-type => 'text/xml', -status => '403 Forbidden');
34
    print XMLout({ auth_status => $status }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
35
    exit 0;
36
}
37
38
# do initial validation
39
my $path_info = $query->path_info();
40
my $biblionumber = undef;
41
if ($path_info =~ m!^/(\d+)$!) {
42
    $biblionumber = $1;
43
} else {
44
    print $query->header(-type => 'text/xml', -status => '400 Bad Request');
45
}
46
if ($query->request_method eq 'GET') {
47
    fetch_bib_framework($query, $biblionumber);
48
} else {
49
    print $query->header(-type => 'text/xml', -status => '405 Method not allowed');
50
    print XMLout({ error => 'Method not allowed' }, NoAttr => 1, RootName => 'response', XMLDecl => 1);
51
    exit 0;
52
}
53
exit 0;
54
55
sub fetch_bib_framework {
56
    my $query = shift;
57
    my $biblionumber = shift;
58
    my $frameworkcode = GetFrameworkCode( $biblionumber );
59
    my $result = {
60
        'frameworkcode' => $frameworkcode
61
    };
62
    print $query->header(-type => 'text/xml',-charset => 'utf-8',);
63
    print XMLout($result, NoAttr => 1, RootName => 'response', XMLDecl => 1, NoEscape => 0);
64
}

Return to bug 16424