From e71832e47e8ee90e6db9f4c74900d4972502cc1b Mon Sep 17 00:00:00 2001 From: vedatakd Date: Fri, 14 Feb 2020 09:30:47 +0300 Subject: [PATCH] fixed location edit --- .../advs-module/resources/js/location.js | 130 ++++++++++-------- 1 file changed, 74 insertions(+), 56 deletions(-) diff --git a/addons/default/visiosoft/advs-module/resources/js/location.js b/addons/default/visiosoft/advs-module/resources/js/location.js index 81c45f9fb..9be0a73d3 100644 --- a/addons/default/visiosoft/advs-module/resources/js/location.js +++ b/addons/default/visiosoft/advs-module/resources/js/location.js @@ -1,109 +1,126 @@ /* Location Data */ +var boundsAction = false; + var getCountry = $('.country-data').data('content'); -if(getCountry == ""){getCountry = default_country;} +if (getCountry == "") { + getCountry = default_country; +} var getCity = $('.city-data').data('content'); -if(getCity == ""){getCity = default_city;} +if (getCity == "") { + getCity = default_city; +} var getDistrict = $('.district-data').data('content'); -if(getDistrict == ""){getDistrict = default_district;} +if (getDistrict == "") { + getDistrict = default_district; +} var getNeighborhood = $('.neighborhood-data').data('content'); -if(getNeighborhood == ""){getNeighborhood = default_neighborhood;} +if (getNeighborhood == "") { + getNeighborhood = default_neighborhood; +} var getVillage = $('.village-data').data('content'); var citySelectName = "city"; var districtSelectName = "district"; var neighborhoodSelectName = "neighborhood"; var villageSelectName = "village"; var countrySelectName = "country"; -jQuery( document ).ready(function( $ ) { +jQuery(document).ready(function ($) { -}).promise().done(function() { +}).promise().done(function () { $('select[name="country"]').val(getCountry); -}).promise().done(function() { +}).promise().done(function () { var cat = getCountry; var level = 1; var name = citySelectName; Locations(cat, level, name); -}).promise().done(function() { +}).promise().done(function () { var cat = getCity; var level = 2; var name = districtSelectName; Locations(cat, level, name); -}).promise().done(function() { +}).promise().done(function () { var cat = getDistrict; var level = 3; var name = neighborhoodSelectName; Locations(cat, level, name); -}).promise().done(function() { +}).promise().done(function () { var cat = getNeighborhood; var level = 4; var name = villageSelectName; Locations(cat, level, name); }); -$(document).on('change', 'select[name="'+countrySelectName+'"]', function(){ +$(document).on('change', 'select[name="' + countrySelectName + '"]', function () { var cat = $(this).val(); var level = 1; var name = citySelectName; + boundsAction = true; Locations(cat, level, name); }); -$(document).on('change', 'select[name="'+citySelectName+'"]', function(){ +$(document).on('change', 'select[name="' + citySelectName + '"]', function () { var cat = $(this).val(); var level = 2; var name = districtSelectName; + boundsAction = true; Locations(cat, level, name) }); -$(document).on('change', 'select[name="'+districtSelectName+'"]', function(){ +$(document).on('change', 'select[name="' + districtSelectName + '"]', function () { var cat = $(this).val(); var level = 3; var name = neighborhoodSelectName; + boundsAction = true; Locations(cat, level, name) }); -$(document).on('change', 'select[name="'+neighborhoodSelectName+'"]', function(){ +$(document).on('change', 'select[name="' + neighborhoodSelectName + '"]', function () { var cat = $(this).val(); var level = 4; var name = villageSelectName; + boundsAction = true; Locations(cat, level, name) }); -function Locations(cat, level, name){ + +function Locations(cat, level, name) { $.ajax({ type: "GET", - data: "cat=" + cat + "&level=" + level, + data: "cat=" + cat + "&level=" + level, url: "/class/ajax", - success: function(msg){ - $('select[name="'+name+'"]').find('option').remove(); - $('select[name="'+name+'"]').append(''); - $.each(msg, function(key, value){ - $('select[name="'+name+'"]').append(''); + success: function (msg) { + $('select[name="' + name + '"]').find('option').remove(); + $('select[name="' + name + '"]').append(''); + $.each(msg, function (key, value) { + $('select[name="' + name + '"]').append(''); }); } - }).promise().done(function() { + }).promise().done(function () { setLocation(level); haritaIslem(0); }); } -function setLocation(level){ - if(level == 1){ - $('select[name="'+citySelectName+'"]').val(getCity); - }else if(level == 2){ - $('select[name="'+districtSelectName+'"]').val(getDistrict); - }else if(level == 3){ - $('select[name="'+neighborhoodSelectName+'"]').val(getNeighborhood); - }else if(level == 4){ - $('select[name="'+villageSelectName+'"]').val(getVillage); +function setLocation(level) { + if (level == 1) { + $('select[name="' + citySelectName + '"]').val(getCity); + } else if (level == 2) { + $('select[name="' + districtSelectName + '"]').val(getDistrict); + } else if (level == 3) { + $('select[name="' + neighborhoodSelectName + '"]').val(getNeighborhood); + } else if (level == 4) { + $('select[name="' + villageSelectName + '"]').val(getVillage); } } var locationedit = $('input[name="map_Val"]').val(); -if(locationedit){ - var coordcenter = new google.maps.LatLng(locationedit); -}else{ +if (locationedit) { + var lat = locationedit.split(",")[0]; + var lng = locationedit.split(",")[1]; + var coordcenter = new google.maps.LatLng(lat, lng); +} else { var coordcenter = new google.maps.LatLng(38.9573415, 35.2415759); } var mapOptions = { - + center: coordcenter, - zoom: 6, + zoom: 20, mapTypeId: google.maps.MapTypeId.STREET }; var secildi = 0; @@ -112,19 +129,19 @@ var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions) function haritaIslem() { var str = ''; - if ($('select[name="'+countrySelectName+'"]').val() != "") { - str += $('select[name="'+countrySelectName+'"] :selected').text() + ' '; + if ($('select[name="' + countrySelectName + '"]').val() != "") { + str += $('select[name="' + countrySelectName + '"] :selected').text() + ' '; } - if ($('select[name="'+citySelectName+'"]').val() != "") { - str += $('select[name="'+citySelectName+'"] :selected').text() + ' '; + if ($('select[name="' + citySelectName + '"]').val() != "") { + str += $('select[name="' + citySelectName + '"] :selected').text() + ' '; } - if ($('select[name="'+districtSelectName+'"]').val() != "") { - str += $('select[name="'+districtSelectName+'"] :selected').text() + ' '; + if ($('select[name="' + districtSelectName + '"]').val() != "") { + str += $('select[name="' + districtSelectName + '"] :selected').text() + ' '; } - if ($('select[name="'+neighborhoodSelectName+'"]').val() != "") { - str += $('select[name="'+neighborhoodSelectName+'"] :selected').text() + ' '; + if ($('select[name="' + neighborhoodSelectName + '"]').val() != "") { + str += $('select[name="' + neighborhoodSelectName + '"] :selected').text() + ' '; } - + if (!str) { return true; } @@ -140,12 +157,11 @@ function haritaIslem() { var lng = results[0].geometry.location.lng(); var latlng = new google.maps.LatLng(lat, lng); var bounds = results[0].geometry.bounds; - - if (bounds != undefined) { + if (boundsAction) { map.fitBounds(bounds); } } - if ($('select[name="'+neighborhoodSelectName+'"]').val() != "" && $('select[name="'+neighborhoodSelectName+'"]').val() != 0 && secildi == 0) { + if ($('select[name="' + neighborhoodSelectName + '"]').val() != "" && $('select[name="' + neighborhoodSelectName + '"]').val() != 0 && secildi == 0) { secildi = 1; } @@ -153,13 +169,12 @@ function haritaIslem() { } function placeMarker(location) { - console.log(location); var lat = location.lat(); var lng = location.lng(); $(".mapVal").val(lat + "," + lng); if (marker) { marker.setPosition(location); - $("#map").data(lat+","+lng); + $("#map").data(lat + "," + lng); } else { marker = new google.maps.Marker({ position: location, @@ -170,19 +185,22 @@ function placeMarker(location) { } editMarket(); + function editMarket() { var locationedit = $('input[name="map_Val"]').val(); - if(locationedit){ + if (locationedit) { + var lat = locationedit.split(",")[0]; var lng = locationedit.split(",")[1]; - var location = new google.maps.LatLng(lat, lng); - $(".mapVal").val($('input[name="map_Val"]')); + + var locationMap = new google.maps.LatLng(lat, lng); + $(".mapVal").val($('input[name="map_Val"]').val()); if (marker) { - marker.setPosition(location); - $("#map").data(lat+","+lng); + marker.setPosition(locationMap); + $("#map").data(lat + "," + lng); } else { marker = new google.maps.Marker({ - position: location, + position: locationMap, map: map }); }