stock.js 2.97 KB
$(function() {


    $(document)
        .on("click","#add-data",function () {
        var count = $(this).data('count');
        $("<div><label>Дата</label><input type='date' name='Shop[modeStr][data]["+count+"][data]'><label>c</label><input type='time' size='10' name='Shop[modeStr][data]["+count+"][from]'><label>до</label><input type='time' name='Shop[modeStr][data]["+count+"][to]'><label>выходной</label><input type='checkbox' name='Shop[modeStr][data]["+count+"][off]'><a class='delete-day-item'>Удалить</a></div>").insertBefore($(this))
        count+=1;
        $(this).data('count', count);
    });
    $(document)
        .on(
            'click', '.delete-day-item', function() {
                var count = $("#add-data").data('count');
                $(this)
                    .parent()
                    .remove();
                count-=1;
                $("#add-data").data('count', count);
            }
        );
    $(document).on( '#shoplang-2-address','blur',  function () {
        var address = $("#shoplang-2-address").val() + " "+$("#select2-w2-container").text();
        console.log(address);
        geocoder.geocode( { 'address': address}, function(results, status) {
            console.log(status);
            if (status == google.maps.GeocoderStatus.OK) {
                //console.log(results[0].geometry.location.lat()+" "+results[0].geometry.location.lng());
                $("#lat").val(results[0].geometry.location.lat());
                $("#lng").val(results[0].geometry.location.lng());
                var marker = AddMarker();
                marker.setMap(map);
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    });

    var start_position = new google.maps.LatLng('50.435', '30.60');
    var styles = [
        {
            stylers: [
                {saturation: -100}
            ]
        }
    ];
    var settings = {
        styles: styles,
        zoom: 12,
        scrollwheel: false,
        center: start_position,
        mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: false,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
        scaleControl: true,
        streetViewControl: true,
        rotateControl: true,
        zoomControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
    if ($("#lat").val() !== "" && $("#lng").val() !== ""){
        var marker = AddMarker();
        marker.setMap(map);
    }
    var geocoder = new google.maps.Geocoder();
    function AddMarker(){
        var newLat = $("#lat").val();
        var newLng = $("#lng").val();
        var coords = new google.maps.LatLng(newLat, newLng);
        var marker = new google.maps.Marker({
            position: coords
        });
        return marker;
    }
});