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

(-)a/C4/Biblio.pm (-6 / +22 lines)
Lines 3410-3415 sub _koha_delete_biblio_metadata { Link Here
3410
3410
3411
=head1 UNEXPORTED FUNCTIONS
3411
=head1 UNEXPORTED FUNCTIONS
3412
3412
3413
=head2 Update005Time
3414
3415
  &Update005Time( $record );
3416
3417
Updates the 005 timestamp of the given record to the current time.
3418
3419
=cut
3420
3421
sub UpdateMarcTimestamp {
3422
    my ( $record ) = @_;
3423
3424
    my $encoding = C4::Context->preference("marcflavour");
3425
3426
    if ( $encoding =~ /MARC21|UNIMARC/ ) {
3427
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3428
        # YY MM DD HH MM SS (update year and month)
3429
        my $f005 = $record->field('005');
3430
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3431
    }
3432
}
3433
3413
=head2 ModBiblioMarc
3434
=head2 ModBiblioMarc
3414
3435
3415
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3436
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
Lines 3462-3473 sub ModBiblioMarc { Link Here
3462
    }
3483
    }
3463
3484
3464
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3485
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3465
    if($encoding =~ /MARC21|UNIMARC/) {
3486
    UpdateMarcTimestamp( $record );
3466
      my @a= (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3467
        # YY MM DD HH MM SS (update year and month)
3468
      my $f005= $record->field('005');
3469
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
3470
    }
3471
3487
3472
    my $metadata = {
3488
    my $metadata = {
3473
        biblionumber => $biblionumber,
3489
        biblionumber => $biblionumber,
(-)a/C4/ImportBatch.pm (-8 / +41 lines)
Lines 27-32 use C4::Items; Link Here
27
use C4::Charset;
27
use C4::Charset;
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use C4::MarcModificationTemplates;
29
use C4::MarcModificationTemplates;
30
use DateTime;
31
use DateTime::Format::Strptime;
30
use Koha::Plugins::Handler;
32
use Koha::Plugins::Handler;
31
use Koha::Logger;
33
use Koha::Logger;
32
34
Lines 1558-1572 sub RecordsFromMARCXMLFile { Link Here
1558
1560
1559
# internal functions
1561
# internal functions
1560
1562
1563
sub _get_import_record_timestamp {
1564
    my ( $marc_record ) = @_;
1565
1566
    my $upload_timestamp = DateTime->now();
1567
1568
    # Attempt to parse the 005 timestamp. This is a bit weird because we have to parse the
1569
    # tenth-of-a-second ourselves.
1570
    my $f005 = $marc_record->field('005');
1571
    if ( $f005 && $f005->data =~ /(\d{8}\d{6})\.(\d)/ ) {
1572
        my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d%H%M%S' );
1573
        my $parsed_timestamp = $parser->parse_datetime($1);
1574
1575
        # We still check for success because we only did enough validation above to extract the
1576
        # tenth-of-a-second; the timestamp could still be some nonsense like the 50th of Jantober.
1577
        if ( $parsed_timestamp ) {
1578
            $parsed_timestamp->set_nanosecond( $2 * 100_000_000 );
1579
            $upload_timestamp = $parsed_timestamp;
1580
        }
1581
    }
1582
1583
    return $upload_timestamp;
1584
}
1585
1561
sub _create_import_record {
1586
sub _create_import_record {
1562
    my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random, $marc_type) = @_;
1587
    my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random, $marc_type) = @_;
1563
1588
1589
    my $upload_timestamp = _get_import_record_timestamp($marc_record);
1590
1564
    my $dbh = C4::Context->dbh;
1591
    my $dbh = C4::Context->dbh;
1565
    my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, 
1592
    my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, 
1566
                                                         record_type, encoding, z3950random)
1593
                                                         record_type, encoding, z3950random, upload_timestamp)
1567
                                    VALUES (?, ?, ?, ?, ?, ?, ?)");
1594
                                    VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
1568
    $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type),
1595
    $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type),
1569
                  $record_type, $encoding, $z3950random);
1596
                  $record_type, $encoding, $z3950random, $upload_timestamp);
1570
    my $import_record_id = $dbh->{'mysql_insertid'};
1597
    my $import_record_id = $dbh->{'mysql_insertid'};
1571
    $sth->finish();
1598
    $sth->finish();
1572
    return $import_record_id;
1599
    return $import_record_id;
