|
|
|
|
@ -1,8 +1,6 @@ |
|
|
|
|
// Fancy widget initializations ------------------------
|
|
|
|
|
|
|
|
|
|
var $specSelects = $('.-spec-select') |
|
|
|
|
|
|
|
|
|
var select2Options = { |
|
|
|
|
var specSelectOptions = { |
|
|
|
|
language: 'ru', |
|
|
|
|
//minimumInputLength: 1, // Commented out to immediately load remote data
|
|
|
|
|
placeholder: '', // Required by `allowClear`
|
|
|
|
|
@ -40,13 +38,13 @@ var select2Options = { |
|
|
|
|
var id = $(element).val() |
|
|
|
|
|
|
|
|
|
if (id !== '') { |
|
|
|
|
$.ajax('/api/specializations/' + id + '/', {dataType: 'json'}) |
|
|
|
|
$.ajax({url: '/api/specializations/' + id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(data) {callback(data)}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$specSelects.select2(select2Options) |
|
|
|
|
$specSelects.select2(specSelectOptions) |
|
|
|
|
|
|
|
|
|
var $specSelect1 = $('.-spec-select-level-1') |
|
|
|
|
var $specSelect2 = $('.-spec-select-level-2') |
|
|
|
|
@ -57,7 +55,7 @@ var $specSelect4 = $('.-spec-select-level-4') |
|
|
|
|
var chosenSpecId = $('#chosenSpecId').val() |
|
|
|
|
|
|
|
|
|
if (chosenSpecId) { |
|
|
|
|
$.ajax({url: '/api/specializations/' + chosenSpecId + '/', method: 'GET'}) |
|
|
|
|
$.ajax({url: '/api/specializations/' + chosenSpecId + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
return updateSpecializationWidgets(spec) |
|
|
|
|
}) |
|
|
|
|
@ -85,6 +83,154 @@ function updateSpecializationWidgets(spec) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $locationSelects = $('.-location-select') |
|
|
|
|
|
|
|
|
|
var locationSelectOptions = { |
|
|
|
|
language: 'ru', |
|
|
|
|
//minimumInputLength: 1, // Commented out to immediately load remote data
|
|
|
|
|
placeholder: '', // Required by `allowClear`
|
|
|
|
|
allowClear: true, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//$locationSelects.select2(locationSelectOptions)
|
|
|
|
|
|
|
|
|
|
var $countrySelect = $('.-location-select-country') |
|
|
|
|
var $regionSelect = $('.-location-select-region') |
|
|
|
|
var $citySelect = $('.-location-select-city') |
|
|
|
|
|
|
|
|
|
var chosenLocationId = $('#chosenLocationId').val() |
|
|
|
|
|
|
|
|
|
$countrySelect.select2(_.merge(locationSelectOptions, { |
|
|
|
|
query: function(query) { |
|
|
|
|
$.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(res) { |
|
|
|
|
query.callback({ |
|
|
|
|
results: _.map(function(item) { |
|
|
|
|
return { |
|
|
|
|
text: item.name, |
|
|
|
|
id: item.id, |
|
|
|
|
origItem: item, |
|
|
|
|
} |
|
|
|
|
}, res.results) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#realtyId').on('change', function($evt) { |
|
|
|
|
var realtyId = Number($(this).val()) |
|
|
|
|
|
|
|
|
|
if (realtyId) { |
|
|
|
|
loadRealtyDetails(realtyId).then(function(res) { |
|
|
|
|
$('#realtyName').val(res.name) |
|
|
|
|
$('#realtyBuildingClassificationId').val(res.building_classification.id).change() |
|
|
|
|
$('#realtyConstructionTypeId').val(res.construction_type.id).change() |
|
|
|
|
//$('#realtyLocationId').val(res.location.id).change()
|
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
$('#realtyName').val('') |
|
|
|
|
$('#realtyBuildingClassificationId').val('').change() |
|
|
|
|
$('#realtyConstructionTypeId').val('').change() |
|
|
|
|
//$('#realtyLocationId').val('').change()
|
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function loadRealtyDetails(realtyId) { |
|
|
|
|
return $.ajax({ |
|
|
|
|
url: '/api/realties/' + realtyId + '/', |
|
|
|
|
method: 'GET', |
|
|
|
|
dataType: 'json', |
|
|
|
|
}) |
|
|
|
|
.then(function(res) {return res}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// File uploading ---------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $fileUploadContainer = $('#fileUploadContainer') |
|
|
|
|
|
|
|
|
|
$('#fileUploadAddBtn').on('click', function($evt) { |
|
|
|
|
$fileUploadContainer.find('.file-upload-widget').last().children('.file-upload-input').click() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('change', '.file-upload-input', function($evt) { |
|
|
|
|
var $fileInput = $(this) |
|
|
|
|
var $fileUploadWidget = $fileInput.parent('.file-upload-widget') |
|
|
|
|
var filePath = $fileInput.val().replace(/\\/g, '/') |
|
|
|
|
var fileName = path.basename(filePath) |
|
|
|
|
//var fileExt = path.extname(filePath)
|
|
|
|
|
var fileSize = $fileInput.get(0).files && humanFileSize($fileInput.get(0).files[0].size) |
|
|
|
|
|
|
|
|
|
if (fileName) { |
|
|
|
|
$fileUploadWidget.children('.file-upload-label').text(fileName + ' ' + fileSize) |
|
|
|
|
|
|
|
|
|
var $newFileUploadWidget = $fileUploadWidget.clone() |
|
|
|
|
$newFileUploadWidget.children('.file-upload-label').text('') |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.children('ul').first().append($newFileUploadWidget) |
|
|
|
|
|
|
|
|
|
$fileUploadWidget.css('display', 'block') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('click', '.file-upload-remove-btn', function($evt) { |
|
|
|
|
var $btn = $(this) |
|
|
|
|
$btn.parent('.file-upload-widget').remove() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('click', '.existing-file-remove-btn', function($evt) { |
|
|
|
|
var $btn = $(this) |
|
|
|
|
$btn.parent('.existing-file-widget').remove() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Helpers ---------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSpecializationTree(spec) { |
|
|
|
|
var specLevel1, specLevel2, specLevel3, specLevel4 |
|
|
|
|
specLevel1 = specLevel2 = specLevel3 = specLevel4 = null |
|
|
|
|
@ -106,7 +252,7 @@ function getSpecializationTree(spec) { |
|
|
|
|
specLevel2 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
|
|
|
|
|
@ -122,11 +268,11 @@ function getSpecializationTree(spec) { |
|
|
|
|
specLevel3 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel2 = spec |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
|
|
|
|
|
@ -143,15 +289,15 @@ function getSpecializationTree(spec) { |
|
|
|
|
specLevel4 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel3 = spec |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel2 = spec |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET', dataType: 'json'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
|
|
|
|
|
@ -172,6 +318,54 @@ function getSpecializationTree(spec) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//function getLocationTree(loc) {
|
|
|
|
|
// var country, region, city, countries, regions, cities
|
|
|
|
|
// country = region = city = countries = regions = cities = null
|
|
|
|
|
//
|
|
|
|
|
// var chosenLocId = ''
|
|
|
|
|
//
|
|
|
|
|
// if (loc.level === 1) {
|
|
|
|
|
// country = loc
|
|
|
|
|
// chosenLocId = loc.id
|
|
|
|
|
//
|
|
|
|
|
// return $.ajax({url: '/api/locations/?level=1', method: 'GET', dataType: 'json'})
|
|
|
|
|
// .then(function(res) {
|
|
|
|
|
// specLevel1 = spec
|
|
|
|
|
//
|
|
|
|
|
// return {
|
|
|
|
|
// specLevel1: specLevel1,
|
|
|
|
|
// specLevel2: specLevel2,
|
|
|
|
|
// specLevel3: specLevel3,
|
|
|
|
|
// specLevel4: specLevel4,
|
|
|
|
|
// chosenSpecId: chosenSpecId,
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
//
|
|
|
|
|
// return $.when({
|
|
|
|
|
// country: country,
|
|
|
|
|
// region: region,
|
|
|
|
|
// city: city,
|
|
|
|
|
// chosenLocId: chosenLocId,
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// ........
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Utils -----------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -194,75 +388,3 @@ function humanFileSize(bytes, si) { |
|
|
|
|
|
|
|
|
|
return bytes.toFixed(1) + ' ' + units[u] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#realtyId').on('change', function($evt) { |
|
|
|
|
var realtyId = Number($(this).val()) |
|
|
|
|
|
|
|
|
|
if (realtyId) { |
|
|
|
|
loadRealtyDetails(realtyId).then(function(res) { |
|
|
|
|
$('#realtyName').val(res.name) |
|
|
|
|
$('#realtyBuildingClassificationId').val(res.building_classification.id).change() |
|
|
|
|
$('#realtyConstructionTypeId').val(res.construction_type.id).change() |
|
|
|
|
$('#realtyLocationId').val(res.location.id).change() |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
$('#realtyName').val('') |
|
|
|
|
$('#realtyBuildingClassificationId').val('').change() |
|
|
|
|
$('#realtyConstructionTypeId').val('').change() |
|
|
|
|
$('#realtyLocationId').val('').change() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function loadRealtyDetails(realtyId) { |
|
|
|
|
return $.ajax({ |
|
|
|
|
url: '/api/realties/' + realtyId + '/', |
|
|
|
|
method: 'GET', |
|
|
|
|
dataType: 'json', |
|
|
|
|
}) |
|
|
|
|
.then(function(res) {return res}) |
|
|
|
|
.fail(function() {console.error('Failed', arguments)}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $fileUploadContainer = $('#fileUploadContainer') |
|
|
|
|
|
|
|
|
|
$('#fileUploadAddBtn').on('click', function($evt) { |
|
|
|
|
$fileUploadContainer.find('.file-upload-widget').last().children('.file-upload-input').click() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('change', '.file-upload-input', function($evt) { |
|
|
|
|
var $fileInput = $(this) |
|
|
|
|
var $fileUploadWidget = $fileInput.parent('.file-upload-widget') |
|
|
|
|
var filePath = $fileInput.val().replace(/\\/g, '/') |
|
|
|
|
var fileName = path.basename(filePath) |
|
|
|
|
//var fileExt = path.extname(filePath)
|
|
|
|
|
var fileSize = $fileInput.get(0).files && humanFileSize($fileInput.get(0).files[0].size) |
|
|
|
|
|
|
|
|
|
if (fileName) { |
|
|
|
|
$fileUploadWidget.children('.file-upload-label').text(fileName + ' ' + fileSize) |
|
|
|
|
|
|
|
|
|
var $newFileUploadWidget = $fileUploadWidget.clone() |
|
|
|
|
$newFileUploadWidget.children('.file-upload-label').text('') |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.children('ul').first().append($newFileUploadWidget) |
|
|
|
|
|
|
|
|
|
$fileUploadWidget.css('display', 'block') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('click', '.file-upload-remove-btn', function($evt) { |
|
|
|
|
var $btn = $(this) |
|
|
|
|
$btn.parent('.file-upload-widget').remove() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$fileUploadContainer.on('click', '.existing-file-remove-btn', function($evt) { |
|
|
|
|
var $btn = $(this) |
|
|
|
|
$btn.parent('.existing-file-widget').remove() |
|
|
|
|
}) |
|
|
|
|
|