shimatta-kenkyusho/shimatta_kenkyusho/static/js/edit-component-modal.js

81 lines
3.0 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function(){
// Create the autocompletion stuff
new AutocompleteText(edit_comp_modal_ids['component_type'], edit_comp_modal_ids['component_type']+'-ac-ul',
function(search, autocomplete) {
api_search_component_types(search, function(result) {
type_names = [];
for(var i = 0; i < result.results.length; i++) {
var r = result.results[i];
type_names.push(r.class_name);
}
autocomplete.show_results(type_names)
}, function() {
// Nothing to do---
})
});
new AutocompleteCustomUi(edit_comp_modal_ids['manufacturer'], edit_comp_modal_ids['manufacturer']+'-ac-ul',
function(search, autocomplete) {
api_search_manufacturer(search, function(result) {
nodes = [];
for (var i = 0; i < result.results.length; i++) {
var manu = result.results[i];
// Construct the ui:
ui = AutocompleteCustomUi.create_media_div(manu.image, [document.createTextNode(manu.name)])
nodes.push({'ui': ui, 'data': manu.name});
}
autocomplete.show_results(nodes, function(data) {
document.getElementById(edit_comp_modal_ids['manufacturer']).value = data;
})
}, function() {
// Nothing to do---
})
});
new AutocompleteCustomUi(edit_comp_modal_ids['pref_distri'], edit_comp_modal_ids['pref_distri']+'-ac-ul',
function(search, autocomplete) {
api_search_distributor(search, function(result) {
nodes = [];
for (var i = 0; i < result.results.length; i++) {
var distri = result.results[i];
// Construct the ui:
ui = AutocompleteCustomUi.create_media_div(distri.image, [document.createTextNode(distri.name)])
nodes.push({'ui': ui, 'data': distri.name});
}
autocomplete.show_results(nodes, function(data) {
document.getElementById(edit_comp_modal_ids['pref_distri']).value = data;
})
}, function() {
// Nothing to do---
})
});
new AutocompleteCustomUi(edit_comp_modal_ids['package'], edit_comp_modal_ids['package']+'-ac-ul',
function(search, autocomplete) {
api_search_package(search, function(result) {
nodes = [];
for (var i = 0; i < result.results.length; i++) {
var pkg = result.results[i];
// Construct the ui:
ui = AutocompleteCustomUi.create_media_div(pkg.image, [document.createTextNode(pkg.name)])
nodes.push({'ui': ui, 'data': pkg.name});
}
autocomplete.show_results(nodes, function(data) {
document.getElementById(edit_comp_modal_ids['package']).value = data;
})
}, function() {
// Nothing to do---
})
});
});