|
|
|
@ -106,23 +106,22 @@ var $citySelect = $('.-location-select-city') |
|
|
|
|
|
|
|
|
|
|
|
// Initialize:
|
|
|
|
// Initialize:
|
|
|
|
|
|
|
|
|
|
|
|
getLocationTree(31).then(function(locs) { |
|
|
|
getLocationTree(null).then(function(locs) { |
|
|
|
$countrySelect.select2(_.merge(locationSelectOptions, {data: locs.countries})) |
|
|
|
$countrySelect.select2(_.merge(locationSelectOptions, {data: locs.countries})) |
|
|
|
$regionSelect.select2(_.merge(locationSelectOptions, {data: locs.regions})) |
|
|
|
$regionSelect.select2(_.merge(locationSelectOptions, {data: locs.regions})) |
|
|
|
$citySelect.select2(_.merge(locationSelectOptions, {data: locs.cities})) |
|
|
|
$citySelect.select2(_.merge(locationSelectOptions, {data: locs.cities})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chosenLocId = $('#chosenLocationId').val() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (chosenLocId) |
|
|
|
|
|
|
|
updateLocationWidgets(chosenLocId) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var chosenLocId = $('#chosenLocationId').val()
|
|
|
|
$locationSelects.on('change', function($evt) { |
|
|
|
//
|
|
|
|
var locId = $evt.added.id |
|
|
|
//if (chosenLocId)
|
|
|
|
updateLocationWidgets(locId) |
|
|
|
// updateLocationWidgets(chosenLocId)
|
|
|
|
}) |
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//$locationSelects.on('change', function($evt) {
|
|
|
|
|
|
|
|
// var locId = $evt.added.id
|
|
|
|
|
|
|
|
// updateLocationWidgets(locId)
|
|
|
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateLocationWidgets(locId) { |
|
|
|
function updateLocationWidgets(locId) { |
|
|
|
@ -131,7 +130,21 @@ function updateLocationWidgets(locId) { |
|
|
|
$regionSelect.select2({data: locs.regions}) |
|
|
|
$regionSelect.select2({data: locs.regions}) |
|
|
|
$citySelect.select2({data: locs.cities}) |
|
|
|
$citySelect.select2({data: locs.cities}) |
|
|
|
|
|
|
|
|
|
|
|
$('#chosenLocationId').val(locId) |
|
|
|
var loc = locs.location |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loc && loc.level === 1) { |
|
|
|
|
|
|
|
$countrySelect.select2('val', locs.country.id) |
|
|
|
|
|
|
|
} else if (loc && loc.level === 2) { |
|
|
|
|
|
|
|
$regionSelect.select2('val', locs.region.id) |
|
|
|
|
|
|
|
$countrySelect.select2('val', locs.country.id) |
|
|
|
|
|
|
|
} else if (loc && loc.level === 3) { |
|
|
|
|
|
|
|
$citySelect.select2('val', locs.city.id) |
|
|
|
|
|
|
|
$regionSelect.select2('val', locs.region.id) |
|
|
|
|
|
|
|
$countrySelect.select2('val', locs.country.id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loc) |
|
|
|
|
|
|
|
$('#chosenLocationId').val(loc.id) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -145,13 +158,13 @@ $('#realtyId').on('change', function($evt) { |
|
|
|
$('#realtyName').val(res.name) |
|
|
|
$('#realtyName').val(res.name) |
|
|
|
$('#realtyBuildingClassificationId').val(res.building_classification.id).change() |
|
|
|
$('#realtyBuildingClassificationId').val(res.building_classification.id).change() |
|
|
|
$('#realtyConstructionTypeId').val(res.construction_type.id).change() |
|
|
|
$('#realtyConstructionTypeId').val(res.construction_type.id).change() |
|
|
|
//$('#realtyLocationId').val(res.location.id).change() // updateLocationWidgets(res.location.id)
|
|
|
|
updateLocationWidgets(res.location.id) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$('#realtyName').val('') |
|
|
|
$('#realtyName').val('') |
|
|
|
$('#realtyBuildingClassificationId').val('').change() |
|
|
|
$('#realtyBuildingClassificationId').val('').change() |
|
|
|
$('#realtyConstructionTypeId').val('').change() |
|
|
|
$('#realtyConstructionTypeId').val('').change() |
|
|
|
//$('#realtyLocationId').val('').change() // updateLocationWidgets(null)
|
|
|
|
updateLocationWidgets(null) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
@ -228,74 +241,65 @@ $fileUploadContainer.on('click', '.existing-file-remove-btn', function($evt) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSpecializationTree(specId) { |
|
|
|
function getSpecializationTree(specId) { |
|
|
|
var specLevel1, specLevel2, specLevel3, specLevel4 |
|
|
|
var specs = { |
|
|
|
specLevel1 = specLevel2 = specLevel3 = specLevel4 = null |
|
|
|
specLevel1: null, specLevel2: null, specLevel3: null, specLevel4: null, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specId + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specId + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
if (spec.level === 1) { |
|
|
|
if (spec.level === 1) { |
|
|
|
specLevel1 = spec |
|
|
|
return _.merge(specs, {specLevel1: spec}) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
specLevel1: specLevel1, |
|
|
|
|
|
|
|
specLevel2: specLevel2, |
|
|
|
|
|
|
|
specLevel3: specLevel3, |
|
|
|
|
|
|
|
specLevel4: specLevel4, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (spec.level === 2) { |
|
|
|
} else if (spec.level === 2) { |
|
|
|
specLevel2 = spec |
|
|
|
var specLevel2 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel1 = spec |
|
|
|
var specLevel1 = spec |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return _.merge(specs, { |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel3: specLevel3, |
|
|
|
}) |
|
|
|
specLevel4: specLevel4, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} else if (spec.level === 3) { |
|
|
|
} else if (spec.level === 3) { |
|
|
|
specLevel3 = spec |
|
|
|
var specLevel3 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel2 = spec |
|
|
|
var specLevel2 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel1 = spec |
|
|
|
var specLevel1 = spec |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return _.merge(specs, { |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel3: specLevel3, |
|
|
|
specLevel3: specLevel3, |
|
|
|
specLevel4: specLevel4, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else if (spec.level === 4) { |
|
|
|
} else if (spec.level === 4) { |
|
|
|
specLevel4 = spec |
|
|
|
var specLevel4 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel3 = spec |
|
|
|
var specLevel3 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel2 = spec |
|
|
|
var specLevel2 = spec |
|
|
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(spec) { |
|
|
|
.then(function(spec) { |
|
|
|
specLevel1 = spec |
|
|
|
var specLevel1 = spec |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return _.merge(specs, { |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel1: specLevel1, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel2: specLevel2, |
|
|
|
specLevel3: specLevel3, |
|
|
|
specLevel3: specLevel3, |
|
|
|
specLevel4: specLevel4, |
|
|
|
specLevel4: specLevel4, |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
@ -313,6 +317,7 @@ function getSpecializationTree(specId) { |
|
|
|
|
|
|
|
|
|
|
|
function getLocationTree(locId) { |
|
|
|
function getLocationTree(locId) { |
|
|
|
var locations = { |
|
|
|
var locations = { |
|
|
|
|
|
|
|
location: null, |
|
|
|
country: null, region: null, city: null, |
|
|
|
country: null, region: null, city: null, |
|
|
|
countries: [], regions: [], cities: [], |
|
|
|
countries: [], regions: [], cities: [], |
|
|
|
} |
|
|
|
} |
|
|
|
@ -320,94 +325,92 @@ function getLocationTree(locId) { |
|
|
|
if (locId === null) { |
|
|
|
if (locId === null) { |
|
|
|
return $.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
return $.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
.then(function(res) { |
|
|
|
.then(function(res) { |
|
|
|
countries = _.map(function(item) { |
|
|
|
return _.merge(locations, { |
|
|
|
return { |
|
|
|
countries: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, res.results), |
|
|
|
text: item.name, |
|
|
|
}) |
|
|
|
id: item.id, |
|
|
|
|
|
|
|
origItem: item, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, res.results) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _.merge(locations, {countries: countries}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return $.ajax({url: '/api/locations/' + locId + '/', method: 'GET', dataType: 'json'}).then(function(loc) { |
|
|
|
return $.ajax({url: '/api/locations/' + locId + '/', method: 'GET', dataType: 'json'}).then(function(loc) { |
|
|
|
|
|
|
|
locations = _.merge(locations, {location: loc}) |
|
|
|
|
|
|
|
|
|
|
|
if (loc.level === 1) { |
|
|
|
if (loc.level === 1) { |
|
|
|
country = loc |
|
|
|
var country = loc |
|
|
|
|
|
|
|
|
|
|
|
return $.when( |
|
|
|
return $.when( |
|
|
|
$.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}), |
|
|
|
$.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}), // Countries
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/?level=2&parent=' + country.id, method: 'GET', dataType: 'json'}) |
|
|
|
$.ajax({url: '/api/locations/?level=2&parent=' + country.id, method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}) // Regions
|
|
|
|
) |
|
|
|
) |
|
|
|
.then(function() { |
|
|
|
.then(function(countries, regions) { |
|
|
|
countries = _.map(function(item) { |
|
|
|
return _.merge(locations, { |
|
|
|
return { |
|
|
|
country: country, |
|
|
|
text: item.name, |
|
|
|
countries: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, countries), |
|
|
|
id: item.id, |
|
|
|
regions: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, regions), |
|
|
|
origItem: item, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}, arguments[0][0].results) // WTF????
|
|
|
|
} else if (loc.level === 2) { |
|
|
|
|
|
|
|
var region = loc |
|
|
|
regions = _.map(function(item) { |
|
|
|
|
|
|
|
return { |
|
|
|
return $.when( |
|
|
|
text: item.name, |
|
|
|
$.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
id: item.id, |
|
|
|
.then(function(res) {return res.results}), // Countries
|
|
|
|
origItem: item, |
|
|
|
|
|
|
|
} |
|
|
|
$.ajax({url: '/api/locations/?level=2&parent=' + region.parent.id, method: 'GET', dataType: 'json'}) |
|
|
|
}, arguments[1][0].results) // WTF either???????
|
|
|
|
.then(function(res) {return res.results}), // Regions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/' + region.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res}), // Country
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/?level=3&parent=' + region.id, method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}) // Cities
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.then(function(countries, regions, country, cities) { |
|
|
|
return _.merge(locations, { |
|
|
|
return _.merge(locations, { |
|
|
|
country: country, |
|
|
|
country: country, |
|
|
|
countries: countries, |
|
|
|
region: region, |
|
|
|
regions: regions, |
|
|
|
countries: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, countries), |
|
|
|
|
|
|
|
regions: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, regions), |
|
|
|
|
|
|
|
cities: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, cities), |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} else if (loc.level === 3) { |
|
|
|
|
|
|
|
var city = loc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $.when( |
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}), // Countries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/' + city.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res}), // Region
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/?level=3&parent=' + city.parent.id, method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}) // Cities
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.then(function(countries, region, cities) { |
|
|
|
|
|
|
|
locations = _.merge(locations, { |
|
|
|
|
|
|
|
region: region, |
|
|
|
|
|
|
|
city: city, |
|
|
|
|
|
|
|
countries: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, countries), |
|
|
|
|
|
|
|
cities: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, cities), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $.when( |
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/?level=2&parent=' + region.parent.id, method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res.results}), // Regions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({url: '/api/locations/' + region.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
|
|
|
.then(function(res) {return res}) // Country
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.then(function(regions, country) { |
|
|
|
|
|
|
|
return _.merge(locations, { |
|
|
|
|
|
|
|
country: country, |
|
|
|
|
|
|
|
regions: _.map(function(item) {return {text: item.name, id: item.id, origItem: item}}, regions), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
//else if (loc.level === 2) {
|
|
|
|
|
|
|
|
// region = loc
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return $.ajax({url: '/api/locations/?level=2', method: 'GET', dataType: 'json'})
|
|
|
|
|
|
|
|
// .then(function(res) {
|
|
|
|
|
|
|
|
// regions = _.map(function(item) {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// text: item.name,
|
|
|
|
|
|
|
|
// id: item.id,
|
|
|
|
|
|
|
|
// origItem: item,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }, res.results)
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// country: country,
|
|
|
|
|
|
|
|
// countries: countries,
|
|
|
|
|
|
|
|
// region: region,
|
|
|
|
|
|
|
|
// regions: regions,
|
|
|
|
|
|
|
|
// city: city,
|
|
|
|
|
|
|
|
// cities: cities,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
//} else if (loc.level === 3) {
|
|
|
|
|
|
|
|
// city = loc
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return $.ajax({url: '/api/locations/?level=3', method: 'GET', dataType: 'json'})
|
|
|
|
|
|
|
|
// .then(function(res) {
|
|
|
|
|
|
|
|
// cities = _.map(function(item) {
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// text: item.name,
|
|
|
|
|
|
|
|
// id: item.id,
|
|
|
|
|
|
|
|
// origItem: item,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }, res.results)
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
|
|
|
// country: country,
|
|
|
|
|
|
|
|
// countries: countries,
|
|
|
|
|
|
|
|
// region: region,
|
|
|
|
|
|
|
|
// regions: regions,
|
|
|
|
|
|
|
|
// city: city,
|
|
|
|
|
|
|
|
// cities: cities,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|