%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/ugotscom/public_html/kma/js/
Upload File :
Create Path :
Current File : /home/ugotscom/public_html/kma/js/location.js

        Encoder.EncodeType = "entity";
        var map, marker, lat, lng, infowindow;

        $(function() {

            $('.input-images').imageUploader();

        });

        $('body').click(function(evt) {
            if ((evt.target.id == "location"))
                return;
            $('.loc-dropdown').empty();
        });

        $("select#status"). change(function(){
            var selectedStatus = $(this). children("option:selected"). val();
                if(selectedStatus == "Rental Wanted" || selectedStatus == "To Buy"){
                   $('.input-images').html('');
                   $('.input-images').imageUploader();  
                   $(".input-images").slideUp("fast");
                }else{
                    $('.input-images').html('');
                    $('.input-images').imageUploader();                 
                    $(".input-images").slideDown("fast");
                }
            });
            
        function setLatLng(selectedLocation) {

            $('.loc-dropdown').empty();
            $('#location').val(selectedLocation);
            $('#placeModal').modal('show');

            L.esri.Geocoding.geocode().text(selectedLocation).run(
                    function(err, results, response) {
                        if (err) {
                            console.log(err);
                            return;
                        }
                        lat = results.results[0].latlng.lat;
                        lng = results.results[0].latlng.lng
                        console.log(lat);
                        console.log(lng);

                        $('#lat').val(lat);
                        $('#lng').val(lng);

                        infowindow = new google.maps.InfoWindow({
                            content : selectedLocation
                        });

                        var options = {
                            types : [ '(cities)' ],
                            componentRestrictions : {
                                country : 'in'
                            }
                        };

                        // The location of ernakulam
                        var ernakulam = {
                            lat : 9.9812208,
                            lng : 76.2989596
                        };

                        // The map, centered at ernakulam
                        map = new google.maps.Map(document
                                .getElementById('map'), {
                            zoom : 13,
                            center : ernakulam,
                            mapTypeControl : false,
                            panControl : false,
                            zoomControl : false,
                            streetViewControl : false
                        });

                        marker = new google.maps.Marker({
                            draggable : true,
                            position : {
                                lat : lat,
                                lng : lng
                            },
                            map : map,
                            animation : google.maps.Animation.DROP

                        });
                        map.panTo(marker.getPosition());

                        map.addListener('click', function(e) {
                            console.log('map click');
                            placeMarkerAndPanTo(e.latLng, map);
                            //getAddress(e.latLng);  user defined func for geocoder
                        });

                        marker.addListener('dragend', function(e) {
                            console.log('dragend');
                            placeMarkerAndPanTo(e.latLng, map);
                            //getAddress(e.latLng);  user defined func for geocoder
                        });

                        infowindow.open(map, marker);

                    });

        }

        $('#location').on(
                'input',
                function() {
                    
                    if ($(this).val() === "") {
                        $('#lat').val("");
                        $('#lng').val("");
                    }
                    var term = $(this).val();
                    console.log(term);
                    //.nearby([10.0088142, 76.3156612], 3000)
                    L.esri.Geocoding.suggest().text(term).run(
                            function(error, response) {

                                if (error) {
                                    return;
                                }

                                console.log(response);
                                $(".loc-dropdown").html("");
                                $.each(response.suggestions, function(i, item) {

                                    $(".loc-dropdown").append(
                                            " <li class='list-group-item' onclick=\"setLatLng('"
                                                    + item.text + "')\">"
                                                    + item.text + "</li>");
                                });

                            });

                });

        function placeMarkerAndPanTo(latLng, map) {

            //infowindow.setContent(latLng + '');
            //infowindow.open(map, marker);
            marker.setPosition(latLng);
            map.panTo(latLng);
            console.log('marker : ' + latLng);
            lat = latLng.lat();
            lng = latLng.lng();
        }

        $("#placeModal").on(
                'hide.bs.modal',
                function() {
                    console.log("setting values for hidden inputs " + lat
                            + " : " + lng);
                    $("#lat").val(lat);
                    $('#lng').val(lng);

                });

        function showPopover(popoverContent, popoverElement) {
            $(popoverElement).popover('enable');
            $(popoverElement).attr("data-content", popoverContent);
            $(popoverElement).popover('show');

            $('html, body').animate({
                scrollTop : $(popoverElement).offset().top - 100
            }, 500);

            setTimeout(function() {

                $(popoverElement).popover('hide');
                $(popoverElement).popover('disable');

            }, 3000);

        }

        $('#post-property-form')
                .submit(
                        function(e) {
                            if ($('#location').val() == null
                                    || $('#location').val() == '') {

                                showPopover('Enter property place', '#location');

                            } else if ($('#lng').val() == null
                                    || $('#lng').val() == ''
                                    || $('#lat').val() == null
                                    || $('#lat').val() == '') {

                                showPopover('Select proper location',
                                        '#location');

                            } else if ($('#type').children('option:selected')
                                    .val() === 'All') {
                                showPopover('Select any property type', '#type');
                            } else {
                                if($("select#status").children("option:selected").val() == "Rent" || $("select#status").children("option:selected").val() == "Sale"){
                                    console.log("rent or sale");
                                    if (!($('.input-images').children('.image-uploader').hasClass('has-files'))) {
                                            console.log("no-image");
                                            showPopover('Please select atleast one image.',
                                                    '.input-images');
                                            return false;   
                                    }
                                }
                                $('#post-property-form').fadeOut('fast');
                                $('.spinner-border').fadeIn('fast');

                                var form = $('#post-property-form')[0]; // You need to use standard javascript object here
                                var fd = new FormData(form);

                                $
                                        .ajax({
                                            url : $('#post-property-form')
                                                    .attr('action'),
                                            data : fd,
                                            processData : false,
                                            contentType : false,
                                            type : 'POST',
                                            success : function(data) {
                                                if (data === 'success') {
                                                    $("#lat").val("");
                                                    $('#lng').val("");
                                                    console.log(data);
                                                    $('#add-result p')
                                                            .html(
                                                                    "Property added successfully");
                                                    $("#added-property-link")
                                                            .html(
                                                                    'view property');
                                                    $("#added-property-link")
                                                            .prop(
                                                                    'href',
                                                                    '../property-details?page=admin&pid='
                                                                            + $(
                                                                                    "#propertyId")
                                                                                    .val());

                                                    $('.spinner-border')
                                                            .fadeOut('fast');
                                                    $('#post-property-form')
                                                            .fadeIn('fast');
                                                    //$('#loader').css('display','none');

                                                    $(':input',
                                                            '#post-property-form')
                                                            .not(
                                                                    ':button, :submit, :reset, :hidden')
                                                            .val('').prop(
                                                                    'checked',
                                                                    false)
                                                            .prop('selected',
                                                                    false);
                                                    $("select").prop(
                                                            "selectedIndex", 0);
                                                    $('.input-images').html('');
                                                    $('.input-images')
                                                            .imageUploader();
                                                    $(
                                                            '#add-property-result-modal')
                                                            .modal('show');

                                                } else if (data === "duplicate") {
                                                    $('.spinner-border')
                                                            .fadeOut('fast');
                                                    $('#post-property-form')
                                                            .fadeIn('fast');
                                                    $('#add-result p')
                                                            .html(
                                                                    "Oops! duplicate entry found for property id");
                                                    $("#added-property-link")
                                                            .html('');
                                                    $("#added-property-link")
                                                            .prop('href', '#');
                                                    $(
                                                            '#add-property-result-modal')
                                                            .modal('show');

                                                } else {

                                                    //to complete error checking
                                                    console
                                                            .log('Error adding property[check sql]');
                                                }

                                            }
                                        });
                            }

                            e.preventDefault();
                        });

        //scroll to image preview
        $(document).ready(function() {
            $(".input-images").click(function() {
                $('html, body').animate({
                    scrollTop : $(".input-images").offset().top
                }, 2000);
            });
        });
   

Zerion Mini Shell 1.0