remotes/origin/setup
ArturBaybulatov 10 years ago
parent b9166f6dd3
commit a046acb0d6
  1. 108
      assets/index.js

@ -15,12 +15,6 @@ $(function() {
quietMillis: 250, quietMillis: 250,
cache: true, cache: true,
//createSearchChoice: function(term, data) {
// if ($(data).filter(function() {return this.text.localeCompare(term) === 0}).length === 0) {
// return {id: term, text: term}
// }
//},
data: function(term, page) { data: function(term, page) {
return { return {
'name__icontains': term, 'name__icontains': term,
@ -34,7 +28,7 @@ $(function() {
return { return {
text: item.name, text: item.name,
id: item.id, id: item.id,
orig_item: item, origItem: item,
} }
}, data.results), }, data.results),
@ -60,57 +54,69 @@ $(function() {
var $specSelect3 = $('.-spec-select-level-3') var $specSelect3 = $('.-spec-select-level-3')
var $specSelect4 = $('.-spec-select-level-4') var $specSelect4 = $('.-spec-select-level-4')
//$specSelect1.on('change', function($evt) { $specSelects.on('change', function($evt) {
// var spec = $evt.added.orig_item getSpecializationTree($evt.added.origItem).then(function(specs) {
// console.log('Select 1 changed:', spec) $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)
$specSelect2.on('change', function($evt) { $specSelect4.select2('data', specs.specLevel4 ? {id: specs.specLevel4.id, text: specs.specLevel4.name, origItem: specs.specLevel4} : null)
var spec = $evt.added.orig_item })
console.log('Select 2 changed:', spec)
$specSelect1.select2('data', {id: spec.parent.id, text: spec.parent.name}, true)
//$.ajax({url: '/api/specializations/99123/', method: 'GET'})
// .then(function(res) {console.log(res)})
// .fail(function() {console.log('Error occurred')})
}) })
//$specSelect3.on('change', function($evt) {
// var spec = $evt.added.orig_item
// console.log('Select 3 changed:', spec)
//})
//
//$specSelect4.on('change', function($evt) {
// var spec = $evt.added.orig_item
// console.log('Select 4 changed:', spec)
//})
window.$specSelect1 = $specSelect1
window.$specSelect2 = $specSelect2
window.$specSelect3 = $specSelect3
window.$specSelect4 = $specSelect4
}) })
//function select2_search ($el, term) { function getSpecializationTree(spec) {
// $el.select2('open'); var specLevel1, specLevel2, specLevel3, specLevel4
// specLevel1 = specLevel2 = specLevel3 = specLevel4 = null
// // Get the search box within the dropdown or the selection
// // Dropdown = single, Selection = multiple if (spec.level === 1) {
// var $search = $specSelect1.data('select2').dropdown.$search.val('b') specLevel1 = spec
// // This is undocumented and may change in the future return $.when({specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4})
// } else if (spec.level === 2) {
// $search.val(term); specLevel2 = spec
// $search.trigger('keyup');
//} return $.ajax({url: '/api/specializations/' + specLevel2.parent.id + '/', method: 'GET'})
.then(function(spec) {
specLevel1 = spec
return {specLevel1: specLevel1, specLevel2: specLevel2, specLevel3: specLevel3, specLevel4: specLevel4}
})
} else if (spec.level === 3) {
specLevel3 = spec
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET'})
.then(function(spec) {
specLevel2 = 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}
})
})
} else if (spec.level === 4) {
specLevel4 = spec
return $.ajax({url: '/api/specializations/' + specLevel4.parent.id + '/', method: 'GET'})
.then(function(spec) {
specLevel3 = spec
return $.ajax({url: '/api/specializations/' + specLevel3.parent.id + '/', method: 'GET'})
.then(function(spec) {
specLevel2 = 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}
})
})
})
}
}
//$('button').on('click', function () {
// var $select = $($(this).data('target'));
// select2_search($select, 'Arizona');
//});

Loading…
Cancel
Save