use Params::Validate ();
use Time::HiRes ();
-use SL::ClientJS;
use SL::Clipboard;
use SL::Controller::Helper::RequirementSpec;
use SL::DB::RequirementSpec;
use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(text_block) ],
- 'scalar --get_set_init' => [ qw(predefined_texts js picture) ],
+ 'scalar --get_set_init' => [ qw(predefined_texts picture) ],
);
+__PACKAGE__->run_before('check_auth');
__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)]);
#
$self->add_new_text_block_form(output_position => $new_where, insert_after_id => $::form->{id}, requirement_spec_id => $::form->{requirement_spec_id});
- $self->invalidate_version->render($self);
+ $self->invalidate_version->render;
}
sub action_ajax_edit {
$self->text_block->add_to_list(position => 'after', reference => $insert_after) if $insert_after;
my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block);
- my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block);
+ my $node = $self->text_block->presenter->jstree_data;
$self->invalidate_version
->hide('#text-block-list-empty')
my $dropped_type = $position ne 'last' ? undef : $::form->{dropped_type} =~ m/^ text-blocks- (?:front|back) $/x ? $::form->{dropped_type} : die "Unknown 'dropped_type' parameter";
my $old_where = $self->text_block->output_position;
- $self->text_block->db->do_transaction(sub {
+ $self->text_block->db->with_transaction(sub {
1;
$self->text_block->remove_from_list;
$self->text_block->output_position($position =~ m/before|after/ ? $dropped_text_block->output_position : $::form->{dropped_type} eq 'text-blocks-front' ? 0 : 1);
$self->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);
+ my $node = $self->text_block->presenter->jstree_data;
$self->invalidate_version
->run(SORTABLE_PICTURE_LIST())
->jstree->create_node('#tree', $::form->{id} ? ('#tb-' . $::form->{id}, 'after') : ("#tb-${front_back}", 'last'), $node)
# filters
#
+sub check_auth {
+ my ($self) = @_;
+ $::auth->assert('requirement_spec_edit');
+}
+
sub load_requirement_spec_text_block {
my ($self) = @_;
$self->text_block(SL::DB::RequirementSpecTextBlock->new(id => $::form->{id})->load || die "No such requirement spec text block");
}
sub init_predefined_texts {
- return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted;
+ return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted(where => [ useable_for_text_blocks => 1 ]);
}
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);
-}
-
sub invalidate_version {
my ($self) = @_;
sub paste_picture {
my ($self, $copied) = @_;
- if (!$self->text_block->db->do_transaction(sub {
+ if (!$self->text_block->db->with_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);
+ return $self->js->error($::locale->text('Saving failed. Error message from the database: #1', $self->text_block->db->error))->render;
}
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);
+ ->render;
}
1;