var buttons = [{
label: 'Закрыть',
cssClass: 'btn-default',
action: function (dialogRef) {
dialogRef.close();
}
}];
// Floating label headings for the contact form
$(function () {
$('form#frmSMS').validator({
custom: {
selected: function ($el) {
// var matchValue = $el.data("selected")
if ($el.val() == 0) {
return true;
}
}
},
}).on('submit', function (e) {
if (!e.isDefaultPrevented()) {
e.preventDefault();
try {
yaCounter11248987.reachGoal('promo_sms_gift');
} catch (e) {
}
// Get the form instance
var $form = $(e.target);
var b = $("input[type=submit][clicked=true]", $form);
b.button('loading');
// Use Ajax to submit form data
$.post($form.attr('action'), $form.serialize(), 'json')
.done(function (result) {
var $msg = $("
");
$.each(result.messages, function (id, message) {
$msg.append('' + message + '');
});
if (result.error === true || result.error === 'true') {
var dialogInstance = BootstrapDialog.show({
type: BootstrapDialog.TYPE_WARNING,
title: 'Упс...',
message: $msg,
buttons: buttons
});
} else {
var dialogInstance = BootstrapDialog.show({
type: BootstrapDialog.TYPE_SUCCESS,
title: 'Получилось!',
message: $msg,
buttons: buttons
});
$form.trigger("reset");
$("select#city option[value=0]").attr("selected", "selected");
}
})
.fail(function (result) {
// console.log(result);
var dialogInstance = BootstrapDialog.show({
type: BootstrapDialog.TYPE_DANGER,
title: 'Упс...',
message: 'На сервере произошла ошибка, перезагрузите страницу и попробуйте еще раз!',
buttons: buttons
});
})
.always(function () {
b.button('reset');
});
}
});
ymaps.ready(init);
function init() {
var cities = ymaps.geoQuery({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {name: 'Екатеринбург', city_id: 12 },
geometry: {type: 'Point', coordinates: [56.850373,60.614488]}
},
{
type: 'Feature',
properties: {name: 'Саратов', city_id: 133 },
geometry: {type: 'Point', coordinates: [51.536544676720276,46.01062864715192]}
},
]
});
ymaps.geolocation.get().then(function (res) {
var obj = cities.getClosestTo(res.geoObjects.get(0));
console.log(obj.properties.get('city_id'));
$("#city").val(obj.properties.get('city_id')).change();
}, function (e) {
console.log('Не удалось установить местоположение');
});
}
});