Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 442b26e2

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 442b26e2b4f442a41fbe5fa256b12c0e01219190
  • Vorgänger 3250f2ee
  • Nachfolger 073a24ab

Pflichtenheftpunkte bearbeiten

Unterschiede anzeigen:

SL/Controller/RequirementSpecItem.pm
7 7
use Time::HiRes ();
8 8

  
9 9
use SL::DB::RequirementSpec;
10
use SL::DB::RequirementSpecComplexity;
10 11
use SL::DB::RequirementSpecItem;
12
use SL::DB::RequirementSpecRisk;
11 13
use SL::Helper::Flash;
12 14
use SL::JSON;
13 15
use SL::Locale::String;
14 16

  
15 17
use Rose::Object::MakeMethods::Generic
16 18
(
17
  scalar => [ qw(requirement_spec item visible_item visible_section) ],
19
  scalar                  => [ qw(requirement_spec item visible_item visible_section) ],
20
  'scalar --get_set_init' => [ qw(complexities risks) ],
18 21
);
19 22

  
20 23
# __PACKAGE__->run_before('load_requirement_spec');
21
__PACKAGE__->run_before('load_requirement_spec_item', only => [qw(dragged_and_dropped edit_section update_section)]);
24
__PACKAGE__->run_before('load_requirement_spec_item', only => [qw(dragged_and_dropped ajax_update ajax_edit)]);
22 25

  
23 26
#
24 27
# actions
......
47 50
  $self->render($js);
48 51
}
49 52

  
50
sub action_new {
51
  my ($self) = @_;
52

  
53
  eval {
54
    my $type         = ($::form->{item_type} || '') =~ m/^ (?: section | (?: sub-)? function-block ) $/x ? $::form->{item_type} : die "Invalid item_type";
55
    $self->{item}    = SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id});
56
    my $section_form = $self->presenter->render("requirement_spec_item/_${type}_form", id => create_random_id(), title => t8('Create a new section'));
57

  
58
    $self->render(\to_json({ status => 'ok', html => $section_form }), { type => 'json' });
59
    1;
60
  } or do {
61
    $self->render(\to_json({ status => 'failed', error => "Exception:\n" . format_exception() }), { type => 'json' });
62
  }
63
}
64

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

  
68
  my $type = ($::form->{item_type} || '') =~ m/^ (?: section | (?: sub-)? function-block ) $/x ? $::form->{item_type} : die "Invalid item_type";
69

  
70
  $self->render(\to_json({ status => 'failed', error => 'not good, not good' }), { type => 'json' });
71
}
72

  
73 53
sub action_dragged_and_dropped {
74 54
  my ($self)       = @_;
75 55

  
76
  $::lxdebug->dump(0, "form", $::form);
77

  
78 56
  my $dropped_item = SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load || die "No such dropped item";
79 57
  my $position     = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter";
80 58

  
......
87 65
  $self->render(\'', { type => 'json' });
88 66
}
89 67

  
90
sub action_edit_section {
68
sub action_ajax_edit {
91 69
  my ($self, %params) = @_;
92
  $self->render('requirement_spec_item/_section_form', { layout => 0 });
70

  
71
  $::lxdebug->dump(0, "form", $::form);
72

  
73
  $self->init_visible_section($::form->{current_content_id}, $::form->{current_content_type});
74
  $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load);
75

  
76
  my $js = SL::ClientJS->new;
77

  
78
  die "TODO: edit section" if $self->item->get_type =~ m/section/;
79

  
80
  if (!$self->visible_section || ($self->visible_section->id != $self->item->get_section->id)) {
81
    my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item);
82
    $js->html('#column-content', $html);
83
  }
84

  
85
  if ($self->item->get_type =~ m/function-block/) {
86
    my $create_item = sub {
87
      [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]
88
    };
89
    my @dependencies =
90
      map { [ $_->fb_number . ' ' . $_->title,
91
              [ map { ( $create_item->($_),
92
                        map { $create_item->($_, '->') } @{ $_->sorted_children })
93
                    } @{ $_->sorted_children } ] ]
94
          } @{ $self->item->requirement_spec->sections };
95

  
96
    my @selected_dependencies = map { $_->id } @{ $self->item->dependencies };
97

  
98
    my $html                  = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
99
    my $id_base               = $self->item->get_type . '-' . $self->item->id;
100
    my $content_top_id        = '#' . $self->item->get_type . '-content-top-' . $self->item->id;
101

  
102
    $js->hide($content_top_id)
103
       ->remove("#edit_${id_base}_form")
104
       ->insertAfter($html, $content_top_id)
105
       ->jstree->select_node('#tree', '#fb-' . $self->item->id)
106
       ->focus("#edit_${id_base}_description")
107
       ->val('#current_content_type', $self->item->get_type)
108
       ->val('#current_content_id', $self->item->id)
109
       ->render($self);
110
  }
93 111
}
94 112

  
95
sub action_update_section {
113
sub action_ajax_update {
96 114
  my ($self, %params) = @_;
97 115

  
98
  $self->item->update_attributes(title => $::form->{title}, description => $::form->{description});
116
  my $js         = SL::ClientJS->new;
117
  my $prefix     = $::form->{form_prefix} || 'text_block';
118
  my $attributes = $::form->{$prefix}     || {};
119

  
120
  foreach (qw(requirement_spec_id parent_id position)) {
121
    delete $attributes->{$_} if !defined $attributes->{$_};
122
  }
123

  
124
  my @errors = $self->item->assign_attributes(%{ $attributes })->validate;
125
  return $js->error(@errors)->render($self) if @errors;
126

  
127
  $self->item->save;
99 128

  
100
  my $result = {
101
    id          => $self->item->id,
102
    header_html => $self->render('requirement_spec_item/_section_header', { layout => 0, output => 0 }, requirement_spec_item => $self->item),
103
    node_name   => join(' ', map { $_ || '' } ($self->item->fb_number, $self->item->title)),
104
  };
105
  $self->render(\to_json($result), { type => 'json' });
129
  my $id_prefix    = $self->item->get_type eq 'function-block' ? '' : 'sub-';
130
  my $html_top     = $self->render('requirement_spec_item/_function_block_content_top',    { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix);
131
  my $html_bottom  = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix);
132
  $id_prefix      .= 'function-block-content-';
133

  
134
  SL::ClientJS->new
135
    ->remove('#' . $prefix . '_form')
136
    ->replaceWith('#' . $id_prefix . 'top-'    . $self->item->id, $html_top)
137
    ->replaceWith('#' . $id_prefix . 'bottom-' . $self->item->id, $html_bottom)
138
    ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item))
139
    ->render($self);
106 140
}
107 141

  
108 142
#
......
141 175
  return $self->visible_section($self->visible_item->get_section);
142 176
}
143 177

  
178
sub init_complexities {
179
  my ($self) = @_;
180

  
181
  return SL::DB::Manager::RequirementSpecComplexity->get_all_sorted;
182
}
183

  
184
sub init_risks {
185
  my ($self) = @_;
186

  
187
  return SL::DB::Manager::RequirementSpecRisk->get_all_sorted;
188
}
189

  
144 190
1;

Auch abrufbar als: Unified diff