window.ParsleyValidator.addValidator('phone', function (value, requirement) { return isValidNumber(value, 'BE'); }, 32).addMessage('nl', 'phone', 'Dit lijkt geen geldig telefoonnummer te zijn.'); /*window.ParsleyValidator.addValidator('vat', function (value, requirement) { return App.vat_regex.test(value.replace(/ /g, "").replace(/\./g, "").replace(/-/g, "")); }, 32).addMessage('nl', 'vat', 'Dit lijkt geen geldig BTW/VAT nummer te zijn.');*/ window.ParsleyValidator.addValidator('iban', function (value, requirement) { return new RegExp("^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$").test(value.replace(/ /g, "").replace(/\./g, "").replace(/-/g, "")); }, 32).addMessage('nl', 'iban', 'Dit lijkt geen geldig IBAN nummer te zijn.'); window.ParsleyValidator.addValidator('id-number', function (value, requirement) { return true; }, 32).addMessage('nl', 'id-number', 'Dit lijkt geen geldig rijksregisternummer te zijn.'); window.ParsleyValidator.addValidator('id-card', function (value, requirement) { return true; }, 32).addMessage('nl', 'id-card', 'Dit lijkt geen geldig identiteitskaartnummer te zijn.'); window.ParsleyValidator.addValidator('date', function(value, requirement){ return /^\d\d-\d\d-\d\d\d\d$/.test(value); }, 32).addMessage('nl', 'date', 'Ongeldige datum.'); var lang; $(document).ready(function(){ $("body").find('.step').each(function(){ $(this).find(".flexItem:has(input,select,textarea)").last().find("select,input,textarea").last().keydown(function (e) { return !(e.which === 9) }); }); $('#phoneNumberMobile').mask('+ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ', {translation: {'Z': {pattern: /[0-9+]/, optional: true}}}); $('#phoneNumberFixed').mask('+ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ', {translation: {'Z': {pattern: /[0-9+]/, optional: true}}}); $('#social_security').mask('00.00.00-000.00', {translation: {'Z': {pattern: /[0-9]/, optional: true}}}); $('#id_number').mask('000-0000000-00', {translation: {'Z': {pattern: /[0-9]/, optional: true}}}); $('[data-toggle="popover"]').popover({ html: true }); $("#acceptConditions").click(function(){ $("#conditionsModal").modal('hide'); $("#conditionCheck").removeClass("fa-circle-thin").addClass("fa-dot-circle-o"); $("#confirmBtn").removeAttr("disabled"); }); $("#cancelAcceptConditions").click(function(){ $("#conditionsModal").modal('hide'); $("#conditionCheck").removeClass("fa-dot-circle-o ").addClass("fa-circle-thin"); }); $(".openConditions").click(function(){ $("#conditionsModal").modal("show"); $("#privacyFrame").attr("src","https://www.forganiser.com/algemene-voorwaarden/"); }); var stepCounter= 0; $("#myWizard").find("section").each(function(){ stepCounter++; $(".paginationCenterChild").append("
") }) var form = $('#myWizard'); $('#wizardButtonContainer .previous').bind('click', function(e) { e.preventDefault(); $('#myWizard').easyWizard('prevStep'); }); $('#wizardButtonContainer .next').bind('click', function(e) { e.preventDefault(); $('#myWizard').easyWizard('nextStep'); }); $(".organisationTypeList li").click(function(){ $(".organisationTypeList li.selected").removeClass("selected"); $(this).addClass("selected"); var typeId = $(this).data("type"); $("#organisationType").val(typeId); }) form.easyWizard({ buttonsClass: 'btn btn-default', submitButtonClass: 'btn btn-primary', nextButton: 'Volgende', showSteps: false, prevButton: 'Vorige', showButtons: false, submitButton: false, before: function(wizardObj, currentStepObj, nextStepObj) { var step = 'step-' + currentStepObj.attr('data-step'); var next_step = 'step-' + nextStepObj.attr('data-step'); $('html, body').animate({scrollTop : 0},400); if(nextStepObj.attr('data-step') > currentStepObj.attr('data-step')){ var isValid = form.parsley().validate(step); if(!isValid){ swal("Velden ontbreken","Gelieve alle ontbrekende velden in te vullen","error"); } else { if (nextStepObj.attr('data-step') == 2) { $("#wizardButtonContainer .submit:hidden").show(); $("#wizardButtonContainer .next:visible").hide(); } else { $("#wizardButtonContainer .next:hidden").show(); $("#wizardButtonContainer .submit:visible").hide(); } $("#paginationWizard").find(".paginationStep.active").removeClass("active"); $("#paginationWizard").find(".paginationStep[data-step="+nextStepObj.attr('data-step') + "]").addClass("active"); } return isValid; } else { $("#wizardButtonContainer .next:hidden").show(); $("#wizardButtonContainer .submit:visible").hide(); $("#paginationWizard").find(".paginationStep.active").removeClass("active"); $("#paginationWizard").find(".paginationStep[data-step="+nextStepObj.attr('data-step') + "]").addClass("active"); return true; } }, }); form.parsley(); $(window).resize(function() { //form.easyWizard('resize', form.find('.active')) }); form.on("submit", function(e){ return false; }); $("#confirmBtn").click(function(){ if(form.parsley().validate()){ var btn = $(this); var form_data = form.serializeArray(); var company = {}; for(var i=0; i < form_data.length; i++){ company[form_data[i].name] = form_data[i].value; } company.image = $("#user-edit-jcrop").attr("src"); $("button").attr('disabled', true).addClass('disabled'); btn.find('.fa-spinner').show(); $.ajax({ type: 'POST', url: '/ws/register/company', data: { company: JSON.stringify(company), }, error: function(){ swal("Fout tijdens registratie","Er liep iets fout bij de registratie, probeer opnieuw.","error") $("button").prop('disabled', false).removeClass('disabled'); btn.find('.fa-spinner').hide(); }, success: function(result){ if(result.type == "success"){ $("body").addClass("finished"); //swal("Registratie succesvol","Bedankt voor je registratie, je ontvangt binnen de 30 minuten een mail met je inlog gegevens. Zijn er vragen contacteer ons dan via support@forganiser.be.".replace("{0}",company.first_name),"success") } else if(result.type == "email_exist"){ swal("E-mailadres bestaat reeds","Dit e-mailadres bestaat reeds in het systeem. Gebruik een ander e-mailadres.","error") btn.find('.fa-spinner').hide(); } else { swal("Fout tijdens registratie","Er liep iets fout bij de registratie, probeer opnieuw.","error") $("button").prop('disabled', false).removeClass('disabled'); btn.find('.fa-spinner').hide(); } } }); } }); }); var me = { set: function(name, value){ window[name] = value; }, get: function(name){ return window[name]; } }; function loadNewImage(){ if(window.jcrop_api != null){ me.get('jcrop_api').destroy(); me.set('jcrop_api', null); me.set('new_image', null); $('#user-edit-jcrop').attr('src', null); $('#user-edit-jcrop').css('max-height', '180px'); } var fu = $(''); fu.one("change", function(evt){ var reader = new FileReader(); reader.onload = function (e) { var oImage = new Image(); oImage.src = e.target.result; oImage.onload = function(){ // Resize original image var rImage = window.helpers.images.resizeImage(oImage, 960, function(dataUri, w, h){ var local_id = me.get('local_id'); if(local_id != null) local_id -= 1; else local_id = -1; me.set('local_id', local_id); me.set('new_image', { id: local_id, original: dataUri }); $('#user-edit-jcrop').css('max-height', '180px'); $('#user-edit-jcrop').attr('src', dataUri).show(); $('#user-edit-jcrop').one('load', function(){ var preview_canvas = document.createElement('canvas'); preview_canvas.width = 200; preview_canvas.height = 200; var imageObj = this; var boundx, boundy, jcrop_api; var updatePreview = function(preview_canvas, imageObj){ return function(c){ var preview_context = preview_canvas.getContext("2d"); if (parseInt(c.w) > 0){ preview_context.drawImage(imageObj, c.x, c.y, c.w, c.h, 0, 0, preview_canvas.width, preview_canvas.height); var new_image = me.get('new_image'); new_image.value = preview_canvas.toDataURL("image/jpeg", 0.9); me.set('new_image', new_image); } } }; $("#btns-has-image").show(); $("#btns-no-image").hide(); }); }); }; /*image.onload = function() { var w = this.width, h = this.height, t = file.type, // ext only: // file.type.split('/')[1], */ } reader.readAsDataURL(evt.target.files[0]); /*window.helpers.images.getSquareImageFromFile(file, function(dataURL){ me.set('image', dataURL); fu.replaceWith(fu.val('').clone(true)); });*/ }); fu.click(); } function addImageToDiv(container, image){ //console.log(image); var obj = $([ '
', '
', '
', '
', '', '
', '
', '', '
', '
', '
', '
' ].join("")); container.append(obj); } function cancelNewImage(){ $('#user-edit-jcrop').attr('src', null).hide(); $('#user-edit-jcrop').css('max-height', '180px'); $("#btns-has-image").hide(); $("#btns-no-image").show(); return false; } (function() { var max_size = 350; if ('undefined' === typeof helpers) { helpers = {}; if ('undefined' !== typeof window) { window.helpers = helpers; } } if ('undefined' === typeof helpers.images) { helpers.images = {}; } /** * Detecting vertical squash in loaded image. * Fixes a bug which squash image vertically while drawing into canvas for some images. * This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel * */ var detectVerticalSquash = function (img) { var iw = img.naturalWidth, ih = img.naturalHeight; var canvas = document.createElement('canvas'); canvas.width = 1; canvas.height = ih; var ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); var data = ctx.getImageData(0, 0, 1, ih).data; // search image edge pixel position in case it is squashed vertically. var sy = 0; var ey = ih; var py = ih; while (py > sy) { var alpha = data[(py - 1) * 4 + 3]; if (alpha === 0) { ey = py; } else { sy = py; } py = (ey + sy) >> 1; } var ratio = (py / ih); return (ratio===0)?1:ratio; }; /** * A replacement for context.drawImage * (args are for source and destination). */ var drawImageIOSFix = function (ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) { var vertSquashRatio = detectVerticalSquash(img); ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio); }; helpers.images.getSquareImageFromFile = function(file, callback){ var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent){ var img = new Image(); img.onload = function() { var canvas = document.createElement('canvas'); var context = canvas.getContext("2d"), round = Math.round; // if width and height are both specified // the resample uses these pixels // if width is specified but not the height // the resample respects proportions // accordingly with orginal size // same is if there is a height, but no width var minValue = Math.min(img.height, img.width); canvas.width = max_size; canvas.height = max_size; // drawImage has different overloads // in this case we need the following one ... drawImageIOSFix(context, img, 0, 0, minValue, minValue, 0, 0, max_size, max_size); callback(canvas.toDataURL("image/jpeg", 0.9)); }; img.src = fileLoadedEvent.target.result; }; fileReader.readAsDataURL(file); }; helpers.images.getImageFromFile = function(file, callback){ var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent){ var img = new Image(); img.onload = function() { var canvas = document.createElement('canvas'); var context = canvas.getContext("2d"), round = Math.round; // if width and height are both specified // the resample uses these pixels // if width is specified but not the height // the resample respects proportions // accordingly with orginal size // same is if there is a height, but no width var currH = img.height; var currW = img.width; var ratio = currH / currW; if(currW >= max_size && ratio <= 1){ currW = max_size; currH = currW * ratio; } else if(currH >= max_size){ currH = max_size; currW = currH / ratio; } canvas.width = currW; canvas.height = currH; drawImageIOSFix(context, img, 0, 0, img.width, img.height, 0, 0, currW, currH); callback(canvas.toDataURL("image/jpeg", 0.9)); }; img.src = fileLoadedEvent.target.result; }; fileReader.readAsDataURL(file); }; helpers.images.resizeImage = function(img, max_size, callback){ var o_width = img.width; var o_height = img.height; var ratio,width,height; if(o_width > o_height){ ratio = o_width / max_size; width = max_size; height = Math.round(o_height / ratio); } else { ratio = o_height / max_size; width = Math.round(o_width / ratio); height = max_size; } //console.log(ratio + " " + width + " " + height); var canvas = document.createElement("canvas"); canvas.width = width; canvas.height = height; // Scale and draw the source image to the canvas canvas.getContext("2d").drawImage(img, 0, 0, width, height); // Convert the canvas to a data URL in PNG format callback(canvas.toDataURL("image/jpeg", 0.9), width, height); } })();