You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.7 KiB
147 lines
3.7 KiB
var EXPO = EXPO || {}; //isolated namespace
|
|
EXPO.registration = EXPO.registration || {};
|
|
if (EXPO.registration.completion) {
|
|
console.warn('WARNING: EXPO.registration..completion is already defined!');
|
|
} else {
|
|
EXPO.registration.completion = (function () {
|
|
/**
|
|
* private (visible inside this module only) variables
|
|
*/
|
|
/**
|
|
* @type {Object} - module API interafce realization
|
|
*/
|
|
var that = {},
|
|
/**
|
|
* fires when data is sended and response recieved
|
|
* @param {Object} data - data recieved from server
|
|
*/
|
|
registrationSuccess = function (data) {
|
|
var $item,
|
|
$popup = $('#end-reg'),
|
|
lineClass = 'pwf-line',
|
|
activeClass = EXPO.common.opt.activeClass,
|
|
phoneClass = 'phone',
|
|
labelClass = 'label',
|
|
errClass = EXPO.common.opt.errMessageClass;
|
|
$('.'+errClass,$popup).removeClass(activeClass);
|
|
if (data.success) {
|
|
location = data.redirect;
|
|
}
|
|
else {
|
|
console.log(data);
|
|
for (var property in data.errors) {
|
|
if (data.errors.hasOwnProperty(property)) {
|
|
$itemWrap = $('#id_'+property).closest('.'+lineClass);
|
|
$('.'+errClass,$itemWrap).addClass(activeClass).text(data.errors[property][0]);
|
|
if($itemWrap.hasClass(phoneClass)){
|
|
$('.'+labelClass,$itemWrap).hide();
|
|
};
|
|
}
|
|
}
|
|
// err-message-box
|
|
}
|
|
},
|
|
placeInput = function (width) {
|
|
$('#id_country').val('159').select2({
|
|
placeholder: "Ваша страна",
|
|
width: width
|
|
});
|
|
|
|
$('#id_city').select2({
|
|
placeholder: "Ваш город",
|
|
width: width,
|
|
ajax: {
|
|
|
|
url: "/city/get-city/",
|
|
dataType: "json",
|
|
quietMillis: 200,
|
|
|
|
data: function(term, page, country){
|
|
var country = $('#id_country').val()
|
|
return {term: term,
|
|
page: page,
|
|
country: country};
|
|
},
|
|
|
|
results: function (data) {
|
|
var results = [];
|
|
$.each(data, function(index, item){
|
|
results.push({
|
|
id: item.id,
|
|
text: item.label
|
|
});
|
|
});
|
|
return {results: results};
|
|
}
|
|
},
|
|
initSelection : function(element, callback) {
|
|
var id= $(element).val();
|
|
var text = $(element).attr('data-init-text');
|
|
callback({id: id, text:text});
|
|
|
|
}
|
|
|
|
});
|
|
};
|
|
/**
|
|
* @type {Object} default setting
|
|
*/
|
|
that.opt = {};
|
|
/**
|
|
* dependencies.Place where you can switch on dependencies for module
|
|
* @type {EXPO.common|*} - mostly used in project functions and data (block.common.js)
|
|
*/
|
|
var com = EXPO.common;
|
|
|
|
$(function () {
|
|
$('body').addClass('body-fixed');
|
|
placeInput('100%');
|
|
$('#id_code_country').select2({
|
|
width: '95px'
|
|
});
|
|
|
|
|
|
$.fancybox.open([
|
|
{
|
|
href: '#end-reg'
|
|
}
|
|
], {
|
|
closeBtn: false, // hide close button
|
|
closeClick: false, // prevents closing when clicking INSIDE fancybox
|
|
modal: true,
|
|
scrolling: 'no',
|
|
helpers: {
|
|
// prevents closing when clicking OUTSIDE fancybox
|
|
overlay: {closeClick: false},
|
|
locked : true
|
|
},
|
|
keys: {
|
|
// prevents closing when press ESC button
|
|
close: null
|
|
}
|
|
|
|
});
|
|
|
|
|
|
$('#end-reg-form').on('submit', function (e) {
|
|
e.preventDefault();
|
|
var url = $(this).attr('action');
|
|
var formData = $(this).serialize();
|
|
$.post(url, formData, registrationSuccess)
|
|
});
|
|
|
|
});
|
|
|
|
/**
|
|
* current module general initialization
|
|
* @param {Object} options - options recieved from web page view
|
|
*/
|
|
that.init = function (options) {
|
|
// settings extending
|
|
$.extend(this.opt, options);
|
|
// begin of initialization
|
|
|
|
};
|
|
return that;
|
|
}());
|
|
}
|
|
|