!(function($,redirect,session){ /** * @class * @classDesc Change Player Information form. * @view * * @author magda.orlowska@gtech.com * @extends {Backbone.View} */ portalGGA.views.PlayerInformation = Backbone.View.extend( /** @lends portalGGA.views.PlayerInformation.prototype */{ events: { "click .billingSameAsMailing": "toggleBillingSameAsMailing", "click #updateProfileButton": "save", "click .optinbtn": "optIn", "change #nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[2\\]": function changed(e) { this.getDays(e); }, "change #nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[1\\]": function changed(e) { this.getDays(e); this.getDob(); }, }, isMobile : { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return /iPhone|iPad|iPod/i.test(navigator.userAgent); }, Opera: function() { return /Opera Mini/i.test(navigator.userAgent); }, Windows: function() { return /IEMobile/i.test(navigator.userAgent); }, any: function() { return (this.Android() || this.BlackBerry() || this.iOS() || this.Opera() || this.Windows()); } }, /** * [constructor description] */ constructor: function PlayerInformationView(options) { Backbone.View.apply(this, arguments); this.securityQuestionsConfigured = []; this.securityQuestionsConfigured = JSON.parse(options.securityQuestions); this.htmlId = options.htmlId; this.model || (this.model = new portalGGA.models.Player()); this.model.fetch(); // Backbone takes care of POST/PUT // sends POST for create and PUT for update, // but backend response for personalinfo does not contain any id attribute, // so we need to mock it // here is ugly workaround to force PUT this.model.personalInfo.id = "self"; this.model.bind("change", this.render, this); this.addAutoTabs(); this.successRedirectURL = options.successRedirectURL; this.loyaltyProfile || (this.loyaltyProfile = new portalGGA.models.player.LoyaltyProfile()); var self = this; /*self.loyaltyProfile.fetch().done(function (){ if(self.loyaltyProfile.get("status") != "ENABLED" ){ $(".optinbtn").parent().show(); } }); // here is ugly workaround to force PUT this.loyaltyProfile.id = "self";*/ jQuery.validator.setDefaults({ highlight: function(element, errorClass, validClass) { if (element.type === "radio" || element.type === "checkbox") { this.findByName(element.name).addClass(errorClass).removeClass(validClass); } else if ($(element).parent().hasClass('input-inline') || $(element).parent().hasClass('input-group')) { $(element).closest('.form-group').addClass('has-error'); } else { $(element).closest('.form-group').removeClass('has-success has-feedback').addClass('has-error has-feedback').find('span').remove(); $(element).closest('.form-row').find('span').remove(); $(element).parent().find('span.glyphicon').remove(); //$('').insertAfter(element); } }, unhighlight: function(element, errorClass, validClass) { if (element.type === "radio" || element.type === "checkbox") { this.findByName(element.name).removeClass(errorClass).addClass(validClass); } else if ($(element).parent().hasClass('input-inline') || $(element).parent().hasClass('input-group')) { $(element).closest('.form-group').removeClass('has-error'); } else { $(element).closest('.form-group').removeClass('has-error has-feedback').find('span').remove(); $(element).closest('.form-group').find('.error').remove(); /* $(element).closest('.form-group').removeClass('has-error has-feedback').addClass('has-success has-feedback').find('span').remove(); $(element).parent().find('span.glyphicon').remove(); $('').insertAfter(element); */ } }, errorPlacement: function(error, element) { if (element.parent('.input-group').length || element.prop('type') === 'checkbox' || element.prop('type') === 'radio') { error.insertAfter(element.parent()); } else if ($(element).parent().hasClass('input-inline') || $(element).parent().hasClass('input-group')) { $(element).closest('.form-group').find('>div').append(error); } else { error.insertAfter(element); } } }); jQuery.validator.addMethod('HomePhone', function(value, element, param) { var homephone=$('input[name="personalInfo[phones][HOME][number][1]"]').val()+$('input[name="personalInfo[phones][HOME][number][2]"]').val()+$('input[name="personalInfo[phones][HOME][number][3]"]').val(); return this.optional(element) || homephone.length>0&&homephone.length==10; }, CQ.I18n.getMessage("jquery.validate.plugin.homePhone")); jQuery.validator.addMethod('homenumbers', function(value, element, param) { var homephone=$('input[name="personalInfo[phones][HOME][number][1]"]').val()+$('input[name="personalInfo[phones][HOME][number][2]"]').val()+$('input[name="personalInfo[phones][HOME][number][3]"]').val(); return this.optional(element) || !isNaN(homephone); }, CQ.I18n.getMessage("jquery.validate.plugin.homenumbers")); jQuery.validator.addMethod('MobilePhone', function(value, element) { var mobile=$('input[name="personalInfo[phones][MOBILE][number][1]"]').val()+$('input[name="personalInfo[phones][MOBILE][number][2]"]').val()+$('input[name="personalInfo[phones][MOBILE][number][3]"]').val(); return this.optional(element) || mobile.length>0&&mobile.length==10 && !isNaN(mobile); }, CQ.I18n.getMessage("jquery.validate.plugin.homePhone")); jQuery.validator.addMethod('mobilenumbers', function(value, element) { var mobile=$('input[name="personalInfo[phones][MOBILE][number][1]"]').val()+$('input[name="personalInfo[phones][MOBILE][number][2]"]').val()+$('input[name="personalInfo[phones][MOBILE][number][3]"]').val(); return this.optional(element) || !isNaN(mobile); }, CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber")); jQuery.validator.addMethod("mobileRequired", function(value, element) { if(value != "") { return value.indexOf(" ") < 0 && value != ""; } else return true; }, CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber")); jQuery.validator.addMethod('DOB', function(value, element, param) { $(element).attr('data-dobvalidate', "true"); var validate_day = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\]').val(); var validate_month = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[1\\]').val(); var validate_year = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[2\\]').val(); if (validate_day && validate_month && validate_year) { var day = validate_day; var month = validate_month; var year = validate_year; var date = new Date(year, month - 1, day); return this.optional(element) || !/Invalid|NaN/.test(date); } else { return true; } }, 'Please enter a valid date of birth'); jQuery.validator.addMethod('DOB18', function(value, element, param) { $(element).attr('data-MOBILEValidate', "true"); var birthday = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\]').val(); var birthmonth = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[1\\]').val(); var birthyear = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[2\\]').val(); var today = new Date(); var nowyear = today.getFullYear(); var nowmonth = today.getMonth(); var nowday = today.getDate(); var age = nowyear - birthyear; var age_month = nowmonth - birthmonth; var age_day = nowday - birthday; var isValid = false; if (age_month < 0 || (age_month == 0 && age_day < 0)) { age = parseInt(age) - 1; } if ((age == 18 && age_month <= 0 && age_day <= 0) || age < 18) { isValid = false; $('label:contains('+CQ.I18n.getMessage("dateofBirth18.Validation")+')').remove(); //$('label:contains("Age should be at least 18 years")').remove(); } else { isValid = true; } return this.optional(element) || isValid; }, CQ.I18n.getMessage("dateofBirth18.Validation")); jQuery.validator.addMethod('DOBRequired', function(value, element, param) { var isValid = false; $(element).attr('data-dobvalidate', "true"); var birthday = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\]').val(); var birthmonth = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[1\\]').val(); var birthyear = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[2\\]').val(); if (birthday && birthmonth && birthyear ) { if (birthday == "") isValid = false; else if (birthmonth == "") isValid = false; else if (birthyear == "") isValid = false; else isValid = true; } else { isValid = true; } //CQ.I18n.getMessage("jquery.validate.plugin.DOB" return this.optional(element) || isValid; }, 'Please enter Date of Birth'); $('form').validate({ rules: { "nonpublicPersonalInfo[dateOfBirthFormated][0]": { required: true, DOB18: true, DOB: true, DOBRequired: true }, "nonpublicPersonalInfo[dateOfBirthFormated][1]": { required: true, DOB18: true, DOB: true, DOBRequired: true }, "nonpublicPersonalInfo[dateOfBirthFormated][2]": { required: true, DOB18: true, DOB: true, DOBRequired: true }, "personalInfo[addresses][MAILING][city]": { required: true, maxlength :50, minlength :3 }, "personalInfo[addresses][MAILING][address1]": { required: true, maxlength :50, minlength :5 }, "personalInfo[phones][HOME][number][1]" :{ required: true, homenumbers: true, minlength: 3, maxlength: 3, HomePhone: true }, "personalInfo[phones][HOME][number][2]" : { required: true, homenumbers: true, minlength: 3, maxlength: 3, HomePhone: true }, "personalInfo[phones][HOME][number][3]" : { required: true, homenumbers: true, minlength: 4, maxlength: 4, HomePhone: true }, "personalInfo[phones][MOBILE][number][1]" :{ mobilenumbers: true, mobileRequired: true, minlength: 3, maxlength: 3, MobilePhone: true }, "personalInfo[phones][MOBILE][number][2]" : { mobilenumbers: true, mobileRequired: true, minlength: 3, maxlength: 3, MobilePhone: true }, "personalInfo[phones][MOBILE][number][3]" : { mobilenumbers: true, mobileRequired: true, minlength: 4, maxlength: 4, MobilePhone: true } }, groups: { SSN: "registration[nonpublicPersonalInfo][socialSecurityNumber][0] "+ "registration[nonpublicPersonalInfo][socialSecurityNumber][1] "+ "registration[nonpublicPersonalInfo][socialSecurityNumber][2]", HomePhone: "personalInfo[phones][HOME][number][1] "+ "personalInfo[phones][HOME][number][2] "+ "personalInfo[phones][HOME][number][3]", MobilePhone: "personalInfo[phones][MOBILE][number][1] "+ "personalInfo[phones][MOBILE][number][2] "+ "personalInfo[phones][MOBILE][number][3]", DOB: "nonpublicPersonalInfo[dateOfBirthFormated][0]"+ "nonpublicPersonalInfo[dateOfBirthFormated][1]"+ "nonpublicPersonalInfo[dateOfBirthFormated][2]", DOBRequired: "nonpublicPersonalInfo[dateOfBirthFormated][0]"+ "nonpublicPersonalInfo[dateOfBirthFormated][1]"+ "nonpublicPersonalInfo[dateOfBirthFormated][2]", DOB18: "nonpublicPersonalInfo[dateOfBirthFormated][0]"+ "nonpublicPersonalInfo[dateOfBirthFormated][1]"+ "nonpublicPersonalInfo[dateOfBirthFormated][2]", homenumbers: "personalInfo[phones][HOME][number][1] "+ "personalInfo[phones][HOME][number][2] "+ "personalInfo[phones][HOME][number][3]", mobilenumbers : "personalInfo[phones][MOBILE][number][1] "+ "personalInfo[phones][MOBILE][number][2] "+ "personalInfo[phones][MOBILE][number][3]", mobileRequired : "personalInfo[phones][MOBILE][number][1] "+ "personalInfo[phones][MOBILE][number][2] "+ "personalInfo[phones][MOBILE][number][3]" }, messages: { DOB: CQ.I18n.getMessage("jquery.validate.plugin.DOB"), HomePhone: CQ.I18n.getMessage("jquery.validate.plugin.homePhone"), "nonpublicPersonalInfo[dateOfBirthFormated][0]": { required :CQ.I18n.getMessage("jquery.validate.plugin.dateofBirthRequired"), DOB: CQ.I18n.getMessage("jquery.validate.plugin.DOB"), DOB18: CQ.I18n.getMessage("dateofBirth18.Validation"), DOBRequired: CQ.I18n.getMessage("jquery.validate.plugin.dobRequired") }, "nonpublicPersonalInfo[dateOfBirthFormated][1]": { required :CQ.I18n.getMessage("jquery.validate.plugin.dateofBirthRequired"), DOB: CQ.I18n.getMessage("jquery.validate.plugin.DOB"), DOB18: CQ.I18n.getMessage("dateofBirth18.Validation"), DOBRequired: CQ.I18n.getMessage("jquery.validate.plugin.dobRequired") }, "nonpublicPersonalInfo[dateOfBirthFormated][2]": { required :CQ.I18n.getMessage("jquery.validate.plugin.dateofBirthRequired"), DOB: CQ.I18n.getMessage("jquery.validate.plugin.DOB"), DOB18: CQ.I18n.getMessage("dateofBirth18.Validation"), DOBRequired: CQ.I18n.getMessage("jquery.validate.plugin.dobRequired") }, "personalInfo[phones][HOME][number][1]": { required :CQ.I18n.getMessage("jquery.validate.plugin.phoneRequired"), homenumbers:CQ.I18n.getMessage("jquery.validate.plugin.homenumbers"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength") // HomePhone: "Please enter phone number" }, "personalInfo[phones][HOME][number][2]": { required :CQ.I18n.getMessage("jquery.validate.plugin.phoneRequired"), homenumbers:CQ.I18n.getMessage("jquery.validate.plugin.homenumbers"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength") //HomePhone: "Please enter phone number" }, "personalInfo[phones][HOME][number][3]": { required :CQ.I18n.getMessage("jquery.validate.plugin.phoneRequired"), homenumbers:CQ.I18n.getMessage("jquery.validate.plugin.homenumbers"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength") //HomePhone: "Please enter phone number" }, "personalInfo[phones][MOBILE][number][1]": { mobilenumbers: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength"), mobileRequired: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber") }, "personalInfo[phones][MOBILE][number][2]": { mobilenumbers: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength"), mobileRequired: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber") }, "personalInfo[phones][MOBILE][number][3]": { mobilenumbers: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber"), minlength: CQ.I18n.getMessage("jquery.validate.plugin.phoneMinlength"), maxlength:CQ.I18n.getMessage("jquery.validate.plugin.phoneMaxlength"), mobileRequired: CQ.I18n.getMessage("jquery.validate.plugin.mobileNumber") }, "personalInfo[addresses][MAILING][city]": { required : CQ.I18n.getMessage("jquery.validate.plugin.cityRequired"), maxlength :CQ.I18n.getMessage("jquery.validate.plugin.cityMaxlength"), minlength :CQ.I18n.getMessage("jquery.validate.plugin.cityMinlength") }, "personalInfo[addresses][MAILING][address1]": { required : CQ.I18n.getMessage("jquery.validate.plugin.streetAddressRequired"), maxlength :CQ.I18n.getMessage("jquery.validate.plugin.streetAddressmaxlength"), minlength :CQ.I18n.getMessage("jquery.validate.plugin.streetAddressminlength") } }, errorPlacement: function(error, element) { if (element.parent('.input-group').length || element.prop('type') === 'checkbox' || element.prop('type') === 'radio') { error.insertAfter(element.parent()); } else if ($(element).parent().hasClass('input-inline') || $(element).parent().hasClass('input-group')) { $(element).closest('.form-group').find('>div').append(error); } else if (element.attr("id") == "nonpublicPersonalInfo[dateOfBirthFormated][1]" || element.attr("id") == "nonpublicPersonalInfo[dateOfBirthFormated][0]" || element.attr("id") == "nonpublicPersonalInfo[dateOfBirthFormated][2]") { $('label:contains('+CQ.I18n.getMessage("dateofBirth18.Validation")+')').remove(); //$('label:contains("Age should be at least 18 years")').remove(); $(element).closest('.form-group').append(error); } else if (element.attr("id") == "personalInfo[phones][HOME][number][0]" || element.attr("id") == "personalInfo[phones][HOME][number][1]" || element.attr("id") == "personalInfo[phones][HOME][number][2]") { $(element).closest('.form-group').append(error); } else if (element.attr("id") == "personalInfo[phones][MOBILE][number][0]" || element.attr("id") == "personalInfo[phones][MOBILE][number][1]" || element.attr("id") == "personalInfo[phones][MOBILE][number][2]") { $(element).closest('.form-group').append(error); } else { error.insertAfter(element); } } }); var deleteMyVIPClubAccountModalTmpl = $("#deleteMyVIPClubAccountModalTmpl").html(); var deleteMyVIPClubAccountSuccessModalTmpl = $("#deleteMyVIPClubAccountSuccessModalTmpl").html(); $("body").append(deleteMyVIPClubAccountModalTmpl); $("body").append(deleteMyVIPClubAccountSuccessModalTmpl); $('[data-notification]').on('click', function(e) { e.preventDefault(); $('#deleteMyVIPClubAccountModal').modal({ backdrop: 'static' }); }); $(document).on('show.bs.modal','#deleteMyVIPClubAccountModal', function () { $('[data-deleteaccount="modal"]').on('click', function(e) { e.preventDefault(); $('#deleteMyVIPClubAccountModal').modal('hide'); self.deleteAccount(); }); $('.deleteAccSuccess').on('click',function(e){ session.logout(); }); }); if(location.href.indexOf("closeAccount")!=-1){ $('[data-notification]').trigger("click"); } }, deleteAccount: function(){ var self =this; var formData= { "removeData":false } $.ajax('/api/v1/players/self/njs/close', { type: 'POST', dataType:"json", data: JSON.stringify(formData), contentType: 'application/json', success: function(data, textStatus, jqXHR) { $('#deleteMyVIPClubAccountSuccessModal').modal({ backdrop: 'static' }); }, error: function (data, textStatus, errorThrown) { $('#messageBar').html(""); $('#messageBar').addClass('show'); $('#messageBar').removeClass('hide'); if(errorThrown=="Unauthorized") portalGGA.utils.globalErrorNotifier.show( "Please login","alert-danger"); else portalGGA.utils.globalErrorNotifier.show( "Internal server error,please try again later","alert-danger"); $('#messageBar').focus(); } }); }, /** * [addAutoTabs description] * @TODO return something (twytrebowicz) */ addAutoTabs : function() { if (!this.isMobile.any()){ portalGGA.utils.forms.automaticTab( this.$('input.autoTab-phonesHome') ); portalGGA.utils.forms.automaticTab( this.$('input.autoTab-phonesMobile') ); portalGGA.utils.forms.automaticTab( this.$('input.autoTab-homePostalCode') ); portalGGA.utils.forms.automaticTab( this.$('input.autoTab-billingPostalCode') ); } }, /** * [render description] * @TODO return something (twytrebowicz) */ render: function() { var temp = this.model.toJSON(), dateOB = portalGGA.utils.formattedLongDate(temp.nonpublicPersonalInfo.dateOfBirth,true); dateOB = new Date(temp.nonpublicPersonalInfo.dateOfBirth); // dateOB = Date.UTC(dateOB.getUTCFullYear(), dateOB.getUTCMonth(), dateOB.getUTCDate(),dateOB.getUTCHours(), dateOB.getUTCMinutes(), dateOB.getUTCSeconds()); temp.nonpublicPersonalInfo.dateOfBirthFormated = [ dateOB.getDate(), dateOB.getMonth(), dateOB.getFullYear() ]; temp.accountinfo = temp.accountinfo || {} temp.accountinfo.email2 = temp.personalInfo.emails.PERSONAL.address; this.getDays(); this.getDob(); //phones portalGGA.models.player.PersonalInfo.parsePhones(temp.personalInfo.phones); //zip codes portalGGA.models.player.PersonalInfo.zipSplit(temp.personalInfo.addresses); portalGGA.utils.forms.deserializeJSON( this.$('input, select'), temp ); var securityQCount = 1; //temp.personalInfo.passwordHints.length; var securityQuestionsRequiredNo = 1; var html = ""; for(var i=0 ; i'+ ''+ ''+ ''+ ' info '+ '
'+ '
'+ ''+ ''+ '
'+ '
'; } $("#ProfileSecurityQuestionsGroup").append(html); var container = $("#ProfileSecurityQuestionsGroup").children('div').length; if(container == 3){ $('#ProfileaddAnotherQuestion').closest('.form-group').removeClass('in').addClass('out'); } /***** Security Question Functionality **/// $('#ProfileaddAnotherQuestion').on('click', function() { var lastInstance = $(this).parent().parent().prev(); //lastInstance.clone().insertAfter(lastInstance); var container = $("#ProfileSecurityQuestionsGroup").children('div').length, maxCount = 2; //console.log(container); if (container <= maxCount) { var cloneinstance = lastInstance.clone(); setTimeout(function() { cloneinstance.addClass('in'); }, 1000); cloneinstance.find('input').attr({'name': cloneinstance.find('input').attr('name').replace(/\d/, (container)),'id': cloneinstance.find('input').attr('id').replace(/\d/, (container))}).val(""); //cloneinstance.find('input').val(""); cloneinstance.find('.form-group').removeClass("has-success has-feedback"); cloneinstance.find('.form-control-feedback').detach(); cloneinstance.find('select').attr({'name': cloneinstance.find('select').attr('name').replace(/\d/, (container)),'id': cloneinstance.find('select').attr('id').replace(/\d/, (container))}).val(""); cloneinstance.find('button').removeClass('hide'); //console.log(cloneinstance); cloneinstance.find('label').map(function() { $(this).text($(this).text().replace(/\d/, container + 1)); }); cloneinstance.find('.required').removeClass('required'); cloneinstance.find('select').attr('securityquestionrequired','true'); cloneinstance.find('input').attr('securityAnswerRequired','true'); // cloneinstance.find('select').attr("id", cloneinstance.find('input').attr('id').replace(/\d/, (container))); // cloneinstance.find('input').attr("id", cloneinstance.find('select').attr('id').replace(/\d/, (container))); // cloneinstance.find('#personalInfo[passwordHints]['+ container+1 +'][securityAnswer][answer]').attr("securityAnswerRequired","true"); if (container == maxCount) { $(this).closest('.form-group').removeClass('in').addClass('out'); cloneinstance.find('label.error').remove(); } cloneinstance.insertAfter(lastInstance); } $('[data-action="delete"]').on('click', function() { el = $(this); //alert(); el.closest('.question').removeClass('in').addClass('out'); // setTimeout(function() { el.closest('.question').remove(); // }, 100); var container = $("#ProfileSecurityQuestionsGroup").children('div').length; var lastChild=$("#ProfileSecurityQuestionsGroup").children().last().prev(); lastChild.find('label').map(function(){ var labelThis=$(this); labelThis.text(labelThis.text().replace(/\d/, container )); // console.log(labelThis.attr('for')) if(labelThis.attr('id')!=undefined && labelThis.attr('name')!=undefined) labelThis.attr({'id':labelThis.attr('id').replace(/\d/, (container-1)),'name':labelThis.attr('name').replace(/\d/, (container-1))}) else if(labelThis.attr('id')!=undefined && labelThis.attr('for')!=undefined) labelThis.attr({'id':labelThis.attr('id').replace(/\d/, (container-1)),'for':labelThis.attr('for').replace(/\d/, (container-1))}) }); lastChild.find('input').attr({'id':lastChild.find('input').attr('id').replace(/\d/, (container-1)),'name':lastChild.find('input').attr('name').replace(/\d/, (container-1))}); lastChild.find('select').attr({'id':lastChild.find('select').attr('id').replace(/\d/, (container-1)),'name':lastChild.find('select').attr('name').replace(/\d/, (container-1))}); //if (count <= maxCount) { $('#ProfileaddAnotherQuestion').closest('.form-group').removeClass('out').addClass('in'); // } }); }); /***** Ending Of Security Question Functionality **/// $('.playerInformation-secQuestion').change(function(){ if(this.id == 'personalInfo[passwordHints][0][securityQuestion][question]' && temp.personalInfo.passwordHints[0].securityQuestion.question != $(this).val()){ $(this).parent().parent().siblings().find('input').attr('securityAnswerRequired','true'); } else if(this.id == 'personalInfo[passwordHints][1][securityQuestion][question]' && temp.personalInfo.passwordHints[1].securityQuestion.question && temp.personalInfo.passwordHints[1].securityQuestion.question != $(this).val()){ $(this).parent().parent().siblings().find('input').attr('securityAnswerRequired','true'); } else if(this.id == 'personalInfo[passwordHints][2][securityQuestion][question]' && temp.personalInfo.passwordHints[2].securityQuestion.question && temp.personalInfo.passwordHints[2].securityQuestion.question != $(this).val()){ $(this).parent().parent().siblings().find('input').attr('securityAnswerRequired','true'); }else { $(this).parent().parent().siblings().find('input').removeAttr('securityAnswerRequired'); } }); $('.personalInfoForm input').addClass("is-filled"); }, /** * Serialize form and extend model json with it. * @author Tomek.Wytrebowicz@gtech.com * @return {Object} serialized form data in JSON with filtered password hints */ serialize: function serialize(){ // this is a not so nice hack, not to overwrite defaults/previous values while set nested object (twytrebowicz) var data = this.model.toJSON(); data.accountinfo = {}; return filterPasswordHints( jQuery.extend(true, data, portalGGA.utils.forms.serializeJSON.apply(this.$el)) ); /** * Filter Passwor Hints - remove sequrity questions with empty answers * @param {Object} data form data * @return {Object} filtered form data */ function filterPasswordHints(data) { if (data.personalInfo && data.personalInfo.passwordHints) { data.personalInfo.passwordHints = $.map( data.personalInfo.passwordHints, function(passwordHint) { if(passwordHint.securityAnswer && !passwordHint.securityAnswer.answer){ passwordHint.securityAnswer.answer = null; } return passwordHint.securityQuestion && passwordHint.securityQuestion.question && passwordHint || null; }); } return data; } }, /** * [toggleBillingSameAsMailing description] * @param {Event} e [description] * @param {Boolean} noAnimation [description] * @return {portalGGA.views.PlayerInformation} self */ toggleBillingSameAsMailing: function(e, noAnimation){ var container = this.$('.billingAddress'), checked = !!this.$('.billingSameAsMailing').is(':checked'); if( noAnimation ){ container.toggle( !checked ); }else{ if( checked ){ container.fadeOut(); }else{ container.fadeIn(); } } return this; }, /** * Save player information. * @author Magda.Orlowska@gtech.com * @author Tomek.Wytrebowicz@gtech.com * @param {Event} [e] * @return {jQuery.Promise} */ save: function save(e){ e && e.preventDefault(); if ($('.personalInfoForm').valid()){ var self = this; portalGGA.utils.globalErrorNotifier.clear(); $("#updateProfileButton").attr('disabled','disabled'); var data = this.serialize(); concatSplittedInputs(data); /*if (data.accountinfo.billingSameAsMailing) { // revrite only data that should be changed data.personalInfo.addresses.BILLING.address1 = data.personalInfo.addresses.MAILING.address1; data.personalInfo.addresses.BILLING.address2 = data.personalInfo.addresses.MAILING.address2; data.personalInfo.addresses.BILLING.address3 = data.personalInfo.addresses.MAILING.address3; data.personalInfo.addresses.BILLING.city = data.personalInfo.addresses.MAILING.city; data.personalInfo.addresses.BILLING.country = data.personalInfo.addresses.MAILING.country; data.personalInfo.addresses.BILLING.state = data.personalInfo.addresses.MAILING.state; data.personalInfo.addresses.BILLING.postalCode = data.personalInfo.addresses.MAILING.postalCode; }*/ //join, filter, numbers var month = data.nonpublicPersonalInfo.dateOfBirthFormated[1]; var date = data.nonpublicPersonalInfo.dateOfBirthFormated[0]; var year = data.nonpublicPersonalInfo.dateOfBirthFormated[2]; var birthDate = new Date(year, month, date); var monthArr=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var dateString = date+" "+monthArr[month]+" "+year+" "+"12:00:00 GMT"; var now_utc = Date.UTC(birthDate.getUTCFullYear(), birthDate.getUTCMonth(), birthDate.getUTCDate(),birthDate.getUTCHours(), birthDate.getUTCMinutes(), birthDate.getUTCSeconds()); data.personalInfo.dateOfBirth =Date.parse(dateString); portalGGA.models.player.PersonalInfo.reparsePhones(data.personalInfo.phones); //zip codes portalGGA.models.player.PersonalInfo.zipJoin(data.personalInfo.addresses); return this.model.personalInfo.set( data.personalInfo, {silent: true} ) .save(data.personalInfo, {silent:true,patch:true, type:"PUT"}) .done(function success(response){ console.info("Success", this, arguments); $("#updateProfileButton").removeAttr('disabled'); var html = handleSuccessResponseTemplate (); $("#successModal").html(html); $("#successModal").find(".modal").modal(); return response; }) .fail(function success(response){ console.warn("Error", this, arguments); $("#updateProfileButton").removeAttr('disabled'); var errorCode = ""; var reason = $.parseJSON(response.responseText); if(reason && reason.fieldErrors && reason.fieldErrors[0] && reason.fieldErrors[0].code){ errorCode = reason.fieldErrors[0].code; } else if(reason && reason.code){ errorCode = reason.code; } else { errorCode = reason; } var html = handleErrorResponseTemplate ({errorCode : errorCode}); $("#errorModal").html(html); $("#errorModal").find(".modal").modal(); return response; }); } }, optIn: function optIn(event) { var self = this; event && event.preventDefault(); var button = $("#joinNow") button.button('loading'); this.loyaltyProfile.save() .done(function success(response){ button.button('reset'); console.info("Succeess", this, arguments); redirect.send(self.successRedirectURL,{ message:{ code:'optin.success', type:'alert-success' }}); return response; }) .fail(function failure(reason){ button.button('reset'); console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); portalGGA.utils.globalErrorNotifier.show(reason); return reason; }); return false; }, daysInMonth: function daysInMonth(month, year) { var noOfDays; if (month == 0 || month == 2 || month == 4 || month == 6 || month == 7 || month == 9 || month == 11) { noOfDays = 31; } else if (month == 3 || month == 5 || month == 8 || month == 10) { noOfDays = 30; } else { noOfDays = (year % 4 == 0) ? 29 : 28; } /*var isLeap = ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)); return [31, (isLeap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];*/ return noOfDays; }, getDays : function getDays() { var selectmonth = document.getElementById("nonpublicPersonalInfo[dateOfBirthFormated][1]").value; var selectday = document.getElementById("nonpublicPersonalInfo[dateOfBirthFormated][0]").value; var selectyear = document.getElementById("nonpublicPersonalInfo[dateOfBirthFormated][2]").value; var noOfDays = this.daysInMonth(selectmonth, selectyear); var birthDay = $("#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\] option:selected").text(); var selOptions = $('#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\]').text(""); for(var numberCount = 1; numberCount <= noOfDays; numberCount++) { if(birthDay == numberCount) { (selOptions).append(""); } else(selOptions).append(""); } if(birthDay != null && birthDay != "") { $("#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\] option[text=" + birthDay + "]").attr("selected", "selected"); } else { $("#nonpublicPersonalInfo\\[dateOfBirthFormated\\]\\[0\\] option[text=DD]").attr("selected", "selected"); } }, getDob : function getDob() { document.getElementById("birthday").value = 'dob'; }, }); /** * Cancatenate phones, ssn numbers, dob, emails, zip codes; * @param {Object} registrationForm data * @requires portalGGA.models.player.PersonalInfo * @see splitInputs * @private * @memberOf portalGGA.views.Registration */ function concatSplittedInputs (data){ /*var month = data.nonpublicPersonalInfo.dateOfBirthFormated[0]; var date = data.nonpublicPersonalInfo.dateOfBirthFormated[1]; var year = data.nonpublicPersonalInfo.dateOfBirthFormated[2]; var birthDate = new Date(year, month, date); data.personalInfo.dateOfBirth =birthDate.getTime();*/ var month = data.nonpublicPersonalInfo.dateOfBirthFormated[1]; var date = data.nonpublicPersonalInfo.dateOfBirthFormated[0]; var year = data.nonpublicPersonalInfo.dateOfBirthFormated[2]; var birthDate = Date.UTC(year, month, date); data.personalInfo.dateOfBirth = null; } }(jQuery,portalGGA.utils.redirect,portalGGA.utils.session));