Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 911159a8

Von Werner Hahn vor 12 Monaten hinzugefügt

  • ID 911159a895424d314fbf18a6034b8a825c4fa41c
  • Vorgänger 9bd3c54d
  • Nachfolger a479bdcc

VariantenKonfiguration: Controller und js Dateien

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) ]
13
  'scalar --get_set_init' => [ qw(variant_property variant_property_value) ]
14 14
);
15 15

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

  
18 19
#
19 20
# actions
......
61 62
  $self->render(\'', { type => 'json' }); # ' emacs happy again
62 63
}
63 64

  
65
sub action_edit_property_value {
66
  my ($self) = @_;
67

  
68
  $self->render_variant_edit_dialog();
69
}
70

  
71
sub action_save_property_value {
72
  my ($self) = @_;
73

  
74
  $self->create_or_update_property_value;
75
}
76

  
77

  
78
sub render_variant_edit_dialog {
79
  my ($self) = @_;
80
  $self->js
81
    ->run(
82
      'kivi.VariantProperty.variant_dialog',
83
      t8('Variant Value'),
84
      $self->render('variant_property/variant_property_value_form', { output => 0 })
85
    )
86
    ->reinit_widgets;
87

  
88
  $self->js->render;
89
}
90

  
64 91
#sub action_list_property_values_list {
65 92
#  my ($self) = @_;
66 93
#
......
87 114
  SL::DB::Manager::VariantProperty->find_by_or_create(id => $::form->{id} || 0)->assign_attributes(%{ $::form->{variant_property} });
88 115
}
89 116

  
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
sub add_javascripts  {
122
  $::request->{layout}->add_javascripts(qw(kivi.VariantProperty.js));
123
}
124

  
90 125
#
91 126
# helpers
92 127
#
......
109 144
  $self->redirect_to(action => 'list_properties');
110 145
}
111 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
}
167

  
112 168
sub _setup_form_action_bar {
113 169
  my ($self) = @_;
114 170

  
js/kivi.VariantProperty.js
1
namespace('kivi.VariantProperty', function(ns) {
2
  var $dialog;
3

  
4
  ns.variant_dialog = function(title, html) {
5
    var id            = 'jqueryui_popup_dialog';
6
    var dialog_params = {
7
      id:     id,
8
      width:  800,
9
      height: 500,
10
      modal:  true,
11
      close: function(event, ui) { $dialog.remove(); },
12
    };
13

  
14
    $('#' + id).remove();
15

  
16
    $dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
17
    $dialog.attr('title', title);
18
    $dialog.html(html);
19
    $dialog.dialog(dialog_params);
20

  
21
    $('.cancel').click(ns.close_dialog);
22

  
23
    return true;
24
  };
25

  
26

  
27
  ns.save_variant_value = function() {
28
    var form = $('#variant_property_value_form').serializeArray();
29
    console.log("my", form)
30
    form.push( { name: 'action', value: 'VariantProperty/save_property_value' }
31
    );
32

  
33
    $.post('controller.pl', form, function(data) {
34
      kivi.eval_json_result(data);
35
    });
36
  };
37

  
38
  ns.add_or_edit_variant_value = function(id) {
39
    $.post('controller.pl', { action: 'VariantProperty/edit_property_value', id: id }, function(data) {
40
      kivi.eval_json_result(data);
41
    });
42
  };
43

  
44
});

Auch abrufbar als: Unified diff