X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FPriceRule.pm;h=0579c534935ad7e6a31cde93eb1b2bda8799e1d4;hb=d4925a8b60f04674885e30d9316dc0263f8b9a84;hp=23dacc03cf821bc92c071c78646c80b9ce6b404b;hpb=bc8c26f36837b8f7e7ded304cdf475b479999277;p=kivitendo-erp.git diff --git a/SL/Controller/PriceRule.pm b/SL/Controller/PriceRule.pm index 23dacc03c..0579c5349 100644 --- a/SL/Controller/PriceRule.pm +++ b/SL/Controller/PriceRule.pm @@ -13,12 +13,11 @@ use SL::DB::Pricegroup; use SL::DB::PartsGroup; use SL::DB::Business; use SL::Helper::Flash; -use SL::ClientJS; use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(models price_rule vc js pricegroups partsgroups businesses) ], + 'scalar --get_set_init' => [ qw(models price_rule vc pricegroups partsgroups businesses) ], ); # __PACKAGE__->run_before('check_auth'); @@ -35,6 +34,8 @@ sub action_list { my $price_rules = $self->models->get; + $self->setup_search_action_bar; + $self->prepare_report; $self->report_generator_list_objects(report => $self->{report}, objects => $price_rules, $::form->{inline} ? (layout => 0, header => 0) : ()); @@ -87,7 +88,7 @@ sub action_add_item_row { ->js ->before('#price_rule_new_items', $html) ->reinit_widgets - ->render($self); + ->render; } sub action_price_type_help { @@ -109,15 +110,36 @@ sub check_auth { sub display_form { my ($self, %params) = @_; my $is_new = !$self->price_rule->id; - my $title = $is_new ? - ($self->price_rule->is_sales ? t8('Create a new sales price rule') : t8('Create a new purchase price rule')) : - ($self->price_rule->is_sales ? t8('Edit sales price rule') : t8('Edit purchase price rule')); + my $title = $self->form_title(($is_new ? 'create' : 'edit'), $self->price_rule->type); + $self->setup_form_action_bar; $self->render('price_rule/form', title => $title, %params ); } +sub form_title { + my ($self, $action, $type) = @_; + + return { + edit => { + customer => t8('Edit sales price rule'), + vendor => t8('Edit purchase price rule'), + '' => t8('Edit price rule'), + }, + create => { + customer => t8('Create a new sales price rule'), + vendor => t8('Create a new purchase price rule'), + '' => t8('Create a new price rule'), + }, + list => { + customer => t8('Sales Price Rules'), + vendor => t8('Purchase Price Rules'), + '' => t8('Price Rules'), + }, + }->{$action}{$type}; +} + sub create_or_update { my $self = shift; my $is_new = !$self->price_rule->id; @@ -171,7 +193,7 @@ sub prepare_report { std_column_visibility => 1, controller_class => 'PriceRule', output_format => 'HTML', - title => ($self->vc eq 'customer' ? t8('Sales Price Rules') : t8('Purchase Price Rules')) , + title => $self->form_title('list', $self->vc), allow_pdf_export => !$::form->{inline}, allow_csv_export => !$::form->{inline}, ); @@ -217,7 +239,7 @@ sub all_price_rule_item_types { } sub add_javascripts { - $::request->{layout}->add_javascripts(qw(kivi.PriceRule.js autocomplete_customer.js autocomplete_vendor.js autocomplete_part.js)); + $::request->{layout}->add_javascripts(qw(kivi.PriceRule.js autocomplete_vendor.js kivi.Part.js kivi.CustomerVendor.js)); } sub init_price_rule { @@ -247,16 +269,12 @@ sub init_vc { $::form->{filter}{type}; } -sub init_js { - SL::ClientJS->new; -} - sub init_businesses { SL::DB::Manager::Business->get_all; } sub init_pricegroups { - SL::DB::Manager::Pricegroup->get_all; + SL::DB::Manager::Pricegroup->get_all_sorted; } sub init_partsgroups { @@ -285,4 +303,71 @@ sub init_models { ); } +sub setup_search_action_bar { + my ($self, %params) = @_; + + return if $::form->{inline}; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#search_form', { action => 'PriceRule/list' } ], + accesskey => 'enter', + ], + + combobox => [ + action => [ + t8('Add'), + ], + link => [ + t8('New Sales Price Rule'), + link => $self->url_for(action => 'new', 'price_rule.type' => 'customer', callback => $self->models->get_callback), + ], + link => [ + t8('New Purchase Price Rule'), + link => $self->url_for(action => 'new', 'price_rule.type' => 'vendor', callback => $self->models->get_callback), + ], + ], # end of combobox "Add" + ); + } +} + +sub setup_form_action_bar { + my ($self) = @_; + + my $is_new = !$self->price_rule->id; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + combobox => [ + action => [ + $is_new ? t8('Create') : t8('Save'), + submit => [ '#form', { action => 'PriceRule/' . ($is_new ? 'create' : 'update') } ], + accesskey => 'enter', + ], + action => [ + t8('Use as new'), + submit => [ '#form', { action => 'PriceRule/create' } ], + disabled => $is_new ? t8('The object has not been saved yet.') : undef, + ], + ], # end of combobox "Save" + + action => [ + t8('Delete'), + submit => [ '#form', { action => 'PriceRule/destroy' } ], + confirm => t8('Do you really want to delete this object?'), + disabled => $is_new ? t8('The object has not been saved yet.') + : $self->price_rule->in_use ? t8('This object has already been used.') + : undef, + ], + + link => [ + t8('Abort'), + link => $self->url_for(action => 'list', 'filter.type' => $self->price_rule->type), + ], + ); + } +} + 1;