Revision e2a8a58a
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Controller/RequirementSpecItem.pm | ||
---|---|---|
5 | 5 |
use parent qw(SL::Controller::Base); |
6 | 6 |
|
7 | 7 |
use List::MoreUtils qw(apply); |
8 |
use List::Util qw(first); |
|
8 | 9 |
use Time::HiRes (); |
9 | 10 |
|
10 | 11 |
use SL::DB::RequirementSpec; |
... | ... | |
17 | 18 |
|
18 | 19 |
use Rose::Object::MakeMethods::Generic |
19 | 20 |
( |
20 |
scalar => [ qw(requirement_spec item visible_item visible_section) ],
|
|
21 |
scalar => [ qw(item visible_item visible_section) ], |
|
21 | 22 |
'scalar --get_set_init' => [ qw(complexities risks) ], |
22 | 23 |
); |
23 | 24 |
|
24 |
# __PACKAGE__->run_before('load_requirement_spec'); |
|
25 |
__PACKAGE__->run_before('load_requirement_spec_item', only => [ qw(dragged_and_dropped ajax_update ajax_edit) ]); |
|
26 |
__PACKAGE__->run_before('init_visible_section', only => [ qw(dragged_and_dropped ajax_list ajax_edit) ]); |
|
25 |
__PACKAGE__->run_before('load_requirement_spec_item', only => [ qw(dragged_and_dropped ajax_update ajax_edit ajax_delete) ]); |
|
26 |
__PACKAGE__->run_before('init_visible_section', only => [ qw(dragged_and_dropped ajax_list ajax_edit ajax_delete) ]); |
|
27 | 27 |
|
28 | 28 |
# |
29 | 29 |
# actions |
30 | 30 |
# |
31 | 31 |
|
32 | 32 |
sub action_ajax_list { |
33 |
my ($self) = @_; |
|
33 |
my ($self, $js) = @_;
|
|
34 | 34 |
|
35 | 35 |
my $js = SL::ClientJS->new; |
36 | 36 |
|
... | ... | |
41 | 41 |
|
42 | 42 |
$self->item(SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load->get_section); |
43 | 43 |
|
44 |
if (!$self->visible_section || ($self->visible_section->id != $self->item->id)) { |
|
45 |
my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item); |
|
46 |
$js->html('#column-content', $html) |
|
47 |
->val('#current_content_type', $self->item->get_type) |
|
48 |
->val('#current_content_id', $self->item->id); |
|
49 |
} |
|
44 |
$self->render_list($js, $self->item) if !$self->visible_section || ($self->visible_section->id != $self->item->id); |
|
50 | 45 |
|
51 | 46 |
$self->render($js); |
52 | 47 |
} |
... | ... | |
190 | 185 |
$js->render($self); |
191 | 186 |
} |
192 | 187 |
|
188 |
sub action_ajax_delete { |
|
189 |
my ($self) = @_; |
|
190 |
|
|
191 |
my $js = SL::ClientJS->new; |
|
192 |
|
|
193 |
$self->item->delete; |
|
194 |
|
|
195 |
if ($self->visible_section && ($self->visible_section->id == $self->item->id)) { |
|
196 |
# Currently visible section is deleted. |
|
197 |
|
|
198 |
my $new_section = first { $_->id != $self->item->id } @{ $self->item->requirement_spec->sections }; |
|
199 |
if ($new_section) { |
|
200 |
$self->render_list($js, $new_section); |
|
201 |
|
|
202 |
} else { |
|
203 |
my $html = $self->render('requirement_spec_item/_no_section', { output => 0 }); |
|
204 |
$js->html('#column-content', $html) |
|
205 |
->val('#current_content_type', '') |
|
206 |
->val('#current_content_id', '') |
|
207 |
} |
|
208 |
|
|
209 |
} elsif ($self->visible_section && ($self->visible_section->id == $self->item->get_section->id)) { |
|
210 |
# Item in currently visible section is deleted. |
|
211 |
|
|
212 |
my $type = $self->item->get_type; |
|
213 |
$js->remove('#edit_function_block_' . $self->item->id . '_form') |
|
214 |
->remove('#' . $type . '-' . $self->item->id); |
|
215 |
|
|
216 |
$self->replace_bottom($js, $self->item->parent_id) if $type eq 'sub-function-block'; |
|
217 |
|
|
218 |
if (1 == scalar @{ $self->item->get_full_list }) { |
|
219 |
if ($type eq 'function-block') { |
|
220 |
$js->show('#section-list-empty'); |
|
221 |
} elsif ($type eq 'sub-function-block') { |
|
222 |
$js->hide('#sub-function-block-container-' . $self->item->parent_id); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
$js->jstree->delete_node('#tree', '#fb-' . $self->item->id) |
|
228 |
->render($self); |
|
229 |
} |
|
230 |
|
|
193 | 231 |
# |
194 | 232 |
# filters |
195 | 233 |
# |
... | ... | |
225 | 263 |
return undef unless $content_id; |
226 | 264 |
return undef unless $content_type =~ m/section|function-block/; |
227 | 265 |
|
228 |
$self->visible_item(SL::DB::RequirementSpecItem->new(id => $content_id)->load); |
|
266 |
$self->visible_item(SL::DB::Manager::RequirementSpecItem->find_by(id => $content_id)); |
|
267 |
return undef unless $self->visible_item; |
|
268 |
|
|
229 | 269 |
return $self->visible_section($self->visible_item->get_section); |
230 | 270 |
} |
231 | 271 |
|
... | ... | |
250 | 290 |
return $js->replaceWith('#' . $id_prefix . 'function-block-content-bottom-' . $item->id, $html); |
251 | 291 |
} |
252 | 292 |
|
293 |
sub render_list { |
|
294 |
my ($self, $js, $item) = @_; |
|
295 |
|
|
296 |
my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $item); |
|
297 |
$js->html('#column-content', $html) |
|
298 |
->val( '#current_content_type', $item->get_type) |
|
299 |
->val( '#current_content_id', $item->id) |
|
300 |
->jstree->select_node('#tree', '#fb-' . $item->id); |
|
301 |
} |
|
302 |
|
|
253 | 303 |
1; |
Auch abrufbar als: Unified diff
Pflichtenheftitems löschen