4 |
4 |
|
5 |
5 |
use parent qw(SL::Controller::Base);
|
6 |
6 |
|
|
7 |
use List::MoreUtils qw(apply);
|
7 |
8 |
use Time::HiRes ();
|
8 |
9 |
|
9 |
10 |
use SL::DB::RequirementSpec;
|
... | ... | |
21 |
22 |
);
|
22 |
23 |
|
23 |
24 |
# __PACKAGE__->run_before('load_requirement_spec');
|
24 |
|
__PACKAGE__->run_before('load_requirement_spec_item', only => [qw(dragged_and_dropped ajax_update ajax_edit)]);
|
|
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 |
27 |
|
26 |
28 |
#
|
27 |
29 |
# actions
|
... | ... | |
37 |
39 |
return $self->render($js);
|
38 |
40 |
}
|
39 |
41 |
|
40 |
|
$self->init_visible_section($::form->{current_content_id}, $::form->{current_content_type});
|
41 |
42 |
$self->item(SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load->get_section);
|
42 |
43 |
|
43 |
44 |
if (!$self->visible_section || ($self->visible_section->id != $self->item->id)) {
|
... | ... | |
51 |
52 |
}
|
52 |
53 |
|
53 |
54 |
sub action_dragged_and_dropped {
|
54 |
|
my ($self) = @_;
|
|
55 |
my ($self) = @_;
|
|
56 |
|
|
57 |
my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter";
|
|
58 |
my $dropped_item = $::form->{dropped_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load : undef;
|
55 |
59 |
|
56 |
|
my $dropped_item = SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load || die "No such dropped item";
|
57 |
|
my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter";
|
|
60 |
my $visible_section_id = $self->visible_section ? $self->visible_section->id : undef;
|
|
61 |
my $old_parent_id = $self->item->parent_id;
|
|
62 |
my $old_type = $self->item->get_type;
|
58 |
63 |
|
59 |
64 |
$self->item->db->do_transaction(sub {
|
60 |
65 |
$self->item->remove_from_list;
|
61 |
66 |
$self->item->parent_id($position =~ m/before|after/ ? $dropped_item->parent_id : $dropped_item->id);
|
62 |
|
$self->item->add_to_list(position => $position, reference => $dropped_item->id);
|
|
67 |
$self->item->add_to_list(position => $position, reference => $::form->{dropped_id} || undef);
|
63 |
68 |
});
|
64 |
69 |
|
65 |
|
$self->render(\'', { type => 'json' });
|
|
70 |
my $js = SL::ClientJS->new;
|
|
71 |
|
|
72 |
$self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load);
|
|
73 |
my $new_section = $self->item->get_section;
|
|
74 |
my $new_type = $self->item->get_type;
|
|
75 |
|
|
76 |
return $self->render($js) if !$visible_section_id || ($new_type eq 'section');
|
|
77 |
|
|
78 |
my $old_parent = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load;
|
|
79 |
my $old_section = $old_parent->get_section;
|
|
80 |
|
|
81 |
# $::lxdebug->message(0, "old sec ID " . $old_section->id . " new " . $new_section->id . " visible $visible_section_id PARENT: old " . $old_parent->id . " new " . $self->item->parent_id . '/' . $self->item->parent->id);
|
|
82 |
|
|
83 |
if ($visible_section_id == $old_section->id) {
|
|
84 |
my $id_prefix = $old_type eq 'sub-function-block' ? 'sub-' : '';
|
|
85 |
$js->remove('#' . $id_prefix . 'function-block-' . $self->item->id);
|
|
86 |
|
|
87 |
if ($old_type eq 'sub-function-block') {
|
|
88 |
$self->replace_bottom($js, $old_parent) ;
|
|
89 |
$js->hide('#sub-function-block-container-' . $old_parent->id) if 0 == scalar(@{ $old_parent->children });
|
|
90 |
|
|
91 |
} elsif (0 == scalar(@{ $old_section->children })) {
|
|
92 |
$js->show('#section-list-empty');
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
if ($visible_section_id == $new_section->id) {
|
|
97 |
$js->hide('#section-list-empty');
|
|
98 |
|
|
99 |
my $id_prefix = $new_type eq 'sub-function-block' ? 'sub-' : '';
|
|
100 |
my $template = apply { s/-/_/g; $_ } $new_type;
|
|
101 |
my $html = "" . $self->render('requirement_spec_item/_' . $template, { output => 0 }, requirement_spec_item => $self->item);
|
|
102 |
my $next_item = $self->item->get_next_in_list;
|
|
103 |
|
|
104 |
if ($next_item) {
|
|
105 |
$js->insertBefore($html, '#' . $id_prefix . 'function-block-' . $next_item->id);
|
|
106 |
} else {
|
|
107 |
my $parent_is_section = $self->item->parent->get_type eq 'section';
|
|
108 |
$js->appendTo($html, $parent_is_section ? '#section-list' : '#sub-function-block-container-' . $self->item->parent_id);
|
|
109 |
$js->show('#sub-function-block-container-' . $self->item->parent_id) if !$parent_is_section;
|
|
110 |
}
|
|
111 |
|
|
112 |
$self->replace_bottom($js, $self->item->parent) if $new_type eq 'sub-function-block';
|
|
113 |
}
|
|
114 |
|
|
115 |
# $::lxdebug->dump(0, "js", $js->to_array);
|
|
116 |
|
|
117 |
$self->render($js);
|
66 |
118 |
}
|
67 |
119 |
|
68 |
120 |
sub action_ajax_edit {
|
69 |
121 |
my ($self, %params) = @_;
|
70 |
122 |
|
71 |
|
$::lxdebug->dump(0, "form", $::form);
|
72 |
|
|
73 |
|
$self->init_visible_section($::form->{current_content_id}, $::form->{current_content_type});
|
74 |
123 |
$self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load);
|
75 |
124 |
|
76 |
125 |
my $js = SL::ClientJS->new;
|
... | ... | |
114 |
163 |
my ($self, %params) = @_;
|
115 |
164 |
|
116 |
165 |
my $js = SL::ClientJS->new;
|
117 |
|
my $prefix = $::form->{form_prefix} || 'text_block';
|
|
166 |
my $prefix = $::form->{form_prefix} || 'function_block';
|
118 |
167 |
my $attributes = $::form->{$prefix} || {};
|
119 |
168 |
|
120 |
169 |
foreach (qw(requirement_spec_id parent_id position)) {
|
... | ... | |
128 |
177 |
|
129 |
178 |
my $id_prefix = $self->item->get_type eq 'function-block' ? '' : 'sub-';
|
130 |
179 |
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 |
180 |
$id_prefix .= 'function-block-content-';
|
133 |
181 |
|
134 |
182 |
my $js = SL::ClientJS->new
|
135 |
183 |
->remove('#' . $prefix . '_form')
|
136 |
|
->replaceWith('#' . $id_prefix . 'top-' . $self->item->id, $html_top)
|
137 |
|
->replaceWith('#' . $id_prefix . 'bottom-' . $self->item->id, $html_bottom)
|
|
184 |
->replaceWith('#' . $id_prefix . 'top-' . $self->item->id, $html_top)
|
138 |
185 |
->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item));
|
139 |
186 |
|
140 |
|
|
141 |
|
if ($self->item->get_type eq 'sub-function-block') {
|
142 |
|
my $parent_html_bottom = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $self->item->parent->load);
|
143 |
|
$js->replaceWith('#function-block-content-bottom-' . $self->item->parent->id, $parent_html_bottom);
|
144 |
|
}
|
|
187 |
$self->replace_bottom($js, $self->item, id_prefix => $id_prefix);
|
|
188 |
$self->replace_bottom($js, $self->item->parent) if $self->item->get_type eq 'sub-function-block';
|
145 |
189 |
|
146 |
190 |
$js->render($self);
|
147 |
191 |
}
|
... | ... | |
173 |
217 |
}
|
174 |
218 |
|
175 |
219 |
sub init_visible_section {
|
176 |
|
my ($self, $content_id, $content_type) = @_;
|
|
220 |
my ($self) = @_;
|
|
221 |
|
|
222 |
my $content_id = $::form->{current_content_id};
|
|
223 |
my $content_type = $::form->{current_content_type};
|
177 |
224 |
|
178 |
225 |
return undef unless $content_id;
|
179 |
226 |
return undef unless $content_type =~ m/section|function-block/;
|
... | ... | |
194 |
241 |
return SL::DB::Manager::RequirementSpecRisk->get_all_sorted;
|
195 |
242 |
}
|
196 |
243 |
|
|
244 |
sub replace_bottom {
|
|
245 |
my ($self, $js, $item_or_id) = @_;
|
|
246 |
|
|
247 |
my $item = (ref($item_or_id) ? $item_or_id : SL::DB::RequirementSpecItem->new(id => $item_or_id))->load;
|
|
248 |
my $id_prefix = $item->get_type eq 'function-block' ? '' : 'sub-';
|
|
249 |
my $html = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $item, id_prefix => $id_prefix);
|
|
250 |
return $js->replaceWith('#' . $id_prefix . 'function-block-content-bottom-' . $item->id, $html);
|
|
251 |
}
|
|
252 |
|
197 |
253 |
1;
|
Pflichtenheftitems: Drag&Drop anständig implementiert