/
addbiblio-text.js
82 lines (68 loc) · 2.31 KB
/
addbiblio-text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
addbiblio = {};
$.extend( addbiblio, {
submit: function() {
$.ajax( {
url: '/cgi-bin/koha/cataloguing/addbiblio-text.pl',
type: 'POST',
dataType: 'json',
data: $( '#f input[name^="tag"]' ).serialize() + '&op=try_parse&record=' + escape(addbiblio.editor.getCode()),
success: addbiblio.submit.finished,
} );
},
insert_itemtype: function( event ) {
var iter = addbiblio.editor.cursorPosition();
addbiblio.editor.insertIntoLine( iter.line, iter.character, $( '#itemtypes' ).val() );
return false;
},
z3950_search: function() {
window.open( "/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=" + addbiblio.biblionumber,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes' );
},
not_duplicate: function() {
$( "#confirm_not_duplicate" ).attr( "value", "1" );
$( "#f" ).get( 0 ).submit();
},
} );
$.extend( addbiblio.submit, {
finished: function( data, status_ ) {
if ( data.error ) {
humanMsg.displayMsg( '<strong>Watch your language:</strong> ' + data.message );
return false;
}
var record = new marc.record(data.record);
var missing_tags = [], missing_subfields = [];
$.each( addbiblio.mandatory.tags, function( i, tag ) {
if ( tag == '000' ) {
if ( !record.leader) missing_tags.push( 'leader' );
} else if ( !record.has( tag ) ) {
missing_tags.push( tag );
}
} );
$.each( addbiblio.mandatory.subfields, function( i, sf ) {
if ( sf[0].substring( 0, 2 ) != '00' && !record.has( sf[0], sf[1] ) ) {
missing_subfields.push( sf.join( '$' ) );
}
} );
if ( missing_tags.length || missing_subfields.length ) {
message = [];
if ( missing_tags.length ) {
message.push( missing_tags.join( ', ' ) + ' tags' );
}
if ( missing_subfields.length ) {
message.push( missing_subfields.join( ', ' ) + ' subfields' );
}
humanMsg.displayMsg( '<strong>Record is missing pieces:</strong> ' + message.join( ' and ' ) + ' are mandatory' );
return;
}
$( '#f' ).get( 0 ).submit();
}
} );
$( function () {
$( '#insert-itemtype' ).click( addbiblio.insert_itemtype );
addbiblio.editor = CodeMirror.fromTextArea('record', {
height: "350px",
parserfile: "parsemarc.js",
stylesheet: koha.themelang + "/lib/codemirror/css/marccolors.css",
path: koha.themelang + "/lib/codemirror/js/",
autoMatchParens: true
});
} );