Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5cec90ad

Von Sven Schöling vor mehr als 11 Jahren hinzugefügt

  • ID 5cec90adf75c31ded8818f1348341563133daec7
  • Vorgänger 5e85b326
  • Nachfolger c2d1e374

caching der Widget und javascriptteile nach js/ verschoben

Unterschiede anzeigen:

js/autocomplete_part.js
1 1
namespace('kivi', function(k){
2
  k.part_picker = function($real, options) {
2
  k.PartPickerCache = { }
3
  k.PartPicker = function($real, options) {
3 4
    var o = $.extend({
4 5
      limit: 20,
5 6
      delay: 50,
......
64 65
        set_item({ id: last_real, name: last_dummy })
65 66
    }
66 67

  
68
    function update_results () {
69
      $.ajax({
70
        url: 'controller.pl?action=Part/part_picker_result',
71
        data: {
72
          'filter.all:substr::ilike': function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val },
73
          'filter.type': $type.val(),
74
          'column': $column.val(),
75
          'real_id': $real.val,
76
        },
77
        success: function(data){ $('#part_picker_result').html(data) }
78
      });
79
    };
80

  
67 81
    $dummy.autocomplete({
68 82
      source: function(req, rsp) {
69 83
        $.ajax($.extend(o, {
......
129 143
    $dummy.after(pcont);
130 144
    pcont.append(picker);
131 145
    picker.addClass('icon16 CRM--Schnellsuche').click(open_dialog);
146

  
147
    return {
148
      real:     function() { return $real },
149
      dummy:    function() { return $dummy },
150
      type:     function() { return $type },
151
      column:   function() { return $column },
152
      update_results: update_results,
153
      set_item: set_item,
154
      reset:    make_defined_state,
155
    }
132 156
  }
133 157
});
134 158

  
135 159
$(function(){
136 160
  $('input.part_autocomplete').each(function(i,real){
137
    kivi.part_picker($(real));
161
    kivi.PartPickerCache[real.id] = new kivi.PartPicker($(real));
138 162
  })
139 163
});
templates/webpages/part/_part_picker_result.html
26 26
[% L.paginate_controls(target='#part_picker_result', selector='#part_picker_result') %]
27 27

  
28 28
<script type='text/javascript'>
29
  var pp = kivi.PartPickerCache[$('#part_picker_real_id').val()];
29 30
  $('div.part_picker_part').each(function(){
30 31
    $(this).click(function(){
31
      var real_id = $('#part_picker_real_id').val();
32
      var $dummy  = $('#' + real_id + '_name');
33
      var $real   = $('#' + real_id);
34

  
35
      $dummy.val($(this).children('input.part_picker_description').val());
36
      $real.val($(this).children('input.part_picker_id').val());
37
      $real.trigger('change');
38

  
32
      pp.set_item({
33
        name: $(this).children('input.part_picker_description').val(),
34
        id:   $(this).children('input.part_picker_id').val(),
35
      });
39 36
      $('#part_selection').jqmClose();
40

  
41 37
      return true;
42 38
    });
43 39
  });
templates/webpages/part/part_picker_search.html
15 15

  
16 16
<script type='text/javascript'>
17 17
  var timer;
18
  var update_results = function(){
19
    var $type   = $('#[% FORM.real_id %]_type');
20
    var $column = $('#[% FORM.real_id %]_column');
21
    $.ajax({
22
      url: 'controller.pl?action=Part/part_picker_result',
23
      data: {
24
        'filter.all:substr::ilike': function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val },
25
        'filter.type': function(){ return $type.val() },
26
        'column': function(){ return $column.val() },
27
        'real_id': [% FORM.real_id.json %],
28
      },
29
      success: function(data){ $('#part_picker_result').html(data) }
30
    });
31
  };
18
  var pp = kivi.PartPickerCache['[% FORM.real_id %]'];
32 19
  $(function(){
33 20
    $('#part_picker_filter').focus();
34
    update_results();
21
    pp.update_results();
35 22
  });
36 23
  $('#part_picker_filter').keypress(function (event){
37 24
    window.clearTimeout(timer);
38
    timer = window.setTimeout(update_results, 100);
25
    timer = window.setTimeout(pp.update_results, 100);
39 26
  });
40 27
</script>

Auch abrufbar als: Unified diff