function goToCouponList(){ window.location.href = "../coupons/index.php"; } /*function generatePsw(){ var rString = randomString(10, '0123456789abcdefghijklmnopqrstuvwxyz'); $('#create_user_5').val(rString); $('#create_user_5_help_box').html("Password generata: "+rString); //console.log(rString); $('#create_user_5').trigger("click"); $('#create_user_5').trigger("focus"); }*/ function create() { var coupon_max_uses=$('#create_coupon_1').val(); var max_user_uses=$('#create_coupon_2').val(); var length=$('#create_coupon_3').val(); ///console.log(length); ///return; var code=$('#create_coupon_4').val(); var disabled=$('#create_coupon_5').val(); var tot_credits=$('#create_coupon_6').val(); if(coupon_max_uses==""){ alert("'Totale utilizzi di questo coupon' è un campo obbligatorio. (min. 0)"); return; } if(max_user_uses==""){ alert("'Totale utilizzi per singola persona' è un campo obbligatorio. (min. 0)"); return; } if(length!="") length=length+" 23:59"; if(code==""){ alert("'Codice del coupon' è un campo obbligatorio. (min. 0)"); return; } if(tot_credits==""){ alert("'Totale dei crediti' è un campo obbligatorio. (min. 0)"); return; } toggleDefaultLoader(); //return; var userData={ "coupon_max_uses":coupon_max_uses, "max_user_uses":max_user_uses, "length":length, "code":code, "disabled":disabled, "tot_credits":tot_credits }; //creo l'utente var user_code=null; var create_deferred = $.Deferred(); $.ajax({ url: remoteAPIurl+'/api/v1/coupon?api_token='+token, crossDomain: true, type: "post", data: userData, dataType: 'json', success: function(result, statusText, resObject){ var code=result.code; if(code===409){ toggleDefaultLoader(); alert("Il codice coupon è già presente a sistema."); return; } goToCouponList(); }, error: function() { console.log('error'); } }); } $(function(){ });