namespace('kivi', function(k){
- k.part_picker = function($real, options) {
+ k.PartPickerCache = { }
+ k.PartPicker = function($real, options) {
var o = $.extend({
limit: 20,
delay: 50,
set_item({ id: last_real, name: last_dummy })
}
+ function update_results () {
+ $.ajax({
+ url: 'controller.pl?action=Part/part_picker_result',
+ data: {
+ 'filter.all:substr::ilike': function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val },
+ 'filter.type': $type.val(),
+ 'column': $column.val(),
+ 'real_id': $real.val,
+ },
+ success: function(data){ $('#part_picker_result').html(data) }
+ });
+ };
+
$dummy.autocomplete({
source: function(req, rsp) {
$.ajax($.extend(o, {
$dummy.after(pcont);
pcont.append(picker);
picker.addClass('icon16 CRM--Schnellsuche').click(open_dialog);
+
+ return {
+ real: function() { return $real },
+ dummy: function() { return $dummy },
+ type: function() { return $type },
+ column: function() { return $column },
+ update_results: update_results,
+ set_item: set_item,
+ reset: make_defined_state,
+ }
}
});
$(function(){
$('input.part_autocomplete').each(function(i,real){
- kivi.part_picker($(real));
+ kivi.PartPickerCache[real.id] = new kivi.PartPicker($(real));
})
});
[% L.paginate_controls(target='#part_picker_result', selector='#part_picker_result') %]
<script type='text/javascript'>
+ var pp = kivi.PartPickerCache[$('#part_picker_real_id').val()];
$('div.part_picker_part').each(function(){
$(this).click(function(){
- var real_id = $('#part_picker_real_id').val();
- var $dummy = $('#' + real_id + '_name');
- var $real = $('#' + real_id);
-
- $dummy.val($(this).children('input.part_picker_description').val());
- $real.val($(this).children('input.part_picker_id').val());
- $real.trigger('change');
-
+ pp.set_item({
+ name: $(this).children('input.part_picker_description').val(),
+ id: $(this).children('input.part_picker_id').val(),
+ });
$('#part_selection').jqmClose();
-
return true;
});
});
<script type='text/javascript'>
var timer;
- var update_results = function(){
- var $type = $('#[% FORM.real_id %]_type');
- var $column = $('#[% FORM.real_id %]_column');
- $.ajax({
- url: 'controller.pl?action=Part/part_picker_result',
- data: {
- 'filter.all:substr::ilike': function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val },
- 'filter.type': function(){ return $type.val() },
- 'column': function(){ return $column.val() },
- 'real_id': [% FORM.real_id.json %],
- },
- success: function(data){ $('#part_picker_result').html(data) }
- });
- };
+ var pp = kivi.PartPickerCache['[% FORM.real_id %]'];
$(function(){
$('#part_picker_filter').focus();
- update_results();
+ pp.update_results();
});
$('#part_picker_filter').keypress(function (event){
window.clearTimeout(timer);
- timer = window.setTimeout(update_results, 100);
+ timer = window.setTimeout(pp.update_results, 100);
});
</script>