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;
$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} },
# 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);
}
}
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'),
$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},
);
}
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__