Lines 1575-1584 sub _create_import_record { Link Here
1575
sub _update_import_record_marc {
1602
sub _update_import_record_marc {
1576
    my ($import_record_id, $marc_record, $marc_type) = @_;
1603
    my ($import_record_id, $marc_record, $marc_type) = @_;
1577
1604
1605
    my $upload_timestamp = _get_import_record_timestamp($marc_record);
1606
1578
    my $dbh = C4::Context->dbh;
1607
    my $dbh = C4::Context->dbh;
1579
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
1608
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?, upload_timestamp = ?
1580
                             WHERE  import_record_id = ?");
1609
                             WHERE  import_record_id = ?");
1581
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id);
1610
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $upload_timestamp, $import_record_id);
1582
    $sth->finish();
1611
    $sth->finish();
1583
}
1612
}
1584
1613
Lines 1599-1610 sub _add_auth_fields { Link Here
1599
sub _add_biblio_fields {
1628
sub _add_biblio_fields {
1600
    my ($import_record_id, $marc_record) = @_;
1629
    my ($import_record_id, $marc_record) = @_;
1601
1630
1631
    my $controlnumber;
1632
    if ($marc_record->field('001')) {
1633
        $controlnumber = $marc_record->field('001')->data();
1634
    }
1602
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1635
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1603
    my $dbh = C4::Context->dbh;
1636
    my $dbh = C4::Context->dbh;
1604
    # FIXME no controlnumber, originalsource
1637
    # FIXME no originalsource
1605
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1638
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1606
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
1639
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn, control_number) VALUES (?, ?, ?, ?, ?, ?)");
1607
    $sth->execute($import_record_id, $title, $author, $isbn, $issn);
1640
    $sth->execute($import_record_id, $title, $author, $isbn, $issn, $controlnumber);
1608
    $sth->finish();
1641
    $sth->finish();
1609
                
1642
                
1610
}
1643
}
(-)a/cataloguing/editor.pl (-1 / +1 lines)
Lines 48-54 my $schema = Koha::Database->new->schema; Link Here
48
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
48
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
49
    {
49
    {
50
        batch_type => [ 'batch', 'webservice' ],
50
        batch_type => [ 'batch', 'webservice' ],
51
        import_status => 'staged',
51
        import_status => [ 'staged', 'staging' ],
52
    },
52
    },
53
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
53
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
54
) ];
54
) ];
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (+52 lines)
Lines 130-135 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
130
            } );
130
            } );
131
        },
131
        },
132
132
133
        GetBatchRecord: function( batch_id, id, callback ) {
134
            $.get(
135
                '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id
136
            ).done( function( data ) {
137
                var record = new MARC.Record();
138
                record.loadMARCXML( data.record );
139
                callback(record);
140
            } ).fail( function( data ) {
141
                callback( { error: data } );
142
            } );
143
        },
144
145
        CreateBatch: function( batch_name, callback ) {
146
            $.ajax( {
147
                type: 'POST',
148
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/',
149
                data: { batch_name: batch_name },
150
            } ).done( function( data ) {
151
                callback( data );
152
            } ).fail( function( data ) {
153
                callback( { error: data } );
154
            } );
155
        },
156
157
        CreateBatchRecord: function( record, batch_id, callback, options ) {
158
            $.ajax( {
159
                type: 'POST',
160
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/',
161
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
162
            } ).done( function( data ) {
163
                callback( data );
164
            } ).fail( function( data ) {
165
                callback( { error: $.parseJSON( data.responseText ) || data.responseText } );
166
            } );
167
        },
168
169
        SaveBatchRecord: function( batch_id, id, record, callback, options ) {
170
            $.ajax( {
171
                type: 'POST',
172
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id,
173
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
174
            } ).done( function( data ) {
175
                callback( data );
176
            } ).fail( function( data ) {
177
                callback( { data: { error: data } } );
178
            } );
179
        },
180
181
        StartBatchExport: function( batch_id, options ) {
182
            window.open( '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '?download=1&' + $.param( options ) );
183
        },
184
133
        GetTagsBy: function( frameworkcode, field, value ) {
185
        GetTagsBy: function( frameworkcode, field, value ) {
134
            var result = {};
186
            var result = {};
135
187
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/preferences.js (+2 lines)
Lines 29-38 define( function() { Link Here
29
29
30
            Preferences.user = $.extend( {
30
            Preferences.user = $.extend( {
31
                // Preference defaults
31
                // Preference defaults
32
                enabledBatches: {},
32
                fieldWidgets: true,
33
                fieldWidgets: true,
33
                font: 'monospace',
34
                font: 'monospace',
34
                fontSize: '1em',
35
                fontSize: '1em',
35
                macros: {},
36
                macros: {},
37
                selected_save_targets: {},
36
                selected_search_targets: {},
38
                selected_search_targets: {},
37
            }, saved_prefs );
39
            }, saved_prefs );
38
        },
40
        },
(-)a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css (-1 / +43 lines)
Lines 59-64 body { Link Here
59
    font-size: 12px;
59
    font-size: 12px;
60
}
60
}
61
61
62
#save-targets input {
63
    display: inline-block;
64
    margin: 1px;
65
    vertical-align: middle;
66
}
67
68
#save-targets input:checked + label {
69
    color: #000;
70
}
71
72
#save-targets label {
73
    color: #666;
