Lines 278-319
Link Here
|
278 |
} |
278 |
} |
279 |
|
279 |
|
280 |
/** |
280 |
/** |
281 |
* check if mandatory subfields are written |
281 |
* check if mandatory/important subfields are written |
|
|
282 |
* @param mandatory true to check for mandatories, false for importants |
282 |
*/ |
283 |
*/ |
283 |
function AreMandatoriesNotOk(){ |
284 |
function AreFieldsNotOk (mandatory = true) { |
284 |
var mandatories = new Array(); |
285 |
var fields = new Array(); |
285 |
var mandatoriesfields = new Array(); |
286 |
var subfields = new Array(); |
286 |
var tab = new Array(); |
287 |
var tab = new Array(); |
287 |
var label = new Array(); |
288 |
var label = new Array(); |
288 |
var flag=0; |
289 |
var flag=0; |
289 |
var tabflag= new Array(); |
290 |
var tabflag= new Array(); |
290 |
[% FOREACH BIG_LOO IN BIG_LOOP %] |
291 |
var StrAlert = ""; |
291 |
[% FOREACH innerloo IN BIG_LOO.innerloop %] |
292 |
var notFilledClass = "subfield_not_filled"; |
292 |
[% IF ( innerloo.mandatory ) %] |
293 |
|
293 |
mandatoriesfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); |
294 |
if (mandatory) { |
|
|
295 |
[% FOREACH BIG_LOO IN BIG_LOOP %] |
296 |
[% FOREACH innerloo IN BIG_LOO.innerloop %] |
297 |
[% IF ( innerloo.mandatory ) %] |
298 |
fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); |
299 |
[% END %] |
300 |
[% FOREACH subfield_loo IN innerloo.subfield_loop %] |
301 |
[% IF ( subfield_loo.mandatory ) %]subfields.push("[% subfield_loo.id | html %]"); |
302 |
tab.push("[% BIG_LOO.number | html %]"); |
303 |
label.push("[% subfield_loo.marc_lib | $raw %]"); |
304 |
[% END %] |
305 |
[% END %] |
294 |
[% END %] |
306 |
[% END %] |
295 |
[% FOREACH subfield_loo IN innerloo.subfield_loop %] |
307 |
[% END %] |
296 |
[% IF ( subfield_loo.mandatory ) %]mandatories.push("[% subfield_loo.id | html %]"); |
308 |
StrAlert = _("Can't save this record because the following field aren't filled:"); |
297 |
tab.push("[% BIG_LOO.number | html %]"); |
309 |
} else { |
298 |
label.push("[% subfield_loo.marc_lib | $raw %]"); |
310 |
[% FOREACH BIG_LOO IN BIG_LOOP %] |
|
|
311 |
[% FOREACH innerloo IN BIG_LOO.innerloop %] |
312 |
[% IF ( innerloo.important ) %] |
313 |
fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); |
314 |
[% END %] |
315 |
[% FOREACH subfield_loo IN innerloo.subfield_loop %] |
316 |
[% IF ( subfield_loo.important ) %]subfields.push("[% subfield_loo.id | html %]"); |
317 |
tab.push("[% BIG_LOO.number | html %]"); |
318 |
label.push("[% subfield_loo.marc_lib | $raw %]"); |
319 |
[% END %] |
299 |
[% END %] |
320 |
[% END %] |
300 |
[% END %] |
321 |
[% END %] |
301 |
[% END %] |
322 |
[% END %] |
302 |
[% END %] |
323 |
StrAlert = _("A few important fields are not filled:"); |
303 |
var StrAlert = _("Can't save this record because the following field aren't filled:"); |
324 |
notFilledClass = "important_subfield_not_filled"; |
|
|
325 |
} |
326 |
|
304 |
StrAlert += "\n\n"; |
327 |
StrAlert += "\n\n"; |
305 |
for(var i=0,len=mandatories.length; i<len ; i++){ |
328 |
for(var i=0,len=subfields.length; i<len ; i++){ |
306 |
var tag=mandatories[i].substr(4,3); |
329 |
var tag=subfields[i].substr(4,3); |
307 |
var subfield=mandatories[i].substr(17,1); |
330 |
var subfield=subfields[i].substr(17,1); |
308 |
var tagnumber=mandatories[i].substr(19,mandatories[i].lastIndexOf("_")-19); |
331 |
var tagnumber=subfields[i].substr(19,subfields[i].lastIndexOf("_")-19); |
309 |
if (tabflag[tag+subfield+tagnumber] == null) { |
332 |
if (tabflag[tag+subfield+tagnumber] == null) { |
310 |
tabflag[tag+subfield+tagnumber]=new Array(); |
333 |
tabflag[tag+subfield+tagnumber]=new Array(); |
311 |
tabflag[tag+subfield+tagnumber][0]=0; |
334 |
tabflag[tag+subfield+tagnumber][0]=0; |
312 |
} |
335 |
} |
313 |
if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(mandatories[i]) != null && ! document.getElementById(mandatories[i]).value || document.getElementById(mandatories[i]) == null)){ |
336 |
if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(subfields[i]) != null && ! document.getElementById(subfields[i]).value || document.getElementById(subfields[i]) == null)){ |
314 |
tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ; |
337 |
tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ; |
315 |
document.getElementById(mandatories[i]).setAttribute('class','input_marceditor noEnterSubmit subfield_not_filled'); |
338 |
document.getElementById(subfields[i]).setAttribute('class','input_marceditor noEnterSubmit ' + notFilledClass); |
316 |
$('#' + mandatories[i]).focus(); |
339 |
$('#' + subfields[i]).focus(); |
317 |
tabflag[tag+subfield+tagnumber][1]=label[i]; |
340 |
tabflag[tag+subfield+tagnumber][1]=label[i]; |
318 |
tabflag[tag+subfield+tagnumber][2]=tab[i]; |
341 |
tabflag[tag+subfield+tagnumber][2]=tab[i]; |
319 |
} else { |
342 |
} else { |
Lines 330-339
Link Here
|
330 |
} |
353 |
} |
331 |
} |
354 |
} |
332 |
|
355 |
|
333 |
/* Check for mandatories field(not subfields) */ |
356 |
/* Check for mandatories/importants field(not subfields) */ |
334 |
for(var i=0,len=mandatoriesfields.length; i<len; i++){ |
357 |
for(var i=0,len=fields.length; i<len; i++){ |
335 |
isempty = true; |
358 |
isempty = true; |
336 |
arr = mandatoriesfields[i]; |
359 |
arr = fields[i]; |
337 |
divid = "tag_" + arr[0] + "_" + arr[1]; |
360 |
divid = "tag_" + arr[0] + "_" + arr[1]; |
338 |
varegexp = new RegExp("^tag_" + arr[0] + "_code_"); |
361 |
varegexp = new RegExp("^tag_" + arr[0] + "_code_"); |
339 |
|
362 |
|
Lines 374-380
Link Here
|
374 |
|
397 |
|
375 |
if(isempty){ |
398 |
if(isempty){ |
376 |
flag = 1; |
399 |
flag = 1; |
377 |
StrAlert += "\t* " + _("Field %s is mandatory, at least one of its subfields must be filled.").format(arr[0]) + "\n"; |
400 |
StrAlert += "\t* "; |
|
|
401 |
if (mandatory) { |
402 |
StrAlert += _("Field %s is mandatory, at least one of its subfields must be filled.").format(arr[0]); |
403 |
} else { |
404 |
StrAlert += _("Field %s is important, at least one of its subfields must be filled.").format(arr[0]); |
405 |
} |
406 |
StrAlert += "\n"; |
378 |
} |
407 |
} |
379 |
|
408 |
|
380 |
} |
409 |
} |
Lines 391-400
Link Here
|
391 |
* |
420 |
* |
392 |
*/ |
421 |
*/ |
393 |
function Check(){ |
422 |
function Check(){ |
394 |
var StrAlert = AreMandatoriesNotOk(); |
423 |
var StrAlert = AreFieldsNotOk(); |
395 |
if( ! StrAlert ){ |
424 |
if( ! StrAlert ){ |
396 |
var StrWarning = AreImportantsNotOk(); |
425 |
var StrWarning = AreFieldsNotOk(false); |
397 |
if (StrWarning){ |
426 |
if (StrWarning){ |
|
|
427 |
StrWarning += "\n" + _("Are you sure you want to save?"); |
398 |
var r=confirm(StrWarning); |
428 |
var r=confirm(StrWarning); |
399 |
if (! r){ |
429 |
if (! r){ |
400 |
return false; |
430 |
return false; |
Lines 408-522
Link Here
|
408 |
} |
438 |
} |
409 |
} |
439 |
} |
410 |
|
440 |
|
411 |
/** |
|
|
412 |
* check if important subfields are written |
413 |
*/ |
414 |
function AreImportantsNotOk(){ |
415 |
var importants = new Array(); |
416 |
var importantsfields = new Array(); |
417 |
var tab = new Array(); |
418 |
var label = new Array(); |
419 |
var flag=0; |
420 |
var tabflag= new Array(); |
421 |
[% FOREACH BIG_LOO IN BIG_LOOP %] |
422 |
[% FOREACH innerloo IN BIG_LOO.innerloop %] |
423 |
[% IF ( innerloo.important ) %] |
424 |
importantsfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); |
425 |
[% END %] |
426 |
[% FOREACH subfield_loo IN innerloo.subfield_loop %] |
427 |
[% IF ( subfield_loo.important ) %]importants.push("[% subfield_loo.id | html %]"); |
428 |
tab.push("[% BIG_LOO.number | html %]"); |
429 |
label.push("[% subfield_loo.marc_lib | $raw %]"); |
430 |
[% END %] |
431 |
[% END %] |
432 |
[% END %] |
433 |
[% END %] |
434 |
var StrWarning = _("A few important fields are not filled:"); |
435 |
StrWarning += "\n\n"; |
436 |
for(var i=0,len=importants.length; i<len ; i++){ |
437 |
var tag=importants[i].substr(4,3); |
438 |
var subfield=importants[i].substr(17,1); |
439 |
var tagnumber=importants[i].substr(19,importants[i].lastIndexOf("_")-19); |
440 |
if (tabflag[tag+subfield+tagnumber] == null) { |
441 |
tabflag[tag+subfield+tagnumber]=new Array(); |
442 |
tabflag[tag+subfield+tagnumber][0]=0; |
443 |
} |
444 |
if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(importants[i]) != null && ! document.getElementById(importants[i]).value || document.getElementById(importants[i]) == null)){ |
445 |
tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ; |
446 |
document.getElementById(importants[i]).setAttribute('class','input_marceditor noEnterSubmit important_subfield_not_filled'); |
447 |
$('#' + importants[i]).focus(); |
448 |
tabflag[tag+subfield+tagnumber][1]=label[i]; |
449 |
tabflag[tag+subfield+tagnumber][2]=tab[i]; |
450 |
} else { |
451 |
tabflag[tag+subfield+tagnumber][0] = 1; |
452 |
} |
453 |
} |
454 |
for (var tagsubfieldid in tabflag){ |
455 |
if (tabflag[tagsubfieldid][0]==0){ |
456 |
var tag=tagsubfieldid.substr(0,3); |
457 |
var subfield=tagsubfieldid.substr(3,1); |
458 |
StrWarning += "\t* "+_("tag %s subfield %s %s in tab %s").format(tag, subfield, tabflag[tagsubfieldid][1], tabflag[tagsubfieldid][2]) + "\n"; |
459 |
//StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n"; |
460 |
flag=1; |
461 |
} |
462 |
} |
463 |
|
464 |
/* Check for importants field(not subfields) */ |
465 |
for(var i=0,len=importantsfields.length; i<len; i++){ |
466 |
isempty = true; |
467 |
arr = importantsfields[i]; |
468 |
divid = "tag_" + arr[0] + "_" + arr[1]; |
469 |
varegexp = new RegExp("^tag_" + arr[0] + "_code_"); |
470 |
|
471 |
if(parseInt(arr[0]) >= 10){ |
472 |
elem = document.getElementById(divid); |
473 |
eleminputs = elem.getElementsByTagName('input'); |
474 |
for(var j=0,len2=eleminputs.length; j<len2; j++){ |
475 |
|
476 |
if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){ |
477 |
inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]); |
478 |
|
479 |
for( var k=0; k<len2; k++){ |
480 |
if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){ |
481 |
isempty = false |
482 |
} |
483 |
} |
484 |
|
485 |
elemselect = elem.getElementsByTagName('select'); |
486 |
for( var k=0; k<elemselect.length; k++){ |
487 |
if(elemselect[k].id.match(inputregexp) && elemselect[k].value){ |
488 |
isempty = false |
489 |
} |
490 |
} |
491 |
} |
492 |
} |
493 |
|
494 |
elemtextareas = elem.getElementsByTagName('textarea'); |
495 |
for(var j=0,len2=elemtextareas.length; j<len2; j++){ |
496 |
// this bit assumes that the only textareas in this context would be for subfields |
497 |
if (elemtextareas[j].value) { |
498 |
isempty = false; |
499 |
} |
500 |
} |
501 |
} else { |
502 |
isempty = false; |
503 |
} |
504 |
|
505 |
if(isempty){ |
506 |
flag = 1; |
507 |
StrWarning += "\t* " + _("Field %s is important, at least one of its subfields must be filled.").format(arr[0]) + "\n"; |
508 |
} |
509 |
} |
510 |
|
511 |
StrWarning += "\n" + _("Are you sure you want to save?"); |
512 |
|
513 |
if(flag){ |
514 |
return StrWarning; |
515 |
} else { |
516 |
return flag; |
517 |
} |
518 |
} |
519 |
|
520 |
/** |
441 |
/** |
521 |
* check if z3950 mandatories are set or not |
442 |
* check if z3950 mandatories are set or not |
522 |
*/ |
443 |
*/ |
523 |
- |
|
|