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 } ); |