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 }) /** * change phone code when country is selected by user */ .on("change", function () { var phoneCode = $('option:selected', this).attr("data-phone-code"); if($.trim(phoneCode) !=''){ $('#id_code_country').select2("val",phoneCode); }else{ $('#id_code_country').select2("val",''); } }); $('#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 () { var $form = $('#end-reg-form'); $('body').addClass('body-fixed'); placeInput('100%'); $('#id_code_country').val('7').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 } }); $form.on('submit', function (e) { e.preventDefault(); var url = $(this).attr('action'); var formData = $(this).serialize(); $.post(url, formData, registrationSuccess) }); $(".url-field:not(.err) input",$form).focusin(function () { $(this).parent().siblings(".hint-box").fadeIn(); }); $(".url-field:not(err) input",$form).focusout(function () { $(this).parent().siblings(".hint-box").fadeOut(); }); }); /** * 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; }()); }