Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cb3a2467

Von Sven Schöling vor etwa 13 Jahren hinzugefügt

  • ID cb3a2467f28049de15810f7ddf1b04632639e530
  • Vorgänger e7d2012d
  • Nachfolger ef90159c

customer_picker

testpage ist zu Dokumentationszwecken noch dabei, aber nicht mehr durch action
erreichbar.

Unterschiede anzeigen:

SL/Controller/Customer.pm
1
package SL::Controller::Customer;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use SL::DB::Customer;
7

  
8
# safety
9
__PACKAGE__->run_before(sub { $::auth->assert('customer_vendor_edit') });
10

  
11
sub action_ajax_autocomplete {
12
  my ($self, %params) = @_;
13

  
14
  my $limit  = $::form->{limit}  || 20;
15
  my $type   = $::form->{type} || {};
16
  my $query  = { ilike => "%$::form->{term}%" };
17
  my @filter;
18
  push @filter, ($::form->{column})
19
    ? ($::form->{column} => $query)
20
    : (or => [ customernumber => $query, name => $query ]);
21

  
22
  $self->{customers} = SL::DB::Manager::Customer->get_all(query => [ @filter ], limit => $limit);
23
  $self->{value} = $::form->{column} || 'name';
24

  
25
  $self->render('ct/ajax_autocomplete2', { no_layout => 1 });
26
}
27

  
SL/Form.pm
701 701
                '<script type="text/javascript" src="js/jscalendar/calendar.js"></script>',
702 702
                '<script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>',
703 703
                '<script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>',
704
                '<script type="text/javascript" src="js/part_selection.js"></script>';
704
                '<script type="text/javascript" src="js/part_selection.js"></script>',
705
                '<script type="text/javascript" src="js/jquery-ui.js"></script>',
706
                '<style "type=text/css">@import url("css/ui-lightness/jquery-ui-1.8.12.custom.css")</style>';
705 707
  push @header, $self->{javascript} if $self->{javascript};
706 708
  push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] };
707 709
  push @header, "<script type='text/javascript'>function fokus(){ document.$self->{fokus}.focus(); }</script>" if $self->{fokus};
SL/Template/Plugin/L.pm
291 291
  ) : '');
292 292
}
293 293

  
294
sub customer_picker {
295
  my ($self, $name, $value, %params) = @_;
296
  my $name_e    = _H($name);
297

  
298
  $self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') .
299
  $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) .
300
  $self->javascript(<<JS);
301
function autocomplete_customer (selector, column) {
302
  \$(function(){ \$(selector).autocomplete({
303
    source: function(req, rsp) {
304
      \$.ajax({
305
        url: 'controller.pl?action=Customer/ajax_autocomplete',
306
        dataType: "json",
307
        data: {
308
          column: column,
309
          term: req.term,
310
          current: function() { \$('#$name_e').val() },
311
          obsolete: 0,
312
        },
313
        success: function (data){ rsp(data) }
314
      });
315
    },
316
    limit: 20,
317
    delay: 50,
318
    select: function(event, ui) {
319
      \$('#$name_e').val(ui.item.id);
320
      \$('#$name_e\_name').val(ui.item.name);
321
    },
322
  })});
323
}
324
autocomplete_customer('#$name_e\_name');
325
JS
326
}
327

  
294 328
sub javascript_tag {
295 329
  my $self = shift;
296 330
  my $code = '';
templates/webpages/ct/ajax_autocomplete2.html
1
[%- USE HTML %][% USE JSON %][
2
[%- FOREACH customer = SELF.customers %]
3
 {
4
   "value": [% customer.${SELF.value}.json %],
5
   "label": [% customer.displayable_name.json %],
6
   "id": [% customer.id.json %],
7
   "customernumber": [% customer.customernumber.json %],
8
   "name": [% customer.name.json %]
9
  }[% ',' UNLESS loop.last %]
10
[%- END %]
11
]
templates/webpages/ct/testpage.html
1
[% USE L %]
2
[% USE T8 %]
3
[% USE LxERP %]
4
[% L.javascript_tag('jquery-ui') %]
5
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.12.custom.css" type="text/css" />
6

  
7
<p>Pick a customer</p>
8
id: [% L.input_tag('customer_id', '') %]
9
nr: [% L.input_tag('customer_customernumber', '') %]
10
desc: [% L.input_tag('customer_name', '') %]
11

  
12
<script type='text/javascript'>
13
function autocomplete_customer (selector, column) {
14
  $(function(){ $(selector).autocomplete({
15
    source: function(req, rsp) {
16
      $.ajax({
17
        url: 'controller.pl?action=Customer/ajax_autocomplete',
18
        dataType: "json",
19
        data: {
20
          column: column,
21
          term: req.term,
22
          current: function() { $('#customer_id').val() },
23
          obsolete: 0,
24
        },
25
        success: function (data){ rsp(data) }
26
      });
27
    },
28
    limit: 20,
29
    delay: 50,
30
    select: function(event, ui) {
31
      $('#customer_id').val(ui.item.id);
32
      $('#customer_customernumber').val(ui.item.customernumber);
33
      $('#customer_name').val(ui.item.name);
34
    },
35
  })});
36
}
37
//autocomplete_customer('#customer_customernumber', 'customernumber');
38
autocomplete_customer('#customer_name', '');
39
</script>
40

  

Auch abrufbar als: Unified diff