Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0cb6c406

Von Werner Hahn vor 11 Monaten hinzugefügt

  • ID 0cb6c406e18310c99251e489b778a054a1848551
  • Vorgänger c095bfe8
  • Nachfolger e9bebce1

VariantProperty: Controller bisher nur für Eigenschaften

Unterschiede anzeigen:

SL/Controller/VariantProperty.pm
1
package SL::Controller::VariantProperty;
2

  
3
use strict;
4

  
5
use parent qw(SL::Controller::Base);
6

  
7
use SL::Helper::Flash;
8
use SL::Locale::String;
9
use SL::DB::Default;
10
use SL::DB::Manager::VariantProperty;
11

  
12
use Rose::Object::MakeMethods::Generic (
13
  'scalar --get_set_init' => [ qw(variant_property) ]
14
);
15

  
16
#__PACKAGE__->run_before('check_auth');
17

  
18
#
19
# actions
20
#
21

  
22
sub action_list_properties {
23
  my ($self) = @_;
24

  
25
  $self->_setup_list_action_bar;
26
  $self->render('variant_property/list',
27
                title             => t8('Variant Property'),
28
                VARIANTPROPERTIES => SL::DB::Manager::VariantProperty->get_all_sorted,
29
               );
30
}
31

  
32
sub action_edit_property {
33
  my ($self) = @_;
34

  
35
  my $is_new = !$self->variant_property->id;
36
  $self->_setup_form_action_bar;
37
  $self->render('variant_property/variant_propertie_form', title => ($is_new ? t8('Add Variant Property') : t8('Edit Variant Property')));
38
}
39

  
40
sub action_save_property {
41
  my ($self) = @_;
42

  
43
  $self->create_or_update;
44
}
45

  
46
sub action_delete_property {
47
  my ($self) = @_;
48

  
49
  if ( eval { $self->shop->delete; 1; } ) {
50
    flash_later('info',  $::locale->text('The shop has been deleted.'));
51
  } else {
52
    flash_later('error', $::locale->text('The shop is in use and cannot be deleted.'));
53
  };
54
  $self->redirect_to(action => 'list');
55
}
56

  
57
sub action_reorder_properties {
58
  my ($self) = @_;
59

  
60
  SL::DB::Shop->reorder_list(@{ $::form->{shop_id} || [] });
61
  $self->render(\'', { type => 'json' }); # ' emacs happy again
62
}
63

  
64
#
65
#inits
66
#
67

  
68
sub init_variant_property {
69
  SL::DB::Manager::VariantProperty::find_by_or_create(id => $::form->{id} || 0)->assign_attributes(%{ $::form->{variant_property} });
70
}
71

  
72
#
73
# helpers
74
#
75

  
76
sub create_or_update_property {
77
  my ($self) = @_;
78

  
79
  my $is_new = !$self->variant_property->id;
80

  
81
  my @errors = $self->variant_property->validate;
82
  if (@errors) {
83
    flash('error', @errors);
84
    $self->action_edit();
85
    return;
86
  }
87

  
88
  $self->variant_property->save;
89

  
90
  flash_later('info', $is_new ? t8('The Variant Property has been created.') : t8('The Variant Property has been saved.'));
91
  $self->redirect_to(action => 'list_property');
92
}
93

  
94
sub _setup_form_action_bar {
95
  my ($self) = @_;
96

  
97
  for my $bar ($::request->layout->get('actionbar')) {
98
    $bar->add(
99
      combobox => [
100
        action => [
101
          t8('Save'),
102
          submit    => [ '#form', { action => "VariantProperty/save_property" } ],
103
          accesskey => 'enter',
104
        ],
105
         action => [
106
          t8('Delete'),
107
          submit => [ '#form', { action => "VariantProperty/delete_property" } ],
108
        ],
109
      ],
110
      action => [
111
        t8('Cancel'),
112
        submit => [ '#form', { action => "VariantProperty/list_properties" } ],
113
      ],
114
    );
115
  }
116
}
117

  
118
sub _setup_list_action_bar {
119
  my ($self) = @_;
120

  
121
  for my $bar ($::request->layout->get('actionbar')) {
122
    $bar->add(
123
      link => [
124
        t8('Add'),
125
        link => $self->url_for(action => 'edit_property'),
126
      ],
127
    )
128
  };
129
}
130

  
131
1;

Auch abrufbar als: Unified diff