74
    display: inline-block;
75
    margin-left: 0.3em;
76
    padding: 0.3em 0;
77
    vertical-align: middle;
78
    width: 10em;
79
}
80
81
#save-targets li {
82
    overflow: hidden;
83
}
84
85
#shortcuts-container {
86
    font-size: 12px;
87
}
88
62
/*> MARC editor */
89
/*> MARC editor */
63
#editor .CodeMirror {
90
#editor .CodeMirror {
64
    line-height: 1.2;
91
    line-height: 1.2;
Lines 205-211 body { Link Here
205
232
206
/*> Search */
233
/*> Search */
207
234
208
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg {
235
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg .ui-modal {
236
    padding: 5px;
209
    width: 90%;
237
    width: 90%;
210
}
238
}
211
239
Lines 446-448 body { Link Here
446
.CodeMirror-gutter-wrapper {
474
.CodeMirror-gutter-wrapper {
447
    position: absolute;
475
    position: absolute;
448
}
476
}
477
478
/* >Batches */
479
#batches-list > li {
480
    border: 2px solid #F0F0F0;
481
    border-radius: 6px;
482
    display: block;
483
    line-height: 3em;
484
    font-size: 115%;
485
}
486
487
#batches-list > li input {
488
    display: inline-block;
489
    margin: 0 1em;
490
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-34 / +316 lines)
Lines 29-34 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
29
            recordtype: 'biblio',
29
            recordtype: 'biblio',
30
            checked: false,
30
            checked: false,
31
        },
31
        },
32
        [%- FOREACH batch = editable_batches -%]
33
            'batch:[% batch.import_batch_id %]': {
34
                name: _("Batch: ") + '[% batch.file_name %]',
35
                recordtype: 'biblio',
36
                checked: false,
37
            },
38
        [%- END -%]
32
        [%- FOREACH server = z3950_servers -%]
39
        [%- FOREACH server = z3950_servers -%]
33
            [% server.id %]: {
40
            [% server.id %]: {
34
                name: '[% server.servername %]',
41
                name: '[% server.servername %]',
Lines 54-61 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
54
61
55
    var state = {
62
    var state = {
56
        backend: '',
63
        backend: '',
57
        saveBackend: 'catalog',
64
        recordID: undefined,
58
        recordID: undefined
65
        saveTargets: {},
59
    };
66
    };
60
67
61
    var editor;
68
    var editor;
Lines 219-234 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
219
            },
226
            },
220
        },
227
        },
