Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9c194331

Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt

  • ID 9c19433144efc5b50d90a969aa9ac6ea65b2dbbf
  • Vorgänger 945bae4c
  • Nachfolger cd07d289

SimpleSystemSetting: Umstellung von »Warengruppen«

Unterschiede anzeigen:

SL/Controller/PartsGroup.pm
package SL::Controller::PartsGroup;
use strict;
use parent qw(SL::Controller::Base);
use SL::Helper::Flash;
use SL::Locale::String;
use SL::DB::Default;
use SL::DB::Manager::PartsGroup;
use Rose::Object::MakeMethods::Generic (
scalar => [ qw(partsgroup) ],
'scalar --get_set_init' => [ qw(all_partsgroups) ],
);
__PACKAGE__->run_before('check_auth');
__PACKAGE__->run_before('load_partsgroup', only => [ qw(edit update delete) ]);
#
# actions
#
sub action_list {
my ($self) = @_;
$self->render('partsgroup/list',
title => t8('Partsgroups'),
);
}
sub action_new {
my ($self) = @_;
$self->partsgroup( SL::DB::PartsGroup->new );
$self->render('partsgroup/form',
title => t8('Add partsgroup'),
);
}
sub action_edit {
my ($self) = @_;
$self->render('partsgroup/form',
title => t8('Edit partsgroup'),
);
}
sub action_create {
my ($self) = @_;
$self->partsgroup( SL::DB::PartsGroup->new );
$self->create_or_update;
}
sub action_update {
my ($self) = @_;
$self->create_or_update;
}
sub action_delete {
my ($self) = @_;
if ( !$self->partsgroup->orphaned ) {
flash_later('error', $::locale->text('The partsgroup has been used and cannot be deleted.'));
} elsif ( eval { $self->partsgroup->delete; 1; } ) {
flash_later('info', $::locale->text('The partsgroup has been deleted.'));
} else {
flash_later('error', $::locale->text('The partsgroup has been used and cannot be deleted.'));
};
$self->redirect_to(action => 'list');
}
sub action_reorder {
my ($self) = @_;
SL::DB::PartsGroup->reorder_list(@{ $::form->{partsgroup_id} || [] });
$self->render(\'', { type => 'json' });
}
#
# filters
#
sub check_auth {
$::auth->assert('config');
}
sub load_partsgroup {
my ($self) = @_;
$self->partsgroup( SL::DB::PartsGroup->new(id => $::form->{id})->load );
}
sub init_all_partsgroups { SL::DB::Manager::PartsGroup->get_all_sorted }
#
# helpers
#
sub create_or_update {
my ($self) = @_;
my $is_new = !$self->partsgroup->id;
my $params = delete($::form->{partsgroup}) || { };
$self->partsgroup->assign_attributes(%{ $params });
my @errors = $self->partsgroup->validate;
if (@errors) {
flash('error', @errors);
$self->render('partsgroup/form',
title => $is_new ? t8('Add partsgroup') : t8('Edit partsgroup'),
);
return;
}
$self->partsgroup->save;
flash_later('info', $is_new ? t8('The partsgroup has been created.') : t8('The partsgroup has been saved.'));
$self->redirect_to(action => 'list');
}
1;
__END__
=encoding utf-8
=head1 NAME
SL::Controller::PartsGroup - CRUD controller for partsgroups
=head1 SYNOPSIS
A new controller to create / edit / delete partsgroups.
Partsgroups can only be deleted if they haven't been used anywhere.
=head1 OBSOLETE PARTSGROUPS
A partsgroup can be deleted if it hasn't been used anywhere / is orphaned.
A partsgroup can be set to obsolete, which means new items can't be assigned
that partsgroup, but old items with that partsgroup can keep it. And you can
also still filter for these obsolete partsgroups in reports.
=head1 ISSUES
Unlike the old version (pe.pl/PE.pm), there is no way to filter/search the
partsgroups in the overview page, it always shows the complete (ordered) list,
ordered by sortkey.
=head1 AUTHOR
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
=cut
SL/Controller/SimpleSystemSetting.pm
],
},
parts_group => {
# Make locales.pl happy: $self->render("simple_system_setting/_parts_group_form")
class => 'PartsGroup',
titles => {
list => t8('Partsgroups'),
add => t8('Add partsgroup'),
edit => t8('Edit partsgroup'),
},
list_attributes => [
{ method => 'partsgroup', title => t8('Description') },
{ method => 'obsolete', title => t8('Obsolete'), formatter => sub { $_[0]->obsolete ? t8('yes') : t8('no') } },
],
},
pricegroup => {
# Make locales.pl happy: $self->render("simple_system_setting/_pricegroup_form")
class => 'Pricegroup',
locale/de/all
'The parts for this delivery order have already been transferred out.' => 'Die Artikel dieses Lieferscheins wurden bereits ausgelagert.',
'The parts have been removed.' => 'Die Waren wurden aus dem Lager entnommen.',
'The parts have been transferred.' => 'Die Waren wurden umgelagert.',
'The partsgroup has been created.' => 'Die Warengruppe wurde erstellt.',
'The partsgroup has been deleted.' => 'Die Warengruppe wurde gelöscht.',
'The partsgroup has been saved.' => 'Die Warengruppe wurde gespeichert.',
'The partsgroup has been used and cannot be deleted.' => 'Die Warengruppe wurde bereits verwendet und kann nicht gelöscht werden.',
'The password is too long (maximum length: #1).' => 'Das Passwort ist zu lang (maximale Länge: #1).',
'The password is too short (minimum length: #1).' => 'Das Password ist zu kurz (minimale Länge: #1).',
'The password is weak (e.g. it can be found in a dictionary).' => 'Das Passwort ist schwach (z.B. wenn es in einem Wörterbuch steht).',
menus/user/00-erp.yaml
name: Partsgroups
order: 900
params:
action: PartsGroup/list
action: SimpleSystemSetting/list
type: parts_group
- parent: system
id: system_part_classification
name: Parts Classification
templates/webpages/partsgroup/form.html
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]
[% SET style="width: 400px" %]
[% SET size=15 %]
<h1>[% HTML.escape(title) %]</h1>
<form action="controller.pl" method="post">
[%- INCLUDE 'common/flash.html' %]
[%- L.hidden_tag("id", SELF.partsgroup.id) %]
<table>
<tr>
<th align="right">[% 'Description' | $T8 %]</th>
<td>
[%- L.input_tag("partsgroup.partsgroup", SELF.partsgroup.partsgroup) %]
</td>
[% IF SELF.partsgroup.id %]
<tr>
<th align="right">[% 'Obsolete' | $T8 %]</th>
<td>[% L.checkbox_tag('partsgroup.obsolete', checked = SELF.partsgroup.obsolete, for_submit=1) %]</td>
</tr>
</tr>
[% END %]
</table>
<p>
[% L.hidden_tag("action", "PartsGroup/dispatch") %]
[% L.submit_tag("action_" _ (SELF.partsgroup.id ? "update" : "create"), LxERP.t8('Save'), onclick="return check_prerequisites();") %]
[%- IF SELF.partsgroup.id AND SELF.partsgroup.orphaned -%]
[% L.submit_tag("action_delete", LxERP.t8('Delete')) %]
[%- END %]
<a href="[% SELF.url_for(action='list') %]">[%- LxERP.t8("Cancel") %]</a>
</p>
<hr>
<script type="text/javascript">
<!--
function check_prerequisites() {
if ($('#partsgroup_partsgroup').val() === "") {
alert(kivi.t8('The description is missing.'));
return false;
}
return true;
}
-->
</script>
templates/webpages/partsgroup/list.html
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%][%- INCLUDE 'common/flash.html' %]
<h1>[% title %]</h1>
<p>
<table width="100%" id="partsgroup_list">
<thead>
<tr class="listheading">
<th align="center" width="1%"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></th>
<th>[% 'Description' | $T8 %]</th>
<th>[% 'Obsolete' | $T8 %]</th>
</tr>
</thead>
<tbody>
[%- FOREACH partsgroup = SELF.all_partsgroups %]
<tr class="listrow" id="partsgroup_id_[% partsgroup.id %]">
<td align="center" class="dragdrop"><img src="image/updown.png" alt="[ LxERP.t8('reorder item') %]"></td>
<td><a href="[% SELF.url_for(action='edit', id=partsgroup.id) %]">[% HTML.escape(partsgroup.partsgroup) %]</a></td>
<td>[% HTML.escape(partsgroup.obsolete) %]</a></td>
</tr>
[%- END %]
</tbody>
</table>
</p>
<hr height="3">
[% L.sortable_element('#partsgroup_list tbody', url=SELF.url_for(action='reorder'), with='partsgroup_id') %]
<p>
<a href="[% SELF.url_for(action='new') %]">[%- 'Add' | $T8 %]</a>
</p>
templates/webpages/simple_system_setting/_parts_group_form.html
[%- USE LxERP -%][%- USE L -%]
<table>
<tr>
<th align="right">[% LxERP.t8("Description") %]</th>
<td>
[%- L.input_tag("object.partsgroup", SELF.object.partsgroup, "data-validate"="required", "data-title"=LxERP.t8("Description")) %]
</td>
</tr>
<tr>
<th align="right">[% LxERP.t8("Obsolete") %]</th>
<td>[% L.checkbox_tag("object.obsolete", checked=SELF.object.obsolete, for_submit=1) %]</td>
</tr>
</table>

Auch abrufbar als: Unified diff