X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/90f4ba5dc6212592754cdddd082640103ee15884..c19b1e03fb03f195d86a5b78f8ce2338f745f599:/SL/Controller/RequirementSpecTextBlock.pm diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index eaf8b6fdc..140a104c8 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -7,6 +7,7 @@ use parent qw(SL::Controller::Base); use Time::HiRes (); use SL::ClientJS; +use SL::Clipboard; use SL::DB::RequirementSpec; use SL::DB::RequirementSpecPredefinedText; use SL::DB::RequirementSpecTextBlock; @@ -19,7 +20,7 @@ use Rose::Object::MakeMethods::Generic 'scalar --get_set_init' => [ qw(predefined_texts) ], ); -__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete ajax_flag dragged_and_dropped)]); +__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete ajax_flag dragged_and_dropped ajax_copy)]); # # actions @@ -126,6 +127,7 @@ sub action_ajax_create { SL::ClientJS->new ->replaceWith('#' . $::form->{form_prefix} . '_form', $html) ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node) + ->jstree->select_node('#tree', '#tb-' . $self->text_block->id) ->render($self); } @@ -247,6 +249,42 @@ sub action_dragged_and_dropped { $self->render($js); } +sub action_ajax_copy { + my ($self, %params) = @_; + + SL::Clipboard->new->copy($self->text_block); + SL::ClientJS->new->render($self); +} + +sub action_ajax_paste { + my ($self, %params) = @_; + + my $copied = SL::Clipboard->new->get_entry(qr/^RequirementSpecTextBlock$/); + if (!$copied) { + return SL::ClientJS->new + ->error(t8("The clipboard does not contain anything that can be pasted here.")) + ->render($self); + } + + my $js = SL::ClientJS->new; + 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'; + + $self->text_block($copied->to_object); + $self->text_block->update_attributes(requirement_spec_id => $::form->{requirement_spec_id}, output_position => $new_output_position); + $self->text_block->add_to_list(position => 'after', reference => $::form->{id}) if $::form->{id}; + + if ($current_output_position == $new_output_position) { + my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); + $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')); + } + + my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); + $js->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node) + ->render($self); +} + # # filters # @@ -273,7 +311,7 @@ sub output_position_from_id { return undef if $type !~ m/text-block/; } - my $text_block = SL::DB::Manager::RequirementSpecTextBlock->find_by(id => $id); + my $text_block = $id ? SL::DB::Manager::RequirementSpecTextBlock->find_by(id => $id) : undef; return $text_block ? $text_block->output_position : undef; }