X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FPart.pm;h=de2cb1d283441f533ac43c749d4df308cfd7ece2;hb=4fef059183b047e18d8fee7b4b75195b83d6ef23;hp=fce0b6fb305982304a19769c1c522d9cc925cb58;hpb=905d9eddfafc30dd4c53e892a6070035f28e6ce0;p=kivitendo-erp.git diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index fce0b6fb3..de2cb1d28 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -194,6 +194,7 @@ sub render_form { my ($self, %params) = @_; $self->_set_javascript; + $self->_setup_form_action_bar; my (%assortment_vars, %assembly_vars); %assortment_vars = %{ $self->prepare_assortment_render_vars } if $self->part->is_assortment; @@ -216,7 +217,6 @@ sub render_form { $self->render( 'part/form', title => $title_hash{$self->part->part_type}, - show_edit_buttons => $::auth->assert('part_service_assembly_edit'), %assortment_vars, %assembly_vars, translations_map => { map { ($_->language_id => $_) } @{$self->part->translations} }, @@ -500,22 +500,19 @@ sub action_ajax_autocomplete { # if someone types something, and hits enter, assume he entered the full name. # if something matches, treat that as sole match - # unfortunately get_models can't do more than one per package atm, so we d it - # the oldfashioned way. + # since we need a second get models instance with different filters for that, + # we only modify the original filter temporarily in place if ($::form->{prefer_exact}) { + local $::form->{filter}{'all::ilike'} = delete local $::form->{filter}{'all:substr:multi::ilike'}; + + my $exact_models = SL::Controller::Helper::GetModels->new( + controller => $self, + sorted => 0, + paginated => { per_page => 2 }, + with_objects => [ qw(unit_obj classification) ], + ); my $exact_matches; - if (1 == scalar @{ $exact_matches = SL::DB::Manager::Part->get_all( - query => [ - obsolete => 0, - SL::DB::Manager::Part->type_filter($::form->{filter}{part_type}), - SL::DB::Manager::PartClassification->classification_filter($::form->{filter}{classification_id}), - or => [ - description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, - partnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, - ] - ], - limit => 2, - ) }) { + if (1 == scalar @{ $exact_matches = $exact_models->get }) { $self->parts($exact_matches); } } @@ -599,6 +596,7 @@ sub add { check_has_valid_part_type($self->part->part_type); $self->_set_javascript; + $self->_setup_form_action_bar; my %title_hash = ( part => t8('Add Part'), assembly => t8('Add Assembly'), @@ -608,8 +606,7 @@ sub add { $self->render( 'part/form', - title => $title_hash{$self->part->part_type}, - show_edit_buttons => $::auth->assert('part_service_assembly_edit'), + title => $title_hash{$self->part->part_type}, ); } @@ -1130,6 +1127,51 @@ sub parse_add_items_to_objects { return \@item_objects; } +sub _setup_form_action_bar { + my ($self) = @_; + + my $may_edit = $::auth->assert('part_service_assembly_edit', 'may fail'); + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + combobox => [ + action => [ + t8('Save'), + call => [ 'kivi.Part.save' ], + disabled => !$may_edit ? t8('You do not have the permissions to access this function.') : undef, + ], + action => [ + t8('Use as new'), + call => [ 'kivi.Part.use_as_new' ], + disabled => !$self->part->id ? t8('The object has not been saved yet.') + : !$may_edit ? t8('You do not have the permissions to access this function.') + : undef, + ], + ], # end of combobox "Save" + + action => [ + t8('Delete'), + call => [ 'kivi.Part.delete' ], + confirm => t8('Do you really want to delete this object?'), + disabled => !$self->part->id ? t8('This object has not been saved yet.') + : !$may_edit ? t8('You do not have the permissions to access this function.') + : !$self->part->orphaned ? t8('This object has already been used.') + : undef, + ], + + 'separator', + + action => [ + t8('History'), + call => [ 'kivi.Part.open_history_popup' ], + disabled => !$self->part->id ? t8('This object has not been saved yet.') + : !$may_edit ? t8('You do not have the permissions to access this function.') + : undef, + ], + ); + } +} + 1; __END__