Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 46ee23a1

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID 46ee23a18c255bd4a0c9a38ddd2045a3988fecc5
  • Vorgänger 04c54ebf
  • Nachfolger e515eeec

Varianten: Bearbeiten von Varianten Eigenschaften und Ausprägungen

Unterschiede anzeigen:

SL/Controller/VariantProperty.pm
10 10
use SL::DB::Manager::VariantProperty;
11 11

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

  
16 16
#__PACKAGE__->run_before('check_auth');
17
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_property) ]);
17
__PACKAGE__->run_before('add_javascripts', only => [ qw(edit_variant_property) ]);
18 18

  
19 19
#
20 20
# actions
21 21
#
22 22

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

  
26 26
  $self->_setup_list_action_bar;
......
30 30
               );
31 31
}
32 32

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

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

  
41
sub action_save_property {
44
sub action_save_variant_property {
42 45
  my ($self) = @_;
43 46

  
44
  $self->create_or_update_property;
47
  $self->create_or_update_variant_property;
45 48
}
46 49

  
47
sub action_delete_property {
50
sub action_delete_variant_property {
48 51
  my ($self) = @_;
49 52

  
50
  if ( eval { $self->shop->delete; 1; } ) {
51
    flash_later('info',  $::locale->text('The shop has been deleted.'));
53
  if ( eval {
54
      SL::DB->client->with_transaction(sub {
55
        $_->delete for $self->variant_property->property_values;
56
        $self->variant_property->delete;
57
      });
58
      1;
59
    } ) {
60
    flash_later('info',  t8('The Variant Property has been deleted.'));
52 61
  } else {
53
    flash_later('error', $::locale->text('The shop is in use and cannot be deleted.'));
62
    flash_later('error', t8('The Variant Property is in use and cannot be deleted.'));
54 63
  };
55
  $self->redirect_to(action => 'list_properties');
64
  $self->redirect_to(action => 'list_variant_properties');
56 65
}
57 66

  
58
sub action_reorder_properties {
67
sub action_reorder_variant_properties {
59 68
  my ($self) = @_;
60 69

  
61 70
  SL::DB::VariantProperty->reorder_list(@{ $::form->{variant_property_id} || [] });
62 71
  $self->render(\'', { type => 'json' }); # ' emacs happy again
63 72
}
64 73

  
65
sub action_edit_property_value {
74
sub action_reorder_variant_property_values {
66 75
  my ($self) = @_;
67 76

  
68
  $self->render_variant_edit_dialog();
77
  SL::DB::VariantPropertyValue->reorder_list(@{ $::form->{variant_property_value_id} || [] });
78
  $self->render(\'', { type => 'json' }); # ' emacs happy again
69 79
}
70 80

  
71
sub action_save_property_value {
81
sub action_edit_variant_property_value {
72 82
  my ($self) = @_;
73 83

  
74
  $self->create_or_update_property_value;
75
}
76

  
77

  
78
sub render_variant_edit_dialog {
79
  my ($self) = @_;
80 84
  $self->js
81 85
    ->run(
82
      'kivi.VariantProperty.variant_dialog',
83
      t8('Variant Value'),
84
      $self->render('variant_property/variant_property_value_form', { output => 0 })
86
      'kivi.VariantProperty.variant_property_value_dialog',
87
      t8('Variant Property Value'),
88
      $self->render(
89
        'variant_property/variant_property_value_form',
90
        { output => 0 },
91
        variant_property_value => SL::DB::Manager::VariantPropertyValue->find_by(
92
            id => $::form->{variant_property_value_id}
93
          ),
94
      )
85 95
    )
86 96
    ->reinit_widgets;
87 97

  
88 98
  $self->js->render;
89 99
}
90 100

  
91
#sub action_list_property_values_list {
92
#  my ($self) = @_;
93
#
94
#  $self->_setup_list_action_bar;
95
#  $self->render('variant_property/variant_property_list',
96
#                title             => t8('Variant Property'),
97
#                VARIANTPROPERTIES => SL::DB::Manager::VariantProperty->get_all_sorted,
98
#               );
99
#}
100

  
101
#sub action_reorder {
102
#  my ($self) = @_;
103
#
104
#  SL::DB::DeliveryTerm->reorder_list(@{ $::form->{delivery_term_id} || [] });
105
#
106
#  $self->render(\'', { type => 'json' });     # ' make Emacs happy
107
#}
108
#
101
sub action_save_variant_property_value {
102
  my ($self) = @_;
103

  
104
  die "'variant_property_value.id' is needed" unless $::form->{variant_property_value}->{id};
105

  
106
  my $variant_property_value = SL::DB::Manager::VariantPropertyValue->find_by(
107
    id => $::form->{variant_property_value}->{id}
108
  ) or die t8("Could not find Variant Property Value");
109

  
110
  $variant_property_value->update_attributes(
111
    %{$::form->{variant_property_value}}
112
  );
113

  
114
  flash_later('info', t8('The Variant Property Value has been saved.'));
115
  $self->redirect_to(
116
    action => 'edit_variant_property',
117
    id     => $variant_property_value->variant_property_id,
118
  );
119
}
120

  
121
sub action_add_variant_property_value {
122
  my ($self) = @_;
123

  
124
  my $new_variant_property_value = SL::DB::VariantPropertyValue->new(
125
    %{ $::form->{new_variant_property_value} },
126
    variant_property => $self->variant_property,
127
  )->save;
128

  
129
  $self->redirect_to(
130
    action => 'edit_variant_property',
131
    id     => $self->variant_property->id,
132
  );
133
}
134

  
109 135
#
110 136
#inits
111 137
#
......
114 140
  SL::DB::Manager::VariantProperty->find_by_or_create(id => $::form->{id} || 0)->assign_attributes(%{ $::form->{variant_property} });
115 141
}
116 142

  
117
sub init_variant_property_value {
118
  SL::DB::Manager::VariantPropertyValue->find_by_or_create(id => $::form->{variant_property_value_id} || 0)->assign_attributes(%{ $::form->{variant_property_value} });
119
}
120

  
121 143
sub add_javascripts  {
122 144
  $::request->{layout}->add_javascripts(qw(kivi.VariantProperty.js));
123 145
}
......
126 148
# helpers
127 149
#
128 150

  
129
sub create_or_update_property {
151
sub create_or_update_variant_property {
130 152
  my ($self) = @_;
131 153

  
132 154
  my $is_new = !$self->variant_property->id;
......
134 156
  my @errors = $self->variant_property->validate;
135 157
  if (@errors) {
136 158
    flash('error', @errors);
137
    $self->action_edit_property();
159
    $self->action_edit_variant_property();
138 160
    return;
139 161
  }
140 162

  
141 163
  $self->variant_property->save;
142 164

  
143 165
  flash_later('info', $is_new ? t8('The Variant Property has been created.') : t8('The Variant Property has been saved.'));
144
  $self->redirect_to(action => 'list_properties');
145
}
146

  
147
sub create_or_update_property_value {
148
  my ($self) = @_;
149

  
150
  $main::lxdebug->dump(0, "TST:FORM ", $::form);
151
  my $is_new = !$self->variant_property_value->id;
152

  
153
#  my @errors = $self->variant_property_value->validate;
154
#  if (@errors) {
155
#    flash('error', @errors);
156
#    $self->action_edit_property();
157
#    return;
158
#  }
159
  $main::lxdebug->dump(0, "TST:PV ", $self->variant_property_value);
160
  $self->variant_property_value->assign_attributes( variant_property_id => $::form->{property_value_id});
161
  $self->variant_property_value->save;
162

  
163
  flash_later('info', $is_new ? t8('The Variant Property Value has been created.') : t8('The Variant Property Value has been saved.'));
164
  $self->action_edit_property();
165
  return;
166
  $self->redirect_to(
167
    action => 'edit_variant_property',
168
    id     => $self->variant_property->id,
169
  );
166 170
}
167 171

  
168 172
sub _setup_form_action_bar {
......
173 177
      combobox => [
174 178
        action => [
175 179
          t8('Save'),
176
          submit    => [ '#form', { action => "VariantProperty/save_property" } ],
180
          submit    => [ '#form', { action => "VariantProperty/save_variant_property" } ],
177 181
          accesskey => 'enter',
178 182
        ],
179 183
         action => [
180 184
          t8('Delete'),
181
          submit => [ '#form', { action => "VariantProperty/delete_property" } ],
185
          submit => [ '#form', { action => "VariantProperty/delete_variant_property" } ],
182 186
        ],
183 187
      ],
184 188
      action => [
185 189
        t8('Cancel'),
186
        submit => [ '#form', { action => "VariantProperty/list_properties" } ],
190
        submit => [ '#form', { action => "VariantProperty/list_variant_properties" } ],
187 191
      ],
188 192
    );
189 193
  }
......
196 200
    $bar->add(
197 201
      link => [
198 202
        t8('Add'),
199
        link => $self->url_for(action => 'edit_property'),
203
        link => $self->url_for(action => 'edit_variant_property'),
200 204
      ],
201 205
    )
202 206
  };

Auch abrufbar als: Unified diff