Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3ea3a603

Von Sven Schöling vor fast 11 Jahren hinzugefügt

  • ID 3ea3a6039063f35a5dffc726d5f0e9a1ab85ef11
  • Vorgänger b832f344
  • Nachfolger 165d1a99

Kundennamenvalidierung: Keinen dberror werfen, sondern flash benutzen.

Ausserdem REs etwas aufgeräumt und ausgelagert

Unterschiede anzeigen:

SL/Controller/CustomerVendor.pm
6 6
use SL::JSON;
7 7
use SL::DBUtils;
8 8
use SL::Helper::Flash;
9
use SL::Locale::String;
9 10

  
10 11
use SL::DB::Customer;
11 12
use SL::DB::Vendor;
......
28 29
    $::auth->assert('customer_vendor_edit');
29 30
  }
30 31
);
31

  
32 32
__PACKAGE__->run_before(
33 33
  '_instantiate_args',
34 34
  only => [
......
62 62
  ]
63 63
);
64 64

  
65
__PACKAGE__->run_before('normalize_name');
66

  
67

  
65 68
sub action_add {
66 69
  my ($self) = @_;
67 70

  
......
167 170
sub action_save {
168 171
  my ($self) = @_;
169 172

  
170
  my $pattern = '[ \t\n\r]+';
171
  my $name = $self->{cv}->name;
172
  $name =~ s/^$pattern//;
173
  $name =~ s/$pattern$//;
174
  $name =~ s/$pattern/ /g;
175
  if ( $name eq '' ) {
176
    $::form->dberror( $::locale->text('Customer missing!') );
173
  if (!$self->{cv}->name) {
174
    flash('error', t8('Customer missing!'));
175
    $self->_pre_render();
176
    $self->render(
177
      'customer_vendor/form',
178
      title => ($self->is_vendor() ? t8('Edit Vendor') : t8('Edit Customer')),
179
      %{$self->{template_args}}
180
    );
177 181
  } else {
178
    $self->{cv}->name($name);
179
  }
180 182

  
181
  $self->_save();
183
    $self->_save();
182 184

  
183
  my @redirect_params = (
184
    action => 'edit',
185
    id     => $self->{cv}->id,
186
    db     => ($self->is_vendor() ? 'vendor' : 'customer'),
187
  );
185
    my @redirect_params = (
186
      action => 'edit',
187
      id     => $self->{cv}->id,
188
      db     => ($self->is_vendor() ? 'vendor' : 'customer'),
189
    );
188 190

  
189
  if ( $self->{contact}->cp_id ) {
190
    push(@redirect_params, contact_id => $self->{contact}->cp_id);
191
  }
191
    if ( $self->{contact}->cp_id ) {
192
      push(@redirect_params, contact_id => $self->{contact}->cp_id);
193
    }
192 194

  
193
  if ( $self->{shipto}->shipto_id ) {
194
    push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
195
  }
195
    if ( $self->{shipto}->shipto_id ) {
196
      push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
197
    }
196 198

  
197
  $self->redirect_to(@redirect_params);
199
    $self->redirect_to(@redirect_params);
200
  }
198 201
}
199 202

  
200 203
sub action_save_and_close {
......
859 862
  $::request->{layout}->add_javascripts('kivi.CustomerVendor.js');
860 863
}
861 864

  
865
sub normalize_name {
866
  my ($self) = @_;
867

  
868
  return unless $self->{cv};
869
  my $name = $self->{cv}->name;
870
  $name =~ s/\s+$//;
871
  $name =~ s/^\s+//;
872
  $name =~ s/\s+/ /g;
873
  $self->{cv}->name($name);
874
}
875

  
862 876
1;

Auch abrufbar als: Unified diff