Revision 4119b9b5
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Controller/RequirementSpecItem.pm | ||
---|---|---|
22 | 22 |
use Rose::Object::MakeMethods::Generic |
23 | 23 |
( |
24 | 24 |
scalar => [ qw(item visible_item visible_section clicked_item sections) ], |
25 |
'scalar --get_set_init' => [ qw(complexities risks) ], |
|
25 |
'scalar --get_set_init' => [ qw(complexities risks js) ],
|
|
26 | 26 |
); |
27 | 27 |
|
28 | 28 |
__PACKAGE__->run_before('check_auth'); |
... | ... | |
34 | 34 |
# |
35 | 35 |
|
36 | 36 |
sub action_ajax_list { |
37 |
my ($self, $js) = @_; |
|
38 |
|
|
39 |
my $js = SL::ClientJS->new; |
|
37 |
my ($self) = @_; |
|
40 | 38 |
|
41 | 39 |
if (!$::form->{clicked_id}) { |
42 | 40 |
# Clicked on "sections" in the tree. Do nothing. |
43 |
return $self->render($js); |
|
41 |
return $self->render($self->js);
|
|
44 | 42 |
} |
45 | 43 |
|
46 | 44 |
my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load; |
47 | 45 |
$self->item($clicked_item->section); |
48 | 46 |
|
49 | 47 |
if (!$self->visible_section || ($self->visible_section->id != $self->item->id)) { |
50 |
$self->render_list($js, $self->item, $clicked_item);
|
|
48 |
$self->render_list($self->item, $clicked_item); |
|
51 | 49 |
} else { |
52 |
$self->select_node($js, $clicked_item);
|
|
50 |
$self->select_node($clicked_item); |
|
53 | 51 |
} |
54 | 52 |
|
55 |
$self->render($js); |
|
53 |
$self->render($self->js);
|
|
56 | 54 |
} |
57 | 55 |
|
58 | 56 |
sub insert_new_item_in_section_view { |
59 |
my ($self, $js) = @_;
|
|
57 |
my ($self) = @_; |
|
60 | 58 |
|
61 |
$js->hide('#section-list-empty'); |
|
59 |
$self->js->hide('#section-list-empty');
|
|
62 | 60 |
|
63 | 61 |
my $new_type = $self->item->item_type; |
64 | 62 |
my $id_prefix = $new_type eq 'sub-function-block' ? 'sub-' : ''; |
... | ... | |
67 | 65 |
my $next_item = $self->item->get_next_in_list; |
68 | 66 |
|
69 | 67 |
if ($next_item) { |
70 |
$js->insertBefore($html, '#' . $id_prefix . 'function-block-' . $next_item->id); |
|
68 |
$self->js->insertBefore($html, '#' . $id_prefix . 'function-block-' . $next_item->id);
|
|
71 | 69 |
} else { |
72 | 70 |
my $parent_is_section = $self->item->parent->item_type eq 'section'; |
73 |
$js->appendTo($html, $parent_is_section ? '#section-list' : '#sub-function-block-container-' . $self->item->parent_id); |
|
74 |
$js->show('#sub-function-block-container-' . $self->item->parent_id) if !$parent_is_section; |
|
71 |
$self->js->appendTo($html, $parent_is_section ? '#section-list' : '#sub-function-block-container-' . $self->item->parent_id);
|
|
72 |
$self->js->show('#sub-function-block-container-' . $self->item->parent_id) if !$parent_is_section;
|
|
75 | 73 |
} |
76 | 74 |
|
77 |
$self->replace_bottom($js, $self->item->parent) if $new_type eq 'sub-function-block';
|
|
75 |
$self->replace_bottom($self->item->parent) if $new_type eq 'sub-function-block'; |
|
78 | 76 |
} |
79 | 77 |
|
80 | 78 |
sub action_dragged_and_dropped { |
... | ... | |
93 | 91 |
$self->item->add_to_list(position => $position, reference => $::form->{dropped_id} || undef); |
94 | 92 |
}); |
95 | 93 |
|
96 |
my $js = SL::ClientJS->new; |
|
97 |
|
|
98 | 94 |
$self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load); |
99 | 95 |
my $new_section = $self->item->section; |
100 | 96 |
my $new_type = $self->item->item_type; |
101 | 97 |
my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section; |
102 | 98 |
|
103 |
return $self->render($js) if !$old_visible_section || ($new_type eq 'section'); |
|
99 |
return $self->render($self->js) if !$old_visible_section || ($new_type eq 'section');
|
|
104 | 100 |
|
105 | 101 |
# From here on $old_visible_section is definitely set. |
106 | 102 |
|
... | ... | |
112 | 108 |
|
113 | 109 |
if ($old_visible_section->id != $new_visible_section->id) { |
114 | 110 |
# The currently visible item has been dragged to a different section. |
115 |
return $self->render_list($js, $new_section, $self->item)
|
|
111 |
return $self->render_list($new_section, $self->item) |
|
116 | 112 |
->render($self); |
117 | 113 |
} |
118 | 114 |
|
119 | 115 |
if ($old_visible_section->id == $old_section->id) { |
120 | 116 |
my $id_prefix = $old_type eq 'sub-function-block' ? 'sub-' : ''; |
121 |
$js->remove('#' . $id_prefix . 'function-block-' . $self->item->id); |
|
117 |
$self->js->remove('#' . $id_prefix . 'function-block-' . $self->item->id);
|
|
122 | 118 |
|
123 | 119 |
if ($old_type eq 'sub-function-block') { |
124 |
$self->replace_bottom($js, $old_parent) ;
|
|
125 |
$js->hide('#sub-function-block-container-' . $old_parent->id) if 0 == scalar(@{ $old_parent->children }); |
|
120 |
$self->replace_bottom($old_parent) ; |
|
121 |
$self->js->hide('#sub-function-block-container-' . $old_parent->id) if 0 == scalar(@{ $old_parent->children });
|
|
126 | 122 |
|
127 | 123 |
} elsif (0 == scalar(@{ $old_section->children })) { |
128 |
$js->show('#section-list-empty'); |
|
124 |
$self->js->show('#section-list-empty');
|
|
129 | 125 |
} |
130 | 126 |
} |
131 | 127 |
|
132 | 128 |
if ($old_visible_section->id == $new_section->id) { |
133 |
$self->insert_new_item_in_section_view($js); |
|
129 |
$self->insert_new_item_in_section_view($self->js);
|
|
134 | 130 |
} |
135 | 131 |
|
136 |
# $::lxdebug->dump(0, "js", $js->to_array); |
|
132 |
# $::lxdebug->dump(0, "js", $self->js->to_array);
|
|
137 | 133 |
|
138 |
$self->render($js); |
|
134 |
$self->render($self->js);
|
|
139 | 135 |
} |
140 | 136 |
|
141 | 137 |
sub action_ajax_add_section { |
... | ... | |
148 | 144 |
my $insert_after = $::form->{id} ? SL::DB::RequirementSpecItem->new(id => $::form->{id})->load->section->id : undef; |
149 | 145 |
my $html = $self->render('requirement_spec_item/_section_form', { output => 0 }, id_base => 'new_section', insert_after => $insert_after); |
150 | 146 |
|
151 |
SL::ClientJS->new
|
|
147 |
$self->js
|
|
152 | 148 |
->remove('#new_section_form') |
153 | 149 |
->hide('#column-content > *') |
154 | 150 |
->appendTo($html, '#column-content') |
... | ... | |
171 | 167 |
sub action_ajax_create { |
172 | 168 |
my ($self, %params) = @_; |
173 | 169 |
|
174 |
my $js = SL::ClientJS->new; |
|
175 | 170 |
my $prefix = $::form->{form_prefix} || die "Missing parameter 'form_prefix'"; |
176 | 171 |
my $attributes = $::form->{$prefix} || die "Missing parameter group '${prefix}'"; |
177 | 172 |
my $insert_after = delete $attributes->{insert_after}; |
178 | 173 |
|
179 | 174 |
my @errors = $self->item(SL::DB::RequirementSpecItem->new(%{ $attributes }))->validate; |
180 |
return $js->error(@errors)->render($self) if @errors; |
|
175 |
return $self->js->error(@errors)->render($self) if @errors;
|
|
181 | 176 |
|
182 | 177 |
$self->item->save; |
183 | 178 |
$self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after; |
... | ... | |
186 | 181 |
|
187 | 182 |
if ($type eq 'section') { |
188 | 183 |
my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); |
189 |
return $self->render_list($js, $self->item)
|
|
184 |
return $self->render_list($self->item) |
|
190 | 185 |
->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node) |
191 | 186 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
192 | 187 |
->render($self); |
... | ... | |
196 | 191 |
my $html = $self->render($template, { output => 0 }, requirement_spec_item => $self->item, id_prefix => $type eq 'function-block' ? '' : 'sub-'); |
197 | 192 |
my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); |
198 | 193 |
|
199 |
$js->replaceWith('#' . $prefix . '_form', $html) |
|
200 |
->hide('#section-list-empty') |
|
201 |
->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#fb-' . $self->item->parent_id, 'last'), $node) |
|
202 |
->jstree->select_node('#tree', '#fb-' . $self->item->id); |
|
194 |
$self->js |
|
195 |
->replaceWith('#' . $prefix . '_form', $html) |
|
196 |
->hide('#section-list-empty') |
|
197 |
->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#fb-' . $self->item->parent_id, 'last'), $node) |
|
198 |
->jstree->select_node('#tree', '#fb-' . $self->item->id); |
|
203 | 199 |
|
204 |
$self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block';
|
|
200 |
$self->replace_bottom($self->item->parent) if $type eq 'sub-function-block'; |
|
205 | 201 |
|
206 |
$js->render($self); |
|
202 |
$self->js->render($self);
|
|
207 | 203 |
} |
208 | 204 |
|
209 | 205 |
sub action_ajax_edit { |
... | ... | |
211 | 207 |
|
212 | 208 |
$self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load); |
213 | 209 |
|
214 |
my $js = SL::ClientJS->new; |
|
215 |
|
|
216 | 210 |
if (!$self->is_item_visible) { |
217 | 211 |
# Show section/item to edit if it is not visible. |
218 | 212 |
|
219 | 213 |
my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item->section); |
220 |
$js->html('#column-content', $html); |
|
214 |
$self->js->html('#column-content', $html);
|
|
221 | 215 |
} |
222 | 216 |
|
223 | 217 |
if ($self->item->item_type =~ m/section/) { |
224 | 218 |
# Edit the section header, not an item. |
225 | 219 |
my $html = $self->render('requirement_spec_item/_section_form', { output => 0 }); |
226 | 220 |
|
227 |
$js->hide('#section-header-' . $self->item->id) |
|
228 |
->remove("#edit_section_form") |
|
229 |
->insertAfter($html, '#section-header-' . $self->item->id) |
|
230 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
|
231 |
->focus("#edit_section_title") |
|
232 |
->val('#current_content_type', 'section') |
|
233 |
->val('#current_content_id', $self->item->id) |
|
234 |
->render($self); |
|
221 |
$self->js |
|
222 |
->hide('#section-header-' . $self->item->id) |
|
223 |
->remove("#edit_section_form") |
|
224 |
->insertAfter($html, '#section-header-' . $self->item->id) |
|
225 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
|
226 |
->focus("#edit_section_title") |
|
227 |
->val('#current_content_type', 'section') |
|
228 |
->val('#current_content_id', $self->item->id) |
|
229 |
->render($self); |
|
235 | 230 |
return; |
236 | 231 |
} |
237 | 232 |
|
... | ... | |
243 | 238 |
my $id_base = 'edit_function_block_' . $self->item->id; |
244 | 239 |
my $content_top_id = '#' . $self->item->item_type . '-content-top-' . $self->item->id; |
245 | 240 |
|
246 |
$js->hide($content_top_id) |
|
247 |
->remove("#${id_base}_form") |
|
248 |
->insertAfter($html, $content_top_id) |
|
249 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
|
250 |
->focus("#${id_base}_description") |
|
251 |
->val('#current_content_type', $self->item->item_type) |
|
252 |
->val('#current_content_id', $self->item->id) |
|
253 |
->render($self); |
|
241 |
$self->js |
|
242 |
->hide($content_top_id) |
|
243 |
->remove("#${id_base}_form") |
|
244 |
->insertAfter($html, $content_top_id) |
|
245 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
|
246 |
->focus("#${id_base}_description") |
|
247 |
->val('#current_content_type', $self->item->item_type) |
|
248 |
->val('#current_content_id', $self->item->id) |
|
249 |
->render($self); |
|
254 | 250 |
} |
255 | 251 |
|
256 | 252 |
sub action_ajax_update { |
257 | 253 |
my ($self, %params) = @_; |
258 | 254 |
|
259 |
my $js = SL::ClientJS->new; |
|
260 | 255 |
my $prefix = $::form->{form_prefix} || die "Missing parameter 'form_prefix'"; |
261 | 256 |
my $attributes = $::form->{$prefix} || {}; |
262 | 257 |
|
... | ... | |
265 | 260 |
} |
266 | 261 |
|
267 | 262 |
my @errors = $self->item->assign_attributes(%{ $attributes })->validate; |
268 |
return $js->error(@errors)->render($self) if @errors; |
|
263 |
return $self->js->error(@errors)->render($self) if @errors;
|
|
269 | 264 |
|
270 | 265 |
$self->item->save; |
271 | 266 |
|
... | ... | |
276 | 271 |
|
277 | 272 |
my $html = $self->render('requirement_spec_item/_section_header', { output => 0 }, requirement_spec_item => $self->item); |
278 | 273 |
|
279 |
return SL::ClientJS->new
|
|
274 |
return $self->js
|
|
280 | 275 |
->remove('#edit_section_form') |
281 | 276 |
->html('#section-header-' . $self->item->id, $html) |
282 | 277 |
->show('#section-header-' . $self->item->id) |
... | ... | |
292 | 287 |
my $html_top = $self->render('requirement_spec_item/_function_block_content_top', { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix); |
293 | 288 |
$id_prefix .= 'function-block-content-'; |
294 | 289 |
|
295 |
my $js = SL::ClientJS->new
|
|
290 |
$self->js
|
|
296 | 291 |
->remove('#' . $prefix . '_form') |
297 | 292 |
->replaceWith('#' . $id_prefix . 'top-' . $self->item->id, $html_top) |
298 | 293 |
->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item)); |
299 | 294 |
|
300 |
$self->replace_bottom($js, $self->item, id_prefix => $id_prefix);
|
|
301 |
$self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block';
|
|
295 |
$self->replace_bottom($self->item, id_prefix => $id_prefix); |
|
296 |
$self->replace_bottom($self->item->parent) if $type eq 'sub-function-block'; |
|
302 | 297 |
|
303 |
$js->render($self); |
|
298 |
$self->js->render($self);
|
|
304 | 299 |
} |
305 | 300 |
|
306 | 301 |
sub action_ajax_delete { |
307 | 302 |
my ($self) = @_; |
308 | 303 |
|
309 |
my $js = SL::ClientJS->new; |
|
310 | 304 |
my $full_list = $self->item->get_full_list; |
311 | 305 |
|
312 | 306 |
$self->item->delete; |
... | ... | |
316 | 310 |
|
317 | 311 |
my $new_section = first { $_->id != $self->item->id } @{ $self->item->requirement_spec->sections }; |
318 | 312 |
if ($new_section) { |
319 |
$self->render_list($js, $new_section);
|
|
313 |
$self->render_list($new_section); |
|
320 | 314 |
|
321 | 315 |
} else { |
322 | 316 |
my $html = $self->render('requirement_spec_item/_no_section', { output => 0 }); |
323 |
$js->html('#column-content', $html) |
|
324 |
->val('#current_content_type', '') |
|
325 |
->val('#current_content_id', '') |
|
317 |
$self->js |
|
318 |
->html('#column-content', $html) |
|
319 |
->val('#current_content_type', '') |
|
320 |
->val('#current_content_id', '') |
|
326 | 321 |
} |
327 | 322 |
|
328 | 323 |
} elsif ($self->is_item_visible) { |
329 | 324 |
# Item in currently visible section is deleted. |
330 | 325 |
|
331 | 326 |
my $type = $self->item->item_type; |
332 |
$js->remove('#edit_function_block_' . $self->item->id . '_form') |
|
333 |
->remove('#' . $type . '-' . $self->item->id); |
|
327 |
$self->js->remove('#edit_function_block_' . $self->item->id . '_form')
|
|
328 |
->remove('#' . $type . '-' . $self->item->id);
|
|
334 | 329 |
|
335 |
$self->replace_bottom($js, $self->item->parent_id) if $type eq 'sub-function-block';
|
|
330 |
$self->replace_bottom($self->item->parent_id) if $type eq 'sub-function-block'; |
|
336 | 331 |
|
337 | 332 |
if (1 == scalar @{ $full_list }) { |
338 | 333 |
if ($type eq 'function-block') { |
339 |
$js->show('#section-list-empty'); |
|
334 |
$self->js->show('#section-list-empty');
|
|
340 | 335 |
} elsif ($type eq 'sub-function-block') { |
341 |
$js->hide('#sub-function-block-container-' . $self->item->parent_id); |
|
336 |
$self->js->hide('#sub-function-block-container-' . $self->item->parent_id);
|
|
342 | 337 |
} |
343 | 338 |
} |
344 | 339 |
} |
345 | 340 |
|
346 |
$js->jstree->delete_node('#tree', '#fb-' . $self->item->id) |
|
347 |
->render($self); |
|
341 |
$self->js->jstree->delete_node('#tree', '#fb-' . $self->item->id)
|
|
342 |
->render($self);
|
|
348 | 343 |
} |
349 | 344 |
|
350 | 345 |
sub action_ajax_flag { |
... | ... | |
352 | 347 |
|
353 | 348 |
$self->item->update_attributes(is_flagged => !$self->item->is_flagged); |
354 | 349 |
|
355 |
SL::ClientJS->new
|
|
350 |
$self->js
|
|
356 | 351 |
->action_if($self->is_item_visible, 'toggleClass', '#' . $self->item->item_type . '-' . $self->item->id, 'flagged') |
357 | 352 |
->toggleClass('#fb-' . $self->item->id, 'flagged') |
358 | 353 |
->render($self); |
... | ... | |
362 | 357 |
my ($self, %params) = @_; |
363 | 358 |
|
364 | 359 |
SL::Clipboard->new->copy($self->item); |
365 |
SL::ClientJS->new->render($self);
|
|
360 |
$self->render($self->js);
|
|
366 | 361 |
} |
367 | 362 |
|
368 | 363 |
sub determine_paste_position { |
... | ... | |
412 | 407 |
} |
413 | 408 |
|
414 | 409 |
sub create_and_insert_node_rec { |
415 |
my ($self, $js, $item, $new_parent_id, $insert_after) = @_;
|
|
410 |
my ($self, $item, $new_parent_id, $insert_after) = @_; |
|
416 | 411 |
|
417 | 412 |
my $node = $self->presenter->requirement_spec_item_jstree_data($item); |
418 |
$js->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : $new_parent_id ? ('#fb-' . $new_parent_id, 'last') : ('#sections', 'last'), $node); |
|
413 |
$self->js->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : $new_parent_id ? ('#fb-' . $new_parent_id, 'last') : ('#sections', 'last'), $node);
|
|
419 | 414 |
|
420 |
$self->create_and_insert_node_rec($js, $_, $item->id) for @{ $item->children || [] };
|
|
415 |
$self->create_and_insert_node_rec($_, $item->id) for @{ $item->children || [] }; |
|
421 | 416 |
|
422 |
$js->jstree->open_node('#tree', '#fb-' . $item->id); |
|
417 |
$self->js->jstree->open_node('#tree', '#fb-' . $item->id);
|
|
423 | 418 |
} |
424 | 419 |
|
425 | 420 |
sub action_ajax_paste { |
426 | 421 |
my ($self, %params) = @_; |
427 | 422 |
|
428 |
my $js = SL::ClientJS->new; |
|
429 | 423 |
my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecItem$/); |
430 | 424 |
|
431 | 425 |
if (!$copied) { |
432 |
return $js->error(t8("The clipboard does not contain anything that can be pasted here.")) |
|
433 |
->render($self); |
|
426 |
return $self->js->error(t8("The clipboard does not contain anything that can be pasted here."))
|
|
427 |
->render($self);
|
|
434 | 428 |
} |
435 | 429 |
|
436 | 430 |
$self->item($self->assign_requirement_spec_id_rec($copied->to_object)); |
... | ... | |
438 | 432 |
$self->sections($req_spec->sections); |
439 | 433 |
|
440 | 434 |
if (($self->item->item_type ne 'section') && !@{ $self->sections }) { |
441 |
return $js->error(t8("You cannot paste function blocks or sub function blocks if there is no section.")) |
|
442 |
->render($self); |
|
435 |
return $self->js->error(t8("You cannot paste function blocks or sub function blocks if there is no section."))
|
|
436 |
->render($self);
|
|
443 | 437 |
} |
444 | 438 |
|
445 | 439 |
$self->clicked_item($::form->{id} ? SL::DB::RequirementSpecItem->new(id => $::form->{id})->load : undef); |
... | ... | |
451 | 445 |
$self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after; |
452 | 446 |
|
453 | 447 |
# Update the tree: create the node for all pasted objects. |
454 |
$self->create_and_insert_node_rec($js, $self->item, $new_parent_id, $insert_after);
|
|
448 |
$self->create_and_insert_node_rec($self->item, $new_parent_id, $insert_after); |
|
455 | 449 |
|
456 | 450 |
# Pasting the very first section? |
457 | 451 |
if (!@{ $self->sections }) { |
458 | 452 |
my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item); |
459 |
$js->html('#column-content', $html) |
|
460 |
->jstree->select_node('#tree', '#fb-' . $self->item->id) |
|
453 |
$self->js->html('#column-content', $html)
|
|
454 |
->jstree->select_node('#tree', '#fb-' . $self->item->id)
|
|
461 | 455 |
} |
462 | 456 |
|
463 | 457 |
# Update the current view if required. |
464 |
$self->insert_new_item_in_section_view($js) if $self->is_item_visible; |
|
458 |
$self->insert_new_item_in_section_view($self->js) if $self->is_item_visible;
|
|
465 | 459 |
|
466 |
$js->render($self); |
|
460 |
$self->js->render($self);
|
|
467 | 461 |
} |
468 | 462 |
|
469 | 463 |
# |
... | ... | |
509 | 503 |
return SL::DB::Manager::RequirementSpecRisk->get_all_sorted; |
510 | 504 |
} |
511 | 505 |
|
506 |
sub init_js { |
|
507 |
my ($self) = @_; |
|
508 |
$self->js(SL::ClientJS->new); |
|
509 |
} |
|
510 |
|
|
512 | 511 |
sub replace_bottom { |
513 |
my ($self, $js, $item_or_id) = @_;
|
|
512 |
my ($self, $item_or_id) = @_; |
|
514 | 513 |
|
515 | 514 |
my $item = (ref($item_or_id) ? $item_or_id : SL::DB::RequirementSpecItem->new(id => $item_or_id))->load; |
516 | 515 |
my $id_prefix = $item->item_type eq 'function-block' ? '' : 'sub-'; |
517 | 516 |
my $html = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $item, id_prefix => $id_prefix); |
518 |
return $js->replaceWith('#' . $id_prefix . 'function-block-content-bottom-' . $item->id, $html); |
|
517 |
return $self->js->replaceWith('#' . $id_prefix . 'function-block-content-bottom-' . $item->id, $html);
|
|
519 | 518 |
} |
520 | 519 |
|
521 | 520 |
sub render_list { |
522 |
my ($self, $js, $item, $item_to_select) = @_;
|
|
521 |
my ($self, $item, $item_to_select) = @_; |
|
523 | 522 |
|
524 | 523 |
my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $item); |
525 |
$self->select_node($js->html('#column-content', $html), $item_to_select || $item); |
|
524 |
$self->js->html('#column-content', $html); |
|
525 |
$self->select_node($item_to_select || $item); |
|
526 | 526 |
} |
527 | 527 |
|
528 | 528 |
sub select_node { |
529 |
my ($self, $js, $item) = @_;
|
|
529 |
my ($self, $item) = @_; |
|
530 | 530 |
|
531 |
$js->val( '#current_content_type', $item->item_type) |
|
532 |
->val( '#current_content_id', $item->id) |
|
533 |
->jstree->select_node('#tree', '#fb-' . $item->id); |
|
531 |
$self->js |
|
532 |
->val( '#current_content_type', $item->item_type) |
|
533 |
->val( '#current_content_id', $item->id) |
|
534 |
->jstree->select_node('#tree', '#fb-' . $item->id); |
|
534 | 535 |
} |
535 | 536 |
|
536 | 537 |
sub create_dependency_item { |
... | ... | |
586 | 587 |
insert_after => $insert_position eq 'insertAfter' ? $insert_reference : undef, |
587 | 588 |
); |
588 | 589 |
|
589 |
my $js = SL::ClientJS->new; |
|
590 |
|
|
591 | 590 |
my $new_section = $self->item->section; |
592 | 591 |
if (!$self->is_item_visible) { |
593 | 592 |
# Show section/item to edit if it is not visible. |
594 | 593 |
|
595 | 594 |
$html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $new_section); |
596 |
$js->html('#column-content', $html) |
|
597 |
->val('#current_content_type', 'section') |
|
598 |
->val('#current_content_id', $new_section->id) |
|
599 |
->jstree->select_node('#tree', '#fb-' . $new_section->id); |
|
595 |
$self->js |
|
596 |
->html('#column-content', $html) |
|
597 |
->val('#current_content_type', 'section') |
|
598 |
->val('#current_content_id', $new_section->id) |
|
599 |
->jstree->select_node('#tree', '#fb-' . $new_section->id); |
|
600 | 600 |
} |
601 | 601 |
|
602 | 602 |
# $::lxdebug->message(0, "alright! clicked ID " . $::form->{id} . " type $clicked_type new_type $new_type insert_pos $insert_position ref " . ($insert_reference // '<undef>') . " parent $parent_id display_ref $display_reference"); |
603 | 603 |
|
604 |
$js->action($insert_position, $html, $display_reference) |
|
605 |
->focus("#${id_base}_description"); |
|
604 |
$self->js->action($insert_position, $html, $display_reference)
|
|
605 |
->focus("#${id_base}_description");
|
|
606 | 606 |
|
607 |
$js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block'; |
|
607 |
$self->js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block';
|
|
608 | 608 |
|
609 |
$js->render($self); |
|
609 |
$self->js->render($self);
|
|
610 | 610 |
} |
611 | 611 |
|
612 | 612 |
sub is_item_visible { |
Auch abrufbar als: Unified diff
Refactoring