'+
'
';
}
$("#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));