Revision 2cf7a2cd
Von Bernd Bleßmann vor mehr als 8 Jahren hinzugefügt
js/autocomplete_part.js | ||
---|---|---|
154 | 154 |
$('#part_selection').dialog('close'); |
155 | 155 |
}; |
156 | 156 |
|
157 |
function handle_changed_text(callbacks) { |
|
158 |
$.ajax({ |
|
159 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
160 |
dataType: "json", |
|
161 |
data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), |
|
162 |
success: function (data) { |
|
163 |
if (data.length == 1) { |
|
164 |
set_item(data[0]); |
|
165 |
if (callbacks && callbacks.match_one) callbacks.match_one(data[0]); |
|
166 |
} else if (data.length > 1) { |
|
167 |
state = STATES.UNDEFINED; |
|
168 |
if (callbacks && callbacks.match_many) callbacks.match_many(data); |
|
169 |
} else { |
|
170 |
state = STATES.UNDEFINED; |
|
171 |
if (callbacks &&callbacks.match_none) callbacks.match_none(); |
|
172 |
} |
|
173 |
annotate_state(); |
|
174 |
} |
|
175 |
}); |
|
176 |
}; |
|
177 |
|
|
157 | 178 |
$dummy.autocomplete({ |
158 | 179 |
source: function(req, rsp) { |
159 | 180 |
$.ajax($.extend(o, { |
... | ... | |
188 | 209 |
} else if (state == STATES.PICKED) { |
189 | 210 |
return true; |
190 | 211 |
} |
191 |
if (event.which == KEY.TAB) event.preventDefault(); |
|
192 |
$.ajax({ |
|
193 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
194 |
dataType: "json", |
|
195 |
data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), |
|
196 |
success: function (data) { |
|
197 |
if (data.length == 1) { |
|
198 |
set_item(data[0]); |
|
199 |
if (event.which == KEY.ENTER) |
|
200 |
$('#update_button').click(); |
|
201 |
} else if (data.length > 1) { |
|
202 |
if (event.which == KEY.ENTER) |
|
203 |
open_dialog(); |
|
204 |
} else { |
|
205 |
} |
|
206 |
annotate_state(); |
|
207 |
} |
|
208 |
}); |
|
209 |
if (event.which == KEY.ENTER) |
|
212 |
if (event.which == KEY.TAB) { |
|
213 |
event.preventDefault(); |
|
214 |
handle_changed_text(); |
|
215 |
} |
|
216 |
if (event.which == KEY.ENTER) { |
|
217 |
handle_changed_text({ |
|
218 |
match_one: function(){$('#update_button').click();}, |
|
219 |
match_many: function(){open_dialog();} |
|
220 |
}); |
|
210 | 221 |
return false; |
222 |
} |
|
211 | 223 |
} else { |
212 | 224 |
state = STATES.UNDEFINED; |
213 | 225 |
} |
214 | 226 |
}); |
215 | 227 |
|
228 |
$dummy.on('paste', function(){ |
|
229 |
setTimeout(function() { |
|
230 |
handle_changed_text(); |
|
231 |
}, 1); |
|
232 |
}); |
|
233 |
|
|
216 | 234 |
$dummy.blur(function(){ |
217 | 235 |
window.clearTimeout(timer); |
218 | 236 |
timer = window.setTimeout(annotate_state, 100); |
Auch abrufbar als: Unified diff
PartPicker: Auch auf Paste-Events reagieren.
Damit wird bei eindeutigem eingefügtem Text der entsprechende Artikel
ausgewählt. Ansonsten wird der Text rot (undefined) dargestellt.
Vorher war es möglich, z.B. eine eindeutige Artikelnummer einzufügen, aber
intern war dennoch kein Artikel ausgewählt. In der Anzeige sah es aber so aus,
als sei alles in Ordnung.