Code:
/**
* Created by tamaram on 6/9/16.
*/
define (function (require){
'use strict';
require('bootstrap-datepicker');
require('realperson');
var Backbone = require('backbone'),
templateFile = require('text!templates-v2/registration-template.html'),
ResendActivationModel = require('models-v2/ResendActivationLinkModel'),
ResendActivationView = require('views-v2/ResendActivationLinkView'),
TermsAndConditionsView = require('views-v2/TermsAndConditionsView'),
InfoMessageView = require('views-v2/InfoMessageView'),
_ = require('underscore'),
helper = require('helper'),
view = Backbone.View.extend({
id: 'modalContainer',
className: 'modal fade',
events: {
'submit #registrationForm': 'registerPlayer',
'shown.bs.modal': 'afterRender',
'hidden.bs.modal': 'removeModal',
'click #resendActivationLink': 'showResendActivationLinkModal',
'click #termsAndConditions': 'showTermsAndConditions'
},
initialize: function () {
this.load();
},
render: function () {
var self = this,
template = _.template(templateFile, {
countries: this.countries,
helper:helper
});
this.$el.html(template);
return this;
},
load: function () {
this.listenTo(this.model, 'invalid', this.showErrors);
this.listenTo(this.model, 'change', this.hideErrors);
this.countries = helper.getCountries();
this.render();
},
afterRender: function () {
var fields = helper.getFormSettings('registration');
this.requiredFields = fields.REQUIRED;
this.markRequiredFields();
$('#captcha').realperson();
$('#dateOfBirthStr').datepicker({
autoclose: true
});
},
show: function () {
this.$el.modal({
backdrop: 'static'
});
},
removeModal: function () {
this.$el.data('bs.modal', null);
this.$el.remove();
},
registerPlayer: function (e) {
e.preventDefault();
var self = this,
firstName = $("#firstName").val(),
lastName = $("#lastName").val(),
alias = $("#alias").val(),
bankAccount = $("#bankAccount").val(),
dateOfBirthStr = $("#dateOfBirthStr").val(),
country = $("#country").val(),
city = $("#city").val(),
zip = $("#zip").val(),
address = $("#address").val(),
phoneNumber = $("#phoneNumber").val(),
municipalCode = $("#municipalCode").val(),
uid = $("#uid").val(),
email = $("#email").val(),
password = $("#password").val(),
repeatedPassword = $("#repeatedPassword").val(),
voucherNumber = $("#voucherNumber").val(),
over18 = $("#over18").is(":checked"),
captcha = $("#captcha").val();
self.startAnimation();
this.model.save({
'firstName': firstName,
'lastName': lastName,
'alias': alias,
'bankAccount': bankAccount,
'dateOfBirthStr': dateOfBirthStr,
'country': country,
'city': city,
'zip': zip,
'address': address,
'phoneNumber': phoneNumber,
'municipalCode': municipalCode,
'uid': uid,
'email': email,
'password': password,
'repeatedPassword': repeatedPassword,
'voucherNumber': voucherNumber,
'over18': over18,
'captcha': captcha,
'requiredFields': this.requiredFields
}, {
success: function (response) {
var successMessage = polyglot.t('successfullRegistration1') + self.model.get('email') + polyglot.t('successfullRegistration2');
if (helper.isErr(response.attributes)) {
self.stopAnimation();
$(".field-error").remove();
for (var key in response.attributes.data.errorMap){
$("#field-" + key).append('<span class="field-error">' + response.attributes.data.errorMap[key] + '</span>');
}
} else {
self.stopAnimation();
self.showInfoMessageModal(polyglot.t('successTitle'), successMessage);
}
},
error: function (response) {
self.stopAnimation();
var message = helper.getSafe(response.attributes, 'message');
self.showInfoMessageModal(polyglot.t('errorTitle'), message);
}
});
},
showErrors: function (model, errors, options) {
var self = this;
self.stopAnimation();
_.each(errors, function (error){
var controlField;
if(error.name == 'title' || error.name == 'over18'){
controlField = $('#field-' + error.name);
}else{
controlField = $('#' + error.name);
}
controlField.css('border', '1px solid #ff9292');
if(typeof error.message != 'undefined'){
$("#field-" + error.name).append('<span class="field-error">' + error.message + '</span>')
}
}, this);
},
hideErrors: function (errors) {
for(var name in errors.changed) {
if(name == 'title' || name == 'over18'){
this.$('#field-' + name).css('border', 'none');
}else{
this.$('#' + name).css('border', '1px solid #ccc');
}
$(".field-error").remove();
}
},
markRequiredFields: function () {
_.each(this.requiredFields, function(field){
$('#field-' + field).append('<span class="fa fa-asterisk form-control-feedback required-field-asterisk"></span>');
});
},
showResendActivationLinkModal: function () {
this.removeModal();
var resendActivationView = new ResendActivationView({model: new ResendActivationModel()});
resendActivationView.show();
},
showTermsAndConditions: function () {
$("#registrationModalContent").hide();
var termsAndConditionsView = new TermsAndConditionsView();
termsAndConditionsView.show($("#registrationModalDialog"), true);
},
showInfoMessageModal: function (title, message) {
this.$el.modal('hide');
this.$el.on('hidden.bs.modal', function (){
var infoMessageView = new InfoMessageView();
infoMessageView.show(title, message);
});
},
startAnimation: function () {
var saveBtn = $('#registerPlayer');
saveBtn.attr('disabled', 'disabled');
saveBtn.prepend('<span class="fa fa-spinner fa-spin" style="padding: 0px 10px; margin-left: -34px;"></span>');
},
stopAnimation: function () {
var saveBtn = $('#registerPlayer');
saveBtn.removeAttr('disabled');
saveBtn.find('span').remove();
}
});
return view;
});
There is that function: