From 402ad79b07e541bf996b3f5f463d3a9ac4705a01 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 9 Aug 2013 15:38:16 +0200 Subject: [PATCH] =?utf8?q?Pflichtenheftbilder:=20Kopieren=20&=20Einf=C3=BC?= =?utf8?q?gen=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecTextBlock.pm | 62 ++++++++++++++++++++--- js/requirement_spec.js | 3 ++ 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index f52cbc8a1..b5d831044 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -20,8 +20,8 @@ use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(text_block picture) ], - 'scalar --get_set_init' => [ qw(predefined_texts js) ], + scalar => [ qw(text_block) ], + 'scalar --get_set_init' => [ qw(predefined_texts js picture) ], ); __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,13 +234,18 @@ sub action_ajax_copy { sub action_ajax_paste { my ($self, %params) = @_; - my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecTextBlock$/); + my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpec(?:TextBlock|Picture)$/); if (!$copied) { return SL::ClientJS->new ->error(t8("The clipboard does not contain anything that can be pasted here.")) ->render($self); } + if (ref($copied) =~ m/Picture$/) { + $self->load_requirement_spec_text_block; + return $self->paste_picture($copied); + } + my $current_output_position = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}); my $new_output_position = $::form->{id} ? $self->output_position_from_id($::form->{id}) : $::form->{output_position}; my $front_back = 0 == $new_output_position ? 'front' : 'back'; @@ -274,7 +279,6 @@ sub action_ajax_add_picture { sub action_ajax_edit_picture { my ($self) = @_; - $self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{picture_id})->load); $self->text_block($self->picture->text_block); $self->render('requirement_spec_text_block/_picture_form', { layout => 0 }); } @@ -304,7 +308,6 @@ sub action_ajax_update_picture { my ($self) = @_; my $attributes = $::form->{ $::form->{form_prefix} } || die "Missing attributes"; - $self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load); if (!$attributes->{picture_content}) { delete $attributes->{picture_content}; @@ -332,7 +335,6 @@ sub action_ajax_update_picture { sub action_ajax_delete_picture { my ($self) = @_; - $self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load); $self->picture->delete; $self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $self->picture->text_block_id)->load); @@ -345,10 +347,31 @@ sub action_ajax_delete_picture { sub action_ajax_download_picture { my ($self) = @_; - $self->picture(SL::DB::RequirementSpecPicture->new(id => $::form->{id})->load); $self->send_file(\$self->picture->{picture_content}, type => $self->picture->picture_content_type, name => $self->picture->picture_file_name); } +sub action_ajax_copy_picture { + my ($self, %params) = @_; + + SL::Clipboard->new->copy($self->picture); + SL::ClientJS->new->render($self); +} + +sub action_ajax_paste_picture { + my ($self, %params) = @_; + + my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecPicture$/); + if (!$copied) { + return SL::ClientJS->new + ->error(t8("The clipboard does not contain anything that can be pasted here.")) + ->render($self); + } + + $self->text_block($self->picture->text_block); # Save text block via the picture the user clicked on + + $self->paste_picture($copied); +} + # # filters # @@ -379,6 +402,10 @@ sub init_predefined_texts { return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted; } +sub init_picture { + return SL::DB::RequirementSpecPicture->new(id => $::form->{picture_id} || $::form->{id})->load; +} + sub init_js { my ($self) = @_; $self->js(SL::ClientJS->new); @@ -429,4 +456,25 @@ sub show_list { return $self->set_function_blocks_tab_menu_class(class => 'text-block-context-menu'); } +sub paste_picture { + my ($self, $copied) = @_; + + if (!$self->text_block->db->do_transaction(sub { + 1; + $self->picture($copied->to_object)->save; # Create new picture from copied data and save + $self->text_block->add_pictures($self->picture); # Add new picture to text block + $self->text_block->save; + })) { + $::lxdebug->message(LXDebug::WARN(), "Error: " . $self->text_block->db->error); + return $self->js->error($::locale->text('Saving failed. Error message from the database: #1', $self->text_block->db->error))->render($self); + } + + my $html = $self->render('requirement_spec_text_block/_text_block_picture', { output => 0 }, picture => $self->picture); + + $self->invalidate_version + ->append('#text-block-' . $self->text_block->id . '-pictures', $html) + ->show('#text-block-' . $self->text_block->id . '-pictures') + ->render($self); +} + 1; diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 2d86dec89..4a6665050 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -660,6 +660,9 @@ ns.create_context_menus = function(is_template) { , edit_picture: { name: kivi.t8('Edit picture'), icon: "edit", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call } , delete_picture: { name: kivi.t8('Delete picture'), icon: "delete", callback: kivi.requirement_spec.ask_delete_text_block_picture } , download_picture: { name: kivi.t8('Download picture'), icon: "download", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } + , sep2: "---------" + , copy_picture: { name: kivi.t8('Copy'), icon: "copy", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } + , paste_picture: { name: kivi.t8('Paste'), icon: "paste", callback: kivi.requirement_spec.standard_text_block_picture_ajax_call } }, general_actions) }); -- 2.20.1