221
        'catalog': {
228
        'catalog': {
222
            titleForRecord: _("Editing catalog record #{ID}"),
229
            titleForRecord: _("Editing catalog record #%s"),
223
            links: [
230
            links: [
224
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber={ID}" },
231
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=%s" },
225
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber={ID}" },
232
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=%s" },
226
            ],
233
            ],
227
            saveLabel: _("Save to catalog"),
234
            saveLabel: _("New catalog record"),
235
            saveExistingLabel: _("Catalog record #%s"),
228
            get: function( id, callback ) {
236
            get: function( id, callback ) {
229
                if ( !id ) return false;
237
                if ( !id ) return false;
230
238
231
                KohaBackend.GetRecord( id, callback );
239
                KohaBackend.GetRecord( id, function( data ) {
240
                    if ( !data.error ) {
241
                        setSaveTargetChecked( 'catalog/', false );
242
                        addSaveTarget( {
243
                            label: backends.catalog.saveExistingLabel.format( id ),
244
                            id: 'catalog/' + id,
245
                            description: '',
246
                            checked: true
247
                        } );
248
                    }
249
250
                    callback(data);
251
                } );
232
            },
252
            },
233
            save: function( id, record, done ) {
253
            save: function( id, record, done ) {
234
                function finishCb( data ) {
254
                function finishCb( data ) {
Lines 243-249 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
243
            }
263
            }
244
        },
264
        },
245
        'iso2709': {
265
        'iso2709': {
246
            saveLabel: _("Save as ISO2709 (.mrc) file"),
266
            saveLabel: _("New ISO2709 (.mrc) file"),
247
            save: function( id, record, done ) {
267
            save: function( id, record, done ) {
248
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
268
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
249
269
Lines 251-257 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
251
            }
271
            }
252
        },
272
        },
253
        'marcxml': {
273
        'marcxml': {
254
            saveLabel: _("Save as MARCXML (.xml) file"),
274
            saveLabel: _("New MARCXML (.xml) file"),
255
            save: function( id, record, done ) {
275
            save: function( id, record, done ) {
256
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
276
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
257
277
Lines 273-278 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
273
        },
293
        },
274
    };
294
    };
275
295
296
    var editable_batches = {
297
        [%- FOREACH batch = editable_batches -%]
298
            [% batch.import_batch_id %]: {
299
                'name': '[% batch.file_name %]',
300
            },
301
        [%- END -%]
302
    };
303
304
    function addSaveTarget( target ) {
305
        state.saveTargets[target.id] = target;
306
        if (target.enabled == null) target.enabled = true;
307
308
        // Have to check that Preferences has been initialized
309
        var saved_value = Preferences.user && Preferences.user.selected_save_targets[target.id];
310
        if ( saved_value != null ) target.checked = saved_value;
311
312
        var target_list = $.map( state.saveTargets, function( target ) {
313
            return target;
314
        } );
315
316
        target_list.sort( function( a, b ) {
317
            return a.label.localeCompare(b.label);
318
        } );
319
320
        $('#save-targets ol').empty();
321
322
        $.each( target_list, function( i, target ) {
323
            var $new_target = $(
324
                '<li><input type="checkbox" class="save-toggle-target" data-target-id="' + target.id + '" id="save-target-' + i + '"' + ( target.checked ? ' checked="checked"' : '' ) + '> <label for="save-target-' + i + '">' + target.label + '</label></li>'
325
            );
326
327
            $new_target.find('input').change( function() {
328
                target.checked = this.checked;
329
            } );
330
331
            $('#save-targets ol').append($new_target);
332
333
            if (!target.enabled) $new_target.hide();
334
        } );
335
    }
336
337
    function setSaveTargetChecked( target_id, checked ) {
338
        if ( state.saveTargets[target_id] == null ) return;
339
340
        state.saveTargets[target_id].checked = checked;
341
        $( '#save-targets input[data-target-id="' + target_id + '"]' )[0].checked = checked;
342
    }
343
344
    function setSaveTargetEnabled( target_id, enabled ) {
345
        if ( !enabled ) {
346
            setSaveTargetChecked( target_id, false );
347
        }
348
349
        state.saveTargets[target_id].enabled = enabled;
350
        $( '#save-targets input[data-target-id="' + target_id + '"]' ).closest('li').toggle(enabled);
351
    }
352
276
    function setSource(parts) {
353
    function setSource(parts) {
277
        state.backend = parts[0];
354
        state.backend = parts[0];
278
        state.recordID = parts[1];
355
        state.recordID = parts[1];
Lines 283-295 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
283
360
284
        document.location.hash = '#' + parts[0] + '/' + parts[1];
361
        document.location.hash = '#' + parts[0] + '/' + parts[1];
285
362
286
        $('#title').text( backend.titleForRecord.replace( '{ID}', parts[1] ) );
363
        $('#title').text( backend.titleForRecord.format( parts[1] ) );
287
364
288
        $.each( backend.links || [], function( i, link ) {
365
        $.each( backend.links || [], function( i, link ) {
289
            $('#title').append(' <a target="_blank" href="' + link.href.replace( '{ID}', parts[1] ) + '">(' + link.title + ')</a>' );
366
            $('#title').append(' <a target="_blank" href="' + link.href.format( parts[1] ) + '">(' + link.title + ')</a>' );
290
        } );
367
        } );
291
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.replace( '{ID}', parts[1] ) );
368
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.format( parts[1] ) );
292
        $('#save-record span').text( backends[ state.saveBackend ].saveLabel );
293
    }
369
    }
