From 57faab8f922edc190b6909b7626a445423de6676 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 3 Apr 2014 14:43:40 +0200 Subject: [PATCH] Part api Funktion um eine Ware als json abzufragen --- SL/Controller/Part.pm | 34 ++++++++++++++++++++++++++++++---- SL/DB/Part.pm | 1 + js/autocomplete_part.js | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 4349b1fda..e64a774a7 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -10,7 +10,7 @@ use SL::Locale::String qw(t8); use SL::JSON; use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(parts models) ], + 'scalar --get_set_init' => [ qw(parts models part) ], ); # safety @@ -33,8 +33,8 @@ sub action_ajax_autocomplete { obsolete => 0, SL::DB::Manager::Part->type_filter($::form->{filter}{type}), or => [ - description => { ilike => $::form->{filter}{'all:substr::ilike'} }, - partnumber => { ilike => $::form->{filter}{'all:substr::ilike'} }, + description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, + partnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, ] ], limit => 2, @@ -72,10 +72,35 @@ sub action_part_picker_result { $_[0]->render('part/_part_picker_result', { layout => 0 }); } +sub action_show { + my ($self) = @_; + + if ($::request->type eq 'json') { + my $part_hash; + if (!$self->part) { + # TODO error + } else { + require Rose::DB::Object::Helpers; + $part_hash = $self->part->as_tree; + $part_hash->{cvars} = $self->part->cvar_as_hashref; + } + + $self->render(\ SL::JSON::to_json($part_hash), { layout => 0, type => 'json', process => 0 }); + } +} + sub init_parts { + if ($::form->{no_paginate}) { + $_[0]->models->disable_plugin('paginated'); + } + $_[0]->models->get; } +sub init_part { + SL::DB::Part->new(id => $::form->{id} || $::form->{part}{id})->load; +} + sub init_models { my ($self) = @_; @@ -83,10 +108,11 @@ sub init_models { controller => $self, sorted => { _default => { - by => 'partnumber', + by => 'description', dir => 1, }, partnumber => t8('Partnumber'), + description => t8('Description'), }, with_objects => [ qw(unit_obj) ], ); diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index ecdaeaabe..9f2c4bd52 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -4,6 +4,7 @@ use strict; use Carp; use List::MoreUtils qw(any); +use Rose::DB::Object::Helpers qw(as_tree); use SL::DBUtils; use SL::DB::MetaSetup::Part; diff --git a/js/autocomplete_part.js b/js/autocomplete_part.js index 62c1bf4bf..a08130b63 100644 --- a/js/autocomplete_part.js +++ b/js/autocomplete_part.js @@ -53,7 +53,7 @@ namespace('kivi', function(k){ function ajax_data(term) { var data = { - 'filter.all:substr::ilike': term, + 'filter.all:substr:multi::ilike': term, 'filter.obsolete': 0, 'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '', no_paginate: $('#no_paginate').prop('checked') ? 1 : 0, -- 2.20.1