David Cook
c061790f97
Currently, clicking twice or more on the Save button will generate duplicate patrons when adding patrons in the Patron module. Of course, there is handling that detects this, so you can choose to either edit the original record (i.e. throw away the duplicate) or create a duplicate record. However, it shouldn't get to that point by clicking on the Save button. That handling seems to be there to handle cases where you go through the whole process of trying to add a new patron only to find out that they already exist in the system (or at least their username/password do). -- This patch uses the "preventDoubleFormSubmit" function (which is also used in holds and fines to prevent double form submits). It was also necessary to edit members.js, since "check_form_borrowers" was forcing form submits despite the "preventDoubleFormSubmit" function. I've changed it from forcing a document.form.submit to return true, which the browser will still submit the form if it's a unique borrower, but the "preventDoubleFormSubmit" function will still prevent multiple submits. I've also added a "waiting" class to staff-global.js which changes the cursor to "wait" (i.e. loading circle graphic). I've included an "AddClass" call in "preventDoubleFormSubmit", so that the cursor graphic will change to show users that the page is loading so that they don't click Save again. Of course, even if they do click save again, there will only be one submit. However, this way - as Chris Cormack mentioned - the user knows that "something" is happening and that the form isn't broken. ------- Test Plan Before applying patch... 1) Fill out the form for a new patron in the Patron module 2) Click "Save" several times 3) Once the page loads, you'll be shown a prompt that says that this borrower already exists. You will have the option to view the original record, edit the original record, or create a new patron anyway 4) Click on edit the existing record, and delete the patron Apply the patch 5) Repeat steps 1 and 2 6) Notice that your cursor has changed into a little "loading" circle graphic when you hover over the "body" of the page, as well as any links or any inputs/buttons of the type "submit" within that form 7) Notice that no matter how many times you press the button, the form is not re-submitted. Eventually you will be taken to the new patron's record (no mention of duplication will occur) Ta da! Multiple form submits are prevented and the loading graphic signals to users that the form was submitted and that Koha is processing their data -- I understand that some people might want to change which elements are given the "waiting" class. I'm happy to renegotiate this as necessary. Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Looks good and works nicely. Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
185 lines
No EOL
5.5 KiB
JavaScript
185 lines
No EOL
5.5 KiB
JavaScript
// this function checks id date is like DD/MM/YYYY
|
|
function CheckDate(field) {
|
|
var d = field.value;
|
|
if (d!=="") {
|
|
var amin = 1900;
|
|
var amax = 2100;
|
|
var date = d.split("/");
|
|
var ok=1;
|
|
var msg;
|
|
if ( (date.length < 2) && (ok==1) ) {
|
|
msg = MSG_SEPARATOR+field.name;
|
|
alert(msg); ok=0; field.focus();
|
|
return;
|
|
}
|
|
var dd = date[0];
|
|
var mm = date[1];
|
|
var yyyy = date[2];
|
|
// checking days
|
|
if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
|
|
msg = MSG_INCORRECT_DAY+field.name;
|
|
alert(msg); ok=0; field.focus();
|
|
return false;
|
|
}
|
|
// checking months
|
|
if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
|
|
msg = MSG_INCORRECT_MONTH+field.name;
|
|
alert(msg); ok=0; field.focus();
|
|
return false;
|
|
}
|
|
// checking years
|
|
if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
|
|
msg = MSG_INCORRECT_YEAR+field.name;
|
|
alert(msg); ok=0; field.focus();
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
//function test if member is unique and if it's right the member is registred
|
|
function unique() {
|
|
var msg1;
|
|
var msg2;
|
|
if ( document.form.check_member.value==1){
|
|
if (document.form.categorycode.value != "I"){
|
|
|
|
msg1 += MSG_DUPLICATE_PATRON;
|
|
alert(msg1);
|
|
check_form_borrowers(0);
|
|
document.form.submit();
|
|
|
|
}else{
|
|
msg2 += MSG_DUPLICATE_ORGANIZATION;
|
|
alert(msg2);
|
|
check_form_borrowers(0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
document.form.submit();
|
|
}
|
|
|
|
}
|
|
//end function
|
|
//function test if date enrooled < date expiry
|
|
// WARNING: format-specific test.
|
|
function check_manip_date(status) {
|
|
if (status=='verify'){
|
|
// this part of function('verify') is used to check if dateenrolled<date expiry
|
|
if (document.form.dateenrolled !== '' && document.form.dateexpiry.value !=='') {
|
|
var myDate1=document.form.dateenrolled.value.split ('/');
|
|
var myDate2=document.form.dateexpiry.value.split ('/');
|
|
if ((myDate1[2]>myDate2[2])||(myDate1[2]==myDate2[2] && myDate1[1]>myDate2[1])||(myDate1[2]==myDate2[2] && myDate1[1]>=myDate2[1] && myDate1[0]>=myDate2[0]))
|
|
|
|
{
|
|
document.form.dateenrolled.focus();
|
|
var msg = MSG_LATE_EXPIRY;
|
|
alert(msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//end function
|
|
|
|
|
|
// function to test all fields in forms and nav in different forms(1 ,2 or 3)
|
|
function check_form_borrowers(nav){
|
|
var statut=0;
|
|
var message = "";
|
|
var message_champ="";
|
|
if (document.form.check_member.value == 1 )
|
|
{
|
|
if (document.form_double.answernodouble) {
|
|
if( (!(document.form_double.answernodouble.checked))){
|
|
document.form.nodouble.value=0;
|
|
} else {
|
|
document.form.nodouble.value=1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (document.form.BorrowerMandatoryField.value==='')
|
|
{}
|
|
else
|
|
{
|
|
var champ_verif = document.form.BorrowerMandatoryField.value.split ('|');
|
|
message += MSG_MISSING_MANDATORY;
|
|
message += "\n";
|
|
for (var i=0; i<champ_verif.length; i++) {
|
|
if (document.getElementsByName(""+champ_verif[i]+"")[0]) {
|
|
var val_champ=eval("document.form."+champ_verif[i]+".value");
|
|
var ref_champ=eval("document.form."+champ_verif[i]);
|
|
//check if it's a select
|
|
if (ref_champ.type=='select-one'){
|
|
// check to see if first option is selected and is blank
|
|
if (ref_champ.options[0].selected &&
|
|
ref_champ.options[0].text === ''){
|
|
// action if field is empty
|
|
message_champ+=champ_verif[i]+"\n";
|
|
//test to know if you must show a message with error
|
|
statut=1;
|
|
}
|
|
} else {
|
|
if ( val_champ === '' ) {
|
|
// action if the field is not empty
|
|
message_champ+=champ_verif[i]+"\n";
|
|
statut=1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( document.form.password.value != document.form.password2.value ){
|
|
if ( message_champ !== '' ){
|
|
message_champ += "\n";
|
|
}
|
|
message_champ+= MSG_PASSWORD_MISMATCH;
|
|
statut=1;
|
|
}
|
|
|
|
//patrons form to test if you checked no to the question of double
|
|
if (statut!=1 && document.form.check_member.value > 0 ) {
|
|
if (!(document.form_double.answernodouble.checked)){
|
|
message_champ+= MSG_DUPLICATE_SUSPICION;
|
|
statut=1;
|
|
document.form.nodouble.value=0;
|
|
} else {
|
|
document.form.nodouble.value=1;
|
|
}
|
|
}
|
|
|
|
if (statut==1){
|
|
//alert if at least 1 error
|
|
alert(message+"\n"+message_champ);
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function Dopop(link) {
|
|
// // var searchstring=document.form.value[i].value;
|
|
var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
|
|
}
|
|
|
|
function Dopopguarantor(link) {
|
|
|
|
var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
if($("#yesdebarred").is(":checked")){
|
|
$("#debarreduntil").show();
|
|
} else {
|
|
$("#debarreduntil").hide();
|
|
}
|
|
$("#yesdebarred,#nodebarred").change(function(){
|
|
if($("#yesdebarred").is(":checked")){
|
|
$("#debarreduntil").show();
|
|
$("#datedebarred").focus();
|
|
} else {
|
|
$("#debarreduntil").hide();
|
|
}
|
|
});
|
|
}); |