294
370
295
    function saveRecord( recid, editor, callback ) {
371
    function saveRecord( recid, editor, callback ) {
Lines 325-330 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
325
401
326
            if (data.newId) {
402
            if (data.newId) {
327
                setSource(data.newId);
403
                setSource(data.newId);
404
405
                var backend = backends[ parts[0] ];
406
407
                setSaveTargetChecked( recid, false );
408
                addSaveTarget( {
409
                    label: backend.saveExistingLabel.format( data.newId[1] ),
410
                    id: data.newId.join('/'),
411
                    description: '',
412
                    checked: true
413
                } );
328
            } else {
414
            } else {
329
                setSource( [ state.backend, state.recordID ] );
415
                setSource( [ state.backend, state.recordID ] );
330
            }
416
            }
Lines 583-588 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
583
        var value = Preferences.user[pref];
669
        var value = Preferences.user[pref];
584
670
585
        switch (pref) {
671
        switch (pref) {
672
            case 'enabledBatches':
673
                $.each( editable_batches, function( batch_id, batch ) {
674
                    $( '#batches-list li[data-batch-id=' + batch_id + '] input' )[0].checked = Preferences.user.enabledBatches[batch_id];
675
                    setSaveTargetEnabled( 'batch:' + batch_id + '/', Preferences.user.enabledBatches[batch_id] || false );
676
                } );
586
            case 'fieldWidgets':
677
            case 'fieldWidgets':
587
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
678
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
588
                break;
679
                break;
Lines 604-609 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
604
                    if ( saved_val != null ) server.checked = saved_val;
695
                    if ( saved_val != null ) server.checked = saved_val;
605
                } );
696
                } );
606
                break;
697
                break;
698
            case 'selected_save_targets':
699
                $.each( state.saveTargets, function( target_id, target ) {
700
                    var saved_val = Preferences.user.selected_save_targets[target_id];
701
702
                    if ( saved_val != null ) setSaveTargetChecked( target_id, saved_val );
703
                } );
704
                break;
705
            case 'selected_search_targets':
706
                $.each( z3950Servers, function( server_id, server ) {
707
                    var saved_val = Preferences.user.selected_search_targets[server_id];
708
709
                    if ( saved_val != null ) server.checked = saved_val;
710
                } );
711
                break;
607
        }
712
        }
608
    }
713
    }
609
714
Lines 617-623 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
617
            } );
722
            } );
618
        }
723
        }
619
724
725
        function _addLiveHandler( sel, event, handler ) {
726
            $( document ).on( event, sel, function (e) {
727
                e.preventDefault();
728
                handler.call( this, e, Preferences.user[pref] );
729
                Preferences.Save( [% USER_INFO.0.borrowernumber %] );
730
                showPreference(pref);
731
            } );
732
        }
733
620
        switch (pref) {
734
        switch (pref) {
735
            case 'enabledBatches':
736
                _addLiveHandler( '#batches-list input', 'change', function() {
737
                    Preferences.user.enabledBatches[ $( this ).closest('li').data('batch-id') ] = this.checked;
738
                } );
739
                break;
621
            case 'fieldWidgets':
740
            case 'fieldWidgets':
622
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
741
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
623
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
742
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
Lines 633-638 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
633
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
752
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
634
                } );
753
                } );
635
                break;
754
                break;
755
            case 'selected_save_targets':
756
                $( document ).on( 'change', 'input.save-toggle-target', function() {
757
                    var target_id = $( this ).data('target-id');
758
                    Preferences.user.selected_save_targets[target_id] = this.checked;
759
                    Preferences.Save( [% USER_INFO.0.borrowernumber %] );
760
                } );
761
                break;
636
            case 'selected_search_targets':
762
            case 'selected_search_targets':
