--- /dev/null
+package SL::Controller::Customer;
+
+use strict;
+use parent qw(SL::Controller::Base);
+
+use SL::DB::Customer;
+
+# safety
+__PACKAGE__->run_before(sub { $::auth->assert('customer_vendor_edit') });
+
+sub action_ajax_autocomplete {
+ my ($self, %params) = @_;
+
+ my $limit = $::form->{limit} || 20;
+ my $type = $::form->{type} || {};
+ my $query = { ilike => "%$::form->{term}%" };
+ my @filter;
+ push @filter, ($::form->{column})
+ ? ($::form->{column} => $query)
+ : (or => [ customernumber => $query, name => $query ]);
+
+ $self->{customers} = SL::DB::Manager::Customer->get_all(query => [ @filter ], limit => $limit);
+ $self->{value} = $::form->{column} || 'name';
+
+ $self->render('ct/ajax_autocomplete2', { no_layout => 1 });
+}
+
'<script type="text/javascript" src="js/jscalendar/calendar.js"></script>',
'<script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>',
'<script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>',
- '<script type="text/javascript" src="js/part_selection.js"></script>';
+ '<script type="text/javascript" src="js/part_selection.js"></script>',
+ '<script type="text/javascript" src="js/jquery-ui.js"></script>',
+ '<style "type=text/css">@import url("css/ui-lightness/jquery-ui-1.8.12.custom.css")</style>';
push @header, $self->{javascript} if $self->{javascript};
push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] };
push @header, "<script type='text/javascript'>function fokus(){ document.$self->{fokus}.focus(); }</script>" if $self->{fokus};
) : '');
}
+sub customer_picker {
+ my ($self, $name, $value, %params) = @_;
+ my $name_e = _H($name);
+
+ $self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') .
+ $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) .
+ $self->javascript(<<JS);
+function autocomplete_customer (selector, column) {
+ \$(function(){ \$(selector).autocomplete({
+ source: function(req, rsp) {
+ \$.ajax({
+ url: 'controller.pl?action=Customer/ajax_autocomplete',
+ dataType: "json",
+ data: {
+ column: column,
+ term: req.term,
+ current: function() { \$('#$name_e').val() },
+ obsolete: 0,
+ },
+ success: function (data){ rsp(data) }
+ });
+ },
+ limit: 20,
+ delay: 50,
+ select: function(event, ui) {
+ \$('#$name_e').val(ui.item.id);
+ \$('#$name_e\_name').val(ui.item.name);
+ },
+ })});
+}
+autocomplete_customer('#$name_e\_name');
+JS
+}
+
sub javascript_tag {
my $self = shift;
my $code = '';
--- /dev/null
+[%- USE HTML %][% USE JSON %][
+[%- FOREACH customer = SELF.customers %]
+ {
+ "value": [% customer.${SELF.value}.json %],
+ "label": [% customer.displayable_name.json %],
+ "id": [% customer.id.json %],
+ "customernumber": [% customer.customernumber.json %],
+ "name": [% customer.name.json %]
+ }[% ',' UNLESS loop.last %]
+[%- END %]
+]
--- /dev/null
+[% USE L %]
+[% USE T8 %]
+[% USE LxERP %]
+[% L.javascript_tag('jquery-ui') %]
+<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.12.custom.css" type="text/css" />
+
+<p>Pick a customer</p>
+id: [% L.input_tag('customer_id', '') %]
+nr: [% L.input_tag('customer_customernumber', '') %]
+desc: [% L.input_tag('customer_name', '') %]
+
+<script type='text/javascript'>
+function autocomplete_customer (selector, column) {
+ $(function(){ $(selector).autocomplete({
+ source: function(req, rsp) {
+ $.ajax({
+ url: 'controller.pl?action=Customer/ajax_autocomplete',
+ dataType: "json",
+ data: {
+ column: column,
+ term: req.term,
+ current: function() { $('#customer_id').val() },
+ obsolete: 0,
+ },
+ success: function (data){ rsp(data) }
+ });
+ },
+ limit: 20,
+ delay: 50,
+ select: function(event, ui) {
+ $('#customer_id').val(ui.item.id);
+ $('#customer_customernumber').val(ui.item.customernumber);
+ $('#customer_name').val(ui.item.name);
+ },
+ })});
+}
+//autocomplete_customer('#customer_customernumber', 'customernumber');
+autocomplete_customer('#customer_name', '');
+</script>
+