20 |
20 |
|
21 |
21 |
use Rose::Object::MakeMethods::Generic
|
22 |
22 |
(
|
23 |
|
scalar => [ qw(text_block picture) ],
|
24 |
|
'scalar --get_set_init' => [ qw(predefined_texts js) ],
|
|
23 |
scalar => [ qw(text_block) ],
|
|
24 |
'scalar --get_set_init' => [ qw(predefined_texts js picture) ],
|
25 |
25 |
);
|
26 |
26 |
|
27 |
27 |
__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete ajax_flag dragged_and_dropped ajax_copy ajax_add_picture)]);
|
... | ... | |
234 |
234 |
sub action_ajax_paste {
|
235 |
235 |
my ($self, %params) = @_;
|
236 |
236 |
|
237 |
|
my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecTextBlock$/);
|
|
237 |
my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpec(?:TextBlock|Picture)$/);
|
238 |
238 |
if (!$copied) {
|
239 |
239 |
return SL::ClientJS->new
|
240 |
240 |
->error(t8("The clipboard does not contain anything that can be pasted here."))
|
241 |
241 |
->render($self);
|
242 |
242 |
}
|
243 |
243 |
|
|
244 |
if (ref($copied) =~ m/Picture$/) {
|
|
245 |
$self->load_requirement_spec_text_block;
|
|
246 |
return $self->paste_picture($copied);
|
|
247 |
}
|
|
248 |
|
244 |
249 |
my $current_output_position = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type});
|
245 |
250 |
my $new_output_position = $::form->{id} ? $self->output_position_from_id($::form->{id}) : $::form->{output_position};
|
246 |
251 |
my $front_back = 0 == $new_output_position ? 'front' : 'back';
|
... | ... | |
274 |
279 |
sub action_ajax_edit_picture {
|
275 |
280 |
my ($self) = @_;
|
276 |
281 |
|
277 |
|
$self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{picture_id})->load);
|
278 |
282 |
$self->text_block($self->picture->text_block);
|
279 |
283 |
$self->render('requirement_spec_text_block/_picture_form', { layout => 0 });
|
280 |
284 |
}
|
... | ... | |
304 |
308 |
my ($self) = @_;
|
305 |
309 |
|
306 |
310 |
my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
|
307 |
|
$self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load);
|
308 |
311 |
|
309 |
312 |
if (!$attributes->{picture_content}) {
|
310 |
313 |
delete $attributes->{picture_content};
|
... | ... | |
332 |
335 |
sub action_ajax_delete_picture {
|
333 |
336 |
my ($self) = @_;
|
334 |
337 |
|
335 |
|
$self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load);
|
336 |
338 |
$self->picture->delete;
|
337 |
339 |
$self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $self->picture->text_block_id)->load);
|
338 |
340 |
|
... | ... | |
345 |
347 |
sub action_ajax_download_picture {
|
346 |
348 |
my ($self) = @_;
|
347 |
349 |
|
348 |
|
$self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load);
|
349 |
350 |
$self->send_file(\$self->picture->{picture_content}, type => $self->picture->picture_content_type, name => $self->picture->picture_file_name);
|
350 |
351 |
}
|
351 |
352 |
|
|
353 |
sub action_ajax_copy_picture {
|
|
354 |
my ($self, %params) = @_;
|
|
355 |
|
|
356 |
SL::Clipboard->new->copy($self->picture);
|
|
357 |
SL::ClientJS->new->render($self);
|
|
358 |
}
|
|
359 |
|
|
360 |
sub action_ajax_paste_picture {
|
|
361 |
my ($self, %params) = @_;
|
|
362 |
|
|
363 |
my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecPicture$/);
|
|
364 |
if (!$copied) {
|
|
365 |
return SL::ClientJS->new
|
|
366 |
->error(t8("The clipboard does not contain anything that can be pasted here."))
|
|
367 |
->render($self);
|
|
368 |
}
|
|
369 |
|
|
370 |
$self->text_block($self->picture->text_block); # Save text block via the picture the user clicked on
|
|
371 |
|
|
372 |
$self->paste_picture($copied);
|
|
373 |
}
|
|
374 |
|
352 |
375 |
#
|
353 |
376 |
# filters
|
354 |
377 |
#
|
... | ... | |
379 |
402 |
return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted;
|
380 |
403 |
}
|
381 |
404 |
|
|
405 |
sub init_picture {
|
|
406 |
return SL::DB::RequirementSpecPicture->new(id => $::form->{picture_id} || $::form->{id})->load;
|
|
407 |
}
|
|
408 |
|
382 |
409 |
sub init_js {
|
383 |
410 |
my ($self) = @_;
|
384 |
411 |
$self->js(SL::ClientJS->new);
|
... | ... | |
429 |
456 |
return $self->set_function_blocks_tab_menu_class(class => 'text-block-context-menu');
|
430 |
457 |
}
|
431 |
458 |
|
|
459 |
sub paste_picture {
|
|
460 |
my ($self, $copied) = @_;
|
|
461 |
|
|
462 |
if (!$self->text_block->db->do_transaction(sub {
|
|
463 |
1;
|
|
464 |
$self->picture($copied->to_object)->save; # Create new picture from copied data and save
|
|
465 |
$self->text_block->add_pictures($self->picture); # Add new picture to text block
|
|
466 |
$self->text_block->save;
|
|
467 |
})) {
|
|
468 |
$::lxdebug->message(LXDebug::WARN(), "Error: " . $self->text_block->db->error);
|
|
469 |
return $self->js->error($::locale->text('Saving failed. Error message from the database: #1', $self->text_block->db->error))->render($self);
|
|
470 |
}
|
|
471 |
|
|
472 |
my $html = $self->render('requirement_spec_text_block/_text_block_picture', { output => 0 }, picture => $self->picture);
|
|
473 |
|
|
474 |
$self->invalidate_version
|
|
475 |
->append('#text-block-' . $self->text_block->id . '-pictures', $html)
|
|
476 |
->show('#text-block-' . $self->text_block->id . '-pictures')
|
|
477 |
->render($self);
|
|
478 |
}
|
|
479 |
|
432 |
480 |
1;
|
Pflichtenheftbilder: Kopieren & Einfügen implementiert