|
|
|
|
@ -23,6 +23,12 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Specialization select -----------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,18 +69,65 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.-spec-select-container').each(function(i, container) { |
|
|
|
|
$('.-spec-work-type-combo-container').each(function(i, container) { |
|
|
|
|
var $container = $(container) |
|
|
|
|
var $specSelects = $container.find('.-spec-select') |
|
|
|
|
var $chosenSpecId = $container.find('.-chosen-spec-id').first() |
|
|
|
|
|
|
|
|
|
var $specSelect1 = $container.find('.-spec-select-level-1').first() |
|
|
|
|
|
|
|
|
|
window.select = $specSelect1 |
|
|
|
|
|
|
|
|
|
var $specSelect2 = $container.find('.-spec-select-level-2').first() |
|
|
|
|
var $specSelect3 = $container.find('.-spec-select-level-3').first() |
|
|
|
|
var $specSelect4 = $container.find('.-spec-select-level-4').first() |
|
|
|
|
var specSelects = [$specSelect1, $specSelect2, $specSelect3, $specSelect4] |
|
|
|
|
|
|
|
|
|
reinitSpecializationsByWorkType($specSelect1, null, $container) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $workTypeSelect = $container.find('.-project-work-type-select-field').first() |
|
|
|
|
|
|
|
|
|
if (!_.isEmpty($workTypeSelect)) { |
|
|
|
|
var workTypeId = Number($workTypeSelect.find('option:selected').first().val()) || 1 |
|
|
|
|
|
|
|
|
|
$workTypeSelect.on('change', function($evt) { |
|
|
|
|
var $that = $(this) |
|
|
|
|
var workTypeId = Number($that.val()) |
|
|
|
|
|
|
|
|
|
reinitSpecializationsByWorkType(specSelects, workTypeId).then(function(rootSpec) { |
|
|
|
|
updateSpecializationWidgets(rootSpec.id, $container, $chosenSpecId, specSelects) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
var $workTypeRadios = $container.find('.-project-work-type-radios-container').first().find('input[type=radio]') |
|
|
|
|
|
|
|
|
|
if (!_.isEmpty($workTypeRadios)) { |
|
|
|
|
var workTypeId = Number($workTypeRadios.filter(':checked').val()) || 1 |
|
|
|
|
|
|
|
|
|
$workTypeRadios.on('change', function($evt) { |
|
|
|
|
var $that = $(this) |
|
|
|
|
var workTypeId = Number($that.val()) |
|
|
|
|
|
|
|
|
|
reinitSpecializationsByWorkType(specSelects, workTypeId).then(function(rootSpec) { |
|
|
|
|
updateSpecializationWidgets(rootSpec.id, $container, $chosenSpecId, specSelects) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
var workTypeId = 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reinitSpecializationsByWorkType(specSelects, workTypeId).then(function(rootSpec_) { |
|
|
|
|
updateSpecializationWidgets(null, $container, $chosenSpecId, specSelects) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var chosenSpecId = $chosenSpecId.val() |
|
|
|
|
|
|
|
|
|
@ -88,15 +141,8 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function reinitSpecializationsByWorkType($specSelect1, workTypeId, $container) { |
|
|
|
|
var $chosenSpecId = $container.find('.-chosen-spec-id').first() |
|
|
|
|
|
|
|
|
|
var $specSelect2 = $container.find('.-spec-select-level-2').first() |
|
|
|
|
var $specSelect3 = $container.find('.-spec-select-level-3').first() |
|
|
|
|
var $specSelect4 = $container.find('.-spec-select-level-4').first() |
|
|
|
|
var specSelects = [$specSelect1, $specSelect2, $specSelect3, $specSelect4] |
|
|
|
|
|
|
|
|
|
$.get('/api/specializations/?parent__name=_root') |
|
|
|
|
function reinitSpecializationsByWorkType(specSelects, workTypeId) { |
|
|
|
|
return $.get('/api/specializations/?parent__name=_root') |
|
|
|
|
.then(function(res) { |
|
|
|
|
var rootSpecs = res.results |
|
|
|
|
|
|
|
|
|
@ -109,13 +155,21 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
var url = format('/api/specializations/?lft__gte=%s&rght__lte=%s', rootSpec.lft, rootSpec.rght) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$specSelect1.select2(_.merge(specSelectOptions, {ajax: {url: url}})) |
|
|
|
|
updateSpecializationWidgets(specId, $container, $chosenSpecId, specSelects) |
|
|
|
|
specSelects[0].select2(_.merge(specSelectOptions, {ajax: {url: url}})) |
|
|
|
|
specSelects[1].select2(_.merge(specSelectOptions, {ajax: {url: null}})) |
|
|
|
|
specSelects[2].select2(_.merge(specSelectOptions, {ajax: {url: null}})) |
|
|
|
|
specSelects[3].select2(_.merge(specSelectOptions, {ajax: {url: null}})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Hardcoded:
|
|
|
|
|
|
|
|
|
|
specSelects[0].select2('container').closest('.col-lg-3').css('display', workTypeId === 2 ? 'none' : 'block') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootSpec |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.reinitSpecializationsByWorkType = reinitSpecializationsByWorkType |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateSpecializationWidgets(specId, $container, $chosenSpecId, specSelects) { |
|
|
|
|
return getSpecializationTree(specId).then(function(specs) { |
|
|
|
|
@ -137,18 +191,17 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
|
|
|
|
|
$chosenSpecId.val(specId) |
|
|
|
|
|
|
|
|
|
specSelects[1].select2('container').css('display', !specLevel1 || _.isEmpty(specLevel1.children) ? 'none' : 'block') |
|
|
|
|
specSelects[2].select2('container').css('display', !specLevel2 || _.isEmpty(specLevel2.children) ? 'none' : 'block') |
|
|
|
|
specSelects[3].select2('container').css('display', !specLevel3 || _.isEmpty(specLevel3.children) ? 'none' : 'block') |
|
|
|
|
specSelects[1].select2('enable', Boolean(specLevel1 && !_.isEmpty(specLevel1.children))) |
|
|
|
|
specSelects[2].select2('enable', Boolean(specLevel2 && !_.isEmpty(specLevel2.children))) |
|
|
|
|
specSelects[3].select2('enable', Boolean(specLevel3 && !_.isEmpty(specLevel3.children))) |
|
|
|
|
|
|
|
|
|
specializationTreeHasLevels(specId).then(function(haveLevels) { |
|
|
|
|
specSelects[1].select2('container').css('display', haveLevels.level2 ? 'block' : 'none') |
|
|
|
|
specSelects[2].select2('container').css('display', haveLevels.level3 ? 'block' : 'none') |
|
|
|
|
specSelects[3].select2('container').css('display', haveLevels.level4 ? 'block' : 'none') |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.updateSpecializationWidgets = updateSpecializationWidgets |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//function repopulateSpecializations() {
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
}()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -160,6 +213,9 @@ $('[data-tooltip]').tooltip({ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Specialization select (simple) -------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -903,6 +959,50 @@ function getLocationTree(locId) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function specializationTreeHasLevels(specId) { |
|
|
|
|
if (specId == null) { |
|
|
|
|
var haveLevels = { |
|
|
|
|
level2: true, |
|
|
|
|
level3: true, |
|
|
|
|
level4: true, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $.when(haveLevels) |
|
|
|
|
} else { |
|
|
|
|
return $.get(format('/api/specializations/%s/', specId)).then(function(spec) { |
|
|
|
|
return $.get(format('/api/specializations/?level=1&lft__lte=%s&rght__gte=%s', spec.lft, spec.rght)).then(function(res) { |
|
|
|
|
var specTreeRoot = res.results[0] |
|
|
|
|
|
|
|
|
|
var url_ = format('/api/specializations/?lft__gt=%s&rght__lt=%s&level=%s', specTreeRoot.lft, specTreeRoot.rght) |
|
|
|
|
|
|
|
|
|
return $.when( |
|
|
|
|
$.get(format(url_, 2)).then(function(res) {return res}), |
|
|
|
|
$.get(format(url_, 3)).then(function(res) {return res}), |
|
|
|
|
$.get(format(url_, 4)).then(function(res) {return res}) |
|
|
|
|
) |
|
|
|
|
.then(function(resLvl1, resLvl2, resLvl3) { |
|
|
|
|
var haveLevels = { |
|
|
|
|
level2: !_.isEmpty(resLvl1.results), |
|
|
|
|
level3: !_.isEmpty(resLvl2.results), |
|
|
|
|
level4: !_.isEmpty(resLvl3.results), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return haveLevels |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Utils -----------------------------------------------
|
|
|
|
|
|