637
                $( document ).on( 'change', 'input.search-toggle-server', function() {
763
                $( document ).on( 'change', 'input.search-toggle-server', function() {
638
                    var server_id = $( this ).closest('li').data('server-id');
764
                    var server_id = $( this ).closest('li').data('server-id');
Lines 726-731 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
726
        showSavedMacros();
852
        showSavedMacros();
727
    }
853
    }
728
854
855
    function addImportBatch(batch) {
856
        var backend_id = 'batch:' + batch.batch_id;
857
        backends[backend_id] = {
858
            titleForRecord: _("Editing record from batch: ") + batch.name,
859
            saveLabel: _("Batch: ") + batch.name,
860
            saveExistingLabel: batch.name + ": #%s",
861
            get: function( id, callback ) {
862
                KohaBackend.GetBatchRecord( batch.batch_id, id, function( data ) {
863
                    if ( !data.error ) {
864
                        setSaveTargetChecked( backend_id + '/', false );
865
                        addSaveTarget( {
866
                            label: batch.name + ": #" + id,
867
                            id: backend_id + '/' + id,
868
                            description: '',
869
                            checked: true
870
                        } );
871
                    }
872
873
                    callback(data);
874
                } );
875
            },
876
            save: function( id, record, done, options ) {
877
                function finishCb( data ) {
878
                    done( {
879
                        error: data.message || data.error,
880
                        newRecord: data.updated_record,
881
                        newId: data.import_record_id && [ backend_id, data.import_record_id ]
882
                    } );
883
                }
884
885
                if ( id ) {
886
                    KohaBackend.SaveBatchRecord( batch.batch_id, id, record, finishCb, { allow_control_number_conflict: options.override_warnings } );
887
                } else {
888
                    KohaBackend.CreateBatchRecord( record, batch.batch_id, finishCb, { allow_control_number_conflict: options.override_warnings } );
889
                }
890
            },
891
        };
892
893
        // Build batch UI
894
        var $batch_entry = $( '<li data-batch-id="' + batch.batch_id + '"><input type="checkbox" />' + batch.name + '</li>' );
895
896
        var $batch_buttons = $('<span class="batch-buttons"></span>').appendTo($batch_entry);
897
        var $export_button = $( '<button>' + _("Export...") + '</button>' ).appendTo($batch_buttons).click( function() {
898
            $('#batches-list .batch-export').hide();
899
            $export_screen.show();
900
        } );
901
902
        var $export_screen = $(
903
            '<form class="batch-export form-horizontal" style="display: none">'
904
            + '<div class="control-group">'
905
            + '<label class="control-label">' + _("Control number range:") + '</label>'
906
            + '<div class="controls"><input class="batch-control-number-start" type="text"> - <input class="batch-control-number-end" type="text"></div>'
907
            + '</div>'
908
            + '<label class="control-label">' + _("Timestamp range (YYYYMMDD or YYYMMDDHHMMSS):") + '</label>'
909
            + '<div class="controls"><input class="batch-timestamp-start" type="text"> - <input class="batch-timestamp-end" type="text"></div>'
910
            + '</div>'
911
            + '<div class="control-group">'
912
            + '<div class="controls"><button class="batch-export-start">' + _("Start export") + '</div>'
913
            + '</form>'
914
        ).appendTo($batch_entry);
915
916
        $export_screen.find('.batch-export-start').click( function() {
917
            function getFormVal(name) {
918
                return $export_screen.find( '.batch-' + name ).val();
919
            }
920
921
            var options = {
922
                start_control_number: getFormVal('control-number-start'),
923
                end_control_number: getFormVal('control-number-end'),
924
                start_timestamp: getFormVal('timestamp-start'),
925
                end_timestamp: getFormVal('timestamp-end'),
926
            };
927
928
            KohaBackend.StartBatchExport( batch.batch_id, options );
929
        } );
930
931
        $('#batches-list').append( $batch_entry );
932
    }
933
729
    $(document).ready( function() {
934
    $(document).ready( function() {
730
        // Editor setup
935
        // Editor setup
731
        editor = new MARCEditor( {
936
        editor = new MARCEditor( {
Lines 775-780 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
775
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
980
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
776
                } );
981
                } );
777
            }, 100);
982
            }, 100);
983
778
        }
984
        }
779
985
780
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
986
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
Lines 815-823 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
815
        $.each( backends, function( id, backend ) {
1021
        $.each( backends, function( id, backend ) {
816
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
1022
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
817
        } );
1023
        } );
818
        saveableBackends.sort();
1024
819
        $.each( saveableBackends, function( undef, backend ) {
1025
        var batch_list = [];
820
            $( '#save-dropdown' ).append( '<li><a href="#" data-backend="' + backend[1] + '">' + backend[0] + '</a></li>' );
1026
1027
        $.each( editable_batches, function( batch_id, batch ) {
1028
            batch_list.push( $.extend( { batch_id: batch_id }, batch ) );
1029
        } );
1030
        batch_list.sort( function( a, b ) {
1031
            return a.name.localeCompare(b.name);
1032
        } );
1033
        $.each( batch_list, function() {
1034
            addImportBatch( this );
821
        } );
1035
        } );
822
1036
823
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
1037
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
Lines 832-846 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
832
1046
833
        // Click bindings
1047
        // Click bindings
