+sub action_ajax_add {
+ my ($self) = @_;
+
+ my $js = SL::ClientJS->new;
+
+ my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1;
+ my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position};
+
+ if ($new_where != $current_where) {
+ my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]);
+ my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where);
+
+ $js->html('#column-content', $html);
+ }
+
+ $self->text_block(SL::DB::RequirementSpecTextBlock->new(
+ requirement_spec_id => $::form->{requirement_spec_id},
+ output_position => $::form->{output_position},
+ ));
+
+ my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
+ my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id});
+
+ $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list'))
+ ->focus('#' . $id_base . '_title')
+ ->render($self);
+}
+