Pflichtenhefte: Erste Version Baumansicht Textblöcke/Abschnitte/Funktionsblöcke
[kivitendo-erp.git] / SL / Controller / RequirementSpecTextBlock.pm
1 package SL::Controller::RequirementSpecTextBlock;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::DB::RequirementSpec;
8 use SL::DB::RequirementSpecTextBlock;
9 use SL::Helper::Flash;
10 use SL::Locale::String;
11
12 use Rose::Object::MakeMethods::Generic
13 (
14  scalar => [ qw(requirement_spec text_block) ],
15 );
16
17 # __PACKAGE__->run_before('load_requirement_spec');
18 __PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(dragged_and_dropped)]);
19
20 #
21 # actions
22 #
23
24 sub action_dragged_and_dropped {
25   my ($self)       = @_;
26
27   $::lxdebug->dump(0, "form", $::form);
28
29   my $position           = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position}                                                      : die "Unknown 'position' parameter";
30   my $dropped_text_block = $position           =~ m/^ (?: before | after ) $/x        ? SL::DB::RequirementSpecTextBlock->new(id => $::form->{dropped_id})->load : undef;
31
32   my $dropped_type       = $position ne 'last' ? undef : $::form->{dropped_type} =~ m/^ textblocks- (?:front|back) $/x ? $::form->{dropped_type} : die "Unknown 'dropped_type' parameter";
33
34   $self->text_block->db->do_transaction(sub {
35     1;
36     $self->text_block->remove_from_list;
37     $self->text_block->output_position($position =~ m/before|after/ ? $dropped_text_block->output_position : $::form->{dropped_type} eq 'textblocks-front' ? 0 : 1);
38     $self->text_block->add_to_list(position => $position, reference => $dropped_text_block ? $dropped_text_block->id : undef);
39   });
40
41   $self->render(\'', { type => 'json' });
42 }
43
44 #
45 # filters
46 #
47
48 sub load_requirement_spec {
49   my ($self) = @_;
50   $self->requirement_spec(SL::DB::RequirementSpec->new(id => $::form->{requirement_spec_id})->load || die "No such requirement spec");
51 }
52
53 sub load_requirement_spec_text_block {
54   my ($self) = @_;
55   $self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $::form->{id})->load || die "No such requirement spec text block");
56 }
57
58 #
59 # helpers
60 #
61
62 1;