+ }
+
+ function ajax_data(term) {
+ var data = {
+ 'filter.all:substr::ilike': term,
+ 'filter.obsolete': 0,
+ 'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '',
+ column: $column && $column.val() ? $column.val() : '',
+ current: $real.val(),
+ };
+
+ if ($type && $type.val())
+ data['filter.type'] = $type.val().split(',');
+
+ if ($unit && $unit.val())
+ data['filter.unit'] = $unit.val().split(',');
+
+ return data;
+ }
+
+ function set_item (item) {
+ if (item.id) {
+ $real.val(item.id);
+ // autocomplete ui has name, ajax items have description
+ $dummy.val(item.name ? item.name : item.description);
+ } else {
+ $real.val('');
+ $dummy.val('');
+ }
+ state = STATES.PICKED;
+ last_real = $real.val();
+ last_dummy = $dummy.val();
+ $real.trigger('change');
+ }
+
+ function make_defined_state () {
+ if (state == STATES.PICKED)
+ return true
+ else if (state == STATES.UNDEFINED && $dummy.val() == '')
+ set_item({})
+ else
+ set_item({ id: last_real, name: last_dummy })
+ }
+
+ function update_results () {
+ $.ajax({
+ url: 'controller.pl?action=Part/part_picker_result',
+ data: $.extend({
+ 'real_id': $real.val(),
+ }, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })),
+ success: function(data){ $('#part_picker_result').html(data) }
+ });
+ };
+
+ function result_timer (event) {
+ window.clearTimeout(timer);
+ timer = window.setTimeout(update_results, 100);
+ }
+
+ function close_popup() {
+ $('#part_selection').dialog('close');