834
        $( '#save-record, #save-dropdown a' ).click( function() {
1048
        $( '#save-record, #save-dropdown a' ).click( function() {
835
            $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner' ).siblings( 'span' ).text( _("Saving...") );
1049
            var enabledTargets = [];
1050
            var targetNames = [];
1051
            $.each( state.saveTargets, function() {
1052
                if ( this.checked ) {
1053
                    enabledTargets.push(this);
1054
                    targetNames.push(this.label);
1055
                }
1056
            } );
1057
            if ( enabledTargets.length == 0 ) {
1058
                humanMsg.displayAlert( _("Please select a save target"), { className: 'humanError' } );
1059
                return false;
1060
            }
1061
1062
            $( '#save-record' ).find('i').attr( 'class', 'icon-loading' ).siblings( 'span' ).text( _("Saving...") );
1063
1064
            var targets_left = enabledTargets.length;
1065
            var errors = false;
836
1066
837
            function finishCb(result) {
1067
            function finishCb(result) {
838
                if ( result.error == 'syntax' ) {
1068
                targets_left--;
839
                    humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
1069
                if ( result.error ) {
840
                } else if ( result.error == 'invalid' ) {
1070
                    if ( result.error == 'syntax' ) {
841
                    humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1071
                        humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
842
                } else if ( !result.error ) {
1072
                    } else if ( result.error == 'invalid' ) {
843
                    humanMsg.displayAlert( _("Record saved "), { className: 'humanSuccess' } );
1073
                        humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1074
                    } else if ( result.error.type == 'control_number_match' ) {
1075
                        humanMsg.displayAlert( _("Control number conflict, cannot save"), { className: 'humanError' } );
1076
                    } else {
1077
                        humanMsg.displayAlert( _("Unknown error, record not saved to one or more targets"), { className: 'humanError' } );
1078
                    }
1079
                    errors = true;
844
                }
1080
                }
845
1081
846
                $.each( result.errors || [], function( undef, error ) {
1082
                $.each( result.errors || [], function( undef, error ) {
Lines 876-895 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
876
                    }
1112
                    }
877
                } );
1113
                } );
878
1114
879
                $( '#save-record' ).find('i').attr( 'class', 'fa fa-hdd-o' );
880
1115
881
                if ( result.error ) {
1116
                if ( targets_left == 0 ) {
882
                    // Reset backend info
1117
                    if ( !errors ) {
883
                    setSource( [ state.backend, state.recordID ] );
1118
                        humanMsg.displayMsg( "<h3>" + _("Record saved to:</h3>") + "</h3>" + '<ul><li>' + targetNames.join('</li><li>') + '</li></ul>', { className: 'humanSuccess' } );
1119
                    }
1120
1121
                    $( '#save-record' ).find('i').attr( 'class', 'icon-hdd' ).end().find('span').text( _("Save") );
884
                }
1122
                }
885
            }
1123
            }
886
1124
887
            var backend = $( this ).data( 'backend' ) || ( state.saveBackend );
1125
            $.each( enabledTargets, function() {
888
            if ( state.backend == backend ) {
1126
                saveRecord( this.id, editor, finishCb, options );
889
                saveRecord( backend + '/' + state.recordID, editor, finishCb );
1127
            } );
890
            } else {
891
                saveRecord( backend + '/', editor, finishCb );
892
            }
893
1128
894
            return false;
1129
            return false;
895
        } );
1130
        } );
Lines 1030-1040 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1030
            }
1265
            }
1031
        } );
1266
        } );
1032
1267
1268
        $('#open-batches').click( function() {
1269
            $('#batches-ui').modal();
1270
1271
            return false;
1272
        } );
1273
1274
        $('#create-batch').click( function() {
1275
            var batch_name = prompt( _("Name of new import batch:") );
1276
            if (batch_name == null) return false;
1277
1278
            KohaBackend.CreateBatch( batch_name, function( data ) {
1279
                if ( data.error ) {
1280
                    humanMsg.displayAlert( _("Could not create import batch"), { className: 'humanError' } );
1281
                } else {
1282
                    humanMsg.displayAlert( _("Import batch created"), { className: 'humanSuccess' } );
1283
1284
                    addImportBatch( editable_batches[data.batch_id] = { batch_id: data.batch_id, name: batch_name } );
1285
1286
                    var backend_id = 'batch:' + data.batch_id;
1287
                    addSaveTarget( {
1288
                        label: backends[backend_id].saveLabel,
1289
                        id: backend_id + '/',
1290
                        description: '',
1291
                        enabled: false,
1292
                    } );
1293
                }
1294
            } );
1295
1296
            return false;
1297
        } );
1298
1299
        $('#manage-batches').click( function() {
1300
            window.open('/cgi-bin/koha/tools/manage-marc-import.pl');
1301
1302
            return false;
1303
        } );
1304
1033
        // Key bindings
1305
        // Key bindings
1034
        bindGlobalKeys();
1306
        bindGlobalKeys();
1035
1307
1036
        // Setup UI
