Lines 135-140
function showMARCdocLinks() {
Link Here
|
135 |
$.cookie("marcdocs_[% borrowernumber %]",'true', { path: "/", expires: 365 }); |
135 |
$.cookie("marcdocs_[% borrowernumber %]",'true', { path: "/", expires: 365 }); |
136 |
} |
136 |
} |
137 |
|
137 |
|
|
|
138 |
/* |
139 |
* Functions to check ISBN validity |
140 |
*/ |
141 |
|
142 |
function _NormalizeISBN(isbn) { |
143 |
// remove non-word characters |
144 |
var normalized_isbn = isbn.replace(/\W|_/g,''); |
145 |
// we want upper-case 'X' |
146 |
return normalized_isbn.toUpperCase(); |
147 |
} |
148 |
|
149 |
function _CheckISBNChecksum10(isbn) { |
150 |
|
151 |
var sum = 0; |
152 |
var i,r; |
153 |
|
154 |
if ( isbn.match(/\d{10}|^\d{9}X$/) ) { |
155 |
// its a 10 digit string, it might end with X |
156 |
for ( i=0; i<9; i++ ) { |
157 |
sum += (i+1) * parseInt(isbn[i],10); |
158 |
} |
159 |
r = sum % 11; |
160 |
if ( r == 10 && isbn[9] == 'X' || |
161 |
r == isbn[9] ) { |
162 |
return isbn; |
163 |
} |
164 |
} |
165 |
return null; |
166 |
} |
167 |
|
168 |
function _CheckISBNChecksum13(isbn) { |
169 |
|
170 |
var sum = 0; |
171 |
var i,r; |
172 |
|
173 |
if ( isbn.match(/^\d{13}$/) ) { |
174 |
for (i=0;i<12;i++) { |
175 |
if ( (i+1) % 2 == 0 ) { |
176 |
// even |
177 |
sum += 3 * parseInt(isbn[i],10); |
178 |
} else { |
179 |
// odd |
180 |
sum += parseInt(isbn[i],10); |
181 |
} |
182 |
} |
183 |
r = (10 - (sum % 10)) % 10; |
184 |
if ( r == isbn[12] ) { |
185 |
return isbn; |
186 |
} |
187 |
} |
188 |
return null; |
189 |
} |
190 |
|
191 |
function IsISBNOk() { |
192 |
|
193 |
var isbn; |
194 |
var isbn_field; |
195 |
[% IF ( marcflavour == 'MARC21' || marcflavour == 'NORMARC' ) %] |
196 |
isbn = $('input[id^="tag_020_subfield_a"]').val(); |
197 |
isbn_field = "020"; |
198 |
[% ELSIF ( marcflavour == 'UNIMARC' ) %] |
199 |
isbn = $('input[id^="tag_010_subfield_a"]').val(); |
200 |
isbn_field = "010"; |
201 |
[% END %] |
202 |
var normalized_isbn = _NormalizeISBN(isbn); |
203 |
|
204 |
if ( normalized_isbn.length == 13 ) { |
205 |
if ( normalized_isbn == _CheckISBNChecksum13(normalized_isbn) ) { |
206 |
return 0; |
207 |
} |
208 |
} else if ( normalized_isbn.length == 10 ) { |
209 |
if ( normalized_isbn == _CheckISBNChecksum10(normalized_isbn) ) { |
210 |
return 0; |
211 |
} |
212 |
} else if ( normalized_isbn.length == 0 ) { |
213 |
// no ISBN, no check |
214 |
return 0; |
215 |
} |
216 |
// Invalid ISBN |
217 |
var StrAlert = "- "+_("The ISBN you entered seems invalid. If you entered it exactly ")+"\n"; |
218 |
StrAlert += _("as it appears on the item, put it in ") + isbn_field + "$z."; |
219 |
return StrAlert; |
220 |
} |
221 |
|
138 |
/** |
222 |
/** |
139 |
* check if mandatory subfields are written |
223 |
* check if mandatory subfields are written |
140 |
*/ |
224 |
*/ |
Lines 158-165
function AreMandatoriesNotOk(){
Link Here
|
158 |
[% END %] |
242 |
[% END %] |
159 |
[% END %] |
243 |
[% END %] |
160 |
[% END %] |
244 |
[% END %] |
161 |
var StrAlert = _("Can't save this record because the following field aren't filled:"); |
245 |
var StrAlert = "- "+_("The following fields aren't filled:"); |
162 |
StrAlert += "\n\n"; |
246 |
StrAlert += "\n"; |
163 |
for(var i=0,len=mandatories.length; i<len ; i++){ |
247 |
for(var i=0,len=mandatories.length; i<len ; i++){ |
164 |
var tag=mandatories[i].substr(4,3); |
248 |
var tag=mandatories[i].substr(4,3); |
165 |
var subfield=mandatories[i].substr(17,1); |
249 |
var subfield=mandatories[i].substr(17,1); |
Lines 249-259
function AreMandatoriesNotOk(){
Link Here
|
249 |
* |
333 |
* |
250 |
*/ |
334 |
*/ |
251 |
function Check(){ |
335 |
function Check(){ |
252 |
var StrAlert = AreMandatoriesNotOk(); |
336 |
var StrAlert = _("Can't save this record\n"); |
253 |
if( ! StrAlert ){ |
337 |
var StrMandatoriesNotOk = AreMandatoriesNotOk(); |
|
|
338 |
[% IF ( RequireValidISBN ) %] |
339 |
var StrISBNNotOk = IsISBNOk(); |
340 |
if( ! StrMandatoriesNotOk && ! StrISBNNotOk ){ |
341 |
[% ELSE %] |
342 |
if( ! StrMandatoriesNotOk ){ |
343 |
[% END %] |
254 |
document.f.submit(); |
344 |
document.f.submit(); |
255 |
return true; |
345 |
return true; |
256 |
} else { |
346 |
} else { |
|
|
347 |
if ( StrMandatoriesNotOk ) |
348 |
StrAlert += StrMandatoriesNotOk; |
349 |
[% IF ( RequireValidISBN ) %] |
350 |
if ( StrISBNNotOk ) |
351 |
StrAlert += StrISBNNotOk; |
352 |
[% END %] |
257 |
alert(StrAlert); |
353 |
alert(StrAlert); |
258 |
return false; |
354 |
return false; |
259 |
} |
355 |
} |
260 |
- |
|
|