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