remotes/origin/setup
Mukhtar 10 years ago
commit 74ee5f6ca4
  1. 237
      assets/index.js
  2. 2
      projects/templates/customer_project_create.html
  3. 21
      projects/templates/customer_project_edit.html

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

@ -264,7 +264,7 @@
<input type='hidden' class="-location-select -location-select-city" style="width: 100%">
</div>
<input type="text" id="chosenLocationId" name="{{ realty_form.location.html_name }}" value="{{ realty_form.location.value }}">
<input type="hidden" id="chosenLocationId" name="{{ realty_form.location.html_name }}" value="{{ realty_form.location.value }}">
<div class="col-lg-3 make-new">
<label>

@ -261,17 +261,20 @@
</div>
<div class="polsF1 polsF2 disTab">
<div class="col-lg-3">
<select
id="realtyLocationId"
class="selectpicker"
name="{{ realty_form.location.html_name }}">
{% for t in realty_form.location.field.queryset %}
<option value="{{ t.pk }}" {% if realty_form.location.value|int == t.pk %}selected="selected"{% endif %}>{{ t.name }}</option>
{% endfor %}
</select>
<input type='hidden' class="-location-select -location-select-country" style="width: 100%">
</div>
<div class="col-lg-6 make-new">
<div class="col-lg-3">
<input type='hidden' class="-location-select -location-select-region" style="width: 100%">
</div>
<div class="col-lg-3">
<input type='hidden' class="-location-select -location-select-city" style="width: 100%">
</div>
<input type="hidden" id="chosenLocationId" name="{{ realty_form.location.html_name }}" value="{{ realty_form.location.value }}">
<div class="col-lg-3 make-new">
<label>
<input
type="checkbox"

Loading…
Cancel
Save