1308
        // Setup UI
1037
        $("#advanced-search-ui, #search-results-ui, #macro-ui").each( function() {
1309
        $(".ui-modal").each( function() {
1038
            $(this).modal({ show: false });
1310
            $(this).modal({ show: false });
1039
        } );
1311
        } );
1040
1312
Lines 1077-1082 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1077
            return false;
1349
            return false;
1078
        } );
1350
        } );
1079
1351
1352
        $.each( backends, function( name ) {
1353
            if ( !this.save ) return; // Not a saving backend
1354
1355
            addSaveTarget( {
1356
                label: this.saveLabel,
1357
                id: name + '/',
1358
                description: '',
1359
            } );
1360
        } );
1361
1080
        // Start editor
1362
        // Start editor
1081
        Preferences.Load( [% USER_INFO.borrowernumber || 0 %] );
1363
        Preferences.Load( [% USER_INFO.borrowernumber || 0 %] );
1082
        displayPreferences(editor);
1364
        displayPreferences(editor);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-widgets-marc21.inc (-1 / +1 lines)
Lines 84-90 Link Here
84
 * single subfield, '@'.
84
 * single subfield, '@'.
85
 */
85
 */
86
86
87
require( [ 'widget' ], function( Widget ) {
87
require( [ 'koha-backend', 'widget' ], function( KohaBackend, Widget ) {
88
    Widget.Register( '000@', {
88
    Widget.Register( '000@', {
89
        makeTemplate: function() {
89
        makeTemplate: function() {
90
            return '     nam a22     7a 4500';
90
            return '     nam a22     7a 4500';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt (-4 / +32 lines)
Lines 46-51 Link Here
46
            <ul id="prefs-menu" class="dropdown-menu">
46
            <ul id="prefs-menu" class="dropdown-menu">
47
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
47
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
48
                <li><a id="set-field-widgets" href="#"></a></li>
48
                <li><a id="set-field-widgets" href="#"></a></li>
49
                <li><a id="open-batches" href="#">Import batches...</a></li>
49
                <li class="divider"></li>
50
                <li class="divider"></li>
50
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
51
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
51
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
52
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
Lines 92-103 Link Here
92
    </fieldset>
93
    </fieldset>
93
</form>
94
</form>
94
95
96
<h3>Save to:</h3>
97
<form id="save-targets">
98
    <fieldset class="brief">
99
    <ol></ol>
100
    </fieldset>
101
</form>
102
95
</div>
103
</div>
96
104
97
</div>
105
</div>
98
</div>
106
</div>
99
107
100
<div id="advanced-search-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
108
<div id="advanced-search-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
101
<div class="modal-dialog modal-lg">
109
<div class="modal-dialog modal-lg">
102
<div class="modal-content">
110
<div class="modal-content">
103
111
Lines 178-184 Link Here
178
</div>
186
</div>
179
</div>
187
</div>
180
188
181
<div id="search-results-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
189
<div id="search-results-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
182
<div class="modal-dialog modal-lg">
190
<div class="modal-dialog modal-lg">
183
<div class="modal-content">
191
<div class="modal-content">
184
192
Lines 225-231 Link Here
225
233
226
</div>
234
</div>
227
235
228
<div id="macro-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
236
<div id="macro-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
229
<div class="modal-dialog modal-lg">
237
<div class="modal-dialog modal-lg">
230
<div class="modal-content">
238
<div class="modal-content">
231
239
Lines 251-256 Link Here
251
</div>
259
</div>
252
</div>
260
</div>
253
261
262
<div id="batches-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="batches-title" aria-hidden="true">
263
264
<div class="modal-header">
265
    <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
266
    <h3 id="batches-title">Import batch settings</h3>
267
</div>
268
269
<div class="modal-body row-fluid">
270
    <div class="span9">
271
        <div id="toolbar" class="btn-toolbar">
272
            <button class="btn btn-small" type="submit" id="create-batch"><i class="icon-plus"></i> <span>Create new batch...</span></button>
273
            <button class="btn btn-small" type="submit" id="manage-batches"><i class="icon-list"></i> <span>Manage import batches...</span></button>
274
        </div>
275
        <ul id="batches-list"></ul>
276
    </div>
277
    <div class="span3">
278
    </div>
279
</div>
280
281
</div>
282
254
<div id="shortcuts-contents" style="display: none">
283
<div id="shortcuts-contents" style="display: none">
255
<table class="table table-condensed">
284
<table class="table table-condensed">
256
    <thead>
285
    <thead>
257
- 

Return to bug 18823