|
|
|
|
@ -1,89 +1,126 @@ |
|
|
|
|
// Fancy widget initializations ------------------------
|
|
|
|
|
|
|
|
|
|
$(function() { |
|
|
|
|
var $specSelects = $('.-spec-select') |
|
|
|
|
var $specSelects = $('.-spec-select') |
|
|
|
|
|
|
|
|
|
var select2Options = { |
|
|
|
|
language: 'ru', |
|
|
|
|
//minimumInputLength: 1, // Commented out to immediately load remote data
|
|
|
|
|
placeholder: '', // Required by `allowClear`
|
|
|
|
|
allowClear: true, |
|
|
|
|
|
|
|
|
|
var select2Options = { |
|
|
|
|
language: 'ru', |
|
|
|
|
//minimumInputLength: 1, // Commented out to immediately load remote data
|
|
|
|
|
placeholder: '', // Required by `allowClear`
|
|
|
|
|
allowClear: true, |
|
|
|
|
ajax: { |
|
|
|
|
url: '/api/specializations/', |
|
|
|
|
dataType: 'json', |
|
|
|
|
quietMillis: 250, |
|
|
|
|
cache: true, |
|
|
|
|
|
|
|
|
|
ajax: { |
|
|
|
|
url: '/api/specializations/', |
|
|
|
|
dataType: 'json', |
|
|
|
|
quietMillis: 250, |
|
|
|
|
cache: true, |
|
|
|
|
|
|
|
|
|
data: function(term, page) { |
|
|
|
|
return { |
|
|
|
|
'name__icontains': term, |
|
|
|
|
page: page, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
results: function(data, page) { |
|
|
|
|
return { |
|
|
|
|
results: _.map(function(item) { |
|
|
|
|
return { |
|
|
|
|
text: item.name, |
|
|
|
|
id: item.id, |
|
|
|
|
origItem: item, |
|
|
|
|
} |
|
|
|
|
}, data.results), |
|
|
|
|
|
|
|
|
|
more: (page * 10) < data.count, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
data: function(term, page) { |
|
|
|
|
return { |
|
|
|
|
'name__icontains': term, |
|
|
|
|
page: page, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
initSelection: function(element, callback) { |
|
|
|
|
var id = $(element).val() |
|
|
|
|
|
|
|
|
|
if (id !== '') { |
|
|
|
|
$.ajax('/api/specializations/' + id, {dataType: 'json'}) |
|
|
|
|
.then(function(data) {callback(data)}) |
|
|
|
|
results: function(data, page) { |
|
|
|
|
return { |
|
|
|
|
results: _.map(function(item) { |
|
|
|
|
return { |
|
|
|
|
text: item.name, |
|
|
|
|
id: item.id, |
|
|
|
|
origItem: item, |
|
|
|
|
} |
|
|
|
|
}, data.results), |
|
|
|
|
|
|
|
|
|
more: (page * 10) < data.count, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
initSelection: function(element, callback) { |
|
|
|
|
var id = $(element).val() |
|
|
|
|
|
|
|
|
|
if (id !== '') { |
|
|
|
|
$.ajax('/api/specializations/' + id + '/', {dataType: 'json'}) |
|
|
|
|
.then(function(data) {callback(data)}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$specSelects.select2(select2Options) |
|
|
|
|
|
|
|
|
|
var $specSelect1 = $('.-spec-select-level-1') |
|
|
|
|
var $specSelect2 = $('.-spec-select-level-2') |
|
|
|
|
var $specSelect3 = $('.-spec-select-level-3') |
|
|
|
|
var $specSelect4 = $('.-spec-select-level-4') |
|
|
|
|
|
|
|
|
|
$specSelects.on('change', function($evt) { |
|
|
|
|
getSpecializationTree($evt.added.origItem).then(function(specs) { |
|
|
|
|
$specSelect1.select2('data', specs.specLevel1 ? {id: specs.specLevel1.id, text: specs.specLevel1.name, origItem: specs.specLevel1} : null) |
|
|
|
|
$specSelect2.select2('data', specs.specLevel2 ? {id: specs.specLevel2.id, text: specs.specLevel2.name, origItem: specs.specLevel2} : null) |
|
|
|
|
$specSelect3.select2('data', specs.specLevel3 ? {id: specs.specLevel3.id, text: specs.specLevel3.name, origItem: specs.specLevel3} : null) |
|
|
|
|
$specSelect4.select2('data', specs.specLevel4 ? {id: specs.specLevel4.id, text: specs.specLevel4.name, origItem: specs.specLevel4} : null) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$specSelects.select2(select2Options) |
|
|
|
|
|
|
|
|
|
var $specSelect1 = $('.-spec-select-level-1') |
|
|
|
|
var $specSelect2 = $('.-spec-select-level-2') |
|
|
|
|
var $specSelect3 = $('.-spec-select-level-3') |
|
|
|
|
var $specSelect4 = $('.-spec-select-level-4') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chosenSpecId = $('#chosenSpecId').val() |
|
|
|
|
|
|
|
|
|
if (chosenSpecId) { |
|
|
|
|
$.ajax({url: '/api/specializations/' + chosenSpecId + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
return updateSpecializationWidgets(spec) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$specSelects.on('change', function($evt) { |
|
|
|
|
updateSpecializationWidgets($evt.added.origItem) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateSpecializationWidgets(spec) { |
|
|
|
|
return getSpecializationTree(spec).then(function(specs) { |
|
|
|
|
var specLevel1 = specs.specLevel1 |
|
|
|
|
var specLevel2 = specs.specLevel2 |
|
|
|
|
var specLevel3 = specs.specLevel3 |
|
|
|
|
var specLevel4 = specs.specLevel4 |
|
|
|
|
var chosenSpecId = specs.chosenSpecId |
|
|
|
|
|
|
|
|
|
$specSelect1.select2('data', specLevel1 ? {id: specLevel1.id, text: specLevel1.name, origItem: specLevel1} : null) |
|
|
|
|
$specSelect2.select2('data', specLevel2 ? {id: specLevel2.id, text: specLevel2.name, origItem: specLevel2} : null) |
|
|
|
|
$specSelect3.select2('data', specLevel3 ? {id: specLevel3.id, text: specLevel3.name, origItem: specLevel3} : null) |
|
|
|
|
$specSelect4.select2('data', specLevel4 ? {id: specLevel4.id, text: specLevel4.name, origItem: specLevel4} : null) |
|
|
|
|
|
|
|
|
|
$('#chosenSpecId').val(chosenSpecId) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getSpecializationTree(spec) { |
|
|
|
|
var specLevel1, specLevel2, specLevel3, specLevel4 |
|
|
|
|
specLevel1 = specLevel2 = specLevel3 = specLevel4 = null |
|
|
|
|
|
|
|
|
|
var chosenSpecId = '' |
|
|
|
|
|
|
|
|
|
if (spec.level === 1) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
return $.when({specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4}) |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.when({ |
|
|
|
|
specLevel1: specLevel1, |
|
|
|
|
specLevel2: specLevel2, |
|
|
|
|
specLevel3: specLevel3, |
|
|
|
|
specLevel4: specLevel4, |
|
|
|
|
chosenSpecId: chosenSpecId, |
|
|
|
|
}) |
|
|
|
|
} else if (spec.level === 2) { |
|
|
|
|
specLevel2 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
return {specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
specLevel1: specLevel1, |
|
|
|
|
specLevel2: specLevel2, |
|
|
|
|
specLevel3: specLevel3, |
|
|
|
|
specLevel4: specLevel4, |
|
|
|
|
chosenSpecId: chosenSpecId, |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else if (spec.level === 3) { |
|
|
|
|
specLevel3 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
@ -92,11 +129,19 @@ function getSpecializationTree(spec) { |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
return {specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
specLevel1: specLevel1, |
|
|
|
|
specLevel2: specLevel2, |
|
|
|
|
specLevel3: specLevel3, |
|
|
|
|
specLevel4: specLevel4, |
|
|
|
|
chosenSpecId: chosenSpecId, |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else if (spec.level === 4) { |
|
|
|
|
specLevel4 = spec |
|
|
|
|
chosenSpecId = spec.id |
|
|
|
|
|
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
@ -109,7 +154,14 @@ function getSpecializationTree(spec) { |
|
|
|
|
return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'}) |
|
|
|
|
.then(function(spec) { |
|
|
|
|
specLevel1 = spec |
|
|
|
|
return {specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
specLevel1: specLevel1, |
|
|
|
|
specLevel2: specLevel2, |
|
|
|
|
specLevel3: specLevel3, |
|
|
|
|
specLevel4: specLevel4, |
|
|
|
|
chosenSpecId: chosenSpecId, |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|